{"record":{"id":"53df927a45e98afe","repo":"affaan-m/ECC","slug":"remote-dispatch-request-id-was-not-found-after-i","errorCode":null,"errorMessage":"Remote dispatch request {id} was not found after insert","messagePattern":"Remote dispatch request (.+?) was not found after insert","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ecc2/src/session/store.rs","lineNumber":1670,"sourceCode":"                target_session_id,\n                task,\n                target_url,\n                task_priority_db_value(priority),\n                agent_type,\n                profile_name,\n                working_dir.display().to_string(),\n                project,\n                task_group,\n                if use_worktree { 1_i64 } else { 0_i64 },\n                source,\n                requester,\n                now.to_rfc3339(),\n                now.to_rfc3339(),\n            ],\n        )?;\n        let id = self.conn.last_insert_rowid();\n        self.get_remote_dispatch_request(id)?.ok_or_else(|| {\n            anyhow::anyhow!(\"Remote dispatch request {id} was not found after insert\")\n        })\n    }\n\n    pub fn list_remote_dispatch_requests(\n        &self,\n        include_processed: bool,\n        limit: usize,\n    ) -> Result<Vec<RemoteDispatchRequest>> {\n        let sql = if include_processed {\n            \"SELECT id, request_kind, target_session_id, task, target_url, priority, agent_type, profile_name, working_dir,\n                    project, task_group, use_worktree, source, requester, status,\n                    result_session_id, result_action, error, created_at, updated_at, dispatched_at\n             FROM remote_dispatch_requests\n             ORDER BY CASE status WHEN 'pending' THEN 0 WHEN 'failed' THEN 1 ELSE 2 END ASC,\n                      priority DESC, created_at ASC, id ASC\n             LIMIT ?1\"\n        } else {\n            \"SELECT id, request_kind, target_session_id, task, target_url, priority, agent_type, profile_name, working_dir,","sourceCodeStart":1652,"sourceCodeEnd":1688,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/ecc2/src/session/store.rs#L1652-L1688","documentation":"Same readback invariant as scheduled tasks but for remote dispatch requests: after INSERT, the store takes last_insert_rowid() and re-fetches via get_remote_dispatch_request. A None result means the just-inserted row vanished or the rowid was wrong, so `Remote dispatch request {id} was not found after insert` is raised.","triggerScenarios":"Row deleted by a concurrent processor between insert and fetch; last_insert_rowid() returning an id from a different table after a failed/no-op insert; unsynchronized multi-thread access to the shared connection.","commonSituations":"A dispatcher worker consuming requests concurrently while another inserts; connection reuse across statements; migration schemas where the INSERT hit a different table than expected.","solutions":["Serialize insert+readback inside a transaction (BEGIN IMMEDIATE ... COMMIT).","Audit for code paths that delete/process remote dispatch requests immediately after creation.","Restrict the connection to a single thread or use a connection per thread so last_insert_rowid is correct.","Verify the INSERT statement targets the intended table and that no BEFORE DELETE trigger interferes."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = result {\n    if e.to_string().contains(\"was not found after insert\") {\n        log::error!(\"dispatch request lost between insert and fetch: {e}\");\n        // surface as 500 / retry with transactional insert\n    } else { return Err(e.into()); }\n}","preventionTips":["Make create + readback atomic with a transaction.","Pause consumer workers during bulk inserts or use row-status flags instead of deletion.","Use a dedicated connection per thread to keep last_insert_rowid valid.","Add a regression test that inserts while a consumer processes concurrently."],"tags":["sqlite","invariant","remote-dispatch","database"],"backgroundTag":"internal-invariant-violation","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}