Skip to content

Keep interactive plugin tools past the Connect timeout - #1084

Merged
SawyerHood merged 2 commits into
mainfrom
bb/debug-issue-1082-thr_72dhrw3s8a
Aug 7, 2026
Merged

SawyerHood merged 2 commits into
mainfrom
bb/debug-issue-1082-thr_72dhrw3s8a

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Summary

  • send the internal plugin-tool response headers before the tool completes
  • deliver the unchanged JSON result through the open response body
  • add server and Connect regressions for responses delayed beyond 30 seconds

Fixes #1082

Tests

  • pnpm exec turbo run test --filter=@bb/server -- --run test/internal/internal-events-tool-calls.test.ts test/services/plugins/plugin-agent-tools.test.ts test/services/pending-interactions.test.ts
  • pnpm exec turbo run test --filter=bb-plugin-ask-user-question
  • pnpm exec turbo run test typecheck --filter=@bb/connect
  • pnpm exec turbo run build typecheck --filter=@bb/server
  • pnpm exec prettier --check apps/server/src/internal/tool-calls.ts apps/server/test/internal/internal-events-tool-calls.test.ts apps/connect/src/worker.test.ts

Risk

The host-daemon JSON contract is unchanged. Existing daemons already read the full response body before they parse the result.

@SawyerHood SawyerHood left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

I am the SlopCop. I am reviewing this change for security, code quality, performance, architecture, and end-to-end behavior.

The stack contains one pull request: #1084, Keep interactive plugin tools past the Connect timeout.

I found no draft or untrusted pull request to skip. I will add a comment after each review phase.

@SawyerHood SawyerHood left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

The code-quality and architecture phase is complete.

I found one medium issue. A canceled Connect response does not cancel the origin request or the plugin tool.

This change makes that existing gap important because an interactive tool can wait for user input without a time limit.

I found no duplicate promise-to-JSON stream helper. The route and daemon contracts still match. This change does not need a daemon protocol increase.

The server and Connect type checks passed. The server file passed 25 tests. The Connect worker file passed 60 tests.

Comment thread apps/server/src/internal/tool-calls.ts Resolved

@SawyerHood SawyerHood left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

The security phase is complete.

It confirmed the medium cancellation issue in the inline comment. A valid daemon can abandon response bodies and retain server, tunnel, Connect, and plugin resources.

I found no additional authentication, authorization, data exposure, JSON serialization, or trust-boundary issue.

The affected Connect and server tests passed. The full Connect suite passed 89 tests.

The full server suite passed 1,335 tests. One unrelated machine-install test failed.

@SawyerHood SawyerHood left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

The performance and end-to-end phase is complete.

It confirmed the medium cancellation issue. Many abandoned interactive calls can retain plugin, server, tunnel, and Connect resources without a time limit.

I found no separate backpressure, timer, concurrency, or timeout defect. Each normal response contains one small JSON chunk.

The internal daemon route has no feasible browser workflow. It requires daemon authentication, a matching host, and a provider tool call.

The real TCP server test passed 25 tests. The Connect relay test passed 60 tests. The host-daemon HTTP and WebSocket transport tests passed 20 tests.

All three affected package type checks passed. A combined custom transport harness did not run because of test-module resolution limits.

@SawyerHood SawyerHood left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

The review is complete for the one-PR stack.

I found one medium issue. Connect does not propagate response cancellation to the origin, so abandoned interactive tools can retain resources indefinitely.

I found no separate security, correctness, architecture, duplication, backpressure, or contract issue.

The affected server, Connect, and host-daemon tests passed. All affected package type checks passed. The full Connect suite passed.

The route has no browser workflow. The real TCP, HTTP, and WebSocket transport tests passed, but a combined custom harness did not run.

Current-head package smoke and version checks passed. Other current-head CI checks remain in progress.

I posted a comment-only review. I did not approve the pull request or request changes.

@SawyerHood
SawyerHood merged commit 4fd3940 into main Aug 7, 2026
12 of 21 checks passed
@SawyerHood
SawyerHood deleted the bb/debug-issue-1082-thr_72dhrw3s8a branch August 7, 2026 00:34
amadad pushed a commit to amadad/bb that referenced this pull request Aug 14, 2026
## Summary

- send the internal plugin-tool response headers before the tool
completes
- deliver the unchanged JSON result through the open response body
- add server and Connect regressions for responses delayed beyond 30
seconds

Fixes get-bb#1082

## Tests

- `pnpm exec turbo run test --filter=@bb/server -- --run
test/internal/internal-events-tool-calls.test.ts
test/services/plugins/plugin-agent-tools.test.ts
test/services/pending-interactions.test.ts`
- `pnpm exec turbo run test --filter=bb-plugin-ask-user-question`
- `pnpm exec turbo run test typecheck --filter=@bb/connect`
- `pnpm exec turbo run build typecheck --filter=@bb/server`
- `pnpm exec prettier --check apps/server/src/internal/tool-calls.ts
apps/server/test/internal/internal-events-tool-calls.test.ts
apps/connect/src/worker.test.ts`

## Risk

The host-daemon JSON contract is unchanged. Existing daemons already
read the full response body before they parse the result.
SawyerHood added a commit that referenced this pull request Sep 25, 2026
…eline (#4321)

## Human comments

## What was wrong

Two bugs, both hit by `bb secret request` from a Codex thread whose CLI
reaches the server through bb connect.

1. `POST /api/v1/plugins/:id/cli` sent nothing until the plugin command
returned. `bb secret request` waits on `bb.ui.requestInput` until the
user submits, so the connect gate's 30s response-head timeout
(`RESP_HEAD_TIMEOUT_MS` in `apps/connect/src/tunnel-do.ts`) returned a
504. The gate does not cancel the upstream request, so the form stayed
open after the command had already failed, and the agent requested the
key again. #1084 fixed the same problem for the daemon's plugin
tool-call route but not for the CLI route.
2. Plugin interactions have `turnId: null` on purpose, so they never
block sends. Their `system/interaction/lifecycle` events are therefore
thread-scoped, and `groupEventProjectionTurns` sorted them as standalone
entries after the whole running turn. The resolved form rows stayed at
the bottom of the timeline. While the thread is active, the last row
group counts as active, and a group of only form rows has no summary
phrase, so the timeline showed a "Working" row that never went away.

## What changed

- `apps/server/src/routes/plugins.ts`: `pluginCliResponse` returns the
plain JSON result when a command finishes within 10s, the same as
before. Otherwise it sends headers immediately, then a `\n` keepalive
every 10s, then the JSON result. The response is marked `no-store,
no-transform`, so neither compression middleware buffers it. JSON allows
leading whitespace, so existing CLIs parse the result unchanged. A
client disconnect still aborts `ctx.signal`. The daemon wire is
unchanged, so there is no `HOST_DAEMON_PROTOCOL_VERSION` bump.
- `packages/thread-view/src/group-event-projection-turns.ts`:
thread-scoped permission-grant, user-question, and plugin-form lifecycle
messages now join the turn that was running at their first sequence.
Messages requested between turns stay standalone. The fix applies to
stored events, so existing threads render correctly.

Not changed: the connect gate still does not tell the tunnel client when
it gives up on a request after 30s. That needs a `bb-connect` deploy.

## How you verified

- New tests: `packages/thread-view/test/build-thread-timeline.test.ts`
covers in-turn placement (fails before the fix, passes after) and
standalone placement between turns.
`apps/server/test/routes/plugin-cli-response.test.ts` covers the fast
JSON path, keepalive before a slow result, a rejected command reported
as exit 1 after streaming began, and client cancel.
- `pnpm exec turbo run typecheck test --filter=@bb/thread-view`
(415/415) and `pnpm exec turbo run typecheck --filter=@bb/server`, plus
the server `test/routes`, `test/services/plugins`, `test/threads`, and
`test/public` suites.
- A 12s plugin CLI command through the full server middleware stack:
headers and the first byte arrive before it finishes, and the body is
not compressed.
- The provider-corpus gate fails the same 341 tests before and after
this change, because its snapshots are out of date on main.
- Manual end-to-end check: an isolated dev app, a real Codex turn, the
form submitted in a headless browser, and a local proxy that copies the
gate's 30s head timeout.
- Old code: 504 at 30,024ms, the form stayed open, and the form row sat
below the final reply.
- Fixed code: headers at 10,004ms, keepalives, the result at 380,635ms
with exit 0, `.env.e2e` written with mode 600, and the form row directly
under its command inside the turn, including after a reload.
- The same projection change, run against the affected production
thread's events, moves both form rows from the tail to seq 285 and 320.

> AGENT GENERATED

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

Co-authored-by: Claude Opus 5.5 <[email protected]>
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#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.

AskUserQuestion multi-question submission can resolve without returning answers

1 participant