Skip to content

Keep secret requests alive through bb connect and in place in the timeline - #4321

Merged
SawyerHood merged 1 commit into
mainfrom
bb/fix-api-key-request-loop-in-bb-thr_ukpvnn9rqt
Sep 25, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
bb/fix-api-key-request-loop-in-bb-thr_ukpvnn9rqt

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

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. Keep interactive plugin tools past the Connect timeout #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

…eline

The plugin CLI route returned nothing until the command finished, so a
`bb secret request` from a thread whose CLI reaches the server through bb
connect hit the gate's 30s response-head timeout and failed with HTTP 504
while its form stayed open. Commands still running after 10s now get their
headers immediately and a newline keepalive every 10s before the JSON
result, which older CLIs still parse.

Plugin forms are thread-scoped interaction events, so the timeline sorted
them after the whole running turn, where an active group of form rows is
labelled "Working". Thread-scoped interaction lifecycles now join the turn
that was running when they were requested.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@SawyerHood
SawyerHood merged commit 96fee8a into main Sep 25, 2026
28 of 30 checks passed
@SawyerHood
SawyerHood deleted the bb/fix-api-key-request-loop-in-bb-thr_ukpvnn9rqt branch September 25, 2026 03:29
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.

1 participant