Repository navigation
fix(auto-reply): keep followup queue drains alive after the triggering request ends - #148025
Patrick-Erichsen merged 3 commits into
Conversation
|
🦞👀 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. |
|
Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 6:23 AM ET / 10:23 UTC (Revision 9). ClawSweeper reviewWhat this changesThe PR gives queued follow-up replies an independent work lifetime, adds deterministic scope-closure coverage, and prevents a Doctor test’s fake Gateway PID from matching its mocked process ancestry. Merge readiness✅ Ready for maintainer review This PR remains necessary: current main and the latest release retain the faulty continuation. No actionable patch defects remain, and the recorded CI cost addresses the previous review’s measurement follow-up. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s follow-up queue holds incoming messages while an agent is busy, then starts later agent turns and delivers their replies. Gateway work admission tracks those delayed turns through completion and shutdown. flowchart TD
A[Incoming message] --> B[Follow-up queue]
B --> C[Debounce and reply-lane wait]
C --> D[Independent drain lifetime]
D --> E[Agent turn]
E --> F[Reply delivery]
E --> G[Tracked cleanup and root release]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +2, Tests +85. Total +87 across 3 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Use the existing detached continuation for queue-owned work while preserving source cancellation, current authority checks, and Gateway shutdown accounting. Do we have a high-confidence way to reproduce the issue? Yes: current source establishes the closed-scope tracking failure, and the contributor records discriminating Gateway before/after delivery traces. This read-only review did not execute a current-main reproduction. Is this the best way to solve the issue? Yes: reusing the established detached-work owner repairs the caller’s lifetime without adding a parallel mechanism or changing queue configuration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9ced5fc07dae. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
1ede44d to
21c02ba
Compare
…pe is closed" before the agent replies (#148548) Related: #144801, #148025 ## What Problem This Solves Fixes LINE messages failing with “Something went wrong while processing your request” before the agent replies. SMS and Zalo use the same webhook pump. ## User Impact Turns can answer, wait for an exec approval, and answer queued follow-ups after the first turn ends. No configuration or migration is required. ## Why This Change Was Made The ingress drain starts dispatches that outlive the pump. Dispatch now leaves the pump's async-work scope while retaining its existing Gateway root until the task settles. Claim settlement and cancellation are unchanged. Cleanup after dispatch no longer holds the incidental webhook root; independently owned plugin cleanup keeps its own lifetime. ## Evidence - A self-signed POST to `/line/webhook` on an isolated Gateway reproduced `Async work scope is closed` on main `a81fd6123fdc`, with a failed transcript turn and no inference request. - The repaired dispatch completed the same flow with synthetic credentials and a local receiver: ordinary reply, approval prompt, denial, approval-turn answer, queued answer, and next answer. All six sends arrived. The dedicated `openclaw approvals pending` and `openclaw approvals resolve <id> deny` commands drove the real approval. - 251 tests across 23 owner/channel files passed on merge `5384b5a718a2` with main `62a4d0c547bc`. Both new lifetime tests fail with the original production code. Type, lint, format, export, architecture and test-partition checks pass. - The original Bash CI timeout did not reproduce in six focused head/base/merge/parent controls. Full CI remains pending on the repaired head. This pass proves the Gateway and delivery boundary, not live LINE service delivery. The contributor also recorded real LINE push receipts at `138cd4fb4b1b`. ## Consumers The shared monitor and plugin state API use the drain. LINE, SMS and Zalo supply detached webhook pumps; boot-started Discord is a scope-free sibling. Public plugin signatures stay unchanged. ## Dispatch and cleanup ownership The owner's intended boundary is: “the completed pump must not be held open for unrelated follow-ups.” Dispatch leaves the pump's async-work scope and retains an existing live Gateway root until dispatch settles. The incidental webhook root then releases. Required plugin cleanup keeps its separate owner and existing shutdown bounds. The decision to leave the pump scope is made once, by `runClaimed` in `src/channels/message/ingress-drain.ts`. Production changes are +10/−2 lines, net +8, across the dispatch owner and its private storage helper. Claim settlement, cancellation, restart admission, and completed-message deduplication remain unchanged. ## Evidence boundaries The signed `/line/webhook` experiment used a real isolated Gateway, synthetic credentials, deterministic inference, and a local LINE request receiver. It captured an ordinary answer, approval prompt, denial notice, approval-turn answer, queued answer, and next answer. Recipient delivery through the real LINE service is not proved by this experiment. The live green build was `6c7067918343`; production bytes are identical at `2b94019ae275`. The final commit changes only an optional test callback invocation. All 251 selected tests passed on merge `5384b5a718a2`, with parents `2b94019ae275` and main `62a4d0c547bc`. Restoring the original production code makes both new lifetime tests fail. The live approval sequence includes #148228. The fresh merge also includes #148301; its reply-source receipt uses separate state that the dispatch scope exit preserves. The live sequence does not include #148301, and this validation does not claim a new streamed-tail recovery experiment. The earlier Bash failure remains classified as a non-reproduced child startup/import timeout. Six focused head, base, merge, and relevant-parent controls passed. Different hosted runtime and shard conditions prevent treating those local passes as proof that the timeout cannot recur. Hosted CI remains a separate landing check. Co-authored-by: Ayaan Zaidi <[email protected]>
21c02ba to
28f598e
Compare
28f598e to
21eb1c9
Compare
…pe is closed" before the agent replies (openclaw#148548) Related: openclaw#144801, openclaw#148025 ## What Problem This Solves Fixes LINE messages failing with “Something went wrong while processing your request” before the agent replies. SMS and Zalo use the same webhook pump. ## User Impact Turns can answer, wait for an exec approval, and answer queued follow-ups after the first turn ends. No configuration or migration is required. ## Why This Change Was Made The ingress drain starts dispatches that outlive the pump. Dispatch now leaves the pump's async-work scope while retaining its existing Gateway root until the task settles. Claim settlement and cancellation are unchanged. Cleanup after dispatch no longer holds the incidental webhook root; independently owned plugin cleanup keeps its own lifetime. ## Evidence - A self-signed POST to `/line/webhook` on an isolated Gateway reproduced `Async work scope is closed` on main `4e8dd8e1859f`, with a failed transcript turn and no inference request. - The repaired dispatch completed the same flow with synthetic credentials and a local receiver: ordinary reply, approval prompt, denial, approval-turn answer, queued answer, and next answer. All six sends arrived. The dedicated `openclaw approvals pending` and `openclaw approvals resolve <id> deny` commands drove the real approval. - 251 tests across 23 owner/channel files passed on merge `5384b5a718a2` with main `d229f4a2ba41`. Both new lifetime tests fail with the original production code. Type, lint, format, export, architecture and test-partition checks pass. - The original Bash CI timeout did not reproduce in six focused head/base/merge/parent controls. Full CI remains pending on the repaired head. This pass proves the Gateway and delivery boundary, not live LINE service delivery. The contributor also recorded real LINE push receipts at `138cd4fb4b1b`. ## Consumers The shared monitor and plugin state API use the drain. LINE, SMS and Zalo supply detached webhook pumps; boot-started Discord is a scope-free sibling. Public plugin signatures stay unchanged. ## Dispatch and cleanup ownership The owner's intended boundary is: “the completed pump must not be held open for unrelated follow-ups.” Dispatch leaves the pump's async-work scope and retains an existing live Gateway root until dispatch settles. The incidental webhook root then releases. Required plugin cleanup keeps its separate owner and existing shutdown bounds. The decision to leave the pump scope is made once, by `runClaimed` in `src/channels/message/ingress-drain.ts`. Production changes are +10/−2 lines, net +8, across the dispatch owner and its private storage helper. Claim settlement, cancellation, restart admission, and completed-message deduplication remain unchanged. ## Evidence boundaries The signed `/line/webhook` experiment used a real isolated Gateway, synthetic credentials, deterministic inference, and a local LINE request receiver. It captured an ordinary answer, approval prompt, denial notice, approval-turn answer, queued answer, and next answer. Recipient delivery through the real LINE service is not proved by this experiment. The live green build was `6c7067918343`; production bytes are identical at `2b94019ae275`. The final commit changes only an optional test callback invocation. All 251 selected tests passed on merge `5384b5a718a2`, with parents `2b94019ae275` and main `d229f4a2ba41`. Restoring the original production code makes both new lifetime tests fail. The live approval sequence includes openclaw#148228. The fresh merge also includes openclaw#148301; its reply-source receipt uses separate state that the dispatch scope exit preserves. The live sequence does not include openclaw#148301, and this validation does not claim a new streamed-tail recovery experiment. The earlier Bash failure remains classified as a non-reproduced child startup/import timeout. Six focused head, base, merge, and relevant-parent controls passed. Different hosted runtime and shard conditions prevent treating those local passes as proof that the timeout cannot recur. Hosted CI remains a separate landing check. Co-authored-by: Ayaan Zaidi <[email protected]>
Closes #152105 ## What Problem This Solves Fixes: A2A tasks return a model-fallback notice instead of the agent's answer when a failed primary model is followed by a successful fallback. ## User Impact A2A clients receive the actual answer in the completed task artifact. Authentication, task retention, cancellation behavior, and the A2A protocol are unchanged. ## Why This Change Was Made A delivery marked `final` can still be a supplemental notice preceding the answer. A2A now uses the existing terminal-reply classifier through the reply-payload SDK instead of treating every final-lane payload as task completion. The SDK contract documents that classification is separate from content, sendability, and authority checks. ## Evidence - Actual CLI-started Gateway, registered A2A JSON-RPC endpoints, and a local OpenAI-compatible HTTP provider: a primary HTTP 503 followed by a successful fallback returned only the fallback notice before the change and the exact answer afterward. Public chat history independently retained the answer in both cases. - Ordinary replies, terminal HTTP 401 diagnostics, cross-peer task isolation, both unsupported cancellation aliases, and slash-command rejection were exercised. Built runtime provenance and a separate public SDK consumer verified the shared classifier. - 207 focused tests passed; the A2A regression fails on the original production code. Build, scoped type-aware lint, documentation syntax, line-limit ratchets, SDK export registration, and the approved SDK surface check passed. - Known separate failure: the second queued followup stalls with `Async work scope is closed` on both baseline and candidate, consistent with the separately owned #148025 work. This PR does not claim an all-green queued-delivery flow or repair that lifecycle. The provider was a controlled local fixture; no paid-provider, native-client, or broader notice-only/TTS/abort proof is claimed. Co-authored-by: Ayaan Zaidi <[email protected]>
Closes openclaw#152105 ## What Problem This Solves Fixes: A2A tasks return a model-fallback notice instead of the agent's answer when a failed primary model is followed by a successful fallback. ## User Impact A2A clients receive the actual answer in the completed task artifact. Authentication, task retention, cancellation behavior, and the A2A protocol are unchanged. ## Why This Change Was Made A delivery marked `final` can still be a supplemental notice preceding the answer. A2A now uses the existing terminal-reply classifier through the reply-payload SDK instead of treating every final-lane payload as task completion. The SDK contract documents that classification is separate from content, sendability, and authority checks. ## Evidence - Actual CLI-started Gateway, registered A2A JSON-RPC endpoints, and a local OpenAI-compatible HTTP provider: a primary HTTP 503 followed by a successful fallback returned only the fallback notice before the change and the exact answer afterward. Public chat history independently retained the answer in both cases. - Ordinary replies, terminal HTTP 401 diagnostics, cross-peer task isolation, both unsupported cancellation aliases, and slash-command rejection were exercised. Built runtime provenance and a separate public SDK consumer verified the shared classifier. - 207 focused tests passed; the A2A regression fails on the original production code. Build, scoped type-aware lint, documentation syntax, line-limit ratchets, SDK export registration, and the approved SDK surface check passed. - Known separate failure: the second queued followup stalls with `Async work scope is closed` on both baseline and candidate, consistent with the separately owned openclaw#148025 work. This PR does not claim an all-green queued-delivery flow or repair that lifecycle. The provider was a controlled local fixture; no paid-provider, native-client, or broader notice-only/TTS/abort proof is claimed. Co-authored-by: Ayaan Zaidi <[email protected]>
21eb1c9 to
d1247b0
Compare
520666d to
e53fa8c
Compare
|
Merged via squash.
|
…g request ends (openclaw#148025) * fix(auto-reply): keep followup queue drains alive after the triggering request ends * test(auto-reply): make followup scope ordering deterministic * test(doctor): keep fake gateway PID outside the test ancestry --------- Co-authored-by: Patrick Erichsen <[email protected]>
…ardown openclaw#162540 deleted the raw-key clearSessionQueues helper while openclaw#148025 landed a test that still imported it for teardown. Use the shared clearFollowupQueueForTest helper; the test enqueues no lane commands.
Relates to gap finding: gap-followup-drain-detached-scope (bug-dig, evidence level A)
What Problem This Solves
Fixes: queued follow-up messages are silently dropped when a follow-up queue drain runs after its triggering request has already settled, in gateway setups where debounce or retries defer the drain past the end of the enqueueing turn.
User Impact
User impact: queued follow-up turns now complete instead of vanishing when the drain outlives the request that enqueued them; operators no longer see repeating "followup queue drain failed" error logs for a queue that can never make progress.
Why This Change Was Made
scheduleFollowupDrainlaunched its drain throughrunWithGatewayIndependentRootWorkContinuation, which gives the detached chain its own admission root but leaves it inheriting the triggering request'sAsyncWorkScope. The queue drain outlives its enqueue request by design (debounce and retries), so once the request settles and its scope closes, tracked agent work inside a drained turn rejects with "Async work scope is closed". That error is neither a deferred-run signal nor a restart-drain signal, so the drain loop logs it and reschedules against the same closed scope forever — the queued follow-up is never delivered. Switching the call site torunWithGatewayDetachedWorkContinuation(the primitive added in #144801 and already used for post-ack webhook work, session auto-reset, and session announcements) gives the drain its own fresh async work scope, so drained turns keep tracking work after the triggering request's scope has closed. This is the remaining un-fixed call site of that family on current main.Follow-up (not in scope): other
runWithGatewayIndependentRootWorkContinuationcall sites (e.g. the conditional branch insrc/hooks/bundled/session-memory/handler.ts) may share this pattern; each needs its own defect evidence before switching, matching how #144801/#146350/#147150 landed one proven site at a time.Evidence
Regression test
src/auto-reply/reply/queue.drain-scope.test.tsmodels the embedded-agent-runner entry (ambient scope tracker bridge) for a drained queued turn and fails deterministically on unpatched code at the original defect.Real Gateway behavior — production follow-up drain after an actual request-scope closure (a2a webhook ingress, discriminating before/after)
The bundled a2a channel ingress dispatches each inbound webhook inside
runDetachedWebhookWork(src/plugin-sdk/webhook-request-guards.ts), which owns a fresh detachedAsyncWorkScopeper request. ASendMessagewithreturnImmediatelyacks first; that scope closes once the enqueue settles. Withmessages.queue.mode: "followup", a second inbound while turn 1 holds the wait tool is enqueued, and the debounced drain only runs after turn 1 settles — i.e. strictly after the triggering request's scope has closed. The production Gateway, real auto-reply queue/drain, embedded-agent run, and HTTP reply delivery to the a2a peer URL are all exercised; only the LLM is a deterministic mock fixture. Harness:extensions/qa-labqa-gateway child + bundled a2a channel + local proof sink + mock-openai server (proof-only, not committed); run on the rebased branch (OpenClaw 2026.9.4,28f598e93c8).AFTER (this branch),
node scripts/run-vitest.mjs extensions/qa-lab/src/proof-148025-followup-drain-after-request-close.e2e.test.tspasses:Gateway log (excerpt): the queued follow-up is enqueued while turn 1 runs; its dispatch completes in 78ms (request ends); the drain creates the queued turn only after turn 1's 30s wait settles, and the reply
GATEWAY_REPEATED_REQUEST_QUEUED_OKis POSTed to the peer URL 31s after the enqueue request ended:Cleanup and root release: the drained turn settles (
run_completed, sessiondone,user=2), zeroAsync work scope is closed/ drain-failure lines appear in the debug log, and the harness's gatewaystop()returns with zero errors, so every admitted root released cleanly.BEFORE (only
src/auto-reply/reply/queue/drain.tsreverted to theupstream/maincall site, same tree, same harness), the identical run fails and the defect fires in the production Gateway:The sink receives only turn 1's reply; the queued follow-up is never delivered — the exact defect this patch repairs, reproduced through the real request-scope closure. Re-applying the one-line call-site switch restores delivery (the AFTER run above).
Regression suites (rebased branch,
upstream/main= 9153127)queue.drain-scope.test.tsplus all queue test files andsrc/process/gateway-work-admission.test.ts: 8 files, 191 tests passed; admission suite 40 tests passed (node scripts/run-vitest.mjs <files>).checks-node-compact-small-12,docker-build-helper.test.ts > covers plugin CLI sources in the Docker plugin sweep) came from the stale base; on the rebased branch that test passes locally (353 passed; the only 3 local failures are environment-specific service-install probes that pass in CI).tsconfig.core.jsoncore lane andtsconfig.core.test.messaging.jsontest shard both exit 0.run-oxlint.mjs(oxlint.core.json) zero findings;oxfmt --checkclean on the changed files.Not run: full 88-shard CI locally (PR CI covers it); the earlier qa-channel trace did not create a per-request scope, so it is superseded by the a2a proof above.
Maintainer follow-up: current CI test cost
Public CI job checks-node-changed-4 measured the focused regression at PR head
8ce7cb9e9606(GitHub test merge79b8eb1e5a905b08a91ca6769acac18179b271e5):queue.drain-scope.test.ts: 1 test passed; test case 4 ms.time -p node --import tsx scripts/ci-run-node-test-shard.mts; the focused child used Bun,vitest.unit-fast.config.ts, and inner parallelism 1 on the documented two-CPU runner.Use these public CI measurements for the review's test-cost follow-up. The separate local
pnpm test src/auto-reply/reply/queue.drain-scope.test.ts --maxWorkers=1wall-time measurement is skipped: CI records the cost of the execution path and runner actually used to gate this head. The earlier Gateway trace above retains its original revision and attribution.The final Doctor fixture checkpoint changes one test line so its fake Gateway PID differs from the test process and parent; production code and assertions are unchanged.