Recover from poisoned org DB client mutex - #50
Merged
sagnik11 merged 1 commit intoAug 17, 2026
Merged
Conversation
A single op that panicked mid-query while holding the cached Postgres client guard poisoned the mutex for the life of the daemon process. Every later org DB write then panicked on the same lock, so metrics, notes, CAS, file change counts, and commit authorship summaries all stopped syncing with no signal beyond a stderr panic line. org_db.rs was the only place that used `.lock().expect(...)`; the rest of the repo already recovers with `unwrap_or_else(|p| p.into_inner())`. Apply the same recovery to all five lock sites. For the client mutex, treat a poisoned lock like the stale-connection case `run()` already handles: drop the entry from CONNECTIONS and redial, because a mid-query panic can leave the Postgres protocol state desynchronized. Also wrap the telemetry flush closure in catch_unwind so a panic reports its own message instead of being hidden behind the join handle's generic "task panicked". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Generated-By: PostHog Desktop Task-Id: a64999a3-c9e3-4fa2-82bf-cebd47dcc615
sagnik11
marked this pull request as ready for review
August 17, 2026 05:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
run()insrc/api/org_db.rslocked the cached Postgres client with.lock().expect("org client mutex poisoned"). If the wrapped op panics mid-query, Rust marks the mutex poisoned for the life of the process.CONNECTIONSmap inside a long-lived daemon, so there is no recovery: every later call panics on the same line.Changes
org_db.rswas the lone outlier; the rest of the repo already recovers withunwrap_or_else(|poisoned| poisoned.into_inner())(about twenty sites insrc/streams/db.rsandsrc/daemon.rs). Apply the same to all five lock sites.run()now drops the entry fromCONNECTIONSand redials — the same recovery it already runs for a dropped connection.catch_unwindso a panic logs its own message instead of the join handle's generic text.Notes
task build,task test,task lint, andtask fmtwere not run here. The change reuses a pattern already established across the repo; please let CI run the suite.panic_messagehelper.Why
The daemon caches the org DB client for its whole life, so a single mid-query panic poisons the mutex permanently and quietly stops the attribution data this product exists to produce. The fix makes the failure recoverable rather than self-sustaining.
Created with PostHog Desktop from this inbox report.