Skip to content

fix(codex): back off between app-server startup retries - #129505

Merged
steipete merged 2 commits into
mainfrom
steipete/codex-setup-activation-retry
Aug 25, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/codex-setup-activation-retry

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

During a live fresh-profile macOS onboarding round (obt826, app + gateway at main 203024e), the Codex candidate's live test failed after 48s with initialize transport failed after request write: codex app-server exited: code=1 ... failed to initialize sqlite state runtime under ~/.codex, and onboarding dropped the user's Codex provider:

Onboarding: Codex candidate failed

The exit itself is an upstream contract: codex 0.149.1's app-server path hard-fails StateRuntime::init after its five-second SQLite busy timeout when another Codex instance (here: a running Codex Desktop) actively uses the same codex home — the codex CLI path merely warns on the identical failure and continues (verified in the sibling ../codex checkout at rust-v0.149.1: codex-rs/app-server/src/lib.rs:613, codex-rs/rollout/src/state_db.rs:45, codex-rs/state/src/sqlite.rs:285).

The OpenClaw defect: the canonical three-attempt startup loop in extensions/codex/src/app-server/attempt-startup.ts restarted immediately, so all three attempts raced the same held-lock window ~6s apart (structured gateway log shows attempts 1→2→3 exhausted at 08:23:07/13/19 UTC). The identical openclaw.setup.activate retried later succeeded in a single attempt ("Inference verified: openai/gpt-5.6-sol", 27s) — the failure class is provably transient.

Why This Change Was Made

Keep the existing bounded three-attempt owner and closed-transport classifier, but wait 1s before attempt 2 and 2s before attempt 3 (zero delay for executable-selection changes), using the existing sleepWithAbort with the startup abandonment signal so cancellation still rejects promptly. Non-transport errors (unsupported version, auth) still fail on the first attempt. This does not mask persistent failures — retries remain capped at three — and does not add a second startup path. Production LOC is net-neutral (13+/13−).

User Impact

Onboarding and any Codex app-server startup survive the common "Codex Desktop is also running" contention window instead of failing the whole candidate; genuinely broken setups still fail fast with the same diagnostics.

Evidence

  • Live root-cause chain in the PR narrative above; call path traced setup.activate → embedded runner → attempt-startup.ts guarded loop → shared-client.ts initialize (details in commit message).
  • New hermetic child-process regressions (attempt-startup-retry.test.ts): first-spawn SQLite exit recovers on attempt 2; a contention window that defeats immediate retries recovers only with backoff (fails pre-fix); persistent exits stop after exactly three attempts; unsupported version fails after exactly one.
  • Focused suites green: 79 tests across attempt-startup-retry / attempt-startup / attempt-timeouts / client. Full check-changed green. Autoreview clean ("patch is correct (0.99)").
  • One neighboring timing-sensitive shared-client test stabilized with fake timers (pre-existing race).

A transient Codex app-server startup exit could burn all three startup
attempts inside one contention window: codex 0.149.1 hard-fails
StateRuntime::init after its five-second SQLite busy timeout when another
Codex instance (e.g. Codex Desktop) is actively using the same codex home,
and the startup loop restarted immediately, so attempts 1-3 raced the same
held lock roughly six seconds apart and onboarding's Codex candidate died
with 'initialize transport failed after request write'. The same
activation retried later succeeds in one attempt.

Keep the canonical three-attempt owner but wait 1s before attempt 2 and 2s
before attempt 3 (zero for executable-selection changes), abortable via
the existing startup abandonment signal. Non-transport errors still fail
immediately. Production LOC net-neutral.

Upstream contract verified in ../codex at rust-v0.149.1:
app-server/src/lib.rs:613 (fatal init), rollout/src/state_db.rs:45 (CLI
warns instead), state/src/sqlite.rs:285 (5s busy_timeout).

Four hermetic child-process regressions: first-spawn exit recovers;
contention outlasting immediate retries recovers only with backoff (fails
pre-fix); persistent exits stop at three attempts; unsupported version
fails after one.
@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.

@steipete
steipete marked this pull request as ready for review August 25, 2026 17:54
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 2:42 PM ET / 18:42 UTC.

ClawSweeper review

What this changes

The PR makes retriable Codex app-server startup failures wait 1 then 2 seconds before bounded retries, with child-process regression coverage for transient SQLite contention.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for maintainer handling. The patch is structurally focused and no discrete code defect was found, but the required direct Codex 0.149.1 contract inspection is blocked because the sibling checkout is absent and network DNS could not fetch it; the PR also carries the protected maintainer label.

Priority: P1
Reviewed head: c067572e279a55dcdc688cd81026cb077f381a75

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The owner-boundary implementation and focused test design are sound on source review, but the required upstream contract and after-fix runtime evidence remain unavailable to this review.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository state identifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply; its before-state screenshot does not by itself verify after-fix recovery.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository state identifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply; its before-state screenshot does not by itself verify after-fix recovery.
Evidence reviewed 6 items Current-main behavior: Current main still retries the classified closed-transport failure immediately inside the canonical three-attempt startup loop.
Changed owner and caller: The PR changes that same startup owner to clear or retire the attempted client before an abortable 1s/2s delay; the embedded-run entry point calls this owner.
Abort contract: The retry delay uses the startup abandonment controller, which is aborted on caller cancellation and startup timeout; the shared retry helper clears its timer and rejects on abort.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/codex/src/app-server/attempt-startup-retry.test.ts

Result: PASS (completed)

[test] starting test/vitest/vitest.extension-codex.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129505-6du1Ho/target

[vitest] still running with no output for 30000ms.
 ✓  extension-codex  extensions/codex/src/app-server/attempt-startup-retry.test.ts (4 tests) 6031ms
     ✓ retries a real app-server after transient sqlite state initialization failure  1382ms
     ✓ waits out transient sqlite contention before retrying app-server startup  1216ms
     ✓ bounds retries when sqlite state initialization keeps failing  3278ms

 Test Files  1 passed (1)
      Tests  4 passed (4)
   Start at  18:43:15
   Duration  30.92s (transform 20.76s, setup 906ms, import 23.64s, tests 6.03s, environment 0ms)

[test] passed 1 Vitest shard in 36.98s
[test] starting test/vitest/vitest.extension-codex.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-129505-6du1Ho/target

 ✓  extension-codex  extensions/codex/src/app-server/attempt-startup-retry.test.ts (4 tests) 5975ms
     ✓ retries a real app-server after transient sqlite state initialization failure  1358ms
     ✓ waits out transient sqlite contention before retrying app-server startup  1200ms
     ✓ bounds retries when sqlite state initialization keeps failing  3264ms

 Test Files  1 passed (1)
      Tests  4 passed (4)
   Start at  18:43:53
   Duration  16.40s (transform 6.46s, setup 408ms, import 9.80s, tests 5.98s, environment 0ms)

[test] passed 1 Vitest shard in 22.16s

Assertions:

  • NOT OBSERVED expect_output: Codex app-server startup retry — command exited successfully; expected output was not observed in the captured pane

How this fits together

The bundled Codex plugin starts an app-server process for embedded agent runs and onboarding. Its startup owner classifies failures, manages the shared client lease, and either opens a thread or reports a startup diagnostic.

flowchart LR
  A[Onboarding or embedded run] --> B[Codex plugin]
  B --> C[App-server startup owner]
  C --> D{Startup outcome}
  D -->|Closed transport| E[Clear client and bounded retry]
  D -->|Other error| F[Startup diagnostic]
  E --> G[Shared app-server client]
  G --> H[Codex thread]
Loading

Before merge

  • Resolve merge risk (P2) - The claimed Codex 0.149.1 SQLite busy-timeout behavior could not be directly audited because the required sibling Codex source is unavailable.
  • Resolve merge risk (P1) - The added delay changes startup availability timing; after-fix evidence should show that a contended real Codex startup recovers within the configured startup budget.
Agent review details

Security

None.

PR surface

Source 0, Tests +214. Total +214 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 13 13 0
Tests 2 215 1 +214
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 228 14 +214

Review metrics

Metric Value Why it matters
Production versus test delta production +13/-13 (net 0); tests +215/-1 (net +214) The retry-owner change is production-net-neutral and the added test surface covers four materially different startup outcomes.

Stored data model

Persistent data-model change detected: persistent cache schema: extensions/codex/src/app-server/attempt-startup-retry.test.ts, serialized state: extensions/codex/src/app-server/attempt-startup-retry.test.ts, vector/embedding metadata: extensions/codex/src/app-server/attempt-startup-retry.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete dependency and runtime proof (recommended)
    Make the exact Codex 0.149.1 source available for contract review and attach a redacted after-fix contention recovery trace before merging.
  2. Pause pending verification
    Leave this protected maintainer PR open until the Codex contract and end-to-end startup timing can be verified.

Technical review

Best possible solution:

Restore access to the exact Codex 0.149.1 source, verify the failure contract, and then land the canonical bounded retry with a redacted after-fix contention recovery trace.

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

No high-confidence current-main execution was performed: source proves the immediate-retry owner and the PR supplies a child-process scenario, but tests were not run in this read-only review and the upstream Codex source is unavailable.

Is this the best way to solve the issue?

Unclear. The patch keeps the retry owner, classifier, cap, and cancellation boundary coherent, but the dependency contract and claimed live recovery still need direct verification.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: A transient app-server startup failure can remove the Codex provider from onboarding and prevent embedded Codex runs.
  • add merge-risk: 🚨 availability: The PR changes retry timing on the app-server startup path that determines whether Codex runs recover or fail.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add 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 maintainer-authored PR, so the external-contributor proof gate does not apply; its before-state screenshot does not by itself verify after-fix recovery.

Label justifications:

  • P1: A transient app-server startup failure can remove the Codex provider from onboarding and prevent embedded Codex runs.
  • merge-risk: 🚨 availability: The PR changes retry timing on the app-server startup path that determines whether Codex runs recover or fail.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • 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 maintainer-authored PR, so the external-contributor proof gate does not apply; its before-state screenshot does not by itself verify after-fix recovery.

Evidence

What I checked:

Likely related people:

  • steipete: Introduced the current startup-loop file and has repeated Codex app-server lifecycle work in local history. (role: feature owner and recent area contributor; confidence: high; commits: 474d7855e481, 2740d9cc952e; files: extensions/codex/src/app-server/attempt-startup.ts, extensions/codex/src/app-server/shared-client.ts)
  • xingzhou: Local history identifies bounded shared app-server startup waits as prior work in this ownership area. (role: adjacent startup-lifecycle contributor; confidence: medium; commits: 745cfc028edb; files: extensions/codex/src/app-server/shared-client.ts)

Rank-up moves

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

  • Provide the exact Codex 0.149.1 source locations supporting the SQLite initialization failure contract.
  • Attach a redacted after-fix startup trace showing recovery from the contention window within the startup timeout.

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.

@steipete
steipete merged commit 3254b7f into main Aug 25, 2026
187 of 195 checks passed
@steipete
steipete deleted the steipete/codex-setup-activation-retry branch August 25, 2026 19:20
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Aug 25, 2026
#129505 added attempt-startup-retry.test.ts without registering it in the
attempt-support shard, so vitest-projects-config's exactly-once coverage
check fails on every PR merge-ref (checks-node-compact-large-11).
steipete added a commit that referenced this pull request Aug 25, 2026
#129505 added extensions/codex/src/app-server/attempt-startup-retry.test.ts
without lane ownership, so the full-suite coverage guard
(test/vitest-projects-config.test.ts) fails on every full run. Register it
beside attempt-startup.test.ts in the attempt-support lane.
steipete added a commit that referenced this pull request Aug 25, 2026
…124301)

* improve(control-ui): align composer stack with current main

* refactor(ui): isolate new-session permission state

* fix(ui): close composer CI regressions

* test(ui): align composer presentation contracts

* test(ui): fix composer browser contracts

* test(ui): stabilize composer browser ownership

* test(ui): target presented mobile composer

* test(ui): select accessible mobile composer

* test(ui): open mobile rail session directly

* fix(ui): keep mobile composer content laid out

* fix(ui): address composer review findings

* fix(ui): close composer interaction gaps

* fix(ui): bound swarm task popover

* fix(ui): restore progress-card docking beside the wide composer

The multiline restructure dropped the .session-progress-card--dock
placement shipped in #129141 and left the completed marker inside the
collapsed-only summary span, so it vanished when the disclosure opened.
Restore the dock positioning block and hoist the marker into the
always-visible summary grid.

* fix(ui): bound swarm task popover by its composer anchor

The popover capped its height against the raw viewport, so on short
mobile viewports its top rendered above the screen. Register the swarm
group with the existing composer popover anchor observer and consume the
measured --chat-composer-popover-max-height, keeping the viewport calc
only as fallback. The new actual-tree mobile regression failed with
-71px top clipping before the fix.

* fix(ui): restore Draft capability controls and split the new-session composer

Restores the Draft option and selected-state indicators the capability
menu lost in the restructure, and moves the capability/visibility
controls into composer-capability-controls.ts so composer.ts drops back
under the 700-line lint gate (677 lines) without a suppression.

* test(ui): prove permission-mode final effect before session creation

Adds mocked-gateway proof that an admin's Full selection reaches
sessions.create as permissionMode:"full" exactly once, and that a
write-scoped operator's retained Full selection is rejected before
creation with a visible status notice and zero create requests. Also
aligns the mobile footer reading-order assertion with the shipped
attachments-draft-model order.

* test(ui): register swarm popover layout test as node-driven

chat-swarm-progress.browser.test.ts drives its own Playwright chromium
from node, but d3396c4 added it without registering it in
nodeDrivenBrowserLayoutTests, so the browser-mode chromium project tried
to fetch it into the page and failed on the node-only playwright import.
This was the deterministic checks-ui failure on both prior heads.

* test(ci): register codex attempt-startup-retry in its support lane

#129505 added extensions/codex/src/app-server/attempt-startup-retry.test.ts
without lane ownership, so the full-suite coverage guard
(test/vitest-projects-config.test.ts) fails on every full run. Register it
beside attempt-startup.test.ts in the attempt-support lane.

* test(ui): expect last-activity suffix in composer summary label

Merge weave: #129520 appends the accessible last-activity to the summary
aria-label; align the restructured composer card's assertion with it.

---------

Co-authored-by: Peter Steinberger <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 26, 2026
)

* fix(codex): back off between app-server startup retries

A transient Codex app-server startup exit could burn all three startup
attempts inside one contention window: codex 0.149.1 hard-fails
StateRuntime::init after its five-second SQLite busy timeout when another
Codex instance (e.g. Codex Desktop) is actively using the same codex home,
and the startup loop restarted immediately, so attempts 1-3 raced the same
held lock roughly six seconds apart and onboarding's Codex candidate died
with 'initialize transport failed after request write'. The same
activation retried later succeeds in one attempt.

Keep the canonical three-attempt owner but wait 1s before attempt 2 and 2s
before attempt 3 (zero for executable-selection changes), abortable via
the existing startup abandonment signal. Non-transport errors still fail
immediately. Production LOC net-neutral.

Upstream contract verified in ../codex at rust-v0.149.1:
app-server/src/lib.rs:613 (fatal init), rollout/src/state_db.rs:45 (CLI
warns instead), state/src/sqlite.rs:285 (5s busy_timeout).

Four hermetic child-process regressions: first-spawn exit recovers;
contention outlasting immediate retries recovers only with backoff (fails
pre-fix); persistent exits stop at three attempts; unsupported version
fails after one.

* chore: drop worker scratch file
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 26, 2026
…penclaw#124301)

* improve(control-ui): align composer stack with current main

* refactor(ui): isolate new-session permission state

* fix(ui): close composer CI regressions

* test(ui): align composer presentation contracts

* test(ui): fix composer browser contracts

* test(ui): stabilize composer browser ownership

* test(ui): target presented mobile composer

* test(ui): select accessible mobile composer

* test(ui): open mobile rail session directly

* fix(ui): keep mobile composer content laid out

* fix(ui): address composer review findings

* fix(ui): close composer interaction gaps

* fix(ui): bound swarm task popover

* fix(ui): restore progress-card docking beside the wide composer

The multiline restructure dropped the .session-progress-card--dock
placement shipped in openclaw#129141 and left the completed marker inside the
collapsed-only summary span, so it vanished when the disclosure opened.
Restore the dock positioning block and hoist the marker into the
always-visible summary grid.

* fix(ui): bound swarm task popover by its composer anchor

The popover capped its height against the raw viewport, so on short
mobile viewports its top rendered above the screen. Register the swarm
group with the existing composer popover anchor observer and consume the
measured --chat-composer-popover-max-height, keeping the viewport calc
only as fallback. The new actual-tree mobile regression failed with
-71px top clipping before the fix.

* fix(ui): restore Draft capability controls and split the new-session composer

Restores the Draft option and selected-state indicators the capability
menu lost in the restructure, and moves the capability/visibility
controls into composer-capability-controls.ts so composer.ts drops back
under the 700-line lint gate (677 lines) without a suppression.

* test(ui): prove permission-mode final effect before session creation

Adds mocked-gateway proof that an admin's Full selection reaches
sessions.create as permissionMode:"full" exactly once, and that a
write-scoped operator's retained Full selection is rejected before
creation with a visible status notice and zero create requests. Also
aligns the mobile footer reading-order assertion with the shipped
attachments-draft-model order.

* test(ui): register swarm popover layout test as node-driven

chat-swarm-progress.browser.test.ts drives its own Playwright chromium
from node, but d3396c4 added it without registering it in
nodeDrivenBrowserLayoutTests, so the browser-mode chromium project tried
to fetch it into the page and failed on the node-only playwright import.
This was the deterministic checks-ui failure on both prior heads.

* test(ci): register codex attempt-startup-retry in its support lane

openclaw#129505 added extensions/codex/src/app-server/attempt-startup-retry.test.ts
without lane ownership, so the full-suite coverage guard
(test/vitest-projects-config.test.ts) fails on every full run. Register it
beside attempt-startup.test.ts in the attempt-support lane.

* test(ui): expect last-activity suffix in composer summary label

Merge weave: openclaw#129520 appends the accessible last-activity to the summary
aria-label; align the restructured composer card's assertion 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

extensions: codex maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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.

1 participant