Skip to content

fix(gateway): wait for recovery readiness in chat fixtures - #186287

Merged
steipete merged 1 commit into
mainfrom
steipete/fix-chat-send-orphan-recovery-exactly-once-20261027
Oct 27, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/fix-chat-send-orphan-recovery-exactly-once-20261027

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The chat.send orphan-recovery regression could observe a second recovery attempt after rejecting stale input. Its fixture awaited startupSettled, which intentionally does not join initial orphan recovery, then seeded interrupted work while the startup scan was still pending. That scan could independently recover the fixture row before the rejected request completed.

This is the missed chat-fixture migration after #181289 separated startup recovery and #181470 introduced the public startup-readiness helper. Both commits are ancestors of the reported evidence build; the residual race is in this fixture. Production pre-admission already validates conflicting input, session incarnation, permission mode, and tool settings before reconciliation.

User Impact

Recovery tests now seed interrupted work after initial startup recovery settles. Operators gain a content-free recovery admission diagnostic. Runtime recovery and authorization behavior are unchanged.

Why This Change Was Made

Wait for the existing /startupz admission signal before returning the chat fixture. Every assertion in server.chat.orphaned-recovery.test.ts remains unchanged.

Add the requested structured chat.send recovery admission log for non-Stop requests carrying main-session recovery custody. It records outcome (rejected, admitted, retried), sessionIdHash, request/source/recovery run IDs, and the incoming chargedAttempts snapshot. No raw session key or message content is logged. The restart-recovery guide documents the event.

Production LOC: +30/−1, net +29, entirely for the requested observability. Fixture LOC: +2; original regression test unchanged. No schema, config, or recovery policy changes.

Evidence

A controlled reproduction delayed the real initial orphan scan until the fixture polled /startupz, or until after synthetic row seeding when that wait was absent. Both sides ran the original assertions; temporary scheduling instrumentation is not included in the patch.

Controlled reproduction Base Candidate
First rejected input: charged attempts 1 → 2 1 → 1
Recovery row after rejection New run and revision; failed status removed Unchanged
Failed/statusless work × new message/retained retry Fails at first rejection All four cases pass

Final committed head c7c1c96e4450938765b42344ab05d47a48ab5155: 4 files, 62 tests passed with OPENCLAW_VITEST_RUNTIME=node node scripts/run-vitest.mjs src/gateway/server.chat.orphaned-recovery.test.ts src/gateway/server-methods/chat-restart-recovery.worker.test.ts src/gateway/server-methods/chat-send-pre-admission.test.ts src/gateway/server-methods/chat-send-dispatch-errors.test.ts --maxWorkers=1. The unchanged integration case passed in 59.5 seconds; the runner verified an unchanged source snapshot.

Changed-file formatting/lint, pnpm tsgo:core, configured commit content/format/freshness hooks, and test-line ratchet passed (38 lines of headroom; baseline untouched). Earlier cold runs hit the existing 90-second timeout on both base and candidate. One intermediate run was invalidated by a concurrent telemetry edit; only the final unchanged-head run above is claimed as final proof.

Independent subagent review (autoreview route unavailable): the helper refused the requested provider route because it did not match operator configuration. Fresh review of the full diff and relevant owners found one P2 issue (Stop incorrectly classified as retry), now fixed. Follow-up P0–P2 review found zero actionable findings. Reviewed snapshot was based on 451ec41c26c67cca7d8a61b7da6b0188cf52249e; the rebase was patch-identical in the affected owners.

This is a correctness repair, not a performance claim: CPU/allocation microbenchmarks and Gateway load tests are not applicable. Exact-head CI run 40579180276 is complete. Node test shards, UI E2E, production/test types, docs, guards, source contracts, baseline ratchets, and the other lint lanes passed. The only failing leaf is check-lint-core-2 on inherited UI lint errors; the aggregate openclaw/ci-gate fails as a consequence. CI is therefore not fully green. This PR is intentionally left unmerged for maintainer handling of the inherited failure.

Inherited CI failure

Failed lint job: five eslint(curly) errors in ui/src/pages/new-session/draft-body.browser.test.tsx (31–32) and ui/src/pages/chat/chat-content-column.browser.test.tsx (288–289, 362).

Both files and .oxlintrc.json are byte-identical between this head and its main parent 5010c3e80f8bb2271bbd347d4639218f84f9fac4. Focused pnpm exec oxlint --threads=1 --config .oxlintrc.json <the two files> reproduces all five errors (exit 1). A separate replay of both files extracted from fresh main 6a321ca3a231fd8ab46c50bff26ca63b08160c87, using the same config with --no-ignore, also fails with the same five curly errors (the last chat line is now 364 after an unrelated two-line addition). The PR changes neither file nor lint configuration.

The aggregate gate labels this failure “new” because an older matching main job passed, explicitly noting that selected scope was not compared. The identical parent blobs and focused current-main replay above establish the file-level inherited failure independently of that coarse classification.

No CI rerun or unrelated UI modification was made. Independent fallback review, hosted Codex review, and ClawSweeper all report zero remaining actionable findings.

Join the public startup admission barrier before seeding recovery work. Keep the exactly-once regression assertions unchanged and add content-free recovery admission outcomes for operators.
@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.

@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-27T20:35:39.139144Z c7c1c96 PR opened
ℹ️ 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: XS 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: 🦐 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. 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 maintainer review before merge.

What this changes

This PR waits for startup admission before seeding chat fixtures and logs recovery admission outcomes.

Example: A recovery fixture seeds interrupted work with chargedAttempts set to 1.

  • Before: A pending startup scan can recover that row independently, increasing chargedAttempts to 2 during a rejected request.
  • After: The fixture waits for startup admission before seeding, so the rejected request leaves chargedAttempts at 1.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported repair with reported integration validation and no concrete findings; behavioral evidence remains harness-based.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its supplied evidence exercises the real Gateway through an integration harness, but does not show the new diagnostic through a shipped-entry-point capture.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Recovery integration coverage can report an extra recovery attempt caused by fixture setup, while operators lack a focused admission diagnostic.
Reason: The maintainer-authored direction restores meaningful recovery coverage and adds bounded observability without changing admission policy.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR repairs a remaining recovery-fixture ordering defect and adds focused diagnostics; no actionable correctness or security finding was identified.

Priority: P2
Reviewed head: c7c1c96e4450938765b42344ab05d47a48ab5155

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No shipped-entry-point capture demonstrates the new structured diagnostic across rejected, admitted, and retried requests.
Agent review details

How this fits together

Gateway startup discovers orphaned sessions independently of startupSettled; chat fixtures consume its public admission signal, while chat.send normalizes, validates, and admits requests through existing recovery owners.

flowchart LR
  A[Gateway startup] --> B[Orphan discovery]
  B --> C[Startup admission signal]
  C --> D[Chat fixture seeding]
  D --> E[Chat send admission]
  E --> F[Recovery outcome log]
Loading

Technical review

Best possible solution:

Reuse the existing startup admission helper while preserving recovery assertions and keeping diagnostics inside the admission owner.

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

Source confirms that startupSettled can finish before orphan discovery; the author reports a controlled reproduction demonstrating the resulting fixture interference, but this read-only review ran no target code.

Is this the best way to solve the issue?

The fixture change addresses the ordering assumption through an existing public signal, and the diagnostic uses the existing admission owner without adding another recovery path.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Startup fixture ordering keeps the original intent (fix: large session stores delay Gateway plugin startup #181289: Allow plugin startup to proceed independently while retaining orphan-recovery admission ordering.)
  • Replay-safe chat admission keeps the original intent (53326b9: Make chat.send own replay-versus-new-work decisions before destructive steering effects.)
  • Shared chat fixture keeps the original intent (a9c15ed: Consolidate repeated lifecycle setup while preserving distinct recovery and persistence contracts.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Masato Hoshino: Raw commit 53326b9 adds src/gateway/server-methods/chat-send-setup.ts:8 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 53326b9e9a81; files: src/gateway/server-methods/chat-send-setup.ts)

PR surface

Source +29, Tests +2, Docs +7. Total +38 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 30 1 +29
Tests 1 2 0 +2
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 39 1 +38

Labels

Label changes:

  • add P2: This repairs recovery integration-test reliability and adds operator diagnostics without changing runtime recovery policy.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp 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:

  • P2: This repairs recovery integration-test reliability and adds operator diagnostics without changing runtime recovery policy.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

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

  • Capture a redacted recovery admission log showing rejected, admitted, and retried outcomes through an isolated Gateway.

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, 4:55 PM ET / 20:55 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

Admin-merging over check-lint-core-2 and the ci-gate that rolls it up. The only errors are five eslint(curly) findings in two untouched browser tests, ui/src/pages/chat/chat-content-column.browser.test.tsx and ui/src/pages/new-session/draft-body.browser.test.tsx. They came in on main with #185821, and #186303 fixes them. Reading the latest run of each check across every page, all other checks at c7c1c96e4450 are complete with no failures.

This also fixes main's server.chat.orphaned-recovery.test.ts red. The failure was the fixture racing the initial startup orphan scan, not a production exactly-once regression: interrupted work that exists at startup is recovered once by that scan, and the rejected input does not add a charge. The added chat.send recovery admission log is content-free (hashed session id, run ids, outcome, incoming chargedAttempts), so the recovery path is observable on Team.

@steipete
steipete merged commit 5a7a011 into main Oct 27, 2026
163 of 169 checks passed
@steipete
steipete deleted the steipete/fix-chat-send-orphan-recovery-exactly-once-20261027 branch October 27, 2026 21:54
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…186287)

Join the public startup admission barrier before seeding recovery work. Keep the exactly-once regression assertions unchanged and add content-free recovery admission outcomes for operators.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS 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