Skip to content

fix(gateway): retry unstarted chat sends across restarts - #173389

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-drain-interruptions-20260919
Oct 15, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-drain-interruptions-20260919

Conversation

@steipete

@steipete steipete commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes unstarted chat messages becoming terminal failures when a Gateway restart interrupts request preparation or queued session admission.

User Impact

Control UI and native chat outboxes retain the original message ID and retry eligible rejected sends when the Gateway is available again. Explicit Stop stays terminal. Apple live sends with attachments still restore the draft for manual retry; already queued attachments use outbox recovery.

Why This Change Was Made

Request-entry shutdown already threw a retryable error, but WebSocket dispatch discarded its metadata. Pending chat admission also wrote a successful terminal abort receipt despite never starting execution. Preserve the structured pre-execution restart refusal and let the existing outbox own retry. Reuse request-entry validation for credential-barrier waiters instead of maintaining a second shutdown response.

Active main-session agent/embedded work already checkpoints through the existing recovery owner before shutdown cancellation. No second recovery store, schema change, generic replay of uncertain RPC writes, or drain-budget extension is introduced.

Evidence

  • Regression before/after: five request-preparation cases failed the new retry-metadata assertions before the fix; the request-entry file then passed 13/13. Initial baseline teardown also detected concurrent source edits; the passing run used frozen source.
  • Pending-admission regression holds the real lifecycle lock, interrupts queued input, and re-admits the same message ID; explicit Stop remains terminal. Focused file passed 15/15 (46.43s wall including compiler preparation).
  • Native outbox regressions cover direct and queued sends, preserved message IDs, and unchanged retry budgets. Swift parser and changed-file SwiftFormat checks passed. Final-head PR CI passes all three Android test variants and both shared-kit compilation scans; the CI plan skips Swift behavioral test execution. No shipped-client restart/reconnect trace was captured.
  • Control UI already retries authoritative retryable send rejections with the same ID; its existing transient-recovery tests cover both reconnect and backoff.
  • Independent subagent review (autoreview route unavailable): no actionable P0/P1/P2 findings. The configured helper refused a provider/config mismatch; no operator configuration changed. Supplemental review of the final cleanup was also clean.

Deploy drain counters overlap and include internal recovery work; they cannot measure unique lost user requests. The expected loss for the tested, authoritative pre-execution rejection cases is zero after successful reconnect, versus terminal failure before. A production-wide lost-items reduction remains unquantified. This is a requested correctness fix, not a latency benchmark; the drain budget remains unchanged. Production LOC: +23 net across seven files. This growth supplies the missing pre-execution error contract and native retry classification; the duplicate credential-barrier shutdown response is deleted, and existing outbox/recovery owners are retained.

Final local proof: request-entry 13/13 (76.15s), affected credential-barrier cases 2/2 after consolidation (49.04s), queued-admission 15/15 (46.43s), Control UI reconnect/backoff retry cases 2/2 (7.80s), changed-file core lint and formatting, Swift parser/SwiftFormat, and git diff --check. Gateway tests use the real kernel/lifecycle ownership; compiler preparation dominates wall time. Broad checks use PR CI; no Testbox/Crabbox leases or production mutations were used.

PR CI evidence

Final head: 32cc7e7e80bfb120523852fab39950552e52efbf; CI run 38789484402, attempt 1. Affected Gateway lanes, all three Android test variants, Android ktlint, both Android native-access configurations, iPhone screenshots, core typechecks, and both shared-kit compilation scans passed. All other executed validation checks passed, including PostgreSQL conformance and the shared-kit analysis intersection. The CI gate is red solely because of the attributed simulator-inventory failure below; security checks passed.

Initial-head CI found three Kotlin newline violations. The follow-up commit changes whitespace only; both changed files passed ktlint 1.8.0 locally and independent review, and final-head CI confirms the correction. The first run also had HTTP 504 failures downloading WebRTC and OpenGrep, plus a Watch simulator-creation failure. No CI reruns were requested.

The final-head iPad screenshot job 116610932878 passed all four app screenshot tests, then failed with No available Apple Watch simulators found. The repository failure classifier reports unknown: No matching job on main, with no Vitest failures to rerun. Manual attribution identifies a runner simulator-inventory failure: apps/ios/fastlane/Fastfile is identical in tested main parent 4d50e81f6c9e23dd16bc34984c0f644783771bad and tested merge 08a73bd924975e552ca3d4899cd730effe73b530 (blob bf48f6e9a4234ab2d844faa05ddab0433de8df90). The CI workflow and iOS project definition also match byte-for-byte. The failure occurs in unchanged simulator discovery after app tests succeed, before any Watch test executes. This is source-and-log attribution, not a claim that an equivalent main CI job ran.

Apple live attachment sends still require manual draft retry, and Swift behavioral regressions were compiled but not executed by this PR's CI plan. Production-wide lost-item counts remain unknown.

@clawsweeper

clawsweeper Bot commented Oct 15, 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 15, 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-15T18:58:14.093214Z 32cc7e7 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: android App: android gateway Gateway runtime size: M labels Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 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: 32cc7e7e80bfb120523852fab39950552e52efbf
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/server/ws-connection/authenticated-request-dispatch.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added 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 Oct 15, 2026
@clawsweeper

clawsweeper Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR preserves retryable restart refusals and lets existing native chat outboxes resend unstarted messages with their original IDs.

Example: The message “survive the restart” waits for session admission when the Gateway restarts.

  • Before: The unstarted message receives a terminal abort result or becomes a failed native outbox entry.
  • After: The Gateway returns a structured restart refusal, and the outbox retries the same message ID after reconnecting.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused owner-level repair with useful integration regressions and no identified defect; runtime confidence remains bounded by harness evidence and incomplete native validation.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied evidence reports Gateway lifecycle regressions and mocked native outbox coverage, without a shipped-client demonstration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A Gateway restart can mark a submitted message as permanently failed even though execution never began.
Reason: The maintainer-authored change restores existing recovery expectations through the existing owners without new settings, schemas, or replay of ambiguous writes.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it repairs a current restart-recovery gap, has established maintainer direction, and introduces no discrete correctness or security defect found in this review.

Priority: P1
Reviewed head: 112e55aaca3c968bddbd0b265101dc6fb32c9e28

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No shipped-client restart/reconnect trace is supplied; native coverage uses mocked transports, and native before/after behavioral execution is not established.
Agent review details

How this fits together

Authenticated chat requests pass through Gateway preparation and session admission before execution; existing client outboxes retain rejected input and reconcile accepted or uncertain sends through receipts and history.

flowchart TD
  A[Chat client outbox] --> B[Authenticated request dispatch]
  B --> C[Request preparation]
  C --> D[Session admission]
  D --> E[Agent execution]
  C --> F[Retryable restart refusal]
  D --> F
  F --> A
  E --> G[Receipts and history]
Loading

Technical review

Best possible solution:

Preserve authoritative pre-execution restart refusals and let the existing route-bound outboxes retry unchanged message IDs.

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

Current-main source shows discarded restart metadata and terminal pending-admission abort receipts; the PR reports before/after Gateway regressions, but no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch repairs the refusal and admission owners while preserving explicit Stop, uncertain-delivery reconciliation, original routes, and existing retry budgets.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Dallin Romney: Raw commit 469837e adds src/gateway/server-request-entry.ts:48 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 469837eddc41; files: src/gateway/server-request-entry.ts)

PR surface

Source +21, Tests +225, Docs +13. Total +259 across 12 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 57 36 +21
Tests 4 227 2 +225
Docs 1 13 0 +13
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 297 38 +259

Review metrics

Metric Value Why it matters
Production versus test growth Production +57/-36; tests +227/-2 Small runtime growth restores error classification; regressions cover distinct Gateway admission and native outbox contracts.

Labels

Label changes:

  • add P1: Gateway restarts can turn submitted, unstarted chat messages into terminal failures across browser and native workflows.
  • 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:

  • P1: Gateway restarts can turn submitted, unstarted chat messages into terminal failures across browser and native workflows.
  • 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.

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 15, 2026, 2:45 PM ET / 18:45 UTC.

@steipete
steipete merged commit fbc9fad into main Oct 15, 2026
125 of 128 checks passed
@steipete
steipete deleted the steipete/perf-micro-drain-interruptions-20260919 branch October 15, 2026 19:22
@steipete

Copy link
Copy Markdown
Contributor Author

Landed as fbc9fad under the authorized unrelated-infrastructure exception, with exact reviewed head 32cc7e7e80bfb120523852fab39950552e52efbf.

CI run 38789484402, attempt 1 has one underlying failure: iPad screenshots passed all four app tests, then unchanged simulator discovery reported No available Apple Watch simulators found. The aggregate CI gate fails solely because of that job. The classifier reports unknown: No matching job on main; attribution comes from the failure log and identical baseline source, not from a claimed main-job reproduction.

Tested merge 08a73bd924975e552ca3d4899cd730effe73b530 has parents main 4d50e81f6c9e23dd16bc34984c0f644783771bad and the reviewed head. apps/ios/fastlane/Fastfile is blob bf48f6e9a4234ab2d844faa05ddab0433de8df90 in both baseline and tested merge; the workflow and iOS project definition also match. The failure precedes any Watch test execution and is independent of the chat retry change.

The other 76 checks passed, including security, affected Gateway lanes, Android tests/lint/native-access checks, iPhone screenshots, PostgreSQL conformance, and shared-kit analysis. Independent review was clean. No CI rerun was requested. Swift behavioral regressions compiled but were not executed by this CI plan; shipped-client restart/reconnect proof remains a gap. Apple live attachment sends still restore the draft for manual retry.

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

* fix(gateway): retry unstarted chat sends across restarts

* style(android): format restart retry handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: android App: android docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-sensitive-changed 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