Repository navigation
fix(state): messages to agents fail right after a Gateway restart instead of waiting - #174958
Conversation
Join each agent's existing startup completion before admitting writes, with bounded slow-host/fleet budgets and request or Gateway cancellation. Keep terminal inspection refusals and read behavior intact, and prepare session storage before authorization acquires mutation facts. Keep cron requests queued until their agent is admitted, without consuming running capacity or transferring source custody. Wake the native queue after preparation and retain its ordinary eligibility, ordering, and capacity checks. Prove pending writes wait and that eight preparing cron jobs leave capacity for a healthy agent; update startup RPC recovery to await the same request.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6896de1993
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const run = () => launchCronRun(state, entry, launch); | ||
| const run = async () => { | ||
| if (preparation) { | ||
| await waitForAgentDatabaseWriteAdmission(preparation.agentId, { |
There was a problem hiding this comment.
Keep timed-out cron preparations queued
When an agent's startup preparation exceeds the bounded write-admission timeout (five minutes plus the queued-batch allowance), this await rejects with AgentDatabaseAdmissionError; the generic rejection handler below then calls cancelCronRunRequests, converting the durable queued occurrence into skipped history. Consequently, a slow but ultimately successful startup permanently loses scheduled runs—and rejects manual runs—instead of waking the retained receipt when admission completes. Cron should join the underlying preparation without the request timeout, or treat this timeout as a reason to leave the receipt queued.
AGENTS.md reference: AGENTS.md:L107-L107
Useful? React with 👍 / 👎.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR makes interactive requests wait for their selected agent’s startup preparation and keeps scheduled work queued until that agent is ready. Example: Agent main takes 45 seconds to prepare after restart while a user submits “Summarize notes.”
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR addresses a concrete startup failure that remains on main; no actionable correctness or security findings remain in this review, and GitHub confirms the conflict is resolved. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway startup prepares agent databases independently; request admission and the durable cron queue consume readiness before allowing session mutations or agent execution. flowchart TD
A[UI or TUI request] --> B[Shared pending request owner]
B --> C[Gateway admission and authorization]
D[Agent startup preparation] --> C
C --> E[Session or agent handler]
D --> F[Durable cron queue]
F --> G[Existing cron launcher]
Technical reviewBest possible solution: Retain the shared admission, request-settlement, and durable queue owners with the approved bounded interactive waits. Do we have a high-confidence way to reproduce the issue? Current-main request behavior and the release report establish the failure path; no target code or reproduction was executed during this read-only review. Is this the best way to solve the issue? The repair uses the existing readiness, retry, cancellation, and queue owners, preserves pre-dispatch refusal, and reconciles dispatched outcomes instead of adding competing retry machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 37642c04282e. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (17 earlier review cycles; latest 8 shown)
Reviewed October 19, 2026, 7:23 AM ET / 11:23 UTC (Revision 18). |
Keep cron readiness on startup's lifetime-cancelled preparation observation, independently of the bounded foreground request budget. Preserve terminal admission refusals and leave queued receipts recoverable on lifecycle shutdown. Merge current main while retaining its resident-store reuse assertion. Cover readiness beyond the request budget, terminal failures, and service/Gateway shutdown through the real startup and native queue owners. Refs: #174958
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0f4737daa9
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| pending.retryStartup = (retryAfterMs) => { | ||
| clearTimeout(startupRetry); | ||
| startupRetry = setTimeout( | ||
| send, | ||
| resolveFiniteTimeoutDelayMs(retryAfterMs, GATEWAY_SUSPEND_IDENTITY_RETRY_AFTER_MS), |
There was a problem hiding this comment.
Keep startup-retry writes resumable during Gateway pauses
When a write has received the method-marked startup refusal and a suspension or restart begins before this retry timer fires, retryStartup invokes send without making the request eligible for pending.resend. The retry therefore ignores bootstrapPause, and a subsequent gateway-suspending or gateway-restarting refusal falls through as a terminal error instead of resuming after the Gateway returns to accepting, even though the first refusal proved that the write was never dispatched. Keep startup-refused writes pause/resume eligible until they settle.
AGENTS.md reference: AGENTS.md:L95-L95
Useful? React with 👍 / 👎.
| timeoutMs: GATEWAY_STARTUP_ADMISSION_WAIT_MS, | ||
| signal: context.runRequest?.signal, | ||
| retainSentResultOnAbort: true, |
There was a problem hiding this comment.
Retain steer commands for the full startup budget
After a restart, when /steer or /redirect targets an agent in a later inspection batch, this fixed 300,000 ms deadline can expire while waitForAgentPreparation() still permits five minutes plus one minute per queued batch. The command is then reported failed and is not resumed when preparation finishes. This newly added slash-command path is separate from the previously reported ordinary chat-send deadline; use the full admission budget or let the existing lifecycle signal govern it.
AGENTS.md reference: AGENTS.md:L95-L95
Useful? React with 👍 / 👎.
Keep startup-refused writes in the existing suspension pause/resume path without changing their serialized frame, cancellation or deadline. Clear send uncertainty when an authoritative refusal proves non-delivery, and restore it only when the request dispatches again. Cover suspension and restart handoff, synchronous refusal, deadline expiry before retry and delivery uncertainty after redispatch.
|
@clawsweeper re-review Please review exact head CI run 39238871915 is running on this exact head. The prior X-publication child-transcript timeout is intermittent and unresolved; a recurrence on this head will stop landing. The accepted directions remain “Wait for that agent”, “Readiness handoff” for cron, and “Longer UI waits”. |
|
🦞👀 Re-review progress:
|
An agent-local startup refusal proves the Gateway-wide recovery fence no longer blocks dispatch. Release the current probe so a ready agent can continue while the slow agent retains its own original request and retry. Keep newer suspension announcements fenced by the existing revision. Cover two-agent rollback recovery and a newer-announcement control through the pending-request owner. Preserve original frames, deadlines and aborts.
|
@clawsweeper re-review Please review exact head The two-agent regression fails on Prior-head CI 39238871915 completed successfully, including the formerly intermittent X-publication case. That remains intermittency evidence, not a claimed X fix. Fresh exact-head CI is required for this seven-line production repair. The accepted agent-specific wait, cron readiness handoff and longer UI wait decisions remain unchanged. |
|
🦞👀 Re-review progress:
|
Merge current main to resolve the runtime-wrapper inventory conflict. Keep the startup wait modules and main's MCP owner modules, and regenerate the Control UI boot manifest for main's reachable layout helper. The merged candidate passes wrapper-closure, pending-request, protocol and TUI settlement tests, plus core types. Keep per-agent recovery probes, original request deadlines, and late-result custody unchanged.
|
@clawsweeper re-review Please review exact head Merged-candidate proof passes: 19 wrapper-closure cases, 48 pending-request/protocol cases, the exact delayed-response TUI diagnostic (one creation/key and retained late success), and core types. Full-candidate independent review through P2 is clean. Original deadlines, cancellation, per-agent progress and cron readiness custody remain unchanged. Fresh exact-head CI is starting; prior-head CI 39238871915 passed including X-publication, with the earlier intermittency still recorded rather than claimed fixed. |
|
🦞👀 Re-review progress:
|
|
Additional operator evidence from 2026.10.4 (383c124), macOS/launchd, observed on 2026-10-19. This supports the need for a per-agent readiness handoff rather than a longer fixed startup delay. Two one-shot
For the second case, the Gateway logged startup phase Both one-shots were subsequently found disabled without a confirmed success/blocker result in their originating conversation. Acceptance work was completed manually later. Deleted job definitions were not recreated: retained native We also isolated the installed retry policy without importing the runtime or touching a live scheduler: the exact pending-inspection text and Release-source check: Suggested regression coverage for the existing owner: pending preparation outlasting any fixed delay, exactly one dispatch when that agent becomes ready, permanent inspection/ownership failure staying terminal, and another restart while waiting retaining custody. Restart after execution or uncertain side effects must not be treated as an unconditional safe replay. No local product patch was installed for this investigation. |
|
Merged via squash auto-merge.
|
What Problem This Solves
Messages and new sessions can fail immediately after a Gateway restart while their selected agent is still preparing. TUI and Control UI requests now wait up to five minutes for that agent, while ready agents proceed independently. The Gateway refuses startup writes before handler dispatch; the existing client request owner retries only the matching method-bound refusal with the original frame, deadline, and cancellation signal. Inspection and ownership failures remain errors.
The durable cron worker owns queue order, capacity, and receipt custody. Readiness wakes its queue without taking the event or occupying a running slot. Readiness capture, observation, and final admission use the service environment, including a distinct state directory. The maintainer decisions remain “Wait for that agent”, “Readiness handoff” for cron, and “Longer UI waits”. The separate #176685 issue is not a blocker.
Stop cancels unsent or authoritatively refused startup work. Once a creation or send is dispatched, the client retains its result under the original operation and idempotency key. This covers TUI typed Stop/Abort, Control UI chat/steer/placement sends, and shared creation callers including Workshop and MCP. Presentation cancellation does not imply server cancellation; late successes reconcile through the existing owners. No configuration option, schema, wire field, or new retry owner is added.
Current head:
bbddb3037f6e5d64087d706f8a13c6dc2bc1ca66. The latest repair keeps startup-refused writes eligible for suspension pause/resume and clears delivery uncertainty after authoritative non-delivery. It also releases a Gateway-wide recovery probe when that probe reaches an agent-local startup refusal, allowing ready agents to progress independently. The existing probe revision prevents an older reply from releasing a newer suspension.Evidence
The two-agent recovery regression fails on
affb6dbb9d8fbecause the ready agent's frame is never sent; the newer-suspension control passes. The focused repair passes all 48 pending-request/protocol cases, the affected package test-type graph, scoped lint, formatting, and whitespace checks. Independent review through P2 found no actionable issues. The exact delayed-response TUI diagnostic passes after the repair: no early settlement or false cancellation, first success adopted, one creation and one key. Focused client tests take 6.14 seconds wall time; the TUI diagnostic takes 64.93 seconds including runtime preparation (44 ms test body).Earlier exact-head proof covers 283 gateway-client, 239 TUI, 795 UI, and 11 browser cases, plus types, lint and import cycles; counts overlap. Final-head CI passes Control UI performance at Chat 1,454,997 B and New Session 1,012,108 B gzip, both below the original 1,490,000 / 1,050,000 B ceilings. No performance budget was changed.
The previous X-publication child-transcript timeout remains intermittent and unexplained: one local failure followed by two passing replays, while the matching main test passed. On
affb6dbb9d8f, the exact CI case passes in 7.9 seconds. That pass is evidence of intermittency, not a causal repair. Synthetic transport tests exercise production owners but do not establish a live-provider or durable external server-write result. Finite sent deadlines and disconnect uncertainty remain unchanged.CI 39238871915 completed successfully on the prior
affb6dbb9d8fhead. Revision 17 on the probe-repair head reported no actionable findings or security issue, with a merge conflict as its remaining requirement. The current signed merge incorporates mainc0498d39fbb9: both appended runtime-module groups are retained and the boot manifest is regenerated for main’s layout helper. The merged tree passes 19 wrapper-closure cases, 48 client cases, the delayed-response TUI diagnostic, core types, and full-candidate independent review through P2. Final exact-head CI 39243302011 passed with 103 successful jobs and 19 skipped. ClawSweeper revision 18 found no correctness or security issue and no remaining before-merge item. The final X-publication case passed in 11.9 seconds; the historical intermittent timeout is not claimed causally repaired.