Repository navigation
fix(ai): prevent idle timeouts on SSE keepalives - #152705
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 8, 2026, 1:59 PM ET / 17:59 UTC (Revision 11). ClawSweeper reviewWhat this changesThe branch reports SSE comment keepalives as connection activity for managed OpenAI-compatible streams while preserving the separate model-progress deadline. Example: A Responses turn receives 11 comment keepalives before replying after six seconds.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR remains useful and is ready from this review: refreshed exact-head runtime evidence resolves the previous proof blocker, and no actionable findings remain. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherOpenClaw's provider transports turn streamed model responses into agent events. The response reader now reports comment keepalives to the existing watchdog before the SDK discards them. flowchart TD
A[Model provider stream] --> B[Guarded response reader]
B --> C{Comment or model data}
C -->|Comment| D[Connection activity]
C -->|Model data| E[SDK and agent events]
D --> F[Idle and progress watchdog]
E --> F
F --> G[Continue turn or cancel stalled request]
Technical reviewBest possible solution: Keep comment observation in the shared response reader and timeout policy in the existing watchdog, preserving model-progress and whole-run limits. Do we have a high-confidence way to reproduce the issue? Yes: current source establishes the discarded-comment and signal-identity mechanism, and supplied exact-head HTTP regressions include a production-only base negative control. This read-only review did not execute the reproduction. Is this the best way to solve the issue? Yes: the callback closes over the correct request signal and observes comments before SDK parsing, repairing the missing handoff without adding a competing timeout owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 41dd80a3b884. Provenance checked
TestingProof path: shipped entry point. Added test files: 5. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -2, Tests +295, Docs 0, Other -1. Total +292 across 15 files. View PR surface stats
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
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 (10 earlier review cycles; latest 8 shown)
|
165621b to
0720de4
Compare
0720de4 to
ab568de
Compare
ab568de to
732f356
Compare
231d31b to
0118c80
Compare
0118c80 to
7ed2e8c
Compare
7ed2e8c to
650a6e6
Compare
Merge current main, keep the existing idle/progress watchdog as policy owner, and share response reading between sanitization, JSON synthesis, and comment liveness. Preserve raw opt-out bytes, response bounds, and cancellation. Trim duplicated regressions while retaining real HTTP/SDK signal-identity proof. Fixes openclaw#152535 Co-authored-by: Wynne668 <[email protected]>
The contributor rebased the same SSE delta during maintainer review. Preserve that head as a merge parent; the resulting tree is identical to the reviewed maintainer candidate.
|
Merged via squash.
|
* fix(ai): honor SSE comment keepalives * fix(ai): honor SSE comment keepalives * refactor(ai): reuse response metadata in stream wrappers * fix(ai): enforce JSON body bounds before decoding --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Wynne668 <[email protected]>
Fixes #152535
What Problem This Solves
Fixes managed OpenAI-compatible turns being aborted as idle while the provider is sending SSE comment keepalives.
User Impact
Responses and Chat Completions turns can continue through comment-only pauses. Comments refresh connection liveness without counting as model or diagnostic progress. Genuine silence still times out; the separate model-progress limit remains twice the idle window. First-event and whole-run deadlines remain unchanged. No configuration or migration is required.
Why This Change Was Made
The OpenAI SDK discards comments and replaces the caller's fetch signal. Each managed request now closes over the signal watched by the existing idle watchdog. The response reader recognizes complete comment lines before optional sanitization and reports non-progress activity.
Maintainer cleanup combines comment observation, SSE sanitization, and JSON synthesis in one response reader. It removes the extra observer stream wrapper, retains bounded parsing and cancellation, and preserves original bytes for official and sanitizer-opt-out streams. Redundant cancellation fixtures and the duplicate silence case were removed; regressions retain transport signal-identity, comment-only progress expiry, byte preservation, and diagnostics coverage.
Original fix by @ZengWen-DT; maintainer cleanup by @steipete. The contributor's concurrent base refresh is preserved as a merge parent without force-pushing. Current-main ChatGPT Responses frame bounds (#166853) and WebSocket expiry recovery (#167063) remain intact and address separate paths.
Evidence
Final head:
c460a1bfa9bb7f0d40afdfc43ca44a14ee9af19b, against main3be885108e5e7c846ee6c97cb3d0a8d206b47ba0. Exact-head CI passed. The PR remains open and unmerged.Fresh secretless AWS proof used lease
cbx_d257ea3490a7(m7i.xlarge, 15.33 GiB usable RAM), bound to the full published SHA. Trusted main's bootstrap verified the head, IMDS credential-endpoint 404, and Node/pnpm pins; the lease used public networking, no Tailscale, no hydration, and an isolated HOME. Contributor code did not execute on the maintainer host.okand exactly one provider request.LLM idle timeout (0s): no response from model(7.28 s wall). This confirms the defect remains on that main. Candidate production was restored afterward and verified byte-for-byte by Git.pnpm tsgo:core(62.82 s), the agents-root/agents-other/packages canonical test-type graphs (155.16 s total), formatting, targeted typed lint for all 13 changed TypeScript files, and diff hygiene. No extensions changed.Real Gateway evidence excerpts:
The Gateway proof took 106.35 s including a 73.47 s supported CLI runtime build. It used isolated
OPENCLAW_STATE_DIRandOPENCLAW_CONFIG_PATH,pnpm openclaw gateway run --bind loopback --port 42969 --auth none, and these actual turn commands:No authenticated external provider call is claimed. The mock's immediate initial event deliberately keeps this proof focused on the idle gap; first-event deadline policy is unchanged. Scope remains managed OpenAI-compatible Responses and Chat Completions; Azure Responses and direct Chat Completions are unchanged.
Test cost and commands
Each changed file ran with
pnpm test <file> --maxWorkers=1:src/agents/provider-transport-fetch.sse.integration.test.tssrc/agents/provider-transport-fetch.test.tssrc/agents/embedded-agent-runner/run/llm-idle-timeout.test.tssrc/agents/embedded-agent-runner/stream-resolution.test.tspackages/ai/src/utils/llm-request-activity.test.tsThe two larger wall times are dominated by the existing embedded-runtime import/compiled-worker preparation, not sleeps in the new regressions. They preserve diagnostic activity and composed-signal lifecycle behavior at their existing owners. Siblings took 102.40 s wall. The successful CI run's Node-test jobs report 3,958 aggregate job-seconds including setup and orchestration; this is the selected CI workload, not an estimate of the added regressions' incremental cost.
Remote validation commands
Every command used the trusted bootstrap invocation below, with the shell payload executing sequentially on the same exact-head lease:
Negative control substituted only production from the pinned main; it retained the final tests, required the original error, then restored all candidate files and verified an empty production diff. The complete serial command exited 0 after 582.97 s (669.85 s including checkout/bootstrap). All task leases were stopped. An initial quota fallback returned 2 GiB; its 8 GiB-class replacement exposed only 7.59 GiB usable memory and was also stopped. Final proof used the 16 GiB class. No required proof was substituted with earlier-head results.
Change size
Exact
git diff --numstattotals against the pinned main:Production moved from +69 to −2 by sharing stream ownership and standard response metadata copying. Tests fell from +341 to +295 while preserving the distinct regressions and existing bounds/cancellation coverage. No changelog, new configuration, schema, or public protocol changes were authored.