Repository navigation
fix(gateway): bind detached lifecycle dispatch - #126040
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 18, 2026, 6:00 PM ET / 22:00 UTC. ClawSweeper reviewWhat this changesThe PR routes detached subagent announcements and queued restart-recovery turns through the active Gateway lifecycle runtime so they can dispatch agent work after the original request scope ends. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessKeep open for maintainer approval: the patch replaces a request-scoped dispatcher that cannot serve detached work with the existing lifecycle-owned Gateway runtime. No discrete correctness defect was found in the proposed change, but its privileged dispatch boundary warrants exact-head validation and human approval. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: FAIL (partial) — step 2 Assertions:
How this fits togetherDetached subagent completion and restart recovery occur after an inbound Gateway request has finished. They need the active Gateway instance to validate and run an internal agent turn, then return completion delivery to the owning session or channel. flowchart LR
A[Subagent completion or recovery event] --> B[Detached delivery path]
B --> C[Lifecycle dispatch bridge]
C --> D[Active Gateway instance]
D --> E[Bound internal agent turn]
E --> F[Session or channel delivery]
Decision needed
Why: The change governs privileged internal dispatch after request teardown, and the protected maintainer label requires explicit human handling rather than automated cleanup. Before merge
Agent review detailsSecurityNone. PR surfaceSource +74, Tests +75. Total +149 across 8 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one lifecycle-owned dispatch facade and land only after its exact-head Gateway checks confirm detached delivery and recovery option propagation. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: current main's detached path reaches a dispatcher that requires a request scope or explicit resolver, while the new focused test establishes the same no-request-scope setup with an active instance runtime. Is this the best way to solve the issue? Yes: using the existing lifecycle-owned Gateway runtime is a cleaner repair than restoring an ambient request-scoped fallback, and it preserves the established internal agent-turn validation path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 41e3968ee4f6. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Land-ready at source head ee634455ed45718d07c83332bb753185461188c4.
|
|
Merged via squash.
|
… warning in the owner chat (#162772) ## What Problem This Solves Fixes: when an automation's owner-conversation repair turn (#161007) times out, the owner chat gets a generic "Request timed out… Please try again" warning that the user never asked for and the session never recorded. ## User Impact A repair turn now posts only what the agent wrote: a fix note, a question, or nothing (NO_REPLY). A runtime failure of the repair itself, such as an idle timeout, run deadline, or provider error, posts nothing. The job's next failure sends the normal failure alert, which names the repair. Ordinary user turns are unchanged and still show the timeout warning. ## Why This Change Was Made **Provenance.** The repair (#161007, fb2052a) dispatches the Gateway `agent` method with `deliver: true` on the instance lifecycle principal. When a run ends on the terminal-timeout path, `run/terminal-timeout.ts` appends a synthetic `{ text, isError: true }` payload. The idle-timeout copy comes from e899b32. `command/post-run.ts` hands that payload to `command/delivery.ts`, which sends it. The only payload selection there is `selectSourceDeliverablePayloads` (#156540), and it filters only `message_tool_only` turns. That path is right for a user's own turn. For a scheduler-authored repair, the warning tells the user to "try again" about a message they never sent, and the brief's NO_REPLY instruction cannot suppress text the runtime generates. `transcript-persistence` already leaves `isError` payloads out of the transcript, so the chat showed a message the session never recorded. **Fix.** Add one host-owned option, `internalDeliverySuppressErrors`. It follows the same path as the existing `internalDeliverySuppressText` (#126040): lifecycle dispatch option → synthetic client `internal` → agent ingress → `AgentCommandOpts`. It is not a wire param or config key. It is a Gateway-only command option (`AgentCommandGatewayOnlyKey`), and `sanitizePublicAgentCommandIngressOpts` clears it, so plugin ingress cannot set it. `selectSourceDeliverablePayloads` now takes the command opts and drops `isError` payloads when the option is set. Both of its callers use it: `delivery.ts`, and `post-run.ts` for the pending-final marker, so restart redelivery matches what was sent. `runGatewayCronFailureRepair` is the only caller that sets it. The run result, `onResultErrorPayload`, lifecycle error status, and history are unchanged. Known limit (owner decision): if the Gateway restarts while a repair turn is running, main-session restart recovery resumes that turn without this option. A timeout on the resumed turn then posts the warning, which is the behavior before this PR and never louder. Persisting the flag would mean a new `restartRecovery*` session field threaded through the claim, adopt and clear logic in about 10 places, all for a compound restart-plus-timeout edge, so it is left out. Also not covered: if the provider has `models.providers.<id>.timeoutSeconds` set, the transport timeout throws a `FailoverError` before delivery, so the repair was already silent there. Nothing changes on that path. **Bounded cost.** No new messages. One fewer message per timed-out repair turn. One boolean is threaded through existing internal plumbing. A plain array filter runs only when the option is set. Hermes check: Hermes cron keeps result delivery and failure notices apart. Failure notices go through their own lane (`failure_deliver`, `for_failure=True`, notification category `diagnostic`, which a target profile can hide; see `cron/scheduler_delivery.py`). The same split applies here: the repair turn delivers its authored result, and the failure lane (cron's alert) owns escalation. ## Evidence - `src/agents/command/delivery.test.ts`, real `deliverAgentCommandResult` with only the outbound transport mocked: - a timeout `isError` payload is delivered by default, which is the ordinary turn and is unchanged; - with the option set, nothing is sent; - with an authored reply plus the timeout, only the authored reply is sent. - Fails on origin/main because the payload is sent. - `src/agents/agent-command-execution-identity.test.ts`: forged plugin ingress with `internalDeliverySuppressErrors: true` is sanitized to `undefined`. - `src/gateway/server.cron-failure-repair.test.ts`, real Gateway with `cron.add`/`cron.run`: the repair turn reaches `agentCommand` with `internalDeliverySuppressErrors: true`. Fails on origin/main. - **Live Telegram Test Server, live model (`openai/gpt-6-astra`), DM owner conversation.** Each run uses an isolated source Gateway with `agents.defaults.timeoutSeconds: 200`. A proxy in front of the real OpenAI API returns a 400 for the automation's own runs, and every model request of the repair turn gets SSE `response.created` and then silence, so the turn's idle watchdog (120s) has to end it. That is a timeout the live model can't be made to produce on demand. Scenario: owned hourly job, `failureAlert {after: 2}`; run ×2 → repair turn; wait 240s; run (3rd failure). | Owner DM | origin/main | PR head `57c23a5` | |---|---|---| | repair turn (owner history: brief, then two aborted assistant turns with `LLM idle timeout (120s)`) | *"The model did not produce a response before the model idle timeout. Please try again, or increase models.providers.<id>.timeoutSeconds…"* posted | nothing posted | | 3rd failure | *"Automation "Inbox sync" failed 3 times / An automatic repair was requested… / Cause: format"* | same alert | Both runs completed: lease released, no listeners left. - qa-lab smoke (throwaway, real isolated source Gateway, qa-channel, mock provider behind a stall proxy, `agents.defaults.timeoutSeconds=20`): the repair run hits `embedded run timeout: runId=cron-failure-repair:…`, and the owner conversation gets no outbound. A normal inbound turn stalled the same way still gets "Request timed out before a response was generated…". The same harness on origin/main delivered that warning to the owner conversation. - Focused suites (`pnpm vitest run <file> --maxWorkers=1`): `src/agents/command/delivery.test.ts` 46 passed in 7.9s; `src/agents/agent-command-execution-identity.test.ts` 15 passed in 5.5s; `src/gateway/server.cron-failure-repair.test.ts` 1 passed in 28.5s (real Gateway startup, unchanged by this PR). LOC vs origin/main: prod +39/−9 (11 files, mostly one-line plumbing), test +33/−1. Co-authored-by: Ayaan Zaidi <[email protected]>
… warning in the owner chat (openclaw#162772) ## What Problem This Solves Fixes: when an automation's owner-conversation repair turn (openclaw#161007) times out, the owner chat gets a generic "Request timed out… Please try again" warning that the user never asked for and the session never recorded. ## User Impact A repair turn now posts only what the agent wrote: a fix note, a question, or nothing (NO_REPLY). A runtime failure of the repair itself, such as an idle timeout, run deadline, or provider error, posts nothing. The job's next failure sends the normal failure alert, which names the repair. Ordinary user turns are unchanged and still show the timeout warning. ## Why This Change Was Made **Provenance.** The repair (openclaw#161007, fc14fc8) dispatches the Gateway `agent` method with `deliver: true` on the instance lifecycle principal. When a run ends on the terminal-timeout path, `run/terminal-timeout.ts` appends a synthetic `{ text, isError: true }` payload. The idle-timeout copy comes from 3799c86. `command/post-run.ts` hands that payload to `command/delivery.ts`, which sends it. The only payload selection there is `selectSourceDeliverablePayloads` (openclaw#156540), and it filters only `message_tool_only` turns. That path is right for a user's own turn. For a scheduler-authored repair, the warning tells the user to "try again" about a message they never sent, and the brief's NO_REPLY instruction cannot suppress text the runtime generates. `transcript-persistence` already leaves `isError` payloads out of the transcript, so the chat showed a message the session never recorded. **Fix.** Add one host-owned option, `internalDeliverySuppressErrors`. It follows the same path as the existing `internalDeliverySuppressText` (openclaw#126040): lifecycle dispatch option → synthetic client `internal` → agent ingress → `AgentCommandOpts`. It is not a wire param or config key. It is a Gateway-only command option (`AgentCommandGatewayOnlyKey`), and `sanitizePublicAgentCommandIngressOpts` clears it, so plugin ingress cannot set it. `selectSourceDeliverablePayloads` now takes the command opts and drops `isError` payloads when the option is set. Both of its callers use it: `delivery.ts`, and `post-run.ts` for the pending-final marker, so restart redelivery matches what was sent. `runGatewayCronFailureRepair` is the only caller that sets it. The run result, `onResultErrorPayload`, lifecycle error status, and history are unchanged. Known limit (owner decision): if the Gateway restarts while a repair turn is running, main-session restart recovery resumes that turn without this option. A timeout on the resumed turn then posts the warning, which is the behavior before this PR and never louder. Persisting the flag would mean a new `restartRecovery*` session field threaded through the claim, adopt and clear logic in about 10 places, all for a compound restart-plus-timeout edge, so it is left out. Also not covered: if the provider has `models.providers.<id>.timeoutSeconds` set, the transport timeout throws a `FailoverError` before delivery, so the repair was already silent there. Nothing changes on that path. **Bounded cost.** No new messages. One fewer message per timed-out repair turn. One boolean is threaded through existing internal plumbing. A plain array filter runs only when the option is set. Hermes check: Hermes cron keeps result delivery and failure notices apart. Failure notices go through their own lane (`failure_deliver`, `for_failure=True`, notification category `diagnostic`, which a target profile can hide; see `cron/scheduler_delivery.py`). The same split applies here: the repair turn delivers its authored result, and the failure lane (cron's alert) owns escalation. ## Evidence - `src/agents/command/delivery.test.ts`, real `deliverAgentCommandResult` with only the outbound transport mocked: - a timeout `isError` payload is delivered by default, which is the ordinary turn and is unchanged; - with the option set, nothing is sent; - with an authored reply plus the timeout, only the authored reply is sent. - Fails on origin/main because the payload is sent. - `src/agents/agent-command-execution-identity.test.ts`: forged plugin ingress with `internalDeliverySuppressErrors: true` is sanitized to `undefined`. - `src/gateway/server.cron-failure-repair.test.ts`, real Gateway with `cron.add`/`cron.run`: the repair turn reaches `agentCommand` with `internalDeliverySuppressErrors: true`. Fails on origin/main. - **Live Telegram Test Server, live model (`openai/gpt-6-astra`), DM owner conversation.** Each run uses an isolated source Gateway with `agents.defaults.timeoutSeconds: 200`. A proxy in front of the real OpenAI API returns a 400 for the automation's own runs, and every model request of the repair turn gets SSE `response.created` and then silence, so the turn's idle watchdog (120s) has to end it. That is a timeout the live model can't be made to produce on demand. Scenario: owned hourly job, `failureAlert {after: 2}`; run ×2 → repair turn; wait 240s; run (3rd failure). | Owner DM | origin/main | PR head `57c23a5` | |---|---|---| | repair turn (owner history: brief, then two aborted assistant turns with `LLM idle timeout (120s)`) | *"The model did not produce a response before the model idle timeout. Please try again, or increase models.providers.<id>.timeoutSeconds…"* posted | nothing posted | | 3rd failure | *"Automation "Inbox sync" failed 3 times / An automatic repair was requested… / Cause: format"* | same alert | Both runs completed: lease released, no listeners left. - qa-lab smoke (throwaway, real isolated source Gateway, qa-channel, mock provider behind a stall proxy, `agents.defaults.timeoutSeconds=20`): the repair run hits `embedded run timeout: runId=cron-failure-repair:…`, and the owner conversation gets no outbound. A normal inbound turn stalled the same way still gets "Request timed out before a response was generated…". The same harness on origin/main delivered that warning to the owner conversation. - Focused suites (`pnpm vitest run <file> --maxWorkers=1`): `src/agents/command/delivery.test.ts` 46 passed in 7.9s; `src/agents/agent-command-execution-identity.test.ts` 15 passed in 5.5s; `src/gateway/server.cron-failure-repair.test.ts` 1 passed in 28.5s (real Gateway startup, unchanged by this PR). LOC vs origin/main: prod +39/−9 (11 files, mostly one-line plumbing), test +33/−1. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Detached subagent completion delivery failed after the originating Gateway request scope ended. Main CI profile 3/6 timed out in
subagent-completion-direct-fallbackbecause all direct-handoff retries lacked an instance binding.Root Cause
The ambient process-global Gateway fallback was correctly removed, but detached announce, descendant wake, and queued generated-media recovery still called the request-scoped in-process dispatcher. Their lifecycle owner had no closure-bound Gateway principal.
Fix
The active Gateway instance now exposes a lifecycle-bound agent-turn dispatcher. It preserves final-result waiting, acceptance/abort hooks, delegated completion-tool handoff, model/scopes, cron continuation, and internal-delivery media facts. Detached announce, descendant wake, and restart recovery share this canonical owner; missing or closed instances fail closed.
Evidence
tbx_01m0bdm8fvgcbv2d5s1zvqdb99: 137/137 Gateway tests plus the detached announce regression passed.The exact Crabline Telegram scenario remains a proof gap: local source-runner artifact freshness scanning prevented the child launch. A qa-channel probe did confirm the former missing-binding error was gone before timing out on its Telegram-specific terminal marker.
AI-assisted: yes. No agent transcript attached.