Skip to content

fix(gateway): wait for chat recovery before reporting ready - #180924

Merged
steipete merged 3 commits into
mainfrom
fix/gateway-ready-session-metadata
Oct 22, 2026
Merged

steipete merged 3 commits into
mainfrom
fix/gateway-ready-session-metadata

Conversation

@steipete

@steipete steipete commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Current main can report Gateway ready while rejecting the native app's first chat.send with UNAVAILABLE / startup-sidecars. The startup recovery gate intentionally blocks new chat, but neither /readyz nor the app's successful-health waiter covered that gate.

User Impact

The app now waits until the Gateway can accept fresh chat. Saved-input recovery keeps its ordering, and broken optional channels do not prevent the app from attaching for repair.

The Gateway bundled with released macOS 2026.10.5 (1b58cb9a1b4f4353e1add63c8506db4d890962e8) predates this chat-admission gate and unlocks all startup methods before sidecar readiness. Its older client still treats successful health as ready, so attaching that client to a current-main Gateway can hit the reproduced failure until the app is updated. The originally reported standalone SessionMetadataUnavailableError: schema-missing remains unreproduced; this PR does not claim to fix that exception and changes no session schema or standalone code.

Why This Change Was Made

Readiness now consumes the kernel's existing chat.send admission set. Startup completion remains separate so it can release recovery's background-work barrier without a cycle. The kernel emits the ready log and trace once when recovery opens admission. The health RPC publishes live coreReady, and the macOS waiter consumes it using its existing bounded startup wait. Older Gateways that omit the field retain their existing compatibility behavior. No sleep or first-turn retry was added.

Evidence

Baseline loose main (9ccfff0640302a1d4d8e074ef85bd285063f14b6): 40/40 immediate app-style health → chat.send requests failed (20 fresh + 20 existing profiles), and all 40 separate five-second controls succeeded. /readyz → chat.send also failed 2/2; /readyz → agent passed 40/40, and native Codex controls passed 8/8. The preserved original emitted-JS artifact passed 40/40 native/CLI replays. No attempt reproduced schema-missing.

Final production-code proof at 1998d40b210b0848a74a8c6cb486b5ab2d48cf81 (production bytes unchanged in final head 2811ae1f8b6bc24950727bc235989360ace292e1): 40/40 app-style health.coreReady → chat.send and 40/40 /readyz → chat.send passed, each with 20 fresh + 20 existing profiles. Native Codex health.coreReady → chat.send passed 4/4 (2 fresh + 2 existing), with actual app-server terminal receipts. Every request completed with its expected reply marker; no first-turn retries or forced shutdowns. Wire sends occurred 0.13–0.53 ms after the first observed ready result on the connected socket. Readiness polling and connection establishment are not first-turn retries.

Final-head required PR CI: passed, 81/81 jobs completed, run 39844299167. Supplemental isolated macOS proof uses trusted main workflow bdd736b63cdd623ea6caf62618b3c2d2314bfec8 with the exact candidate as target_ref: https://github.com/openclaw/openclaw/actions/runs/39844320679 . This supplemental run does not replace required PR CI.

Focused owner regressions fail before the fix and pass afterward. Commands use pnpm test <file> --maxWorkers=1:

File Result Wall time
src/gateway/server/readiness.test.ts 18/18 12.627 s
src/gateway/server-kernel.test.ts 7/7 98.966 s
src/gateway/server-startup-observers.test.ts 4/4 15.731 s
src/gateway/server-methods/health.owner-routing.test.ts 16/16 46.53 s
src/gateway/server-request-context.test.ts Passed 64.99 s
src/gateway/server-agent-database-startup.test.ts 13/13 178.16 s
src/gateway/server-startup-workspace-readiness.test.ts (failed CI cases) 2/2 25.43 s

The database matrix ran before the final logging-only relocation; the final kernel test verifies actual shared admission, startup/readiness separation, accepted chat, and exactly one ready log/trace. Health tests cover cached and fresh responses. Swift parse/format/source lint, native localization verification, and protocol generation/determinism checks pass. At the final production head, all six native waiter regression cases passed in 0.096 s in macOS test job 120065456501. Two native service-custody failures matched scheduled main run 39832966696: absent-service pause and named-profile stop both dispatched an unexpected uninstall. Their owning stop paths and fixtures are unchanged. Final-head macOS package build and both macOS Node shards passed. The final-head Swift run reports exactly the same four assertions in those two service-custody tests as scheduled main; no additional native failures. The supplemental full run remains in progress and is not green. Four independent Codex P0–P2 reviews across the implementation and test corrections found no actionable issues.

pnpm check:changed completed in 573.029 s. Changed-file line-cap, formatting, core/test typechecks, targeted lint, and the other selected guards pass. Three aggregate checks remain red with exact matches on clean origin/main (df27c0c): max-lines suppressions (3 unchanged UI files), core test-root budgets (gateway-root 725/720; infra 730/720), and unused exports (42 production / 58 full-tree entries). None of those paths overlap the changed files; no test roots were added. The supplemental full run remains separate from the green required PR gate.

CI on the first head exposed two workspace-reload tests that treated startupSettled as traffic readiness. Both reproduced locally. The first correction used a readiness poll, which hit Vitest's default one-second polling deadline in qualification CI. The final fixture awaits the readiness owner's event with the test abort signal; both cases pass in 25.43 s. All migration/configuration assertions remain intact, and production code is unchanged by these fixture corrections.

Prior-head PR run 39840804132 had an Android fake-transport retirement timeout; the entire Android tree and its workflow inputs were identical to its tested main parent. The prior native qualification also exposed existing deadcode dependency/file checks, whose complete failing sets match clean main. These historical failures are retained as failures, not claimed green; final-head results are linked above.

The supplemental full graph has also exposed unchanged baseline failures. Focused clean-main Node replays reproduce the cron root-drain count, Decision cold-load deadline, aborted-runtime signal identity, finalized-statement test observations, and Gateway projection/RFB assertions. The unrelated UI failures use unchanged UI/build inputs: a stale Activity chunk filename expectation, a synthetic RTL geometry check, and a paste-preview timing check. Their failures are retained; they are not claimed green or fixed by this PR.

@clawsweeper

clawsweeper Bot commented Oct 22, 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 22, 2026 19:18
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 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-22T20:02:06.539679Z — 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 app: macos App: macos app: web-ui App: web-ui gateway Gateway runtime size: S labels Oct 22, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes Gateway readiness and the macOS startup waiter follow the existing fresh-chat recovery gate.

Example: A client sends chat immediately after Gateway readiness succeeds during restart recovery.

  • Before: Readiness can succeed while chat.send returns UNAVAILABLE with startup-sidecars.
  • After: Readiness remains false with chat-recovery until fresh chat admission opens.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, useful repair with reported production-path replays and distinct owner regressions; no actionable patch finding was established.
Proof confidence 🐚 platinum hermit (4/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body records real Gateway first-chat replays, while native macOS runtime qualification remains pending.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: The Gateway can appear ready while rejecting the native app’s first chat request during recovery.
Reason: The maintainer-approved direction restores truthful readiness without adding retries, configuration, or another recovery owner; the separately unreproduced schema-missing exception is explicitly excluded.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR fixes a current readiness mismatch, and the introduced hunks contain no actionable correctness or security finding.

Priority: P1
Reviewed head: 87cc47b32bc00ce6d8693a6c6475023acf6fd616

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gateway kernel owns startup admission; HTTP probes and the health RPC expose its readiness, which the macOS process manager consumes before reporting the Gateway usable.

flowchart TD
  A[Startup recovery] --> B[Kernel chat admission]
  B --> C[Readiness checker]
  C --> D[HTTP ready probe]
  C --> E[Health RPC]
  E --> F[macOS startup waiter]
Loading

Technical review

Best possible solution:

Use the kernel’s existing chat admission state for readiness and let the macOS waiter consume its live coreReady projection.

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

Current-main source exposes the mismatch between readiness and chat admission, and the PR records repeated failing baseline requests; this read-only review did not execute target code.

Is this the best way to solve the issue?

The patch fixes the reporting boundary through existing owners, preserves recovery ordering and startup deadlines, and retains compatibility with Gateways that omit coreReady.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 054ac7af1d04.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Exact introduced change: The introduced diff reuses the existing unavailable-method set, projects live coreReady through both health response paths, and extends the existing macOS bounded waiter. (src/gateway/server-runtime-state-prepare.ts:431, 87cc47b32bc0)
  • Current-main readiness gap: Fetched main checks startup, database admission, child runtime, and plugin replacement before channel readiness, but does not consult the fresh-chat admission gate. (src/gateway/server/readiness.ts:149, 054ac7af1d04)
  • Recovery ordering preserved: Startup observers release chat admission after saved-input recovery hands off custody; startup completion remains separate so recovery can run without waiting on traffic readiness. (src/gateway/server-startup-observers.ts:199, 87cc47b32bc0)
  • Reported production-path verification: The full PR body reports 40 successful health.coreReady-to-chat replays, 40 successful HTTP-readiness-to-chat replays across fresh and existing profiles, and four native Codex replays. The final commit changes only workspace-readiness test waits. (87cc47b32bc0)
  • Exact-head checks remain unresolved: The reviewed head has failing check-dependencies and android-test-play checks, while macos-swift tests remain in progress. Annotations identify deadcode checks and Android unit tests but do not establish a diff-caused defect. Detailed logs redirect to a blocked artifact host; neither inherited failure nor contributor fault is established. (87cc47b32bc0)
  • Repository policy and history: Root and applicable Gateway, macOS, and docs AGENTS.md files were applied; the maintainer-notes directory is absent. Scoped history and earlier paths were searched, with some historical blob searches limited by disabled lazy fetching. Final status remained clean. (AGENTS.md:1, 87cc47b32bc0)

Likely related people:

  • Peter Steinberger: Raw commit 8190c32 adds src/gateway/server/readiness.ts:86 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 8190c326ce49; files: src/gateway/server/readiness.ts)

PR surface

Source +44, Tests +106, Docs +11. Total +161 across 16 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 8 49 5 +44
Tests 7 118 12 +106
Docs 1 19 8 +11
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 186 25 +161

Labels

Label changes:

  • add P1: False readiness breaks the first native chat request during a real startup workflow.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: False readiness breaks the first native chat request during a real startup workflow.
  • 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.

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 22, 2026, 3:47 PM ET / 19:47 UTC.

@steipete
steipete merged commit 82cf0b7 into main Oct 22, 2026
150 of 151 checks passed
@steipete
steipete deleted the fix/gateway-ready-session-metadata branch October 22, 2026 20:22
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

* fix(gateway): wait for chat recovery before reporting ready

* test(gateway): await readiness before workspace reload

* test(gateway): synchronize workspace setup with ready event
amittell added a commit to amittell/openclaw that referenced this pull request Oct 23, 2026
Main 784d9ce conflicted in two files.

server-methods/health.ts: keep this branch's respondFresh path and runtime-config client filter, and add main's live coreReady (openclaw#180924) to both the cached and the fresh response objects inside the filter.
server/health-state.ts: keep this branch's config-key fenced collection loop, and pass main's cronStorePath (openclaw#180875) to its collectGatewayHealthSnapshot call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: macos App: macos app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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