Skip to content

fix(sessions): preserve accepted input during announcements - #160962

Closed
chuanleiguo wants to merge 35 commits into
openclaw:mainfrom
chuanleiguo:codex/preserve-live-pending-input
Closed

chuanleiguo wants to merge 35 commits into
openclaw:mainfrom
chuanleiguo:codex/preserve-live-pending-input

Conversation

@chuanleiguo

@chuanleiguo chuanleiguo commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes accepted user turns failing with Pending input is no longer active in its admitted transcript when a same-session announcement treats their promoted input as an orphan.

User Impact

Announcements preserve another live turn's accepted input without executing it or including it in the announcement's model context. The original turn can continue exactly once; cancellation still prevents execution. Bedrock runtime replay retains the original input identity. No configuration, schema, stored-format, permission, retention-policy or migration change is required.

Why This Change Was Made

Promotion removes the pending database row before its live owner finishes. Orphan repair must consult that current owner, including collected inputs, and exclude foreign input when rebuilding announcement context. Lifecycle persistence also preserves the original pre-adoption chat reservation. Bedrock runtime keeps distinct user turns until the existing provider stream boundary performs its merge.

Integration repairs preserve canonical archive recovery and admitted requester handoff after the launching tool ends. They keep physical database identity, live authority, FIFO commits and deletion ordering intact.

Candidate: 1d139df8f22efadd549f1e165cd5ed13aaa7d424, integrated with official main 3cb68020b6a5a7a82b881d1ccde4cc30c7da769c for actual conflicts. All three original protections remain absent from that upstream source: foreign live-input custody, pre-adoption chat reservation, and distinct Bedrock runtime user turns. Official #160128 fixes compacted current input; it does not protect a different live input from announcements.

Evidence

Current candidate

  • Ten focused runtime/persistence files: 270/270 passed, wrapper wall 230.10 s. Includes seven accepted-input boundary cases, 53 lifecycle cases, Bedrock/sanitized replay, requester settlement, pending-input retirement, archive worker/retention and physical identity/reclamation coverage.
  • Core production types: passed, 100.35 s. Changed test types: passed, 47.71 s.
  • Format, scoped lint, line-cap, max-lines, assertion-safety and timeout-race ratchets: passed. Independent Codex autoreview completed. The initial pass was scoped-clean; the final pass reported one P2 archive-batch concern, rejected after checking the actual owning query: readPublishedSessionArchiveBatchInDatabase already applies .where("published_at", "is not", null) before ordering and .limit(limit). Unpublished rows cannot consume its batch. No accepted actionable P0–P2 findings remain.
  • CI cost/placement and route suites: 410/410 passed (158.99 s Vitest). Real GitHub personal publication suite: 50/50 passed (67.13 s Vitest). The original 23 local planner/uniqueness failures fail with the four duplicate entries and pass after removing only those entries. All 14 selected files total 730/730 passing cases.

Executed operator commit-boundary proof

The complete requester-wake E2E file passed 27/27, Vitest duration 52.02 s. Its two real SQLite cases reached the final worker commit authorization stage:

Operator state at final commit Observed result Persisted result Case time
Live Settlement succeeds; continuation settled Child turn ID released; pending requester-yield wake and exact child batch persisted 0.847 s
Revoked immediately before commit Rejects with outcome: not-committed; continuation remains unsettled Complete persisted child-row map equals its pre-operation image 0.830 s

Both cases use real registry registration, sessions_yield, settleRequesterRun and SQLite persistence. The observer changes only operator liveness before forwarding the real commit request to its real admission/grant path; source authority remains valid. No fake database, rollback or worker grant is substituted. This execution supplies the public observed result requested by hosted review revision 20.

The accepted-input file takes 33.99 s (seven cases): it exercises the real attempt boundary, SQLite ownership and provider-context conversion rather than a helper predicate. Archive retention shares existing suite-owned state; no live-provider fixture was added to per-PR CI. New-head CI timing is pending.

Previous CI failures and upstream repairs

Run 36597840024 tested the previous head 5a960e8076c82f45f113622ae1091e53b150373a. Its four failed jobs are addressed by adopted official changes:

Failure Owning upstream repair adopted
UI splash composer geometry read before resize publication 531f0a229c36 and e603e31e7cdf (#161509), frame sampling plus ResizeObserver completion
CI placement fixture drift 450dba2dc67a, fixed workload/capacity inputs while retaining real runtime timings
GitHub personal publication session incarnation mismatch 82ad20b96722, synchronize the actual durable entry and restore it; retain original assertions
Windows PowerShell fixture cold spawn ETIMEDOUT 5eeecd39f956, use existing cold-spawn budget; production inspection budget/identity checks unchanged

Equivalent branch-local metadata, worker observer, snapshot cleanup, SDK drainage, CLI fixture and placement fixture repairs were removed in favor of current upstream owners. A local planner failure after integration exposed four duplicate database-consumer registrations; only those redundant registrations were removed, keeping their existing upstream isolation routes and the new live-input test route. No planner guard or assertion was weakened.

Windows and browser CI outcomes must still be verified on the new remote head; this macOS run does not establish Windows execution or browser geometry proof. No workflow was dispatched or rerun for green.

Real Gateway/provider verification retained for unchanged original behavior

Passed on the exact source candidate committed as d75cd3e3cd7c5f3e204148cb8100c69b4eccd068, using an isolated real Gateway, SQLite, browser-authenticated WebSocket RPCs, native agent runtime and a real OpenAI-compatible Responses service. Prompts were synthetic; provider responses, tool decisions and announcement delivery were not stubbed.

Public sessions.create made an explicit non-main session. A real model turn called sessions_spawn; browser chat.send naturally persisted U before its started ACK. The fixture held dispatch scheduling only, not promotion or ownership receipts. Completing the child produced a real announcement whose provider request contained zero copies of U, while U's original canonical record and pre-adoption claim stayed unchanged. Releasing U's dispatch produced one provider request containing one copy of U and one final reply. Cancelling a second promoted input through chat.abort then releasing dispatch produced zero new provider requests and no remaining live input owner.

Phase Real provider requests HTTP result Copies of U
Parent setup and actual tool use 4 All 200 0
Child completion 1 200 0
Parent announcement 1 200 0
Original U continuation 1 200 1
Cancelled input after dispatch release 0 No request 0

Trace date: 2026-09-29; synthetic run nonce d7a39832-e5af-43c5-acbb-cc87c290c4ad. Both proof record and runner exit 0 passed. The isolated Gateway/state were cleaned up. This is real Responses-provider proof; Bedrock is covered by committed runtime/SDK boundary tests with a synthetic stream, not live AWS proof. No conversation, private endpoint, model identity or credential is published.

Remote CI and hosted review must be assessed for the candidate above before calling the PR merge-ready. This PR remains open; no merge or auto-merge is requested.

@clawsweeper

clawsweeper Bot commented Sep 29, 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 labels Sep 29, 2026
@chuanleiguo
chuanleiguo marked this pull request as ready for review September 29, 2026 04:42
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 29, 2026
@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

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

ClawSweeper review

What this changes

The branch preserves accepted messages during same-session announcements, retains Bedrock input identities, and repairs requester settlement and archive cleanup ownership.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary: current main does not protect another live input from announcement repair. The updated commit-boundary observations address the previous authority-proof blocker, and no actionable introduced defect was found.

Priority: P1
Reviewed head: 1d139df8f22efadd549f1e165cd5ed13aaa7d424

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful repair with strong behavior evidence, resolved authority proof, and no supported blocking finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Retained Gateway/Responses observations prove announcement exclusion, single continuation, and cancellation for the preserved input guards. Exact-candidate SQLite observations now prove allowed settlement and operator revocation before commit, satisfying the prior authority-proof request. Existing archive layouts remain covered without a schema or stored-format migration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Retained Gateway/Responses observations prove announcement exclusion, single continuation, and cancellation for the preserved input guards. Exact-candidate SQLite observations now prove allowed settlement and operator revocation before commit, satisfying the prior authority-proof request. Existing archive layouts remain covered without a schema or stored-format migration.
Evidence reviewed 9 items Pinned introduced changes: Reviewed the merge-base-to-head changes across agents, session storage, Gateway lifecycle, tests, and worker routing. Raw commit records confirm the original head has parents 5a960e8 and 3cb6802. The supplied stale test merge was not used to infer removal of main behavior.
Central repair remains absent on main: Current main's pre-persisted-turn implementation reconciles the current input but lacks foreign live-input reconciliation. Searches also found none of the branch's foreign-custody, reserved-chat-run, or runtime-replay protections. The branch consults live custody and removes the foreign keyed user only from this attempt's model context.
Merged restart repair is distinct: GitHub confirms #160128 merged as 6dc7dbe. Its supplied discussion describes compacted current-input persistence suppression after restart, rather than protecting a different live input during announcements. It therefore does not supersede this PR.
Findings None None.
Security None None.

How this fits together

OpenClaw stores accepted conversation input in SQLite before agent execution. Announcements and resumed turns share that transcript, so session custody and lifecycle checks determine which input may enter provider requests or be settled.

flowchart TD
  A[Accepted user message] --> B[SQLite transcript and live custody]
  C[Child completion announcement] --> D[Session preparation]
  B --> D
  D --> E{Input belongs to another live turn}
  E -->|Yes| F[Announcement context excludes input]
  E -->|Original owner resumes| G[Provider executes original input]
  G --> H[Authorized settlement and lifecycle publication]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +198, Tests +744. Total +942 across 32 files.

View PR surface stats
Area Files Added Removed Net
Source 18 305 107 +198
Tests 14 815 71 +744
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 32 1120 178 +942

Review metrics

Metric Value Why it matters
Production versus test growth production +200 net lines; tests/support +741; test routing +1 Production growth is explained by live-input custody, settlement authority, and archive compatibility repairs.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/agents/embedded-agent-runner/run/attempt-session-prepare.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Technical review

Best possible solution:

Keep accepted input under its existing live owner, exclude it from foreign announcement context, and retain current-authority checks through settlement.

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

Yes: promote accepted input, hold its dispatch, and complete a child announcement in the same session. Current-main orphan repair lacks the live-custody exclusion; this reviewer inspected the path without executing it.

Is this the best way to solve the issue?

Yes: the patch repairs the existing custody, provider-boundary, and lifecycle owners without introducing a competing dispatcher or configuration mode.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The reported race prevents an already accepted user turn from continuing during a same-session announcement.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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): Retained Gateway/Responses observations prove announcement exclusion, single continuation, and cancellation for the preserved input guards. Exact-candidate SQLite observations now prove allowed settlement and operator revocation before commit, satisfying the prior authority-proof request. Existing archive layouts remain covered without a schema or stored-format migration.
  • proof: sufficient: Contributor real behavior proof is sufficient. Retained Gateway/Responses observations prove announcement exclusion, single continuation, and cancellation for the preserved input guards. Exact-candidate SQLite observations now prove allowed settlement and operator revocation before commit, satisfying the prior authority-proof request. Existing archive layouts remain covered without a schema or stored-format migration.

Evidence

What I checked:

  • Pinned introduced changes: Reviewed the merge-base-to-head changes across agents, session storage, Gateway lifecycle, tests, and worker routing. Raw commit records confirm the original head has parents 5a960e8 and 3cb6802. The supplied stale test merge was not used to infer removal of main behavior. (1d139df8f22e)
  • Central repair remains absent on main: Current main's pre-persisted-turn implementation reconciles the current input but lacks foreign live-input reconciliation. Searches also found none of the branch's foreign-custody, reserved-chat-run, or runtime-replay protections. The branch consults live custody and removes the foreign keyed user only from this attempt's model context. (src/agents/embedded-agent-runner/run/pre-persisted-user-turn.ts:209, 1d139df8f22e)
  • Merged restart repair is distinct: GitHub confirms fix: resume compacted turns after a Gateway restart #160128 merged as 6dc7dbe. Its supplied discussion describes compacted current-input persistence suppression after restart, rather than protecting a different live input during announcements. It therefore does not supersede this PR. (6dc7dbeee89f)
  • Retained real Gateway proof: The captured body, sourceRevision 61b2fd826f8d768f93cc0da00ed2c8269d271eb657c11d85b699d5052d6b1b63, records an isolated Gateway, SQLite, authenticated WebSocket RPCs, and real Responses-provider execution at d75cd3e. Announcement requests contained zero copies of the accepted input; continuation contained one copy in one request; cancellation produced no request. Tree identities verify unchanged foreign-input reconciliation and pending-custody modules, and the historical lifecycle blob retains the same reservation guard. (src/gateway/session-lifecycle-state.ts:453, d75cd3e3cd7c)
  • Previous authority-proof request addressed: The updated captured body and contributor comment report exact-candidate execution of both real SQLite settlement cases: live authority committed the expected child batch in 0.847 seconds; revocation at commit rejected as not-committed in 0.830 seconds and preserved the complete persisted preimage. Source inspection confirms the observer forwards the real admission/grant path and changes operator liveness only. This supplies the observed execution requested by the previous review. (src/agents/subagents/registry/subagent-registry.requester-wake-settlement.test-support.ts:93, 1d139df8f22e)
  • Authority reaches the persistence boundary: Requester settlement carries the admitted run's operator authority into the existing caller context. Registry operations capture caller assertions, which check operator liveness and source custody; the new production-path SQLite observations cover rejection before the final commit. The earlier settlement authority concern is therefore resolved rather than repeated. (src/agents/requester-run-settlement.ts:143, 1d139df8f22e)

Likely related people:

  • steipete: 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 (20 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-29T12:07:24.239Z sha aebcc04 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-29T12:15:34.415Z sha aebcc04 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-29T13:31:15.713Z sha 00fe594 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-29T14:13:48.480Z sha 76b28c7 :: blocked before merge. :: none
  • reviewed 2026-09-29T14:36:59.992Z sha 03bcde4 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-29T14:54:01.020Z sha 03bcde4 :: blocked before merge. :: none
  • reviewed 2026-09-29T15:18:23.178Z sha e019f46 :: needs real behavior proof before merge. :: [P2] Recheck operator authority before settling requester children
  • reviewed 2026-09-29T16:36:05.114Z sha 5a960e8 :: needs real behavior proof before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Sep 29, 2026
@chuanleiguo

chuanleiguo commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Current candidate: 1d139df8f22efadd549f1e165cd5ed13aaa7d424, after resolving actual conflicts against official main 3cb68020b6a5a7a82b881d1ccde4cc30c7da769c.

The PR remains necessary: upstream still lacks the foreign live-input announcement exclusion, pre-adoption chat reservation guard, and distinct Bedrock runtime input identity. Official #160128 covers compacted current input, not the foreign live input handled here.

The four failures in run 36597840024 adopt their official upstream repairs. Equivalent local fixture/observer/cleanup changes were removed. A reproduced local planner failure identified four duplicate database-consumer routes after integration; removing only redundant registrations fixes the original failures while keeping the official isolation routes and all assertions.

Local validation: 730/730 cases across 14 files, production/test types, format/lint and all relevant ratchets passed. The two real SQLite operator cases reached final commit: live authority persists the pending requester-yield batch (0.847 s); revocation immediately before commit rejects as not-committed, leaves continuation unsettled and preserves the complete persisted preimage (0.830 s). The full requester-wake file passes 27/27, 52.02 s. This supplies the executed proof requested by hosted review revision 20. Full commands, costs, retained real-provider evidence and gaps are in the updated PR body.

Independent autoreview completed. Its final P2 archive-batch concern is rejected because the actual SQL filters published_at IS NOT NULL before LIMIT; unpublished records cannot fill that batch.

New-head remote CI and hosted review are pending. This is current-candidate local proof, not a claim that remote CI is green. No merge or auto-merge is requested.

@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 29, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Sep 29, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 29, 2026
Keep prepared snapshot retirement attached to its original staging owner.
Adapt async metadata and retained-worker test fixtures without weakening
their assertions, and prove operator revocation at the real SQLite commit.

Adopt upstream fixture fixes 313f621 and fd38060 by Peter Steinberger.
@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Sep 29, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Sep 29, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the cli CLI command changes label Oct 1, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 1, 2026
@chuanleiguo

Copy link
Copy Markdown
Contributor Author

Superseded by #162473, which carries only the core fix (foreign live-input custody at the attempt boundary) rebased on current main: 1 commit, 8 files. The pre-adoption lifecycle reservation and the Bedrock distinct-user-turn replay will follow as separate PRs. The archive/settlement changes here were conflict-integration churn and are dropped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime 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: XL 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