Skip to content

fix: worker reply corrections repeat stale live text - #131869

Merged
steipete merged 2 commits into
mainfrom
steipete/nice-lamarr-fef0a7
Aug 28, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/nice-lamarr-fef0a7

Conversation

@steipete

@steipete steipete commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #131867

What Problem This Solves

Fixes an issue where users watching worker-turn replies would see stale text or repeated fragments when an authoritative assistant snapshot corrected, shortened, or bounded an earlier preview. Empty final snapshots could also leave a discarded draft visible.

Why This Change Was Made

Worker snapshots are per assistant message, while Gateway live chat is cumulative across the run. The producer now supplies stable message identity through the existing itemId field, and the Gateway replaces only that message's contribution while retaining the bounded completed prefix. Simply forwarding replace or adding text-overlap deduplication would erase pre-tool text or legitimate repeated messages.

The producer reconciles late/mixed commentary before deriving both snapshots and deltas. Empty clears reach the chat broadcast. Native Codex provisional replacement and local TUI unkeyed merging retain their existing contracts; transcript persistence, worker authority, and workspace reconciliation still own their existing boundaries. No protocol, configuration, SQLite schema, dependency, or public SDK surface is added.

Removed duplicate completion-only emission and unused broadcast-length state. Test-only socket fixtures now use short paths and listen for the WebSocket server's forwarded bind errors, avoiding macOS path-limit setup hangs. The chat adapter is isolated in a test-support module without adding a production test seam or lint suppression.

Source provenance: worker runtime foundation, 6cd11338588e3dc520b9b38d34312948c84f1608, 2026-07-13; code author and merger @steipete. Stable-release regression status is not established.

User Impact

Corrected, shortened, empty, and bounded worker previews update the current message without replaying earlier text. Intentional pre-tool prose and distinct identical messages remain visible. Late commentary is excluded from answer text, and a later workspace-reconciliation failure still reports an error rather than premature success.

The source documentation for Cloud workers explains the snapshot and durability boundaries. AI-assisted with Codex.

Evidence

  • Red proof: 15 composed boundary regressions failed against unchanged production. For example, expected Before tool\nRevised, received Before tool\nDraft with stale suffixRevised; an empty final retained the draft. Two additional producer-delta tests failed before their corresponding refinements.
  • Boundary: actual worker live producer → client → local WebSocket/admission → receiver → agent bus → createAgentEventHandler, with synthetic provider/session input. The final suite contains 17 regressions covering repeated legitimate messages, repeated completion, late/mixed phases, Unicode byte bounds, capped-prefix retirement, missing previews, out-of-order requests, and ACK replay.
  • Focused local validation: 461 passing snapshot-owner/sibling tests on the earlier rebased head 59e44c27146889e1c6dcd397423dbeeacdccd705 (production bytes unchanged by the test repair) across owner and sibling runs, including worker runtime/fault injection, Gateway event merging, cleanup, launcher terminal results, and native Codex. This includes all 17 composed projection cases, 72 worker tests, 367 Gateway tests (including the current-main reload fixture), and 22 Codex projector tests. The earlier selected local TUI run passed 7 cases.
  • Local gate: node scripts/check-changed.mjs passed, including production/core-test types, scoped lint, formatting, dependency/architecture guards, dead exports, and import cycles. Fresh branch-mode Codex autoreview of the complete new head against pinned main, plus precommit review of the canonical fixture repair, reported no actionable P0 findings.
  • Dependency contracts: directly inspected upstream Codex at d65d31593926f26bc6dd030240bc009be87ef75d, including event_mapping.rs:362-418, item-scoped deltas and authoritative completion; inspected ws bind-error forwarding directly.
  • Size: production +90/-37 (net +53). The growth is the missing message-scope and bounded-prefix ownership plus phase-aware snapshot/delta normalization; the unkeyed merger remains necessary for current Codex/TUI callers. Tests/support +453/-51 (net +402), including the reused fixture repair; docs +2/-0.

Current head: e0399babb4881eabb242a00c39baaa01879dd2bd (snapshot commit plus canonical test repair), original rebase base: 11a491beccfd4f52a9b0e8e605e61457265a943c. The only rebase conflict retained main’s stronger reload fixture unchanged, so that file is absent from this PR.

Validation retry: an initial broad run and an isolated maintenance case timed out during module import on a heavily loaded host. Temporary diagnostic checkpoints localized the delay to import and then passed; they were removed. The original focused command subsequently passed on unchanged committed bytes, with no timeout, assertion, mock, or runtime changes. The changed gate also passed.

CI fixture repair: the first hosted attempt and an additional local diagnostic exposed a real test contract defect: the host-denial fixture treated the first 1.5-second Code Mode slice as terminal. Reused the isolated canonical test commit from #131866, e76dd81421492eb7de46dcce402efa9bd988f3af, without its macOS workflow change. Terminal assertions now resume the original run through the existing bounded public-wait helper; they never replay the command. The deterministic host-repair case exhausts the unchanged budget after real command completion and verifies one wait, one hook, one spawn, and exact output. Raw parked, late-settlement, cancellation and approval assertions remain. Grouped host-denial/lifecycle/bridge verification passed 82 tests on the committed repair bytes; scoped core-test types, lint, formatting, architecture and export gates passed. Fresh precommit Codex autoreview reported no actionable findings. No Code Mode production behavior or execution budget changed.

Hosted CI: current head e0399babb4881eabb242a00c39baaa01879dd2bd passed CI 33190487790 on attempt 1, including required gate job 98917967212 and the repaired Code Mode shard 98914790463. The unmodified native hosted-gate verifier passed with this exact-head CI and Workflow Sanity 33186279701 from the earlier same-PR head through its supported recent-cohort rule; both committed heads have identical workflow/native tooling. Current Workflow Sanity retry 33190487776 remains pending/stalled; it is not claimed as passed. Parent reviewed and approved the current committed patch. Earlier snapshot head 59e44c27146889e1c6dcd397423dbeeacdccd705 passed run 33186321002 on attempt 2, but retry-green was not treated as resolving the fixture defect. The fixture defect was repaired before the current first-attempt green run.

ClawSweeper disposition: no introduced functional or security finding. The +53 production lines establish active-message/prefix ownership inside the canonical projector; the existing unkeyed branch protects current Codex/TUI callers, not an alternate worker replacement path. Direct inspection of main at c17d442a6e2121bf2f4edb5d6c1397d6e45cf84c found the four production owners and worker fixture unchanged from the tested base, resolving the reviewer's unavailable-blob gap. The later Codex-contract rank-up is also verified directly at the pinned upstream revision: turn.rs:2554-2580 derives deltas from active item identity; bespoke_event_handling.rs:979-1033 relays canonical completion; README:1587-1636 specifies item lifecycle and authoritative completion. The existing unkeyed Codex/TUI path remains unchanged. Its storage detector is a false positive: no durable schema, migration, retention, or storage semantics change. The latest review at 2026-08-28 16:39 UTC has no actionable findings. Its three pre-merge moves are addressed: parent accepted the canonical scope/LOC justification, direct current-main evidence is recorded, and exact-head required CI is green. No repair dispatch is needed. Live/visual proof remains intentionally unavailable under the scope below.

Primary reproduction: node scripts/run-vitest.mjs src/gateway/worker-environments/live-chat.test.ts.

Rebased focused verification:

node scripts/run-vitest.mjs src/gateway/worker-environments/live-chat.test.ts src/gateway/server-chat.agent-events.test.ts src/gateway/server-chat.stream-text-merge.test.ts src/gateway/worker-environments/live-events.test.ts src/gateway/worker-environments/worker-turn-launcher-terminal-results.test.ts src/gateway/chat-abort.test.ts src/gateway/server-close.test.ts src/gateway/server-maintenance.test.ts src/gateway/server-reload-channel-restart.test.ts src/worker/worker.fault-injection.test.ts src/worker/embedded-agent-live.runtime.test.ts src/worker/worker.runtime.test.ts extensions/codex/src/app-server/event-projector.assistant.test.ts
node scripts/check-changed.mjs
node scripts/run-vitest.mjs src/agents/code-mode.bridge.host-denial.test.ts src/agents/code-mode.bridge.lifecycle.test.ts src/agents/code-mode.bridge.test.ts

Proof limits: No live provider, live cloud machine, browser/Control UI, or operator Gateway flow was run. Browser/remote Gateway control and media uploads were explicitly outside the authorized scope; the proof above is deterministic local socket/service behavior, not live authenticated or visual proof. The separate persisted/live overlap issue and its earlier malformed-fragment recording are not attributed to this defect without raw payload evidence.

@clawsweeper

clawsweeper Bot commented Aug 28, 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 gateway Gateway runtime size: L maintainer Maintainer-authored PR labels Aug 28, 2026
@steipete
steipete marked this pull request as ready for review August 28, 2026 15:40
@clawsweeper clawsweeper Bot added 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 Aug 28, 2026
@clawsweeper

clawsweeper Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 28, 2026, 12:39 PM ET / 16:39 UTC.

ClawSweeper review

What this changes

The PR gives worker live assistant snapshots a stable message identity so Gateway chat replaces corrected, shortened, and empty previews without replaying earlier text.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open: current main still matches the PR base on the affected production owners, while this branch supplies the missing per-message replacement scope. It is maintainer-authored and carries a maintainer label; exact-head checks and parent review remain.

Priority: P2
Reviewed head: e0399babb4881eabb242a00c39baaa01879dd2bd

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has a coherent owner-boundary repair and strong composed regression coverage, with exact-head checks still required before landing.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This maintainer-authored PR is exempt from the external contributor proof gate; its composed production-boundary evidence was reviewed as supplemental validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external contributor proof gate; its composed production-boundary evidence was reviewed as supplemental validation.
Evidence reviewed 5 items Existing protocol identity: The worker live assistant payload already permits a bounded nonempty item identifier; the PR consumes this existing field rather than changing the protocol.
Producer and projection owner: The worker assigns an identity per assistant-message lifecycle and Gateway retains the completed prefix when that identity changes, allowing the current snapshot to replace only its own contribution.
Current-main necessity: Fetched current main is unchanged from the pinned PR base for the affected live-preview production owners, so the repair is not already present there.
Findings None None.
Security None None.

How this fits together

Worker runtime streams assistant previews to the Gateway over the worker live-event service. Gateway chat projection turns them into visible updates while transcript persistence remains a separate durable path.

flowchart LR
  A[Worker assistant events] --> B[Worker live-event client]
  B --> C[Gateway live-event receiver]
  C --> D[Gateway chat projector]
  D --> E[Active assistant scope]
  E --> F[Visible chat update]
  C --> G[Durable transcript path]
Loading

Before merge

  • Resolve merge risk (P1) - Worker/Gateway preview replacement semantics are compatibility-sensitive, and exact-head checks are still in progress.
  • Resolve merge risk (P1) - The bug fix adds 53 net production lines; the message-scope state is source-justified, but parent review should confirm it remains the canonical owner.
  • Complete next step (P2) - Exact-head checks and parent review remain required; no narrow automated repair is indicated.
Agent review details

Security

None.

PR surface

Source +111, Tests +344, Docs +2. Total +457 across 16 files.

View PR surface stats
Area Files Added Removed Net
Source 7 152 41 +111
Tests 8 391 47 +344
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 545 88 +457

Review metrics

Metric Value Why it matters
Production versus test delta production +53 net; tests and support +402 net; docs +2 The added state tracks active-message ownership and is covered by a composed production-boundary regression suite.

Stored data model

Persistent data-model change detected: durable storage schema: src/gateway/worker-environments/live-chat.test-support.ts, durable storage schema: src/worker/embedded-agent-live.runtime.ts, durable storage schema: src/worker/worker-fault-injection.test-support.ts, unknown-data-model-change: src/worker/embedded-agent-live.runtime.ts, unknown-data-model-change: src/worker/worker-fault-injection.test-support.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #131867
Summary: This PR is the explicit candidate repair for the canonical worker live-preview defect.

Members:

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

Merge-risk options

Maintainer options:

  1. Complete exact-head validation (recommended)
    Wait for required checks on the current head and review the active-message scope as the canonical compatibility boundary before merge.

Technical review

Best possible solution:

Land the scoped Gateway projection after exact-head validation confirms the composed worker-to-Gateway replacement cases and parent review accepts the bounded active-message state.

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

Yes, in source: the old cumulative merge appends a non-prefix worker snapshot delta, and the added composed test exercises the correction and empty-replacement order. This read-only review did not execute the suite.

Is this the best way to solve the issue?

Yes. The existing worker protocol already carries item identity, and holding the completed prefix beside the active identity at the Gateway projector avoids a competing worker-specific merge path.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: The PR repairs incorrect but non-crashing worker live-reply rendering.
  • merge-risk: 🚨 compatibility: Existing worker live snapshots will be merged under new replacement semantics after merge.
  • 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. Not applicable: This maintainer-authored PR is exempt from the external contributor proof gate; its composed production-boundary evidence was reviewed as supplemental validation.

Evidence

What I checked:

Likely related people:

  • steipete: History attributes the cloud-worker runtime foundation and later worker live-preview maintenance to this contributor. (role: feature owner and recent area contributor; confidence: high; commits: 6cd11338588e, 9ed96868ebf0, 459c70e14a2c; files: src/worker/embedded-agent-live.runtime.ts, src/gateway/server-chat.ts, src/gateway/live-chat-projector.ts)
  • weiqinl: Current history includes a recent agents/workspace change touching the worker and Gateway live path. (role: recent adjacent contributor; confidence: medium; commits: a61cfc1fd3aa; files: src/worker/embedded-agent-live.runtime.ts, src/gateway/server-chat.ts)

Rank-up moves

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

  • Let the exact-head required checks complete.
  • Obtain parent review of the compatibility-sensitive active-message scope.

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-08-28T15:58:41.413Z sha 59e44c2 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-28T16:17:58.992Z sha 59e44c2 :: needs maintainer review before merge. :: none

@steipete steipete self-assigned this Aug 28, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Aug 28, 2026
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Aug 28, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready at e0399babb4881eabb242a00c39baaa01879dd2bd; parent review approved this exact committed patch.

CI 33190487790 passed on attempt 1, including required gate 98917967212 and repaired Code Mode shard 98914790463. The unmodified native hosted-gate verifier accepts that exact-head CI plus Workflow Sanity 33186279701 from the earlier same-PR head 59e44c27146889e1c6dcd397423dbeeacdccd705 through its normal recent-cohort rule. Workflow/native-tooling bytes are identical between those heads. Current Workflow Sanity retry 33190487776 is still pending/stalled, not passed; no lint enforcement or verifier policy was changed.

Proof commands:

node scripts/run-vitest.mjs src/gateway/worker-environments/live-chat.test.ts
node scripts/run-vitest.mjs src/agents/code-mode.bridge.host-denial.test.ts src/agents/code-mode.bridge.lifecycle.test.ts src/agents/code-mode.bridge.test.ts
node scripts/check-changed.mjs
node scripts/check-changed.mjs -- src/agents/code-mode.bridge.host-denial.test.ts src/agents/code-mode.bridge.lifecycle.test.ts src/agents/code-mode.test-support.ts
node scripts/verify-pr-hosted-gates.mjs --repo openclaw/openclaw --sha e0399babb4881eabb242a00c39baaa01879dd2bd --pr 131869 --output .artifacts/pr-131869-hosted-gates.json

The 17 composed snapshot cases pass within 461 owner/sibling tests; the unchanged production is also covered by current-head CI. The canonical test-only continuation repair from #131866 (e76dd81421492eb7de46dcce402efa9bd988f3af) passes 82 grouped tests, retains real public wait resumption, and preserves one hook/spawn/output assertions. It fixes the original failed first-slice assumption rather than accepting retry-green. Fresh precommit and branch Codex autoreviews were clean at the configured P0 threshold.

ClawSweeper's three pre-merge moves are addressed: parent accepted the canonical message-scope/prefix/phase ownership and justified +53 production LOC; direct main inspection at c17d442a6e2121bf2f4edb5d6c1397d6e45cf84c found no affected-owner drift; required exact-head CI is green. Tests/support are +402 net, docs +2. The stored-data warning is a false positive: no DDL/schema/migration/persistence change, only process-local state and existing wire itemId.

No live provider, remote Gateway, browser/Control UI, or visual proof was run because the operator explicitly excluded those flows and media uploads. Composed local socket/service tests are not represented as live or visual proof. No uncommitted tooling investigation is included. Proceeding with normal OPENCLAW_TESTBOX=1 scripts/pr prepare-run 131869 and scripts/pr merge-run 131869.

@steipete
steipete merged commit 2f7d141 into main Aug 28, 2026
247 of 249 checks passed
@steipete
steipete deleted the steipete/nice-lamarr-fef0a7 branch August 28, 2026 17:42
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

agents Agent runtime and tooling 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. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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.

[Bug]: Worker reply corrections append to stale live text

1 participant