Skip to content

fix(server): keep held-open tool-call responses out of compression - #8407

Merged
ymichael merged 1 commit into
mainfrom
bb/8332-process-server-crash-loop-unhandled-aborter-thr_fwi4z4ak52
Nov 30, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/8332-process-server-crash-loop-unhandled-aborter-thr_fwi4z4ak52

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

POST /internal/session/tool-call streams its body so the daemon receives the response head before a long-running plugin tool finishes (#1084). The app-wide Hono compress() middleware wrapped that held-open stream in a CompressionStream. When the daemon cancels the request (for example, a thread stop during a plugin tool call), PluginToolCallRegistry settles the call synchronously on the same abort. The source therefore enqueues and closes while @hono/node-server cancels the compressed reader. On Node 26.4.0–26.6.0, that race leaves an unhandled AbortError rejection (destroyer → webstreams/adapters:498 → ServerResponse.cancel). Under the default --unhandled-rejections=throw, the server's uncaughtException handler then calls process.exit(1). Node 26.7.0 fixed the race upstream; 22.x, 26.3.1 and 26.7+ are unaffected. #8376 removed the most frequent trigger, the workflows engine stopping a worker during bb_workflow_result. Any thread stop during an in-flight plugin tool call still crashed affected Node versions.

What changed

  • apps/server/src/internal/tool-calls.ts: the streamed tool-call response sets cache-control: no-store, no-transform, so compression skips it. The plugin CLI keepalive stream in routes/plugins.ts already uses the same header. The body is one small JSON chunk that gzip could not emit before the call settled anyway.
  • apps/server/test/internal/internal-events-tool-calls.test.ts: new real-socket test. It starts a pending plugin tool call with accept-encoding: gzip, deflate, asserts the response is not content-encoded, aborts the request as the daemon does, and waits for the plugin's signal to abort.

There is no wire or protocol change: the daemon already accepted uncompressed responses.

How you verified

  • Standalone hono + compress() + @hono/node-server repro: Node 26.4.0, 26.5.0 and 26.6.0 crash on 20/20 cancels with compression and 0/20 without it. Node 22.23.1, 26.3.1, 26.7.0, 26.8 and 26.12.1 are 0/20 in both modes.
  • New test before the fix: fails on Node 22 (content-encoding: gzip). With the encoding assertion skipped, Node 26.4.0 reports the issue's exact unhandled AbortError stack through the real route.
  • After the fix on Node 26.4.0: internal-events-tool-calls.test.ts and internal-tool-call-regressions.test.ts pass (37 tests) with no unhandled errors.
  • pnpm exec turbo run typecheck lint --filter=@bb/server passes.
  • pnpm exec turbo run test --filter=@bb/server -- test/internal/internal-events-tool-calls.test.ts test/internal/internal-tool-call-regressions.test.ts test/services/plugins/plugin-agent-tools.test.ts passes (57 tests).

Fixes #8332

AGENT GENERATED

🤖 Generated with Claude Code

The internal tool-call route streams its body so the daemon gets response
headers before a long plugin tool finishes. Hono's compress() wrapped that
stream in a CompressionStream. When the daemon cancels the request (thread
stop), the registry settles the call on the same abort, so the source closes
while node-server cancels the compressed reader. On Node 26.4-26.6 that race
leaves an unhandled AbortError rejection, which the server's
uncaughtException handler turns into process.exit(1).

Mark the response no-store, no-transform, as the plugin CLI keepalive
stream already does.

Fixes #8332

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@blacksmith-sh

This comment has been minimized.

@ymichael
ymichael merged commit b88c387 into main Nov 30, 2026
54 of 55 checks passed
@ymichael
ymichael deleted the bb/8332-process-server-crash-loop-unhandled-aborter-thr_fwi4z4ak52 branch November 30, 2026 21:54
scowalt pushed a commit to scowalt/bb that referenced this pull request Dec 1, 2026
…et-bb#8407)

## Human comments

## What was wrong

`POST /internal/session/tool-call` streams its body so the daemon
receives the response head before a long-running plugin tool finishes
(get-bb#1084). The app-wide Hono `compress()` middleware wrapped that
held-open stream in a `CompressionStream`. When the daemon cancels the
request (for example, a thread stop during a plugin tool call),
`PluginToolCallRegistry` settles the call synchronously on the same
abort. The source therefore enqueues and closes while
`@hono/node-server` cancels the compressed reader. On Node
26.4.0–26.6.0, that race leaves an unhandled `AbortError` rejection
(`destroyer` → `webstreams/adapters:498` → `ServerResponse.cancel`).
Under the default `--unhandled-rejections=throw`, the server's
`uncaughtException` handler then calls `process.exit(1)`. Node 26.7.0
fixed the race upstream; 22.x, 26.3.1 and 26.7+ are unaffected. get-bb#8376
removed the most frequent trigger, the workflows engine stopping a
worker during `bb_workflow_result`. Any thread stop during an in-flight
plugin tool call still crashed affected Node versions.

## What changed

- `apps/server/src/internal/tool-calls.ts`: the streamed tool-call
response sets `cache-control: no-store, no-transform`, so compression
skips it. The plugin CLI keepalive stream in `routes/plugins.ts` already
uses the same header. The body is one small JSON chunk that gzip could
not emit before the call settled anyway.
- `apps/server/test/internal/internal-events-tool-calls.test.ts`: new
real-socket test. It starts a pending plugin tool call with
`accept-encoding: gzip, deflate`, asserts the response is not
content-encoded, aborts the request as the daemon does, and waits for
the plugin's signal to abort.

There is no wire or protocol change: the daemon already accepted
uncompressed responses.

## How you verified

- Standalone hono + `compress()` + `@hono/node-server` repro: Node
26.4.0, 26.5.0 and 26.6.0 crash on 20/20 cancels with compression and
0/20 without it. Node 22.23.1, 26.3.1, 26.7.0, 26.8 and 26.12.1 are 0/20
in both modes.
- New test before the fix: fails on Node 22 (`content-encoding: gzip`).
With the encoding assertion skipped, Node 26.4.0 reports the issue's
exact unhandled `AbortError` stack through the real route.
- After the fix on Node 26.4.0: `internal-events-tool-calls.test.ts` and
`internal-tool-call-regressions.test.ts` pass (37 tests) with no
unhandled errors.
- `pnpm exec turbo run typecheck lint --filter=@bb/server` passes.
- `pnpm exec turbo run test --filter=@bb/server --
test/internal/internal-events-tool-calls.test.ts
test/internal/internal-tool-call-regressions.test.ts
test/services/plugins/plugin-agent-tools.test.ts` passes (57 tests).

Fixes get-bb#8332

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

process-server crash loop: unhandled AbortError on streamed response cancel (workflows worker stop during bb_workflow_result), Node 26

1 participant