Skip to content

fix: user turns fail when the runtime changes during preparation - #185573

Merged
steipete merged 4 commits into
mainfrom
codex/retry-superseded-runtime-generation
Oct 27, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/retry-superseded-runtime-generation

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

User turns can fail when a plugin or model runtime is replaced during preparation. A stale reply-dispatch selection can reject the turn before execution, and auth refresh can stop after another publication supersedes its first fresh-generation retry. Automatic config reloads also log a terminal failure while admitted plugin work is still settling.

User Impact

Unpinned preparation retries once against the current generation. A stale reply-dispatch pin is dropped only before execution. Executing turns and nested work keep their admitted generation; model/tool execution is never replayed. Auth publication retries supersession on up to two fresh generations, then fails visibly and retains catalog recovery for a later read. Other auth lifecycle failures retain their existing one-retry bound.

Automatic reload keeps its bounded failed writer receipt, then retries the saved configuration after admitted plugin work and cleanup settle. Keeping that receipt open could deadlock a writer that itself holds admitted work. Explicit lifecycle requests retain bounded errors. Work that never settles leaves the saved configuration pending while the previous runtime serves.

Why This Change Was Made

Retry belongs at preparation admission, before execution has effects. Reload deferral belongs at the automatic reload owner after rollback and writer settlement. The previous automatic retry observer is removed from the shared application path. Duplicate candidate cleanup in an inner finally is removed because the outer finally owns the same cleanup on every exit; no line cap or baseline is changed.

Evidence

CI is the behavioral proof channel because the loaded local host did not reach Vitest assertions and the supported remote route failed during setup. Neither setup failure is counted as red evidence. Local validation is limited to touched-file formatting/lint and the production, agents-other, and gateway-root typecheck lanes.

Test-only head 7cb8b029b90ab4cc969d5498ac3bddd194d840cd, run 40464146623:

  • checks-node-changed-1: preparation, auth, and reply regressions fail at assertions. The reply test rejects with the superseded-generation error instead of completing its reply, before execution.
  • checks-node-changed-compact-large-45: Node and Bun reach settlement, then fail because reload emits error logs instead of deferral.
  • The first reload fixture attempt in run 40461643245 failed setup and is excluded; that run independently demonstrated preparation/auth assertion failures.

Baseline check-dependencies reports an unlisted uptime invocation in scripts/perf/local-workspace-manifest-measure.ts, unused encodeLocalWorkspaceTreePacks / LocalWorkspaceTreePack exports in src/gateway/worker-environments/local-workspace-cas.ts, and three unused perf scripts (chat-history-response-page-measure.mjs, system-prompt-request-measure.ts, worktree-index-metadata-measure.ts). These source files and Knip configuration are unchanged from the base; this is inherited dead-code inventory debt, not an installation or registry failure. No dependency/baseline change is included.

P1 autoreview on production head 3528393e652f648627369cd463694bed22c83aaf completed with scoped-clean status and no accepted/actionable findings. Implementation run 40466480856 passed the preparation, reply, and reload regressions. The exhausted-auth case reached its later recovery assertion, where its mock returned an already-retired registry. The fixture now returns fresh registries unless explicit reuse is requested, matching the production uncached acquisition boundary; assertions and retry bounds are unchanged. That run also reproduces the test-only baseline worker-turn context-engine failures (extra reconcile event in direct/outer ownership cases). Final-head CI results are recorded below. Test-only CI file durations were 4.64s for leases, 11.34s for auth recovery, and 5.65s for reply fallback; actual test execution remained under five seconds per file. Local wall-time measurements are unavailable under the coordinator's CI-only behavioral-proof instruction.

P1 autoreview of the final three-line fixture commit 5f7f1f1cab39d57ad06a502b23f7c43e5f6cd0b4 also completed with scoped-clean status. Both reviews used the canonical helper with --max-priority P1, TMPDIR from getconf DARWIN_USER_TEMP_DIR, and TMP/TEMP unset.

The whole PR changes 11 files (+294/-58, net +236): production +113/-47 (net +66), tests +166/-5 (net +161), docs +15/-6 (net +9). The reload case reuses the existing 145-test shared Gateway suite; its candidate execution was 256ms. That suite's cold baseline duration was 118.04s on Node and 48.92s on Bun; no new per-test Gateway boot was introduced.

Final-head CI

Head: 5f7f1f1cab39d57ad06a502b23f7c43e5f6cd0b4. Run 40468097614 is terminal: failure, with one inherited failing test shard. All newly added regressions pass in the CI-selected Bun lane.

Check / behavior Result
Preparation supersession and bounded retry PASS, including ordinary-error propagation
Reply dispatch after captured generation replacement PASS
Auth supersession, exhaustion, and later recovery PASS; containing group 166/166 tests
Reload deferral after work and cleanup PASS
Production/test types, lint, guards, ratchets, docs, prompt checks, security-fast PASS
Worker context-engine direct/outer ownership FAIL: extra reconcile event; identical assertions fail in unchanged test-only run
Required openclaw/ci-gate FAILURE from the inherited worker-context tests

No rerun, suppression, cap/baseline adjustment, or unrelated worker/dependency repair was used. Final Node behavioral and live Gateway/model proof were not selected/run; local Vitest remains excluded by the coordinator's CI-only instruction. Ready for coordinator review; not merged.

@clawsweeper

clawsweeper Bot commented Oct 27, 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 gateway Gateway runtime agents Agent runtime and tooling size: S labels Oct 27, 2026
@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. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR adds regression coverage for runtime replacement during turn preparation, auth refresh, reply dispatch, and config reload.

Example: A config publication changes responsePrefix from "before" to "after" while a turn's runtime is preparing.

  • Before: Admission can reject with a superseded-runtime error.
  • After: The new test expects admission to retry against the current config; production behavior is unchanged in this head.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Relevant, focused regression staging with no discrete introduced bug found; implementation and assertion-level validation remain incomplete.
Proof confidence 🦪 silver shellfish (2/6) This maintainer-authored, tests-only draft changes no shipped behavior, so the ordinary contributor runtime-proof gate does not apply to this head.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: A user turn can fail before execution when a concurrent runtime publication replaces the generation being prepared.
Reason: The maintainer-authored direction addresses a concrete owned failure while retaining the established distinction between unfinished preparation and admitted execution.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this maintainer-owned draft open: the regressions address a current preparation failure, but this head does not implement the intended fix.

Priority: P2
Reviewed head: cedc38df3deb4fb0d6f9f14598f7d82b055927fe

Before merge

  • Complete next step - Implement the intended repair in the existing admission, reply-dispatch, auth-publication, and reload owners.

Findings

None.

Tests

  • Missing end-to-end proof: The new regressions have no verified assertion-level red/green result, and this head contains no production fix to exercise end to end.
Agent review details

How this fits together

Gateway and reply admission acquire prepared model runtimes from shared lifecycle owners, which coordinate config publications, credentials, plugin generations, and retained execution leases.

flowchart TD
  A[User turn] --> B[Gateway or reply admission]
  B --> C[Prepared runtime lease owner]
  D[Config and auth publications] --> C
  C --> E[Retained plugin generation]
  E --> F[Reply execution and nested work]
Loading

Technical review

Best possible solution:

Use the existing runtime owners to retry unfinished admission once while preserving admitted generations, bounded auth recovery, and deferred reload settlement.

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

Current source directly rejects superseded preparation and stale captured dispatch generations; no assertion-level execution of the new regressions was verified.

Is this the best way to solve the issue?

The tests target distinct lifecycle boundaries and reuse existing fixtures, but the production repair must be reviewed before its completeness or safety can be established.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Deferred reload regression and diagnostics changes intended behavior with a stated reason (4b17ae2: test(gateway,cli,feishu): remove low-value tests (batch d409) #179934 consolidated test scaffolding while retaining lifecycle and error-path coverage; the base case already checked retry after work and cleanup settled.)
  • Retained-generation execution contract keeps the original intent (55ac0be: Matching nested work must borrow its still-open parent lease so replacement can drain it without rejecting the work needed to finish.)

Testing

Proof path: none.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 76a477e adds src/agents/prepared-model-runtime.reply-fallback.test.ts:171 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 76a477ed09bd; files: src/agents/prepared-model-runtime.reply-fallback.test.ts)
  • Patrick Erichsen: Raw commit 03088a9 adds src/agents/prepared-model-runtime.reply-fallback.test.ts:84 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 03088a97195d; files: src/agents/prepared-model-runtime.reply-fallback.test.ts)

PR surface

Tests +157. Total +157 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 4 161 4 +157
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 161 4 +157

Labels

Label changes:

  • add P2: Runtime replacement can reject a preparing turn, but the evidence does not establish a broad outage or urgent released regression.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Runtime replacement can reject a preparing turn, but the evidence does not establish a broad outage or urgent released regression.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 27, 2026, 2:46 AM ET / 06:46 UTC.

Retry unpinned preparation on the current generation before execution while preserving admitted generations for running and nested work. Bound auth publication retries and defer automatic reloads until admitted plugin work and cleanup settle.
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M and removed size: S labels Oct 27, 2026
@steipete
steipete marked this pull request as ready for review October 27, 2026 07:19
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-27T07:22:56.504522Z 3528393 Draft marked ready
ℹ️ 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.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 5f7f1f1cab39d57ad06a502b23f7c43e5f6cd0b4
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/prepared-model-runtime-auth-publication.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@steipete
steipete merged commit a59112f into main Oct 27, 2026
134 of 138 checks passed
@steipete
steipete deleted the codex/retry-superseded-runtime-generation branch October 27, 2026 08:49
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…nclaw#185573)

* test: cover runtime replacement during turn preparation

* test: provide persisted hashes for reload deferral proof

* fix: retry runtime preparation superseded before execution

Retry unpinned preparation on the current generation before execution while preserving admitted generations for running and nested work. Bound auth publication retries and defer automatic reloads until admitted plugin work and cleanup settle.

* test: acquire fresh registries for auth recovery proof
RomneyDa added a commit that referenced this pull request Oct 28, 2026
…5573)

* test: cover runtime replacement during turn preparation

* test: provide persisted hashes for reload deferral proof

* fix: retry runtime preparation superseded before execution

Retry unpinned preparation on the current generation before execution while preserving admitted generations for running and nested work. Bound auth publication retries and defer automatic reloads until admitted plugin work and cleanup settle.

* test: acquire fresh registries for auth recovery proof

(cherry picked from commit a59112f)

Co-authored-by: RomneyDa <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 29, 2026
…s lane FRV tests (#187567)

* docs(secrets): include Beam mirror token in credential matrix

(cherry picked from commit dfa7774)

* test(infra): supply versions list in astral ClawHub detail fixture

The backport of #182753 (74e414a) dropped the versions: { items: [] }
default that main's readDetail helper supplies, so the release-branch
fixture fails the versions response guard.

* test(web-search): carry #179703 envelope bound into release security test

Main's 47c1c2a raised the aggregate JSON envelope bound from 22,000 to
23,000 because rows now keep their titles and site names (more wrap
envelopes); the 20,000-char untrusted content cap is unchanged. The release
backport 2b35452 put the new tests in web-search-budget.test.ts and
missed this assertion in the release-only security test file.

* test(auto-reply): expect preserved multiline /side input in registry test

Backport 9b93c22 (#176293, main d7359a7) intentionally preserves
multiline /btw, /side and /loop arguments. The release-only registry test
still asserted the old first-line truncation for /side; main no longer has
that assertion.

* test(pdf): hold a Codex OAuth login in the ChatGPT PDF fixture

Backport f41ea65 (#181356, main f64e38f) intentionally resolves a
ChatGPT catalog row with only an API key as stale, routing it to the Platform
contract. Port main's matching fixture update from 280c7c7 (shipped
inside an unrelated visitor-access commit) so the test exercises the Codex
subscription route it names.

* test(auto-reply): expect agent inventory workspace for reply runtime

Release backports 23e702a (#185573) and 59b6c10 (main 786cfd7)
together adopt #185512's design: replies prepare the configured agent
inventory workspace (preserveWorkspaceDirOnRefresh: false) and nested runs
borrow it, while the reply workspace stays the execution boundary. Main's
copy of this test no longer asserts the acquire input (db8180b).

* test(agents): expect unverifiable stateless reasoning to be omitted

Backport c93fe0b (#185774, main 86ddabd) intentionally stops
replaying reasoning that has neither a replay ID nor authorized encrypted
state when store is disabled. Main removed this test earlier (542e074);
the release copy still expected the unverifiable item.

* fix(plugins): allow retained registrations on reused inspections

Catalog scope growth can reuse the same physical registry inspection. Keep
its already-owned registrations in place instead of transferring them into
their own resource map and failing with a duplicate-custody error.

Preserve live-owner validation and all distinct-inspection transfer and
disposal behavior. Extend the resource-backed lifecycle regression with
self-adoption before abandoned growth and promotion.

Proof: regression fails on unchanged production; fixed resource lifecycle
and all seven selected catalog cases pass. Targeted native types, typed
lint, format, suppression tests, runtime/static cycles and planner pass.
Independent review found no actionable P0-P2 findings.

(cherry picked from commit 52df852)

* test(agents): seed the worker catalog in the isolated-completion owner test

Backport 0c77c1d (#182952, main 4c3bf18, which shipped no test)
carried a test adapted from another line that seeded discovered rows only
through the in-process catalog builder. On this branch Gateway-configured
agents load their full catalog through the catalog worker, so the setup never
saw the row and the test failed from the commit that added it. Seed the worker
mock too and match the row by its own fields (the catalog adds provenance).
Verified: the test fails at the lease assertion when #182952's
runtimePluginPurpose normalization is removed and passes with it.

---------

Co-authored-by: Peter Steinberger <[email protected]>
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 P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. security-sensitive-changed size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant