Skip to content

fix(sessions): make input relocation transaction-safe - #139002

Merged
fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:fix/session-rewrite-custody-atomicity
Sep 5, 2026
Merged

fuller-stack-dev merged 1 commit into
openclaw:mainfrom
fuller-stack-dev:fix/session-rewrite-custody-atomicity

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Sep 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #138967. That change authorizes transcript rewrites before appending the exact admitted user copy, but two commit-boundary gaps remain:

  • immediate replay can fail while the materialized active-path projection is dirty
  • an earlier throwing post-commit observer can skip relocation publication after SQLite has committed

This change keeps relocation transaction-local through nested savepoints, publishes the final binding before fallible observers, and checks the selected visible transcript ancestry when the materialized projection is dirty. It deliberately ignores a divergent physical append cursor. Receipt IDs, approved message bytes, source consumption IDs, session scope, and lifecycle authority remain unchanged.

Proof

  • Current-base red: 7 focused failures on cd4504de2d, including all four direct/collected and context-visible/context-excluded rewrite variants plus direct and replay split-cursor cases
  • Patched focused suites: 64 tests passed
  • Adjacent rewrite, compaction, pending-input, worker-commit, deletion, and lifecycle suites: 171 tests passed
  • Strict source-blind behavior contract: 64 tests passed twice
  • node scripts/check-changed.mjs -- <8 changed files>
  • Autoreview: no P0-P2 findings

The original production trigger remains unproven. This PR addresses the reproduced custody and commit-order failures with synthetic fixtures only.

@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 5, 2026
@fuller-stack-dev fuller-stack-dev self-assigned this Sep 5, 2026
@fuller-stack-dev
fuller-stack-dev marked this pull request as ready for review September 5, 2026 10:52
@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: 🦐 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 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

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

ClawSweeper review

What this changes

Keeps accepted messages linked to rewritten transcript entries through commits and rollbacks, and checks replay against the selected conversation branch.

Warning

SQLite table change

This PR modifies persisted SQLite tables in src/infra/sqlite-post-commit.ts. Prefer a design that avoids changing persisted SQLite tables. If the change is necessary, verify migration and upgrade compatibility against an existing database before merge.

Merge readiness

⛔ Blocked before merge - 1 item remains

This PR remains necessary: current main still has the targeted transaction-boundary gaps. No blocking findings remain, and the previous migration-proof blocker is unsupported by the diff.

Priority: P2
Reviewed head: 5110a240a1e3d04726c3681812f48d33b827abcf

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with relevant regression coverage and no remaining blocking finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored internal transaction repair is exempt from contributor live-proof requirements. Supplied evidence exercises SQLite custody and rewrite boundaries with synthetic fixtures, and explicitly leaves the original production trigger unproven.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored internal transaction repair is exempt from contributor live-proof requirements. Supplied evidence exercises SQLite custody and rewrite boundaries with synthetic fixtures, and explicitly leaves the original production trigger unproven.
Evidence reviewed 10 items Verified patch scope: The pinned merge-base-to-head delta contains the eight supplied files. Raw test-merge parents match the pinned base followed by the exact PR head, and its resulting changes contain the same eight paths.
Migration blocker does not apply: The new state consists of process-local WeakMaps and callbacks. The introduced diff changes no DDL, schema version, migration, serialized format, or database-opening contract, supporting the author's clarification at #139002 (comment).
Transaction-owned relocation: Relocation resolves the transaction-local binding, restores prior state on rollback, and publishes committed bindings before fallible observers. Database, session, exact-message, and live-owner checks remain in place.
Findings None None.
Security None None.

How this fits together

OpenClaw stores conversation history in per-agent SQLite databases. Transcript maintenance copies entries onto a new branch; accepted-input tracking must follow those copies without accepting stale entries or changing the admitted message.

flowchart TD
  A[Accepted message] --> B[Live input owner]
  B --> C[Transcript rewrite transaction]
  C --> D{Transaction outcome}
  D -->|Rollback| E[Restore previous binding]
  D -->|Commit| F[Publish binding before observers]
  F --> G[Replay checks selected conversation branch]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +110, Tests +228. Total +338 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 5 160 50 +110
Tests 3 230 2 +228
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 390 52 +338

Review metrics

Metric Value Why it matters
Production versus test growth Production net +110 lines; tests net +228 lines Production growth supplies transaction-local rollback and commit ordering while reusing the existing ancestry parser; it adds no configuration or stored format.

Stored data model

Persistent data-model change detected: serialized state: src/config/sessions/session-accessor.sqlite-pending-inputs.ts, unknown-data-model-change: src/config/sessions/session-accessor.sqlite-pending-inputs.ts, unknown-data-model-change: src/infra/sqlite-post-commit.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep relocation state owned by the transaction lifecycle and reuse normalized ancestry; explicit rollback state is necessary because an observer-only change cannot preserve bindings across nested savepoints.

Do we have a high-confidence way to reproduce the issue?

Yes at the transaction-owner boundary: immediate replay during a dirty projection and relocation behind a throwing observer have clear source paths and focused regression cases. The original live incident was not reproduced.

Is this the best way to solve the issue?

Yes. The patch repairs commit ownership and shares the canonical branch parser; catching observer errors alone would leave nested relocation and rollback incorrect.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against eec37f21426a.

Labels

Label justifications:

  • P2: This repairs bounded, source-supported transcript replay and commit-order failures without evidence of a widespread current outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored internal transaction repair is exempt from contributor live-proof requirements. Supplied evidence exercises SQLite custody and rewrite boundaries with synthetic fixtures, and explicitly leaves the original production trigger unproven.

Evidence

What I checked:

  • Verified patch scope: The pinned merge-base-to-head delta contains the eight supplied files. Raw test-merge parents match the pinned base followed by the exact PR head, and its resulting changes contain the same eight paths. (a9d31660d0c8)
  • Migration blocker does not apply: The new state consists of process-local WeakMaps and callbacks. The introduced diff changes no DDL, schema version, migration, serialized format, or database-opening contract, supporting the author's clarification at fix(sessions): make input relocation transaction-safe #139002 (comment). (src/infra/sqlite-post-commit.ts:9, 5110a240a1e3)
  • Transaction-owned relocation: Relocation resolves the transaction-local binding, restores prior state on rollback, and publishes committed bindings before fallible observers. Database, session, exact-message, and live-owner checks remain in place. (src/config/sessions/session-accessor.sqlite-pending-inputs.ts:255, 5110a240a1e3)
  • Earlier ancestry findings resolved: Replay membership now uses the existing normalized selected-path scanner. It neither follows the physical append cursor nor walks raw parents after resolving a visible leaf, addressing both retained earlier findings. (src/config/sessions/transcript-visible-events.ts:42, 5110a240a1e3)
  • Caller and transaction boundaries: Transcript rewriting enters through withSessionPendingInputRelocation and the synchronous message appender. Agent writes wrap the existing synchronous SQLite transaction helper; shared-state writes use the same publication wrapper and retain their existing behavior when no relocation is staged. (src/state/openclaw-agent-db.ts:604, 5110a240a1e3)
  • Regression coverage and proof limits: Inspected tests cover throwing observers, outer and nested rollback, immediate replay, inactive branches, split cursors, and direct/collected rewrites with context exclusion. The captured body reports seven pre-fix failures, 64 focused passes, and 171 adjacent passes, while explicitly stating that the original production trigger remains unproven. Tests were not executed during this read-only review. (src/config/sessions/session-accessor.pending-inputs.test.ts:211, 5110a240a1e3)

Likely related people:

  • fuller-stack-dev: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • 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 (3 earlier review cycles)
  • reviewed 2026-09-05T11:08:58.142Z sha c15f5ba9e321e28495e8fbd440bfa1cddee52fc6 :: blocked before merge. :: [P2] Check visible ancestry instead of the physical append cursor
  • reviewed 2026-09-05T11:37:10.700Z sha 51d3f7c9167caffee896daa407da883dd1231769 :: blocked before merge. :: [P2] Use normalized ancestors after resolving the visible leaf
  • reviewed 2026-09-05T11:57:40.401Z sha 5110a24 :: blocked before merge. :: none

@fuller-stack-dev
fuller-stack-dev force-pushed the fix/session-rewrite-custody-atomicity branch from c15f5ba to 51d3f7c Compare September 5, 2026 11:24
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@fuller-stack-dev
fuller-stack-dev force-pushed the fix/session-rewrite-custody-atomicity branch from 51d3f7c to 5110a24 Compare September 5, 2026 11:51
@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 5, 2026
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

The remaining “SQLite table change” item is a classifier false positive. This PR changes no SQLite schema, table, DDL, migration, or serialized on-disk format. src/infra/sqlite-post-commit.ts adds process-local WeakMap transaction callback state; session-accessor.sqlite-pending-inputs.ts adds a process-local WeakMap binding keyed by the existing owner and database handle. Existing database open/upgrade code is unchanged. Focused coverage includes handle reopen, lifecycle rotation, nested rollback, outer commit failure, and two rewrites in one transaction. Please clear the data-model compatibility blocker. @clawsweeper re-review

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@fuller-stack-dev
fuller-stack-dev merged commit 140eb56 into openclaw:main Sep 5, 2026
215 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

@fuller-stack-dev
fuller-stack-dev deleted the fix/session-rewrite-custody-atomicity branch September 5, 2026 12:12
roboclaw-bot added a commit that referenced this pull request Sep 5, 2026
…tody

Refresh the task branch from main after #139002 landed. Reuse its canonical
transaction-local custody staging and remove the rewrite-specific publication
collector; keep manager adoption ahead of insert observers.

Worked on by:
- @VACInc

Co-authored-by: VACInc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 6, 2026
@VACInc

VACInc commented Sep 7, 2026

Copy link
Copy Markdown
Member

The complementary atomic transcript-publication repair #138984 has merged as b0ae5b6.

It retains the existing accepted-input authority and transaction-local relocation behavior while publishing the replacement history coherently. Recorded regression coverage includes active versus closed/replaced admission, rejection before durable changes, input custody, and reader agreement after rewrites.

This is follow-through on the shared transcript lifecycle, not a claim that the earlier input-ownership repair was unnecessary or replaced.

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 P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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