Repository navigation
fix(sessions): commit branch replacement before publishing identity - #138178
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: blocked before merge. Reviewed September 4, 2026, 8:35 AM ET / 12:35 UTC. ClawSweeper reviewWhat this changesThe PR atomically writes a branched SQLite transcript and successor session identity before the in-memory session manager adopts and publishes that identity, with rollback and stale-writer tests. Merge readiness⛔ Blocked before merge - 1 item remains No concrete correctness finding remains: the prior source-writer-fence blocker is addressed at the durable persistence owner and covered by focused race cases. This active maintainer-authored PR remains necessary because current main still mutates the manager before the durable branch replacement; exact-head hosted checks remain the landing gate. Priority: P1 Review scores
Verification
How this fits togetherSession branching creates a new conversation history from a selected message. The session manager prepares the branch, while the session-accessor owns the queued SQLite commit, writer validation, and subsequent identity notification used by gateway consumers. flowchart LR
A[Existing session transcript] --> B[Branch request]
B --> C[Detached branch tree]
C --> D[SQLite session persistence]
D --> E[Identity and transcript commit]
E --> F[Manager adopts branch]
F --> G[Gateway identity observers]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +25, Tests +233. Total +258 across 6 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one accessor-owned atomic branch-replacement operation that validates source and successor writer authority, commits both durable records together, then adopts the exact validated successor target before notifying observers. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main changes the manager identity before its persistence transaction, and the focused regression tests model failed and queued writer-replacement paths. This read-only review did not execute the reproduction. Is this the best way to solve the issue? Yes. Moving the compound mutation to the SQLite accessor is the clean owner-boundary repair; retaining manager-side transaction coordination would continue to combine stale state assembly with durable-write authority. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f1e1dca03d2b. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
60019d9 to
aca8327
Compare
aca8327 to
504f27e
Compare
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
Commit before manager adoption/publication is the right ordering. Revalidating the source writer fence inside the transaction closes the stale-writer takeover path. Looks sound.
504f27e to
5b08c5c
Compare
|
Merged via squash.
|
…penclaw#138178) * fix(sessions): commit branch replacement before publishing identity * fix(sessions): preserve writer fences across branch replacement
What Problem This Solves
Session branching mutates the loaded manager before queued persistence commits. A failed replacement can therefore expose an identity that was never stored; queued metadata updates can also be overwritten. The branch must preserve the admitted writer claim while moving to its successor identity.
Why This Change Was Made
Prepare the branch on a detached tree and persist it through one compound session operation. Inside the existing synchronous transaction, the owner rereads the source lifecycle and metadata, validates the captured source writer fence, writes the successor identity/transcript, and retains the successor authority check. It samples the activity timestamp after the queue releases. After commit, it gives the manager the exact validated successor target, including its writer fence, before publishing the identity event.
The manager no longer coordinates a generic transaction, reloads stale metadata, or reconstructs an unfenced successor target. Existing exclusive-write, Kysely, codec and transaction owners remain in use.
User Impact
Queued or failed branches leave the current manager and durable identity intact. Successful branches preserve current metadata and activity time. A writer replaced while the branch waits cannot take over the newer writer's session; a retained manager also cannot lose its fence after its first successful branch. Closure-bound cross-target writes continue to reject.
The public
createBranchedSession(leafId)signature and persisted representations are unchanged. There are no schema, migration, retention, index or configuration changes.Evidence
Review Follow-through
The source-fence timing finding was reproduced. Normal non-initial attempt contexts carry a scalar writer fence without an additional closure assertion; requesting that fence with the successor ID loses the exact source match. The accessor now captures and checks the source fence before rebinding. Review also identified loss of that fence from a retained manager after the first branch; returning the validated successor target fixes that producer boundary. Both repairs retain the existing successor assertion.
The branch was refreshed onto pinned main
3ebdeb8e23045a3096e29945f40c8f03e07164f3to include the canonical QA documentation-reference fix. Final candidate:504f27e551a5d37c79a529f61d74e74bcd1ed842, treee8efed67a53201b5a84cb2afea0edac51d74c85d. Required hosted CI remains the landing gate.Final candidate verification
Final candidate
5b08c5c66bd106a61b6f29d982c5b7ac4fe683b4is rebased onto91aad5cfcf054c05e4c0ac78c0156d07a7a8e6bf. The feature patch is unchanged, and the persistence owners, callers, codecs, and schema contracts have no relevant intervening drift. The shared CI fixture failure was independently repaired in #138238; the canonical repair passed all 1,666 tests in the original 112-file runner configuration on the rebased cron candidate.All eight database changes were exercised together on the final combined staged tree
8fa80406d1564bac0cc3968df20be6ee12d93dc1: 228 tests across 13 files passed. A separate native run used one synthetic state root to verify retained KV/blob facade objects across physical connection reopen, corrupt-sweep rollback, real cron command receipts across Gateway restart, stale/exact delivery acknowledgement and media custody, 1,201-message branch context/presence, transcript byte preservation through two memory reindexes, current-writer success, strict-closure refusal, and stale successor append/branch rejection. A fresh process reopened the final state and passed integrity checks. Source remained unchanged; synthetic state and Gateway processes were removed. This is local macOS runtime proof; hosted platform/security CI remains a separate required gate.