Skip to content

fix(workflows): let structured replies finish before worker cleanup - #8376

Merged
ymichael merged 1 commit into
mainfrom
slopcop/issue-8371
Nov 30, 2026
Merged

ymichael merged 1 commit into
mainfrom
slopcop/issue-8371

Conversation

@bb-slop-cop

@bb-slop-cop bb-slop-cop Bot commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · new-issue-autopilot

Human comments

What was wrong

Structured-result submission awaited worker shutdown before the result tool could return. Settling the workflow call also made the worker immediately eligible for maintenance cleanup, so removing the direct stop alone still allowed premature cancellation. Both paths reproduced on trusted main b0ddaad731565d7e4de68d824120d802fc78f7d5 and again in a second clean checkout.

Reproduction and root-cause report

What changed

  • Remove synchronous worker stops from accepted, duplicate, and exhausted-retry structured-result submissions.
  • Protect newly terminal workers from cleanup for up to 30 seconds, using the existing maintenance timer rather than adding timers or configuration.
  • Release the guard when the worker settles or fails; retire workers that never settle after the deadline.
  • Extend the real-plugin integration test and add an accepted/exhausted × idle/deadline regression table.

Only the workflows subsystem changes: 3 files, 109 changed text lines (99 additions + 10 deletions). No dependency, generated file, stored-data, public API, or server/daemon protocol change.

How you verified

  • Before the production fix, the focused real-plugin test fails on both clean trusted checkouts: a stop occurs before the reply, and maintenance records 3 stops / 1 archive before worker settlement.
  • All four new lifecycle cases fail before the production fix and pass afterward.
  • pnpm exec turbo run test --filter=bb-plugin-workflows -- src/server-harness.test.ts src/service-policy.test.ts -t 'runs a structured workflow asynchronously|defers terminal structured cleanup': 5 focused cases pass.
  • pnpm exec turbo run test lint typecheck --filter=bb-plugin-workflows: 296 tests pass across 14 files; lint and typecheck pass. Lint retains one existing warning in unchanged UI code.
  • pnpm exec oxfmt on changed files and git diff --check pass; all changes are text.

Live provider-stream interruptions and the separately reported Node 26 crash are not exercised. An unfiltered monorepo build hits unrelated SDK runtime build-order failures; the relevant Turbo dependency builds and workflow checks pass.

Fixes #8371

AGENT GENERATED

@ymichael
ymichael merged commit efe1d36 into main Nov 30, 2026
33 checks passed
@ymichael
ymichael deleted the slopcop/issue-8371 branch November 30, 2026 21:16
ymichael added a commit that referenced this pull request Nov 30, 2026
…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
(#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](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
scowalt pushed a commit to scowalt/bb that referenced this pull request Dec 1, 2026
…et-bb#8376)

🚨 **SLOP COP** 🚨 · `new-issue-autopilot`

## Human comments

## What was wrong

Structured-result submission awaited worker shutdown before the result
tool could return. Settling the workflow call also made the worker
immediately eligible for maintenance cleanup, so removing the direct
stop alone still allowed premature cancellation. Both paths reproduced
on trusted main `a8c32288cf24894fbe85cb3a9ca0469c7a997ed6` and again in
a second clean checkout.

[Reproduction and root-cause
report](https://get-bb.github.io/reports/issues/8371.html)

## What changed

- Remove synchronous worker stops from accepted, duplicate, and
exhausted-retry structured-result submissions.
- Protect newly terminal workers from cleanup for up to 30 seconds,
using the existing maintenance timer rather than adding timers or
configuration.
- Release the guard when the worker settles or fails; retire workers
that never settle after the deadline.
- Extend the real-plugin integration test and add an accepted/exhausted
× idle/deadline regression table.

Only the workflows subsystem changes: **3 files, 109 changed text lines
(99 additions + 10 deletions)**. No dependency, generated file,
stored-data, public API, or server/daemon protocol change.

## How you verified

- Before the production fix, the focused real-plugin test fails on both
clean trusted checkouts: a stop occurs before the reply, and maintenance
records 3 stops / 1 archive before worker settlement.
- All four new lifecycle cases fail before the production fix and pass
afterward.
- `pnpm exec turbo run test --filter=bb-plugin-workflows --
src/server-harness.test.ts src/service-policy.test.ts -t 'runs a
structured workflow asynchronously|defers terminal structured cleanup'`:
5 focused cases pass.
- `pnpm exec turbo run test lint typecheck
--filter=bb-plugin-workflows`: 296 tests pass across 14 files; lint and
typecheck pass. Lint retains one existing warning in unchanged UI code.
- `pnpm exec oxfmt` on changed files and `git diff --check` pass; all
changes are text.

Live provider-stream interruptions and the separately reported Node 26
crash are not exercised. An unfiltered monorepo build hits unrelated SDK
runtime build-order failures; the relevant Turbo dependency builds and
workflow checks pass.

Fixes get-bb#8371

> AGENT GENERATED

<!-- slopcop:rule=new-issue-autopilot run=run_y92ufcalmx29w84b
sha=issue-8371 kind=summary -->

Co-authored-by: SawyerHood <[email protected]>
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.

workflows: submitStructuredResult stops the worker mid-call before bb_workflow_result returns

2 participants