{"record":{"id":"c47b21a7a671a59b","repo":"tinyhumansai/openhuman","slug":"device-not-found-after-insert","errorCode":null,"errorMessage":"device not found after insert","messagePattern":"device not found after insert","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/openhuman/security/devices/store.rs","lineNumber":45,"sourceCode":"    let now = Utc::now().to_rfc3339();\n    with_connection(config, |conn| {\n        conn.execute(\n            \"INSERT OR REPLACE INTO paired_devices \\\n             (channel_id, label, device_pubkey, core_session_token_hash, \\\n              shared_secret_encrypted, created_at, last_seen_at, revoked) \\\n             VALUES (?1, ?2, ?3, ?4, NULL, ?5, NULL, 0)\",\n            params![\n                channel_id,\n                label,\n                device_pubkey,\n                core_session_token_hash,\n                now\n            ],\n        )\n        .context(\"insert_device: INSERT failed\")?;\n        Ok(())\n    })?;\n    get_device(config, channel_id)?.ok_or_else(|| anyhow::anyhow!(\"device not found after insert\"))\n}\n\n/// Update `last_seen_at` for a device (called on `tunnel:peer-status` online events).\npub fn touch_device(config: &Config, channel_id: &str) -> Result<()> {\n    let now = Utc::now().to_rfc3339();\n    with_connection(config, |conn| {\n        conn.execute(\n            \"UPDATE paired_devices SET last_seen_at = ?1 WHERE channel_id = ?2 AND revoked = 0\",\n            params![now, channel_id],\n        )\n        .context(\"touch_device: UPDATE failed\")?;\n        Ok(())\n    })\n}\n\n/// Mark a device as revoked (soft delete).\npub fn revoke_device(config: &Config, channel_id: &str) -> Result<bool> {\n    let rows = with_connection(config, |conn| {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/749120085864ce16e0f273c7b86fac7740b39c5b/src/openhuman/security/devices/store.rs#L27-L63","documentation":"A device row was inserted into `paired_devices` (INSERT OR REPLACE reported success) but the immediate follow-up read of that device found nothing. This is an internal consistency check in `insert_device`: the row should be readable in the same connection/transaction, so a miss implies the insert silently no-oped or the read query diverges from the write — a store-level invariant break, not caller input.","triggerScenarios":"Thrown at src/openhuman/security/devices/store.rs:45 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the SQLite schema matches the INSERT column set (migration drift)","Verify no trigger or constraint silently discarded the row","Inspect store logs around the insert/read pair","Retry the pairing operation after confirming schema integrity"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"749120085864ce16e0f273c7b86fac7740b39c5b","analyzedAt":"2026-08-17T21:21:45.363Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}