Skip to content

fix(gateway): settle live fixtures before Codex reconnects - #128965

Merged
steipete merged 4 commits into
mainfrom
fix/prepared-runtime-continuation-race-retry-20260824
Aug 25, 2026
Merged

steipete merged 4 commits into
mainfrom
fix/prepared-runtime-continuation-race-retry-20260824

Conversation

@jalehman

@jalehman jalehman commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Related: #127710

What Problem This Solves

Fixes an issue where release validation could connect a Codex backend before the Gateway had finished mandatory sidecar startup, producing fixture-induced missing prepared-runtime failures during initial connection or restart/resume checks. The same live fixtures also serialized retired per-agent default markers and therefore exercised migration code instead of the canonical keyed-agent configuration.

Why This Change Was Made

Codex live validation now awaits the Gateway-owned startupSettled promise after every start and before each client connection. All remaining serialized live Gateway configs use keyed agent entries without retired default markers. The already-landed CLI fixture slice is no longer part of this branch, and no production runtime behavior changes.

User Impact

Maintainers can trust the affected release checks to validate prepared-runtime publication and restart/resume behavior rather than fixture startup races or legacy config normalization. This PR does not claim to fix the separate production race discussed in #127710.

Evidence

  • Immutable failure: release checks run 32766198480 recorded a real Codex child as succeeded while parent delivery remained pending with the prepared reply dispatch runtime unavailable.
  • Real-behavior proof on the earlier equivalent startup-settlement head:
  • Current rebased head:
    • direct canonical config-builder proof: 13/13 passed, with 132 provider cases intentionally excluded from the focused run;
    • gateway.compaction-hot-reload.e2e.test.ts: 1/1 passed against the built CLI and full Gateway path;
    • exact-head CI run https://github.com/openclaw/openclaw/actions/runs/32905507930 exposed a shared-module-cache collision in agent.test.ts: the Gateway methods project could bind production imports before the suite's deep mocks. The canonical failed-job rerun expanded the same leak to 11 selected-agent/session failures;
    • agent.test.ts now owns a dedicated isolated Gateway-methods project that retains the shared runner and setup. The complete 284-test suite passes in 35 seconds, and the 23-test project ownership audit passes;
    • pnpm check:changed passed after the routing repair;
    • fresh Codex autoreview reported no accepted/actionable findings.
  • Exact Codex contract inspected at 97729885d4707a123db31ae80f5fb0eeda6b7706:
    • codex-rs/core/src/tools/handlers/multi_agents_v2/spawn.rs:124-139 binds spawned agents to the parent thread and turn;
    • codex-rs/app-server/src/bespoke_event_handling.rs:1277-1302 emits terminal turn status and final agent message through TurnCompleted.
  • Both ClawSweeper rank-up moves are complete: buildLiveGatewayConfig no longer emits the retired marker, and the reduced branch is rebased and re-proved on current main.
  • An attempted full provider-file run passed 144 tests but its single provider-matrix case exceeded the existing 180-second models.json setup budget after 294 seconds; the focused builder proof above avoids that unrelated live-provider setup lane.

LOC classification against current main:

  • production: 0;
  • tests/live-test support and CI routing: +90/-27 (net +63).

AI-assisted. I reviewed the Gateway lifecycle owner, every changed fixture, the exact Codex protocol source, and the validation results.

@clawsweeper

clawsweeper Bot commented Aug 25, 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 gateway Gateway runtime size: XS maintainer Maintainer-authored PR labels Aug 25, 2026
@jalehman
jalehman marked this pull request as ready for review August 25, 2026 01:57
@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 25, 2026, 2:23 PM ET / 18:23 UTC.

ClawSweeper review

What this changes

This PR makes Gateway live fixtures use full startup, wait for startup settlement before Codex connections and reconnects, and removes retired per-agent default markers from several fixture inputs.

Merge readiness

⚠️ Needs maintainer review before merge - 3 items remain

Keep open. The merged CLI slice does not supersede the distinct Codex work, but the live-model fixture still serializes a retired default marker, leaving part of the stated normalization fix incomplete.

Priority: P2
Reviewed head: f9b474adbcb0d1ecca03ab636d5df8d6977d62cd

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The live proof is strong, but the patch leaves a concrete fixture-generation path incomplete.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The PR discussion supplies exact-head Testbox evidence exercising full Gateway startup, native Codex turns, child delivery, and restart/resume behavior.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The PR discussion supplies exact-head Testbox evidence exercising full Gateway startup, native Codex turns, child delivery, and restart/resume behavior.
Evidence reviewed 6 items Merged CLI slice: Current main history includes the focused CLI live-harness repair; maintainer discussion confirms it covers only this PR's three-file CLI slice.
Startup boundary: The public Gateway contract defines startupSettled as completion of mandatory sidecar startup, and deferred startup resolves it only after sidecars and startup logging settle.
Incomplete canonical fixture generation: The changed test inputs omit default markers, but buildLiveGatewayConfig still emits default: true and its callers serialize that result for live Gateway runs.
Findings 1 actionable finding [P2] Remove the retired marker from the generated live configuration
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/gateway/gateway-models.profiles.live.test.ts

Result: FAIL (failed) — step 1 run node scripts/run-vitest.mjs src/gateway/gateway-models.profiles.live.test.ts: previous terminal command was still running after 30 seconds: "node scripts/run-vitest.mjs src/gateway/gateway-models.profiles.live.test.ts"

[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128965-7UP1ah/target

No test files found, exiting with code 1


 gateway-core

include: gateway-models.profiles.live.test.ts
exclude:  dist/**, test/fixtures/**, apps/macos/**, apps/macos/.build/**, **/node_modules/**, **/vendor/**, dist/OpenClaw.app/**, **/._*, **/*.live.test.ts, **/
*.e2e.test.ts, server-methods/**/*.test.ts, packages/gateway-protocol/src/**/*.test.ts, **/*client*.test.ts, **/*reconnect*.test.ts, **/*android-node*.test.ts,
**/*gateway-cli-backend*.test.ts, **/*server*.test.ts, gateway.test.ts, embeddings-http.test.ts, models-http.test.ts, openai-http.test.ts, openresponses-http.te
st.ts, probe.auth.integration.test.ts, server.startup-matrix-migration.integration.test.ts, sessions-history-http.test.ts

 gateway-client

include:
exclude:  dist/**, test/fixtures/**, apps/macos/**, apps/macos/.build/**, **/node_modules/**, **/vendor/**, dist/OpenClaw.app/**, **/._*, **/*.live.test.ts, **/
*.e2e.test.ts, src/gateway/**/*server*.test.ts, src/gateway/server-methods/**/*.test.ts

 gateway-methods

include:
exclude:  dist/**, test/fixtures/**, apps/macos/**, apps/macos/.build/**, **/node_modules/**, **/vendor/**, dist/OpenClaw.app/**, **/._*, **/*.live.test.ts, **/
*.e2e.test.ts

 gateway-server

include:
exclude:  dist/**, test/fixtures/**, apps/macos/**, apps/macos/.build/**, **/node_modules/**, **/vendor/**, dist/OpenClaw.app/**, **/._*, **/*.live.test.ts, **/
*.e2e.test.ts, server-methods/**/*.test.ts, gateway.test.ts, server.startup-matrix-migration.integration.test.ts, sessions-history-http.test.ts, server.sessions
.compaction-read-errors.test.ts

 gateway-server-isolated

include:
exclude:  dist/**, test/fixtures/**, apps/macos/**, apps/macos/.build/**, **/node_modules/**, **/vendor/**, dist/OpenClaw.app/**, **/._*, **/*.live.test.ts, **/
*.e2e.test.ts

[test] failed 1 Vitest shard in 5.99s
[vitest] FAILED (exit 1)
[test] FAILED (exit 1)

Assertions:

  • FAIL expect_output: gateway-models.profiles.live.test.ts

How this fits together

Gateway live fixtures start an isolated Gateway, publish prepared runtimes during startup, then connect backend clients to exercise agent turns and delivery. They feed release validation rather than changing production request handling.

flowchart LR
  A[Fixture configuration] --> B[Gateway startup]
  B --> C[Runtime publication]
  C --> D[Startup settled]
  D --> E[Backend client connects]
  E --> F[Agent turn validation]
Loading

Before merge

  • Remove the retired marker from the generated live configuration (P2) - Late finding: these updated inputs are overwritten by buildLiveGatewayConfig, which still emits dev.default: true here and serializes it for real live runs. The config loader then migrates that marker during startup, so this leaves the fixture on the normalization path the PR aims to avoid. Remove the marker from the builder and update the expected config.
  • Resolve merge risk (P1) - The review environment cannot inspect the current-main tree or the required sibling Codex source, so a final current-base and dependency-contract check remains necessary before merge.
  • Complete next step (P2) - The protected maintainer-labeled PR should stay in normal review while its one mechanical fixture fix and current-base verification are completed.

Findings

  • [P2] Remove the retired marker from the generated live configuration — src/gateway/gateway-models.profiles.live.test.ts:4738
Agent review details

Security

None.

PR surface

Source 0, Tests -5. Total -5 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 1 0
Tests 6 7 12 -5
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 8 13 -5

Review metrics

Metric Value Why it matters
Production versus test LOC production +0/-0; test and live-test support +8/-13 The branch changes release-harness behavior without altering the production Gateway path.

Merge-risk options

Maintainer options:

  1. Canonicalize the generated live config (recommended)
    Remove the default marker from buildLiveGatewayConfig, update its expectations, then rebase and rerun focused release-harness proof.
  2. Pause for environment verification
    Hold the PR until a reviewer can compare the exact merge result with current main and inspect the referenced Codex contract.

Technical review

Best possible solution:

Make every serialized live Gateway configuration use keyed entries without retired default markers, then retain the startup-settlement waits and validate the rebased exact head.

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

Yes, from source: the builder serializes a default marker for live Gateway runs, which the config-load migration removes during startup. A current-main live execution was not run in this read-only review.

Is this the best way to solve the issue?

No. The startup-settlement waits use the correct Gateway-owned promise, but the live-model config builder still emits the retired marker that the PR intends to eliminate.

Full review comments:

  • [P2] Remove the retired marker from the generated live configuration — src/gateway/gateway-models.profiles.live.test.ts:4738
    Late finding: these updated inputs are overwritten by buildLiveGatewayConfig, which still emits dev.default: true here and serializes it for real live runs. The config loader then migrates that marker during startup, so this leaves the fixture on the normalization path the PR aims to avoid. Remove the marker from the builder and update the expected config.
    Confidence: 0.96
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR discussion supplies exact-head Testbox evidence exercising full Gateway startup, native Codex turns, child delivery, and restart/resume behavior.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (linked_artifact): The PR discussion supplies exact-head Testbox evidence exercising full Gateway startup, native Codex turns, child delivery, and restart/resume behavior.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P2: The defect can make release validation exercise a legacy fixture-normalization path rather than the intended startup boundary.
  • merge-risk: 🚨 automation: The changed startup conditions and serialized fixture config determine whether live release checks validate the correct runtime path.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (linked_artifact): The PR discussion supplies exact-head Testbox evidence exercising full Gateway startup, native Codex turns, child delivery, and restart/resume behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR discussion supplies exact-head Testbox evidence exercising full Gateway startup, native Codex turns, child delivery, and restart/resume behavior.

Evidence

What I checked:

Likely related people:

  • vincentkoc: Merged the focused CLI live-harness repair and clarified that the Codex restart-settlement work remains distinct. (role: recent area contributor; confidence: high; commits: 0d4e8f2f5ce7; files: src/gateway/gateway-cli-backend.live-helpers.ts, src/gateway/gateway-cli-backend.live.test.ts)
  • Peter Steinberger: History shows substantial earlier work on Gateway Codex harness session and stress behavior. (role: historical Codex-harness contributor; confidence: medium; commits: 2cb9a7564807, 5bfb47e28348; files: src/gateway/gateway-codex-harness.live.test.ts)

Rank-up moves

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

  • Remove default: true from buildLiveGatewayConfig and update its assertions.
  • Rebase the remaining changes on current main and rerun focused exact-head harness proof.

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 (4 earlier review cycles)
  • reviewed 2026-08-25T02:02:55.387Z sha 18e0d89 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-25T02:44:56.591Z sha 18e0d89 :: found issues before merge. :: [P2] Wait for startup after each restart
  • reviewed 2026-08-25T08:02:36.530Z sha d46580b :: needs maintainer review before merge. :: none
  • reviewed 2026-08-25T12:37:37.782Z sha f9b474a :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 25, 2026
@clawsweeper clawsweeper Bot added 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. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 25, 2026
@jalehman

Copy link
Copy Markdown
Contributor Author

Real-behavior proof — exact head d46580b65b0d274e01d1283ebbc8a4e05d44233e

Validated the amended restart path through the real Codex app-server harness on isolated Blacksmith Testboxes.

Behavior exercised

  • full, non-minimal Gateway startup;
  • real Codex app-server turns;
  • OpenClaw/native subagent completion and parent delivery;
  • three complete Gateway shutdown/start cycles;
  • startupSettled awaited before every reconnect;
  • the same Codex thread resumed after each restart;
  • prior durable context returned exactly;
  • each reconnect used a fresh client identity.

The restart loop and assertions are at src/gateway/gateway-codex-harness.live.test.ts:2465. They verify the prior marker, new marker, unchanged thread ID, resumed action, and changed client ID for every restart.

Results

  • Targeted restart/resume proof — Testbox tbx_01m0w0ttf45ny8bzq4m2w5894t; live harness passed in 272.41s.
  • Combined subagent-delivery + restart/resume proof — Testbox tbx_01m0w15pvfddcq9dszaj81en07; live harness passed in 311.87s.
  • Both delegated Testbox commands returned exit code 0, then the leases were stopped and reported completed.
  • The linked wrapper runs show cancelled because stopping the externally controlled Testbox cancels Blacksmith's waiting wrapper step after the remote command has completed; the delegated command receipts are the proof result.
  • Current exact-head PR CI: 116 passing checks, 0 pending/failing.

Command shape:

OPENCLAW_LIVE_TEST=1 \
OPENCLAW_LIVE_CODEX_HARNESS=1 \
OPENCLAW_LIVE_CODEX_HARNESS_RESUME_STRESS=1 \
OPENCLAW_LIVE_CODEX_HARNESS_RESUME_STRESS_RESTARTS=3 \
OPENCLAW_LIVE_CODEX_HARNESS_SUBAGENT_PROBE=1 \
OPENCLAW_VITEST_MAX_WORKERS=1 \
pnpm test:live:codex-harness

Codex contract inspection at 97729885d4707a123db31ae80f5fb0eeda6b7706 confirmed spawned-agent parent lineage in spawn.rs:124 and terminal turn delivery in bespoke_event_handling.rs:1277.

This is real-behavior proof for #128965's fixture/startup-settlement change. It does not claim to reproduce or resolve the separate production race discussed in #127710.

@steipete steipete self-assigned this Aug 25, 2026
@steipete
steipete force-pushed the fix/prepared-runtime-continuation-race-retry-20260824 branch from d46580b to f9b474a Compare August 25, 2026 12:31
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 25, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Thanks @jalehman. The reusable CLI live-harness repair was narrowed into #129041, with your contribution preserved through co-author credit, and has landed on main as 0d4e8f2. The remaining broader fixture changes are outside that canonical repair, so this PR is superseded and is being closed.

@vincentkoc vincentkoc closed this Aug 25, 2026
@vincentkoc vincentkoc reopened this Aug 25, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Correction: #129041 superseded only this PR’s three-file CLI live-harness slice. The current head f9b474adbcb0d1ecca03ab636d5df8d6977d62cd also contains distinct Codex restart-settlement and fixture work, so #128965 is reopened and remains open pending exact-head review and proof.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 25, 2026
@steipete
steipete force-pushed the fix/prepared-runtime-continuation-race-retry-20260824 branch from f9b474a to e127538 Compare August 25, 2026 22:18
@steipete steipete changed the title fix: release live backends publish prepared runtimes fix(gateway): settle live fixtures before Codex reconnects Aug 25, 2026
@steipete
steipete force-pushed the fix/prepared-runtime-continuation-race-retry-20260824 branch from 36e1b47 to eff2447 Compare August 25, 2026 23:10
@steipete

Copy link
Copy Markdown
Contributor

Land-ready on exact head eff2447c8685107f7e0768b7881bcbe6599ad320.

Completed work:

  • removed the retired agent-default marker from the generated live configuration and all sibling fixtures;
  • awaited the Gateway-owned startupSettled promise before initial Codex connection and every restart reconnect;
  • routed agent.test.ts through a dedicated isolated Gateway-methods project after exact-head CI proved shared module-cache contamination across two attempts;
  • applied both ClawSweeper rank-up moves; fresh autoreview and native review artifacts report zero findings.

Proof:

Known proof gap: an attempted full provider-matrix run passed 144 tests before its single provider setup case exceeded the existing models.json setup budget. The focused builder proof and prior real Codex Testbox runs cover the changed paths.

@steipete
steipete merged commit d68ddc6 into main Aug 25, 2026
138 of 139 checks passed
@steipete
steipete deleted the fix/prepared-runtime-continuation-race-retry-20260824 branch August 25, 2026 23:32
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

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

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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.

3 participants