Repository navigation
fix: prevent durable SQLite user turns from orphan cleanup - #117393
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 9:11 AM ET / 13:11 UTC. ClawSweeper reviewWhat this changesThe PR waits for the user-turn recorder’s runtime-persistence barrier before embedded-agent session reconciliation can classify and remove orphaned transcript entries. Merge readinessThe patch is a narrow, owner-aligned repair for a recorder/session timing race and source inspection supports its ordering. Keep this member-authored, maintainer-labeled PR open for normal review until its exact-head SQLite proof and remaining CI complete. Priority: P1 Review scores
Verification
How this fits togetherEmbedded agent setup prepares a restored session, consults the user-turn recorder and SQLite transcript state, then reconciles the boundary before constructing the prompt for the model. The recorder owns persistence completion, while boundary reconciliation decides whether a durable user turn is current or orphaned. flowchart LR
A[Incoming agent turn] --> B[User-turn recorder]
B --> C[Runtime persistence barrier]
B --> D[SQLite transcript row]
C --> E[Session boundary reconciliation]
D --> E
E --> F[Prepared prompt session]
F --> G[Model run]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +1, Tests +21. Total +22 across 2 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the recorder-owned barrier immediately before session-boundary reconciliation, retain the focused ordering regression, and merge only after the exact-head SQLite flip proof confirms the original restart/queue lifecycle no longer fails. Do we have a high-confidence way to reproduce the issue? Yes—source establishes the race shape: the boundary consults Is this the best way to solve the issue? Yes—the wait belongs immediately before the consumer that classifies or removes transcript entries, using the recorder’s existing authoritative barrier rather than adding a second persistence mechanism, retry, timeout, or config surface. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 20ac22f647a4. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
06b52a6 to
fabb873
Compare
Related: #116894
Follow-up to #116924
What Problem This Solves
Fixes an intermittent failure where a SQLite-backed agent turn could remove its already-durable current user message as an orphan after restart or queue timing delayed the recorder's persistence lifecycle. The resulting prompt append then failed with
Session transcript parent entry was not persisted.This is separate from #116859; that PR's auth-fixture changes do not touch the session persistence path.
Why This Change Was Made
The SQLite row can be committed before the recorder's runtime-persistence barrier settles. Session retry normalization already waits for that barrier, but first-attempt session-boundary reconciliation did not. The boundary could therefore read the durable keyed user leaf while
hasPersisted()was not yet authoritative, remove it, clear suppression, and then collide with the durable idempotency row.The fix awaits the recorder's existing persistence barrier immediately before orphan reconciliation. It keeps #116924's recorder-confirmed exact-key invariant and does not add retries, timeouts, config, compatibility paths, or schema changes.
User Impact
SQLite-backed sessions no longer intermittently fail an otherwise valid agent turn during restart, queued-turn, plugin-SDK consumer, or concurrent session lifecycle timing.
Evidence
attempt-session-runtime-prepare.test.ts, 3/3 passed.