Skip to content

fix(sessions): commit branch replacement before publishing identity - #138178

Merged
steipete merged 2 commits into
mainfrom
codex/db-prep-session-branch
Sep 4, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/db-prep-session-branch

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

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

  • 69 focused branch, manager, codec, bounded-context, stale-parent and writer-context tests passed, plus the complete six-file changed gate.
  • Both writer-only takeover cases failed before repair in isolated SDK/SQLite processes. The repaired source rejects without changing the current manager, durable owner or identity notifications; stale successor appends reject too.
  • Current scalar-writer success, queued metadata preservation, commit-time recency, rollback without publication and strict target rejection are covered.
  • Fresh independent P0–P2 review is scoped-clean on the complete repaired candidate.
  • Earlier combined shared-root runtime proof covered exact transcript bytes, context/presence and memory reindex isolation. Final exact-head independent validation also passed the four-process branch proof, both takeover reproductions, current-writer branch/append/reopen, strict closure refusal, and stale successor append/branch rejection. Manager identity and raw transcript hashes stay unchanged on rejection; all synthetic state was cleaned up.
  • Production: +90/-65 (net +25). Tests: +366/-133 (net +233). Growth establishes one commit/adoption/publication owner using existing primitives.

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 3ebdeb8e23045a3096e29945f40c8f03e07164f3 to include the canonical QA documentation-reference fix. Final candidate: 504f27e551a5d37c79a529f61d74e74bcd1ed842, tree e8efed67a53201b5a84cb2afea0edac51d74c85d. Required hosted CI remains the landing gate.

Final candidate verification

Final candidate 5b08c5c66bd106a61b6f29d982c5b7ac4fe683b4 is rebased onto 91aad5cfcf054c05e4c0ac78c0156d07a7a8e6bf. 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.

@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 4, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 8:35 AM ET / 12:35 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: 5b08c5c66bd106a61b6f29d982c5b7ac4fe683b4

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-boundary repair with direct failure and stale-authority coverage; only normal exact-head hosted validation remains.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository state identifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply; its body nevertheless records exact-head local runtime and focused race-validation claims for the changed SQLite branch path.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository state identifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply; its body nevertheless records exact-head local runtime and focused race-validation claims for the changed SQLite branch path.
Evidence reviewed 5 items Detached state prevents premature publication: The branch is constructed separately and only copied into the live manager by the commit callback, so a queued or failed durable write cannot expose the successor identity early.
Source writer fence is captured before rebinding: The persistence owner derives the writer fence against the source target, validates it before changing the durable identity, then validates the successor target before replacing branch events.
Focused regression coverage: The new tests assert no manager mutation or identity event when transcript insertion fails, and table-drive lifecycle, writer, guarded-target, metadata, and retained-successor-writer races.
Findings None None.
Security None None.

How this fits together

Session 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]
Loading

Before merge

  • Resolve merge risk (P1) - This changes the commit ordering for durable session identity and transcript state; exact-head hosted checks should complete before merge to catch integration regressions beyond the focused race coverage.
Agent review details

Security

None.

PR surface

Source +25, Tests +233. Total +258 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 4 90 65 +25
Tests 2 366 133 +233
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 456 198 +258

Review metrics

Metric Value Why it matters
Production versus test delta production +90/-65 (net +25); tests +366/-133 (net +233) The production growth consolidates branch replacement at the persistence owner; the larger test delta covers failure and authority-race boundaries.

Merge-risk options

Maintainer options:

  1. Complete the exact-head session gate (recommended)
    Merge after the pending required checks validate the new durable identity/transcript ordering on this exact head.

Technical review

Best 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.

Labels

Label justifications:

  • P1: A stale writer or failed branch can otherwise leave active conversation state associated with an identity that was not durably committed.
  • merge-risk: 🚨 session-state: The patch changes ordering and fencing for persisted session identity and transcript replacement.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository state identifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply; its body nevertheless records exact-head local runtime and focused race-validation claims for the changed SQLite branch path.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-04T10:30:56.027Z sha 60019d9 :: blocked before merge. :: none
  • reviewed 2026-09-04T11:15:09.744Z sha aca8327589cd66ca03e41295f314944997ead8d5 :: blocked before merge. :: [P1] Validate the source writer fence before rebinding the session

@steipete
steipete force-pushed the codex/db-prep-session-branch branch from 60019d9 to aca8327 Compare September 4, 2026 11:01
@steipete
steipete marked this pull request as ready for review September 4, 2026 11:05
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@steipete
steipete force-pushed the codex/db-prep-session-branch branch from aca8327 to 504f27e Compare September 4, 2026 12:00

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@steipete
steipete force-pushed the codex/db-prep-session-branch branch from 504f27e to 5b08c5c Compare September 4, 2026 12:25
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 4, 2026
@steipete
steipete merged commit a9d4f39 into main Sep 4, 2026
188 checks passed
@steipete
steipete deleted the codex/db-prep-session-branch branch September 4, 2026 13:06
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…penclaw#138178)

* fix(sessions): commit branch replacement before publishing identity

* fix(sessions): preserve writer fences across branch replacement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants