Repository navigation
fix(gateway): harden hook admission and shutdown - #125893
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Land-ready evidenceVerified head: Root cause and best-fix verdictThe repair closes four owner gaps: the shared HTTP-body path could terminate oversized/timed-out requests before response transport closure; the installed plugin guard still destroyed immediately; deferred wakes accepted an explicit session despite main-session next-heartbeat ownership; and direct-close readiness plus multi-listener shutdown lacked generation-local/all-listener ownership. This is the best fix, not a downstream mitigation. Shared response-close policy now owns Gateway readers, installed plugin guards, and plugin webhook readers; hook normalization owns the invalid mode/session combination; lifecycle state owns direct-close draining; and listener teardown independently settles every listener. Immediate request destruction, consumer-only guards, and sequential listener closure were rejected because they retain response loss or incomplete cleanup. ClawSweeper rank-up movesLatest completed review: #125893 (comment) All eight moves were applied; none were skipped:
The review is under 12 hours old and all post-review pushes were limited to its findings, the required conflict rebase, and the resulting sibling-test correction, so policy does not require a re-review request. Local proof
Hosted CI, Testbox, and retries
Scope, size, and proof gapsProduction LOC: +98/-64 (net +34). Tests: +319/-39 (net +280). Docs: +2/-2. Shrink-only assertion-safety baseline: +1/-1. No storage behavior, SQLite schema/version, protocol field, durable replay/idempotency design, dependency, generated-file, or release-note change is included. Known gap: no operator-owned live Gateway was restarted or mutated. This bounded deterministic HTTP/lifecycle repair instead has real raw-socket Gateway and Feishu response-order proof, shutdown lifecycle regressions, 210 focused passing tests across the final local commands, exact-head hosted CI, and native Testbox gate reuse. No external provider API is involved. |
|
Codex review: found issues before merge. Reviewed August 18, 2026, 12:36 PM ET / 16:36 UTC. ClawSweeper reviewWhat this changesUpdates Gateway and plugin webhook body-limit handling, deferred wake admission, draining readiness, and multi-listener shutdown behavior. Merge readiness⛔ Blocked by patch quality or review findings - 8 items remain Keep open: the patch leaves the installed plugin webhook guard able to reset 413/408 responses and removes current main’s bounded agent-harness shutdown. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: FAIL (partial) — step 2 Assertions:
How this fits togetherGateway HTTP handlers and plugin webhook transports read untrusted request bodies before dispatching work or returning structured errors. Gateway lifecycle code also transitions health probes to draining and tears down listeners and runtime owners during shutdown. flowchart LR
A[Webhook client] --> B[Gateway or plugin body reader]
B --> C{Body limit or timeout?}
C -->|yes| D[Structured HTTP error]
D --> E[Flush response then close socket]
C -->|no| F[Hook dispatch]
G[Gateway shutdown] --> H[Draining state and listener cleanup]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +36, Tests +246, Docs 0, Other 0. Total +282 across 19 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Apply the shared post-finish close policy to every body-limit owner, retain grace-bounded harness disposal, and prove both with real listener regressions. Do we have a high-confidence way to reproduce the issue? Yes—source establishes both paths: the installed guard destroys the request immediately after a 413/408, and agent-harness disposal can await a never-settling promise. Is this the best way to solve the issue? No; the response-first invariant must be enforced in the installed guard as well as reader helpers, and the existing bounded harness cleanup must remain. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d8c1d90edb49. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Flush structured 413 and 408 hook responses before closing oversized or timed-out request sockets, and reject deferred wake requests that target an explicit session. Direct Gateway close now marks startup and readiness as draining immediately and attempts every HTTP listener shutdown before reporting an incomplete close.
Give the HTTP request fuzz double the IncomingMessage destroy contract exercised after 413 and 408 responses finish.
Route installed webhook body-limit failures through the shared response-first close owner and require complete Feishu 413/408 responses before terminal connection closure. Retain the current-main grace bound for agent-harness disposal so one stuck harness cannot block listener teardown.
3d4e578 to
ea73a97
Compare
Keep the slow-body request alive through response finish, then assert cleanup when the mock response transport closes.
|
Merged via squash.
|
* fix(gateway): harden hook admission and shutdown Flush structured 413 and 408 hook responses before closing oversized or timed-out request sockets, and reject deferred wake requests that target an explicit session. Direct Gateway close now marks startup and readiness as draining immediately and attempts every HTTP listener shutdown before reporting an incomplete close. * test(gateway): model request destruction in fuzzing Give the HTTP request fuzz double the IncomingMessage destroy contract exercised after 413 and 408 responses finish. * fix(gateway): preserve response and shutdown bounds Route installed webhook body-limit failures through the shared response-first close owner and require complete Feishu 413/408 responses before terminal connection closure. Retain the current-main grace bound for agent-harness disposal so one stuck harness cannot block listener teardown. * test(telegram): model response-close request cleanup Keep the slow-body request alive through response finish, then assert cleanup when the mock response transport closes.
What Problem This Solves
Fixes an issue where Gateway and plugin webhook callers could receive a reset without the structured 413/408 body when an oversized or timed-out request was terminated before the response transport closed.
It also fixes two shutdown/admission inconsistencies: deferred
/hooks/wakerequests accepted an explicit session even though next-heartbeat delivery is owned by the agent main session, and a direct Gateway close could remain startup-ready while shutdown was already underway. When multiple HTTP listeners were present, one incomplete close could also prevent later listeners from being closed.Why This Change Was Made
The repair puts response-first request closing in the shared HTTP-body owner and reuses it from Gateway, installed plugin guards, and plugin webhook readers. Hook normalization now rejects
next-heartbeatplussessionKey; the generation-local lifecycle state marks direct close as draining immediately; and HTTP listener shutdown independently settles every listener before propagating an incomplete-close failure.The branch was rebased after review so current main’s five-second agent-harness disposal bound and never-settling regression remain intact. The scope is deliberately bounded: no storage, SQLite schema/version, Gateway protocol field, durable replay/idempotency design, dependency, generated-file, or release-note change.
User Impact
Operators now receive complete structured 413/408 hook and plugin-webhook errors before terminal connection closure. Deferred wake requests cannot misleadingly target an explicit session, health probes report draining as soon as a direct close begins, every bound HTTP listener gets a shutdown attempt even when another listener is stuck, and a stuck agent harness cannot block listener teardown.
Evidence
node scripts/run-vitest.mjs src/infra/http-body.test.ts src/plugin-sdk/webhook-request-guards.test.ts src/gateway/hooks.test.ts src/gateway/http-common.test.ts src/gateway/server-close.test.ts src/gateway/server-http.hooks-request-timeout.test.ts src/gateway/server-kernel.test.ts src/gateway/server.hooks-admission.test.ts src/gateway/http-common.fuzz.test.ts extensions/feishu/src/monitor.webhook-security.test.tspassed 10 files / 196 tests after rebase.ECONNRESETallowance is gone.node scripts/run-vitest.mjs extensions/telegram/src/miniapp/routes.test.tspassed 14/14 after its request double was updated to model response transport close.git diff --checkpassed. Fresh branch-wide Codex autoreview againstorigin/mainand the follow-up Telegram autoreview were clean with no accepted/actionable findings.a2581370489c40da51cf92b5205cb1656fcb134f: https://github.com/openclaw/openclaw/actions/runs/32165730816undici/undici-typesconflicts insrc/agents/mcp-oauth-fetch.ts,src/gateway/mcp-app-standalone.ts, andsrc/infra/net/**; no changed-file type errors were reported. Exact-head hosted CI is authoritative for the clean dependency environment.