Skip to content

fix: preserve cloud turns when follow-up input arrives - #132887

Merged
steipete merged 8 commits into
mainfrom
codex/cloud-input-admission
Aug 30, 2026
Merged

steipete merged 8 commits into
mainfrom
codex/cloud-input-admission

Conversation

@steipete

@steipete steipete commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #132547

Why

An agent follow-up could append to a cloud session's transcript while its first worker turn was still running. That changed the worker's expected base and caused stale-base-leaf. The same input-ownership gap could duplicate CLI input or let an ACP prompt start before its canonical input existed.

What changes

Gateway agent admission, including sessions_send, retains approved input in per-agent SQLite before ACK without changing the active transcript. The existing execution owner appends the exact input and consumes its pending record in one transaction when its turn starts. Worker transcript fencing and the existing queues/scheduler remain unchanged.

Pending rows retain text and existing media metadata after cancellation or restart, but grant no execution authority. Promotion requires the original private live closure, physical session, lifecycle, run and current transcript anchor. Cancelled/interrupted input is readable in bounded Control UI and sessions_history projections, separately from model history, and requires an explicit new send. The writer queue preserves caller async context; stale branch projections cannot replace active anchors. Native, CLI and ACP execution use the canonical recorder, and terminal mirrors cannot synthesize replacement input.

Live testing also repaired two UI defects: pending input now refreshes through the existing session/connection-fenced history owner without a reload, and canonical/live tool echoes coalesce using the actual __openclaw.runId history identity. The original top-level-only fixtures missed that payload shape; three corrected regressions fail before the final repair.

The additive custody design was explicitly accepted before implementation. Schema version stays 19, with lazy first-use creation and older-reader compatibility. No new configuration option, dependency, protocol version, scheduler or automatic replay path.

Verification

Live-tested head f4919de936b9fd7aec9439124e2e6737cde43d86: full CI passed, normal package/UI build passed, and real Chrome/cloud proof passed using an OpenAI API-key profile and openai-responses.

Main advanced during live testing, so the branch was rebased to ea11b879f12498b718024d4df4f8de61ef6d1d2f. Range-diff confirms all production commits are unchanged; only three generated prompt snapshot hashes/counts changed. Canonical generation and independent snapshot verification passed, and the resolution passed Codex review. The rebased CI run passed all jobs except a pre-existing process-fixture readiness race: the fixture published its PID before installing its SIGTERM handler. Commit 3d4cfe67478c2f26ddf392fda347cf95c7dd5a82 fixes that ordering in the tracked-process and sibling watchdog fixtures, without changing assertions, timeouts or production code. Forced-interleaving proof fails before and passes after; all 34 tests in the file, the changed-file gate and Codex review pass. Final-head CI passed: 193 successful jobs and seven intentional skips, including the required aggregate gate. No additional production behavior was introduced by the rebase or fixture correction.

The final UI-created AWS cloud session ran one 120-second command. While it was active, a browser follow-up and a Gateway agent follow-up were submitted. The active command appeared once; the agent input appeared as one retained pending row without a reload.

Observed boundary UTC time / canonical position
Input dae3095b-818f-4a9b-884f-d8688b9a88e4 accepted while first turn active 01:23:59.320
First reply committed 01:25:25.373 / seq 14
Exact input ID and text promoted once 01:25:35.277 / seq 15
Second reply committed 01:25:40.041 / seq 16
Settled state One canonical exec invocation; pending 0; execution claim cleared

The pending indicator retired without a reload. The ordinary browser follow-up also completed afterward. Earlier real flows additionally covered Control UI parent creation → actual sessions_spawn → sessions_send, with direct AWS filesystem marker verification. The worker's content-addressed production bundle is unchanged across these UI/test follow-ups; final Gateway/UI build is the exact head above.

Abrupt restart proof: a separate accepted input was captured while an API-backed cloud command was active, then only the isolated Gateway was SIGKILLed. After restart and a normal authenticated history read, the exact input ID/text/acceptance timestamp remained, its state was interrupted, the old execution claim was cleared, and no canonical event or output replayed that pending input. The UI explicitly says it will not run automatically. The earlier graceful-stop attempt raced promotion; the final abrupt test captures both sides of the actual crash.

Focused verification includes 335 initial owner tests, 68 shared-owner siblings, 267 follow-up tests (4 platform skips), 580 native/script tests, 291 Gateway handler tests, 112 UI invalidation tests and the final 364 UI ownership/history/stream/pending tests. Core/UI/full core-test types, type-aware lint and complete changed-file gates pass. The earlier CI timeout cascade came from obsolete eager-write mocks; the handler suite now uses the admission boundary. Required P0-only independent Codex reviews reported no findings.

Frozen pre-fix tests reproduce stale-base-leaf in the original execution order, CLI duplication and ACP pre-prompt omission. Repeated on final head 3d4cfe67478c2f26ddf392fda347cf95c7dd5a82, the actual three-process candidate → frozen older-reader d3c07b02e244e73470df4a930911e8d58c4e456d append → candidate reopen proof passed. It preserves the exact pending ID/message bytes/interrupted disposition, schema 19 and schema metadata. All 13 frozen source/loader hashes match the original baseline receipt; the older accessor performs an ordinary append and the candidate still displays the retained pending input. Storage tests cover atomic rollback, cancellation, lifecycle/physical-session replacement, exact identity and bounded pages.

Direct Codex contract inspection: codex-rs/core/src/session/inject.rs:15, including active queuing, idle recording and no-new-turn injection. No Codex protocol change. Shallow OpenClaw history does not establish the original introducing PR.

Production LOC: +1708/-278, net +1430; tests net +1276; generated +27; docs +21. Growth implements the accepted custody, lifecycle cleanup and bounded visibility contract. Moving append alone would lose accepted input after interruption; the existing execution and transcript owners are reused.

Scope and follow-ups

ClawSweeper rank-up follow-through: the reported merge conflict is resolved by the generated-only rebase, with final-head CI passed after the verified fixture correction; live pending/promotion and single-card proof for the unchanged production patch is supplied; the accepted storage design, older-reader proof and direct Codex inspection are recorded above. No access check, reviewer isolation or native workflow guard was bypassed.

Before and after

Before the final metadata repair: duplicate command around the browser follow-up.

Before: duplicate live command

After: one command, separate retained input, no reload.

After: one command and one pending input

Completed: replies in canonical order and no pending indicator.

Completed cloud flow

After abrupt restart: retained input is explicitly interrupted and non-executable.

Retained interrupted input

All six task-owned cloud leases were verified released. The isolated Gateway, tunnels, package server and test tab are stopped; the temporary API-key file, private runtime state and task dependencies were removed.

@clawsweeper

clawsweeper Bot commented Aug 29, 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 docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Aug 29, 2026
@steipete
steipete marked this pull request as ready for review August 29, 2026 22:44
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 29, 2026
@clawsweeper

clawsweeper Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 10:09 PM ET / August 30, 2026, 02:09 UTC.

ClawSweeper review

What this changes

The PR stages cloud follow-up input in per-agent SQLite until its own turn starts, then shows retained input separately in Gateway history and the Control UI.

Warning

SQLite table change

This PR modifies persisted SQLite tables in src/state/openclaw-agent-pending-inputs-schema.ts, src/state/openclaw-agent-schema.sql. 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.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

Keep this maintainer-authored PR open for confirmation of its material durable-state design. Current main still appends the user turn during admission; the branch moves custody to the execution owner without weakening the worker transcript fence, and no discrete patch defect was found.

Priority: P1
Reviewed head: 3d4cfe67478c2f26ddf392fda347cf95c7dd5a82
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The technical repair and focused boundary coverage are solid; durable retention remains a maintainer product decision.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository state identifies this as a MEMBER-authored PR, so the external-contributor proof gate does not apply; its body nevertheless records a real Chrome/cloud before-and-after flow and abrupt-restart observation for the changed custody path.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository state identifies this as a MEMBER-authored PR, so the external-contributor proof gate does not apply; its body nevertheless records a real Chrome/cloud before-and-after flow and abrupt-restart observation for the changed custody path.
Evidence reviewed 5 items Current main remains affected: Current main persists the recorder during Gateway admission, before the later session execution path, matching the reported opportunity to advance an active worker's transcript base.
Admission and promotion share the authoritative owner: The proposed admission stages a keyed input after live-run validation, while transcript append accepts it only inside the matching private pending-input scope and consumes custody atomically.
Boundary and downgrade coverage: The changed tests cover overlapping worker admission without a stale-base rejection and an older reader opening a store with the additive table before candidate reopen.
Findings None None.
Security None None.

How this fits together

Gateway admission accepts agent input before execution, while cloud workers commit against a fixed transcript base. This change holds follow-up input outside that transcript until the session execution owner promotes it, then projects the retained state to history consumers.

flowchart LR
  A[Gateway follow-up request] --> B[Admission]
  B --> C[Durable pending input]
  C --> D[Session execution owner]
  D --> E[Canonical transcript]
  C --> F[History API]
  F --> G[Control UI]
Loading

Decision needed

Question Recommendation
Should OpenClaw retain cancelled or restart-interrupted cloud follow-up text in per-agent SQLite for later inspection, while requiring an explicit new send to run it? Confirm retained non-executable custody: Accept the proposed bounded SQLite record and explicit resend behavior for cancelled and interrupted cloud follow-ups.

Why: This is a durable user-visible retention and recovery policy, not a mechanical correctness choice; the linked acceptance record was unavailable for independent review.

Before merge

  • Resolve merge risk (P1) - The PR adds retained per-agent SQLite input state and changes its cancellation/restart semantics; the supplied body links prior design acceptance, but that linked discussion could not be independently read in this environment.
  • Resolve merge risk (P1) - Path-classified production growth is +1,755/-293 (net +1,462), a large review surface for a bug fix even though the new custody boundary is substantively justified.
  • Resolve merge risk (P1) - The Codex prompt-snapshot implication remains externally unverified because the required sibling checkout is unavailable.
  • Complete next step (P2) - A maintainer must confirm the durable retention policy and the unavailable Codex-contract check before merge; no narrow mechanical repair is identified.
Agent review details

Security

None.

PR surface

Source +1466, Tests +1244, Docs +21, Generated +15, Other +8. Total +2754 across 74 files.

View PR surface stats
Area Files Added Removed Net
Source 47 1761 295 +1466
Tests 22 1389 145 +1244
Docs 2 21 0 +21
Config 0 0 0 0
Generated 1 15 0 +15
Other 2 10 2 +8
Total 74 3196 442 +2754

Review metrics

Metric Value Why it matters
Production and test delta production +1,755/-293 (net +1,462); tests +1,396/-148; docs/generated excluded The substantial production expansion implements durable custody, promotion, lifecycle cleanup, and UI/history projection rather than a local worker retry.

Stored data model

Persistent data-model change detected: database schema: src/state/openclaw-agent-pending-inputs-schema.ts, database schema: src/state/openclaw-agent-schema.sql, vector/embedding metadata: apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift, vector/embedding metadata: src/gateway/server-methods/chat-pending-inputs.ts, vector/embedding metadata: src/sessions/user-turn-transcript.message.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #132547
Summary: This PR is the candidate fix for the documented cloud follow-up transcript-admission failure.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Confirm the persisted-input contract (recommended)
    Approve the retained-input lifecycle after reviewing the additive-table and downgraded-reader evidence.
  2. Pause for a revised recovery policy
    Hold the PR if cancelled or interrupted input should be deleted or handled differently, because that changes the durable product contract.

Technical review

Best possible solution:

Keep one stage-then-promote custody flow: retain accepted input only until the live execution owner appends it, preserve interrupted input as non-executable, and obtain explicit maintainer confirmation of that persistent product contract.

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

Yes: current main visibly persists the follow-up during admission, and the changed worker-boundary regression composes overlapping admission with the worker's fixed base.

Is this the best way to solve the issue?

Yes for the technical defect: the branch moves input custody to the admission/execution boundary instead of weakening the worker compare-and-swap. The durable retention policy still needs maintainer confirmation.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P1: The PR addresses a cloud-session follow-up that can invalidate an active worker turn.
  • merge-risk: 🚨 compatibility: It adds an additive SQLite table and Gateway history fields consumed by existing installations and clients.
  • merge-risk: 🚨 session-state: It changes the lifecycle of accepted input across execution, cancellation, restart, and transcript promotion.
  • 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: The repository state identifies this as a MEMBER-authored PR, so the external-contributor proof gate does not apply; its body nevertheless records a real Chrome/cloud before-and-after flow and abrupt-restart observation for the changed custody path.

Evidence

What I checked:

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record or confirm the maintainer decision for retained interrupted input and independently recheck the cited Codex contract when its source checkout is available.

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 (8 earlier review cycles)
  • reviewed 2026-08-29T22:53:33.223Z sha c3d485a :: needs maintainer review before merge. :: none
  • reviewed 2026-08-29T23:10:09.284Z sha 64ce643 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-30T00:00:38.980Z sha 550d7f6 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-30T00:11:53.700Z sha 7fdb0d0 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-30T00:49:39.533Z sha 5a46b0ce6b5809505237c6d5284c8c740ca669a6 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-30T01:23:26.145Z sha f4919de936b9fd7aec9439124e2e6737cde43d86 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-30T01:35:11.250Z sha f4919de936b9fd7aec9439124e2e6737cde43d86 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-30T01:55:07.251Z sha ea11b87 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 30, 2026
@steipete
steipete force-pushed the codex/cloud-input-admission branch from f4919de to ea11b87 Compare August 30, 2026 01:38
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 30, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Final maintainer verification for 3d4cfe67478c2f26ddf392fda347cf95c7dd5a82:

The retained interrupted-input policy was explicitly accepted in the task conversation before implementation, as recorded in #132547 (comment). Pending custody grants no replay authority; interruption retains readable input and requires an explicit new send. The production growth implements that accepted custody and bounded visibility boundary while reusing the existing scheduler and transcript writer.

I personally inspected the sibling Codex source at 2181224dad147a9ed37e698b66487aba54acdb65, specifically codex-rs/core/src/session/inject.rs:15–35, 43–67, and 116–134 for active queuing, idle recording, and no-new-turn injection. No Codex protocol change is made here.

The three-process older-reader proof was repeated on the final head: candidate → frozen d3c07b02e244e73470df4a930911e8d58c4e456d reader and ordinary append → candidate reopen. All processes passed; all 13 frozen source/loader hashes matched the original receipt. Exact pending ID/message bytes/interrupted state, schema version 19, and schema metadata survived unchanged.

Real API-key cloud creation and follow-ups through the Control UI and agent tools passed, including no-reload pending visibility, single promotion after the first reply, one visible command, and abrupt-restart retention without replay. The PR body contains the timeline and sanitized screenshots. The later rebase and readiness-fixture correction do not change the live-tested production patch. Final CI is green: https://github.com/openclaw/openclaw/actions/runs/33286890304. Native review and hosted preparation passed on that exact head. This addresses the latest ClawSweeper rank-up requests; its unavailable local context does not leave a new code finding unresolved.

@steipete
steipete merged commit 6c9954c into main Aug 30, 2026
267 checks passed
@steipete
steipete deleted the codex/cloud-input-admission branch August 30, 2026 02:19
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 30, 2026
* fix: preserve cloud turns when follow-up input arrives

* test: align session admission fixtures and checks

* fix: refresh accepted input during active cloud turns

* test: use complete page state for pending input events

* fix(ui): keep live tool echoes with their canonical invocation

* docs: clarify durable pending input coverage

* fix(ui): read canonical run identity for tool activity

* test: publish process readiness after signal setup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: 🐚 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.

Cloud follow-up admission advances the transcript beneath an active worker turn

1 participant