Skip to content

fix: preserve pending user turns through asynchronous transcript writes - #163753

Merged
joshavant merged 1 commit into
mainfrom
codex/fix-async-user-turn-custody
Oct 3, 2026
Merged

joshavant merged 1 commit into
mainfrom
codex/fix-async-user-turn-custody

Conversation

@joshavant

@joshavant joshavant commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes accepted user turns failing before model execution when asynchronous transcript writes use a physical database path but admission retained an alias, such as /tmp versus /private/tmp on macOS. Reusing a guarded session manager could also retain the previous turn's prepared message, recorder, and persistence suppression.

User Impact

Accepted input persists once with its approved bytes and current turn's custody, including through aliased paths and reused managers. Async writes and live-owner checks remain in place. No schema, configuration, retention, or migration changes are required.

Why This Change Was Made

Preserves main's dual-locator custody contract from fa56f5e2e9e: databasePath remains the native/process-cache locator, while workerDatabasePath carries the physical identity captured at database open and is serialized to workers. Admission aggregation, append, consumption, recovery, and history compare the captured canonical identity without changing native cache ownership or resolving aliases during append. Incognito custody retains its native locator.

Re-guarding replaces the prepared user-turn message, recorder, and replay key and resets one-shot persistence suppression. Existing live-owner, lifecycle, session, row, transaction, and commit checks remain authoritative.

Evidence

Rebased once onto 350e91cf765632fd23169c0603aa94272ceade36 after GitHub and merge-tree confirmed three conflicts introduced by the dual-locator main change. Integrated head: 9dc0726e145d26ab56063e73c60b1aa629f15400.

  • Extended the existing physical/alias regression to read history through the physical locator. With main's custody comparisons and the guard refresh retained, the physical case passed while the alias case failed (interrupted instead of queued). Both pass with the integrated comparisons. The prior same-locator history assertion could not detect this incorrect resolution.
  • Independent negative control: restoring main's old wrapper while retaining the identity repair makes both physical and alias cases fail with Pending input cannot be appended outside its admitted turn, confirming the refresh repair remains necessary.
  • 216 focused tests passed across 10 files, covering transcript guards, async session persistence, worker custody, native incognito, pending history, rollback, cancellation, aggregate revalidation, restart, commit revocation, and user-turn persistence.
  • Measured changed-test cost: pnpm test src/agents/session-tool-result-guard.transcript-events.test.ts --maxWorkers=1 passed 15 tests in 27.72 s wall, including compiler preparation; Vitest reported 9.18 s. Pending history (4 tests) and worker custody (2 tests) passed together in a 9.18 s Vitest shard. The conflict-resolution regression extends an existing case; it adds no process boot, timer, worker pin, or production seam.
  • pnpm changed:lanes --json selected core/coreTests only. pnpm check:changed --base 350e91cf765632fd23169c0603aa94272ceade36 passed, including production core types, all 27 core test typecheck graphs, semantic lint, dead-export scans, database ownership guards, and zero runtime import cycles.
  • Exact-head CI changed-test cost: transcript-events passed 15 tests in 10.59 s of test-runner time (8.78 s Vitest); the physical/alias cases took 1.506 s / 1.032 s. Pending history passed 4 tests in 6.11 s of test-runner time (4.86 s Vitest). These timings exclude shared job setup; the containing jobs took 189 s / 195 s, respectively.
  • Fresh integrated-diff P2 autoreview: scoped-clean; no actionable P0/P1/P2 findings.
  • Exact integrated-head issue-109025-completion-policy-live: 1 passed, 0 failed, exit 0, 32.993 s QA wall time. The isolated OpenClaw runtime completed qa-channel ingress, native child spawn, parent yield before child completion, dormant parent resume with exact-sender restricted exec authority, and visible final delivery. Parent successful tools were exactly sessions_spawn: 1, sessions_yield: 1, exec: 1; child successful tools were read: 4. The scenario requires the live provider contract; only this single row ran, with retry count 0.
  • ClawSweeper exact-head re-review: Ready for maintainer review, proof sufficient, no correctness or security findings. One explicit exact-head re-review was requested.
  • Exact-head CI passed at 9dc0726e145d26ab56063e73c60b1aa629f15400: 48 successful jobs, 22 intentionally skipped, 0 failed. The combined CI/security gate, dependency review, and security-sensitive review are successful. No CI rerun or further push was needed. GitHub reports OPEN, ready for review, MERGEABLE, CLEAN, with automerge disabled.

This PR remains ready for review; no merge, queue, or automerge is requested.

@clawsweeper

clawsweeper Bot commented Oct 2, 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.

@joshavant

Copy link
Copy Markdown
Collaborator Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@joshavant
joshavant marked this pull request as ready for review October 2, 2026 19:52
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Oct 2, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 Oct 2, 2026
@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 1:21 AM ET / 05:21 UTC (Revision 3).

ClawSweeper review

What this changes

The PR preserves accepted user messages during asynchronous transcript writes by comparing captured database locators consistently and refreshing prepared-turn state when a session manager is reused.

Merge readiness

✅ Ready for maintainer review

The integrated patch remains useful: pinned main still lacks both repairs, and no actionable introduced defect was found. The previous review had no findings; the updated source and evidence support that conclusion.

Priority: P1
Reviewed head: 9dc0726e145d26ab56063e73c60b1aa629f15400

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with relevant negative controls, reported exact-head runtime evidence, and no actionable review findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured body reports an exact-head isolated OpenClaw runtime completing real ingress, asynchronous turn execution, resume, and final delivery. Focused physical/alias and reused-guard controls cover the specific persistence repairs; live-owner and revocation checks remain authoritative. No stored-data contract changes require migration proof, and tests were not rerun by this reviewer.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body reports an exact-head isolated OpenClaw runtime completing real ingress, asynchronous turn execution, resume, and final delivery. Focused physical/alias and reused-guard controls cover the specific persistence repairs; live-owner and revocation checks remain authoritative. No stored-data contract changes require migration proof, and tests were not rerun by this reviewer.
Evidence reviewed 9 items Pinned introduced change: Read the complete merge-base-to-head patch and affected production modules. The branch refreshes prepared message, recorder, replay key, and one-shot suppression; its database changes preserve the native locator while comparing the captured canonical locator.
Current main still needs guard refresh: The pinned main wrapper retains the first prepared recorder and replay key and does not replace its pending prepared message when re-guarded. GitHub source inspection confirmed the repair is not already present.
Custody remains live and scoped: Canonical-locator matching still requires the exact session, message key, pending row, and lifecycle generation. Promotion retains live-owner checks, including recursive aggregate-source validation and host revalidation for worker custody. Database identity is cached at open rather than resolved again during append.
Findings None None.
Security None None.

How this fits together

OpenClaw stages accepted user messages before adding them to the session transcript. The transcript guard carries approved message bytes and live custody into the database writer, which records the message and consumes its pending input.

flowchart TD
  A[Accepted user message] --> B[Pending input admission]
  B --> C[Prepared turn and live owner]
  C --> D[Reused transcript guard]
  D --> E[Database custody checks]
  E --> F[Committed session transcript]
  E --> G[Pending input consumption]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +23, Tests +21. Total +44 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 4 41 18 +23
Tests 2 85 64 +21
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 126 82 +44

Review metrics

Metric Value Why it matters
Changed test cost 15 tests; 27.72 s wall, 9.18 s Vitest The PR records the required focused-test cost while extending the existing persistence regression.

Technical review

Best possible solution:

Keep one transcript-persistence owner that records approved input exactly once across aliased paths and manager reuse while preserving live custody checks.

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

Yes, from source: aliased admission and asynchronous persistence compare inconsistent locators, and re-guarding retains earlier prepared-turn state on pinned main. The PR reports independent failing controls; this review did not execute them.

Is this the best way to solve the issue?

Yes. The patch repairs existing owners, reuses identity captured at database open, and refreshes turn state without changing storage formats or relaxing live authorization.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9d2ebf60d97a.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Accepted user turns can fail before model execution in the asynchronous agent workflow.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body reports an exact-head isolated OpenClaw runtime completing real ingress, asynchronous turn execution, resume, and final delivery. Focused physical/alias and reused-guard controls cover the specific persistence repairs; live-owner and revocation checks remain authoritative. No stored-data contract changes require migration proof, and tests were not rerun by this reviewer.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports an exact-head isolated OpenClaw runtime completing real ingress, asynchronous turn execution, resume, and final delivery. Focused physical/alias and reused-guard controls cover the specific persistence repairs; live-owner and revocation checks remain authoritative. No stored-data contract changes require migration proof, and tests were not rerun by this reviewer.

Evidence

What I checked:

  • Pinned introduced change: Read the complete merge-base-to-head patch and affected production modules. The branch refreshes prepared message, recorder, replay key, and one-shot suppression; its database changes preserve the native locator while comparing the captured canonical locator. (src/agents/session-tool-result-guard-wrapper.ts:349, 9dc0726e145d)
  • Current main still needs guard refresh: The pinned main wrapper retains the first prepared recorder and replay key and does not replace its pending prepared message when re-guarded. GitHub source inspection confirmed the repair is not already present. (src/agents/session-tool-result-guard-wrapper.ts:114, 9d2ebf60d97a)
  • Custody remains live and scoped: Canonical-locator matching still requires the exact session, message key, pending row, and lifecycle generation. Promotion retains live-owner checks, including recursive aggregate-source validation and host revalidation for worker custody. Database identity is cached at open rather than resolved again during append. (src/config/sessions/session-accessor.sqlite-pending-inputs.ts:533, 9dc0726e145d)
  • Regression reaches asynchronous persistence: The physical/alias cases stage approved input, reuse an asynchronously opened guarded manager, call the production asynchronous persistence entrypoint, and inspect committed approved bytes, consumption, history, and single hook execution. Existing sibling tests reject copied receipts and cancellation after an await, and check transaction/commit custody changes. (src/agents/session-tool-result-guard.transcript-events.test.ts:214, 9dc0726e145d)
  • Integrated-head validation and live evidence: The captured PR body reports separate old-code negative controls for locator matching and guard refresh, 216 passing focused tests, changed gates, and an isolated exact-head live runtime scenario completing channel ingress, child spawn, parent yield/resume, and final delivery. These are contributor-reported results; this read-only review did not execute tests. The live result supports working turn persistence, while the focused controls specifically cover aliases and manager reuse. (9dc0726e145d)
  • Merged area history: Current-main history identifies the awaited-persistence refactor by Peter Steinberger and the dual-locator change by roboclaw-bot. GitHub verified feat(plugin-sdk): awaited session persistence; deprecate sync transcript writes #163264 and fix(qa): restore Telegram release validation #163488 as merged; the latter supplies the locator contract this patch preserves. (src/config/sessions/session-accessor.sqlite-pending-inputs.ts:104, fa56f5e2e9e6)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • roboclaw-bot: 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-10-02T19:56:54.781Z sha 7d6b4c1 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-02T20:09:53.941Z sha 7d6b4c1 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Oct 2, 2026
@joshavant
joshavant force-pushed the codex/fix-async-user-turn-custody branch from 7d6b4c1 to 9dc0726 Compare October 3, 2026 05:16
@joshavant

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

Please review exact head 9dc0726e145d26ab56063e73c60b1aa629f15400. Rebased once onto 350e91cf765632fd23169c0603aa94272ceade36 to resolve the verified dual-locator conflict. The integrated change preserves native databasePath and captured canonical workerDatabasePath, canonical custody comparisons, and async guard refresh. Focused owner/sibling proof (216 tests), changed gates, fresh P2 autoreview, and the isolated issue-109025 completion-policy live row all pass; details are in the updated PR body.

Review only. Do not merge, queue, or enable automerge.

@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@joshavant
joshavant merged commit b440340 into main Oct 3, 2026
137 checks passed
@joshavant
joshavant deleted the codex/fix-async-user-turn-custody branch October 3, 2026 05:29
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

1 participant