Skip to content

test(agents): add native loopback regression for outer-abort SSE cancellation - #109185

Merged
steipete merged 2 commits into
openclaw:mainfrom
Pick-cat:fix/proxy-sse-stream-deadline
Jul 18, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
Pick-cat:fix/proxy-sse-stream-deadline

Conversation

@Pick-cat

@Pick-cat Pick-cat commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Adds native loopback regression coverage proving that the existing outer AbortSignal cancels a keepalive-style dripping proxy SSE body in streamProxy (/api/stream). Without this coverage, a future change to the abort handler or reader cleanup path could silently break total-stream-lifetime ownership without any test catching it.

Why This Change Was Made

streamProxy bounds pre-header waits and per-chunk SSE idle, but the total stream lifetime after headers is owned by the caller's signal / outer agent-provider abort budget. A dripping keepalive SSE body (chunks every 20ms) resets per-chunk idle forever, so only the outer abort can terminate it. This PR adds a native loopback regression proving that path works end-to-end with real Node http + fetch + ReadableStream.

An earlier revision proposed an opt-in streamDeadlineMs proxy-local wall-clock. ClawSweeper review (P1) identified that no production caller needed it and the outer signal already owns total stream lifetime, so a second deadline source would create a competing timeout contract. This revision removes streamDeadlineMs entirely and narrows to the regression proof only (Maintainer option 1, recommended).

Non-goals: adding a proxy-local total-stream deadline; changing the existing outer-abort contract; live proxy provider auth.

Collision check: searched open PRs for proxy SSE abort, streamDeadlineMs, proxy stream lifetime; no same-file or same-problem open PR was found.

User Impact

No user-visible behavior change. This is a test-only PR that protects the existing outer-abort SSE cancellation contract against regressions.

Verification

  • Exact head: ece303619a791e886a15d94b9723c5a206f5624b
  • oxfmt --check src/agents/runtime/proxy.test.ts - passed; exit 0.
  • oxlint src/agents/runtime/proxy.test.ts - passed; exit 0.
  • git diff --check - passed; exit 0.

Focused tests:

node scripts/run-vitest.mjs src/agents/runtime/proxy.test.ts -- --run --reporter=verbose
[test] starting test/vitest/vitest.agents.config.ts

 RUN  v4.1.9 /tmp/openclaw-109185

 ✓ |agents| src/agents/runtime/proxy.test.ts > streamProxy > reconstructs a text signature from text_start before streamed deltas 366ms
 ✓ |agents| src/agents/runtime/proxy.test.ts > streamProxy > flushes a final SSE frame without a trailing newline 6ms
 ✓ |agents| src/agents/runtime/proxy.test.ts > streamProxy > forwards prompt cache affinity separately from session identity 3ms
 ✓ |agents| src/agents/runtime/proxy.test.ts > streamProxy > applies timeoutMs before proxy response headers arrive 8ms
 ✓ |agents| src/agents/runtime/proxy.test.ts > streamProxy > bounds non-2xx proxy JSON error reads 97ms
 ✓ |agents| src/agents/runtime/proxy.test.ts > streamProxy > caps unterminated pending SSE bytes before a frame delimiter arrives 57ms
 ✓ |agents| src/agents/runtime/proxy.test.ts > streamProxy > caps delimiter-terminated SSE success body bytes 46ms
 ✓ |agents| src/agents/runtime/proxy.test.ts > streamProxy > re-arms the SSE idle timeout after each received chunk 4ms
 ✓ |agents| src/agents/runtime/proxy.test.ts > streamProxy > does not apply the pre-header timeout as an absolute stream deadline 3ms
 ✓ |agents| src/agents/runtime/proxy.test.ts > streamProxy > returns an error result when the SSE read idles 4ms
 ✓ |agents| src/agents/runtime/proxy.test.ts > streamProxy > honors a longer configured SSE read idle timeout 2ms
 ✓ |agents| src/agents/runtime/proxy.test.ts > streamProxy > releases the proxy response reader after a terminal stream 1ms
 ✓ |agents| src/agents/runtime/proxy.test.ts > streamProxy > returns an error result when EOF arrives without a terminal event 1ms
 ✓ |agents| src/agents/runtime/proxy.test.ts > streamProxy loopback /api/stream > cancels a dripping native SSE body when the outer abort signal fires 147ms

 Test Files  1 passed (1)
      Tests  14 passed (14)
   Start at  09:20:33
   Duration  3.38s

[test] passed 1 Vitest shard in 10.64s

Mutation check: temporarily commented out reader.cancel() in the abortHandler (src/agents/runtime/proxy.ts:287) -> loopback test fails (1 failed | 13 passed) -> restored -> 14 passed. Proves the regression test catches abort-handler breakage.

Real behavior proof

Behavior addressed: a dripping keepalive SSE body (20ms cadence) that resets per-chunk idle is canceled by the outer AbortSignal within 1.5s, not by per-chunk idle (which never fires because drip resets it).

Real environment tested: Linux, Node 22, real http.createServer loopback on 127.0.0.1, real fetch / ReadableStream (no mocked reader or fetch).

Exact commands run:

node scripts/run-vitest.mjs src/agents/runtime/proxy.test.ts -- --run --reporter=verbose

Observed output:

✓ |agents| src/agents/runtime/proxy.test.ts > streamProxy loopback /api/stream > cancels a dripping native SSE body when the outer abort signal fires 147ms

Tests  14 passed (14)

Evidence:

  • Drip cadence: 20ms (resets per-chunk idle every 20ms; idle timeout 10s never fires)
  • Outer abort latency: < 1,500ms (asserted; observed 147ms)
  • Cancellation result: stopReason: "aborted", errorMessage: "Request aborted by user"
  • All 14 tests pass including 13 existing proxy tests (no regression)
  • Mutation check: removing reader.cancel() from abort handler -> test fails -> restored -> passes

What was not tested: live remote proxy provider outage with provider credentials; non-HTTP/1.1 transports; proxy auth flows.

Risk / Compatibility

Low. Test-only change; no production code modified. No new API surface, config, or behavior contract. The regression test uses native Node http + fetch on loopback, matching the production streamProxy code path.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Jul 16, 2026
@Pick-cat
Pick-cat force-pushed the fix/proxy-sse-stream-deadline branch from 7befc51 to 6db6697 Compare July 16, 2026 16:40
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 16, 2026
@clawsweeper

clawsweeper Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 18, 2026, 3:25 AM ET / 07:25 UTC.

Summary
The PR adds a native Node HTTP loopback regression test showing that a caller-provided outer abort signal cancels a continuously dripping /api/stream SSE response.

PR surface: Tests +85. Total +85 across 1 file.

Reproducibility: not applicable. This PR adds regression coverage rather than reporting a new user-facing failure. Its supplied loopback setup is a concrete way to exercise the existing outer-abort behavior.

Review metrics: none identified.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Let the focused/current-head checks complete or refresh them after 03f2c287ff0794289e7c8709ba8b4c958a337f5f before merging.

Risk before merge

  • [P1] The PR body’s detailed focused-test transcript names the earlier ece3036 head, while the current head is 03f2c28; current-head checks should complete or be refreshed before merge.

Maintainer options:

  1. Decide the mitigation before merge
    Keep the caller-owned outer-abort contract and land the deterministic native-loopback regression once the current-head validation confirms it remains stable.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P2] No discrete repair is supported; the remaining action is routine assigned-maintainer review and completion of current-head validation.

Security
Cleared: The patch is limited to a test file and Node built-in HTTP/events imports; it adds no dependency, credential, workflow, or production execution surface.

Review details

Best possible solution:

Keep the caller-owned outer-abort contract and land the deterministic native-loopback regression once the current-head validation confirms it remains stable.

Do we have a high-confidence way to reproduce the issue?

Not applicable: this PR adds regression coverage rather than reporting a new user-facing failure. Its supplied loopback setup is a concrete way to exercise the existing outer-abort behavior.

Is this the best way to solve the issue?

Yes. A native local HTTP server with real fetch and stream consumption is the narrowest maintainable guard for reader cancellation, and it avoids reintroducing the rejected competing stream-deadline policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 85087cbb5f69.

Label changes

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • remove rating: 🦞 diamond lobster: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P3: This is focused regression coverage for an existing runtime behavior and introduces no user-visible feature or production-path change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The submitted terminal evidence directly exercises a real local HTTP SSE server, native fetch, and a real readable stream, showing the intended outer-abort result; the current-head deterministic refinement should still be covered by normal PR checks.
  • proof: sufficient: Contributor real behavior proof is sufficient. The submitted terminal evidence directly exercises a real local HTTP SSE server, native fetch, and a real readable stream, showing the intended outer-abort result; the current-head deterministic refinement should still be covered by normal PR checks.
Evidence reviewed

PR surface:

Tests +85. Total +85 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 91 6 +85
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 91 6 +85

What I checked:

  • Current PR direction: The current head is 03f2c287ff0794289e7c8709ba8b4c958a337f5f, whose recorded commit message is “test(agents): make proxy abort regression deterministic”; the PR remains test-only in src/agents/runtime/proxy.test.ts. (src/agents/runtime/proxy.test.ts:606, 03f2c287ff07)
  • Existing abort contract: The reviewed runtime contract attaches the caller signal to the fetch request, cancels an acquired response reader on abort, and classifies an aborted signal as an aborted stream result; the new loopback scenario targets that existing behavior rather than adding a second timeout policy. (src/agents/runtime/proxy.ts:287, 85087cbb5f69)
  • Direct behavior proof: The PR body records a real Node http.createServer loopback, native fetch, and ReadableStream run where the dripping body is cancelled by the outer signal and the focused proxy suite passes; this is stronger than a mocked-reader-only test. (src/agents/runtime/proxy.test.ts:606, ece303619a79)
  • Adjacent feature provenance: The related merged proxy hardening PR established bounded proxy SSE/body-read handling; this PR covers the distinct caller-owned outer-abort path and does not duplicate that implementation. (src/agents/runtime/proxy.test.ts:606, cc757839d5e2)
  • Release status: This PR is unmerged, so its added regression coverage is not in the stated latest release v2026.7.1; no implemented-on-main close provenance applies.

Likely related people:

  • steipete: Assigned this PR and pushed the latest deterministic-test refinement at the current head. (role: recent branch maintainer and assigned reviewer; confidence: high; commits: 03f2c287ff07; files: src/agents/runtime/proxy.test.ts)
  • zhangguiping-xydt: Authored the merged proxy stream hardening work that established the related SSE response-boundary coverage. (role: adjacent proxy-stream feature contributor; confidence: medium; commits: cc757839d5e2; files: src/agents/runtime/proxy.ts, src/agents/runtime/proxy.test.ts)
  • Pick-cat: Authored this regression test and has prior merged work in the proxy-capture area, providing relevant context without making them the sole ownership route. (role: adjacent proxy contributor; confidence: medium; commits: 7cde0ac8c0a8; files: src/proxy-capture/runtime.ts, src/agents/runtime/proxy.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (5 earlier review cycles)
  • reviewed 2026-07-16T16:49:16.813Z sha 6db66977fc569d5b563a597bf598773f0697d4bc :: needs real behavior proof before merge. :: [P1] Preserve longer configured stream lifetimes
  • reviewed 2026-07-16T21:50:11.279Z sha 7a5e2b272819854961dd238dea82b15f4867ffbb :: found issues before merge. :: [P1] Remove the unused parallel stream deadline
  • reviewed 2026-07-16T23:51:52.506Z sha 7a5e2b272819854961dd238dea82b15f4867ffbb :: found issues before merge. :: [P1] Remove the unused parallel stream deadline
  • reviewed 2026-07-17T01:29:18.012Z sha ece303619a791e886a15d94b9723c5a206f5624b :: needs maintainer review before merge. :: none
  • reviewed 2026-07-17T02:11:48.222Z sha ece303619a791e886a15d94b9723c5a206f5624b :: needs maintainer review before merge. :: none

@Pick-cat
Pick-cat force-pushed the fix/proxy-sse-stream-deadline branch from 6db6697 to 7a5e2b2 Compare July 16, 2026 21:42
@Pick-cat Pick-cat changed the title fix(agents): dripping proxy SSE streams hang past chunk-idle timeout fix(agents): dripping proxy SSE bodies cancel via outer abort Jul 16, 2026
@Pick-cat

Copy link
Copy Markdown
Contributor Author

Addressed ClawSweeper feedback on head 7a5e2b27281:

  1. Removed the unconditional one-hour proxy-local ceiling — total lifetime stays with outer signal / agent-provider abort by default.
  2. streamDeadlineMs is opt-in only (no default).
  3. Added native loopback /api/stream drip proof for outer abort cancellation and for explicit streamDeadlineMs.

Proof:

OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/agents/runtime/proxy.test.ts
→ 16 passed (includes 2 loopback cases)
autoreview clean (Claude; overall patch is correct 0.95)

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 17, 2026
@Pick-cat Pick-cat changed the title fix(agents): dripping proxy SSE bodies cancel via outer abort test(agents): add native loopback regression for outer-abort SSE cancellation Jul 17, 2026
@Pick-cat
Pick-cat force-pushed the fix/proxy-sse-stream-deadline branch from 7a5e2b2 to ece3036 Compare July 17, 2026 01:23
@Pick-cat

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 17, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. labels Jul 17, 2026
@steipete steipete self-assigned this Jul 18, 2026
@steipete
steipete force-pushed the fix/proxy-sse-stream-deadline branch from ece3036 to 2b50a42 Compare July 18, 2026 07:21
Pick-cat and others added 2 commits July 18, 2026 08:22
…ellation

Adds a native loopback /api/stream regression proving that the existing
outer AbortSignal cancels a keepalive-style dripping SSE body. The drip
resets per-chunk idle, so only the outer abort can terminate the stream
within budget.

Removes the previously proposed streamDeadlineMs opt-in: no production
caller needed it and the outer signal already owns total stream lifetime.

Co-Authored-By: nebulacoder-v8.0 <[email protected]>
@steipete
steipete force-pushed the fix/proxy-sse-stream-deadline branch from 2b50a42 to 03f2c28 Compare July 18, 2026 07:23
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Jul 18, 2026
@steipete
steipete merged commit e3eb112 into openclaw:main Jul 18, 2026
101 of 103 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 19, 2026
…ellation (openclaw#109185)

* test(agents): add native loopback regression for outer-abort SSE cancellation

Adds a native loopback /api/stream regression proving that the existing
outer AbortSignal cancels a keepalive-style dripping SSE body. The drip
resets per-chunk idle, so only the outer abort can terminate the stream
within budget.

Removes the previously proposed streamDeadlineMs opt-in: no production
caller needed it and the outer signal already owns total stream lifetime.

Co-Authored-By: nebulacoder-v8.0 <[email protected]>

* test(agents): make proxy abort regression deterministic

---------

Co-authored-by: nebulacoder-v8.0 <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…ellation (openclaw#109185)

* test(agents): add native loopback regression for outer-abort SSE cancellation

Adds a native loopback /api/stream regression proving that the existing
outer AbortSignal cancels a keepalive-style dripping SSE body. The drip
resets per-chunk idle, so only the outer abort can terminate the stream
within budget.

Removes the previously proposed streamDeadlineMs opt-in: no production
caller needed it and the outer signal already owns total stream lifetime.

Co-Authored-By: nebulacoder-v8.0 <[email protected]>

* test(agents): make proxy abort regression deterministic

---------

Co-authored-by: nebulacoder-v8.0 <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants