Skip to content

fix: resume cloud-worker fallbacks from committed history - #177477

Merged
steipete merged 5 commits into
mainfrom
steipete/cs-161211-1019
Oct 19, 2026
Merged

steipete merged 5 commits into
mainfrom
steipete/cs-161211-1019

Conversation

@steipete

@steipete steipete commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #161211

What Problem This Solves

A cloud-worker fallback can reuse the original admission leaf after the failed candidate committed output, causing stale-base-leaf. Recorded first attempts also need to avoid a redundant full transcript read.

User Impact

Fallback continues from committed assistant/tool output and its accompanying runtime context. Ordinary first attempts use one transcript read. Foreign output, user messages, unrelated custom messages, and non-message entries retain the admission fence. No configuration or migration is required.

Why This Change Was Made

The worker input owner carries the full source version already captured by the fenced model-context read. When its sequence matches the admission, it skips the unfenced read without another lookup or cache. Later writes still face the strict commit check; a metadata-only append can conservatively trigger a suffix read.

When the source has advanced, the fallback accepts only assistant/tool-result rows explicitly owned by this run, plus untagged openclaw.runtime-context and openclaw.system-update messages. At least one owned output row is required. Any foreign run ID, user message, unrelated custom type, or other entry type rejects the suffix. Transcript commit checks are unchanged.

Custom context rows retain their original metadata. The earlier attempt to tag them globally was reverted because replay and prompt selection also consume run ownership. The exception now lives solely in the worker fallback predicate.

The regression exercises the real fallback runner, launcher, wire projection, and transcript committer with a fake failing worker. It keeps error-only, tool-result, and both runtime-context variants, verifies the one-open common path, and covers rejected suffixes. Wire fixtures use the production projection and typed agent messages without casts. The final diff from the original PR base is +59/−7 production lines, +213/−7 test lines, and +5 documentation lines. This follow-up is +119/−68 across four files.

Evidence

The performance acceptance rule was recorded before measurement: an ordinary recorded first attempt must perform exactly one model-context open, with no added metadata lookup. The two admission fixtures measured 2 opens before and 1 after; both assertions remain in the regression.

  • Original failure: both fallback variants reproduced stale-base-leaf on 11d0c854192 (72.04 s wall).
  • CI regression reproduced on 760a549b3ef: the hidden-system-context test observed the extra __openclaw field (154.23 s wall).
  • Requested local rerun: pnpm test src/gateway/worker-environments/transcript-commit.test.ts src/agents/embedded-agent-runner/run/attempt.settled-turn-finalization-context.test.ts test/gateway-openai-compaction-replay.e2e.test.ts src/gateway/worker-environments/worker-turn-detached-context.test.ts --maxWorkers=1 took 1718.00 s wall, including 21m 33.8s preparing the E2E runtime. The hidden-context and fallback files passed 41/41 (115.78 s Vitest duration); the finalization file had 2 passed, 1 failed (81.11 s). The wrapper stopped before E2E.
  • Separate pnpm test test/gateway-openai-compaction-replay.e2e.test.ts --maxWorkers=1: 64.26 s wall, one failure at line 102 (continuation text occurs twice, expected once).
  • The finalization failure is inherited: with both PR runtime files restored to exact pre-PR 11d0c854192 contents, the same assertion failed (50.01 s wall, 2 passed, 1 failed). Main already repairs that stale expectation in 248aa9a5f678, preserving the hidden internal_system prompts required by fix: rate-limited runs lose the prompt cache on retry #177050. No unrelated test or prompt behavior was changed here.
  • The Gateway replay failure is also inherited: rebuilt the Gateway with both PR runtime files restored to exact pre-PR 11d0c854192 contents, then reran the same E2E. It failed at the same line 102 with the same expected-2/actual-3 signature (276.94 s wall, including 3m 47.7s runtime build). Both temporary baseline substitutions were restored exactly afterward. The failing replay expectation remains unresolved here; no assertion was weakened.
  • Restored ownership helper: pnpm test src/sessions/transcript-events.test.ts --maxWorkers=1 passed 17/17 (3.75 s wall).
  • Gateway test types: node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.gateway-other.json --incremental passed (9.71 s wall). This includes the previously failing fixture lines.
  • pnpm run tsgo:core passed (12.54 s); type-aware lint via node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json passed (101.50 s, including artifact-lock wait). Oxfmt and git diff --check passed.
  • node --import ./scripts/tsx.mjs scripts/check-test-mock-exports.mts passed: 8,220 grandfathered factories (88.06 s wall). No baseline entries were changed.
  • The environment warning is inherited: this branch and origin/main at d8bcebf445ec both contain 460 production OPENCLAW_* names against a budget of 452. This PR adds none; the budget is unchanged.
  • Independent isolated Codex autoreview: scoped-clean through P2 on this follow-up; no actionable findings. The follow-up removes global custom-row tagging and keeps the exception solely at worker fallback selection.
  • Retained performance proof: 60 worker-boundary and durable/admitted/incognito session-manager tests passed (332.30 s wall).
  • These results do not claim a green full suite. Final-head PR CI is pending; no live cloud/provider flow was run. The worker transport is synthetic and uses the real fallback/launcher/committer boundary.

@clawsweeper

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

@steipete
steipete marked this pull request as ready for review October 19, 2026 16:25
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T18:04:51.603097Z c6d5afd New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Oct 19, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 486e5b1ff5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +205 to +208
suffix.every(
(entry) =>
entry.type === "message" && readSessionTranscriptRunId(entry.message) === turn.runId,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Handle worker runtime-context rows when resuming fallbacks

On normal non-raw cloud-worker turns, the worker persists an openclaw.runtime-context or openclaw.system-update custom message before the assistant output, but attachSessionTranscriptRunId deliberately adds run ownership only to assistant and tool-result messages. Consequently this predicate rejects the otherwise same-run suffix, leaves baseLeafId at the original admission, and the fallback's next transcript commit still fails with stale-base-leaf—the regression test misses this because it manually commits only assistant/tool-result rows. Account for these worker-owned custom rows, or persist sufficient run ownership on them, when selecting the fallback base.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 19, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M and removed size: S labels Oct 19, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Landing note for head c6d5afde891e: the only failing checks are inherited from main, not caused by this PR.

  • check-docs runs pnpm format:check, which fails only on src/agents/tools/nodes-tool-media.ts. This PR does not touch that file (changed files: docs/concepts/model-failover.md, src/agents/sessions/session-manager.ts, src/gateway/worker-environments/worker-turn-user-message.ts, and its test); it arrived with the main merge.
  • checks-node-changed-14: test/gateway-openai-compaction-replay.e2e.test.ts ("replays persisted provider state on the next embedded turn", expected length 2, got 3) reproduces locally with all of this PR's runtime changes removed (276.94 s run), so it is a pre-existing main failure.

All other required checks are green, the fallback, hidden-context and one-read regressions pass, and Codex autoreview is clean. Landing via the inherited-failure admin exception.

@steipete
steipete merged commit cf4c7b5 into main Oct 19, 2026
131 of 135 checks passed
@steipete
steipete deleted the steipete/cs-161211-1019 branch October 19, 2026 18:12
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 20, 2026
…ory (openclaw#177477)

A failover-eligible model error on a cloud-worker turn relaunched the fallback candidate on the original admission base, but the first candidate had already committed its own output under the same run id, so every fallback failed with stale-base-leaf. When the transcript advanced past the admitted entry (checked against the fenced read's snapshot watermark, so normal first attempts still do one transcript read), the fallback now continues from the current leaf if the suffix is entirely this run's assistant/tool-result output plus untagged runtime-context/system-update rows. Any foreign run's rows or user message keep the strict admission fence.

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

Labels

agents Agent runtime and tooling clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloud-worker model fallback relaunches on the admission base and fails with stale-base-leaf

1 participant