Repository navigation
Add opt-in idle Claude query release - #2808
Conversation
a2d721c to
78a5f91
Compare
78a5f91 to
f4bbd57
Compare
|
🚨 SLOP COP 🚨 · I am the Slop Cop. I am now reviewing this pull request for security, quality, performance, architecture, and test behavior. |
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
Plain English summary
This change can close an inactive Claude Code process after 30 seconds. The next message starts a new process and continues the same thread. The option remains off by default.
Findings
-
High — active monitor work can lose its Claude process. Claude reports some background work as a
monitortask. The translator drops that task before it records lifecycle state. The idle check then sees no open work and can close Claude. Track hidden monitor state and add an idle-release test. -
High — the daemon protocol version needs an increase. The new required option crosses the server-to-daemon command boundary.
HOST_DAEMON_PROTOCOL_VERSIONremains 176. This breaks mixed-version behavior and conflicts with repository policy. Increase the version and its contract test. -
Medium — a new thread without a turn stays resident. The start path creates the Claude query but does not schedule the idle timer. The resume and fork paths schedule it. Add the same call and a no-turn start test.
Architecture
The agent runtime already has a 30-minute session reaper. This feature controls a different inner Claude process, so it does not exactly duplicate that reaper. The start, resume, and fork paths repeat setup and timer duties. A shared helper or a small residency controller can prevent lifecycle differences.
Security and performance
I found no security defect. I found no separate performance defect. The timer cancels stale work, and concurrent wake requests share one promise.
Validation
- The Claude provider suite passed 347 tests in 24 files.
- The Claude provider type check passed.
- The focused server suite passed 30 tests.
- GitHub reports all current checks as successful.
- A browser cannot exercise this host-side JSON-RPC bridge, so doobie does not apply.
- The tests mock the Claude query and do not prove actual operating-system process exit.
These findings need fixes. I posted a comment-only review, as required.
126b6a7 to
f41aff0
Compare
|
🚨 SLOP COP 🚨 · I am the Slop Cop. I am reviewing this pull request for security, quality, performance, architecture, and test behavior. |
| } | ||
| const replacementSession = createThreadSession(attachment); | ||
| attachment.residentSession = replacementSession; | ||
| startResidentThreadSession(attachment, providerThreadId); |
There was a problem hiding this comment.
🚨 slopcop/review — Do not resume an empty new session
A new attachment receives a session ID before Claude reads its first input. If idle release closes it first, Claude creates no conversation file. This wake path then passes that unused ID as resume. The first turn fails with No conversation found with session ID. Track whether Claude persisted the conversation. Start an empty new attachment with its existing sessionId, and use resume only after a turn. Add a start-without-turn, release, and wake test.
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
Plain English summary
This pull request adds an optional setting that closes Claude after 30 seconds with no active work. A later message starts Claude again and keeps the same thread context. The setting stays off by default.
Finding
- Medium — a new thread can fail after release before its first input. The bridge assigns a session ID before Claude reads any input. Claude does not save an empty conversation. After release, the wake path sends that unused ID as
resume. Claude then returnsNo conversation found with session ID, and the first turn fails. Track whether Claude saved the conversation. UsesessionIdfor an empty new thread, and useresumeonly after Claude saves a turn. Add a test for start, no input, release, and wake.
Architecture and code reuse
BB also closes a full idle provider session after 30 minutes. This change closes only the inner Claude process after 30 seconds. These two systems have different duties, so this code does not duplicate the runtime reaper.
Start, resume, and fork still repeat attachment construction. A shared attachment factory could reduce future lifecycle differences, but this is an optional refactor.
Security and performance
I found no security defect. I found no other performance defect. The code keeps one timer for each enabled resident attachment and cancels obsolete timers.
Validation
- The Claude provider suite passed 349 tests in 24 files.
- The Claude provider type check passed.
- The focused server suite passed 30 tests.
- The SDK 0.3.245 check reproduced the empty-session failure with zero token use.
- A live development server reached the real Claude program, but the expired local OAuth session blocked a full response.
- Doobie does not apply because this change has no browser route.
git diff --checkpassed.- All current GitHub checks passed.
I posted a comment-only review, as required. I recommend a fix for the empty-session wake before merge.
## Human comments ## What was wrong The opt-in Claude idle releaser treated translated turns, background-task presentation state, BB-forwarded tool calls, and interactive requests as the complete residency signal. That omitted Claude's authoritative `running` and `requires_action` session states and its pending session-cron snapshot, so the 30-second timer could stop a process that was still working or waiting to deliver a scheduled wakeup. ## What changed The Claude bridge now includes authoritative SDK session state and the Stop hook's replace-all `session_crons` snapshot in the shared quiescence decision. `running`, `requires_action`, and any pending scheduled work keep the query resident; `idle` with an empty cron snapshot permits the existing grace-period release. The existing authoritative `background_tasks_changed` handling and older-CLI task-bookend fallback remain intact. No daemon wire contract, CLI, guide, or configuration surface changed. ## How you verified - Added timer regressions for `running` and `requires_action` transitioning to `idle`; they failed before the fix because `query.close()` ran and pass after it. - Added a timer regression for a nonempty Stop-hook session-cron snapshot transitioning to empty; it failed before the fix and now preserves the query until the snapshot clears. - Ran `pnpm exec turbo run test typecheck build --filter=bb-plugin-provider-claude-code --force` after rebasing onto current `origin/main`: 24 test files and 351 tests passed; typecheck and build passed; 6/6 Turbo tasks succeeded. - `git diff --check` passed. Follow-up to #2808. > AGENT GENERATED
## Human comments
## What was wrong
bb threads never got the Claude in Chrome browser tools, even when the
interactive `claude` CLI had Chrome enabled by default. Claude Code
(2.1.259) skips the `claudeInChromeDefaultEnabled` default in
headless/SDK mode and only honors an explicit `--chrome` flag. Checked
directly: `claude -p` loads 0 Chrome tools, `claude -p --chrome`
connects the `claude-in-chrome` MCP server and loads 22 tools. bb never
passed the flag.
## What changed
- `plugins/provider-claude-code/server.ts`: new `chromeEnabled` boolean
setting (default off) and its derived provider option.
- `session-params.ts`, `bridge/commands.ts`: carry `chromeEnabled`
through thread start/resume/fork and turn start/steer params.
- `bridge/session-options.ts`, `bridge/sdk-session.ts`: when enabled,
pass `extraArgs: { chrome: null }` to the Agent SDK, which becomes
`--chrome` on the Claude process.
- `bridge/bridge.ts`: a changed setting on a turn updates the
attachment's session options and marks the resident session to restart
before the next turn with the same provider thread id, so context is
kept. A resume with a changed setting replaces the session through the
existing construction-config comparison.
- Docs: `docs/configuration.md`, bb-cli skill
`references/configuration.md`, and the providers guide template.
- No `HOST_DAEMON_PROTOCOL_VERSION` bump: the option rides inside the
provider plugin's `providerOptions` bag and plugin-internal bridge
params, same as `idleQueryReleaseEnabled` (#2808).
## How you verified
- New tests: `buildSessionOptions` emits `extraArgs` only when enabled;
bridge test that a turn flipping `chromeEnabled` restarts the Claude
process with `resume` set and emits `session/replaced`; server test for
the setting descriptor and derived option; session-params and
thread-runtime-config assertions updated.
- `pnpm exec turbo run typecheck --filter=bb-plugin-provider-claude-code
--filter=@bb/server` clean.
- `pnpm exec turbo run test --filter=bb-plugin-provider-claude-code
--force`: 25 files, 354 tests pass. `@bb/server`
`thread-runtime-config.test.ts`: 30 pass.
- Manual: `claude -p --chrome --output-format stream-json --verbose` on
this host lists `claude-in-chrome` as connected with 22
`mcp__claude-in-chrome__*` tools; without the flag, none.
> AGENT GENERATED
Human comments
What was wrong
The Claude provider represented a bb thread attachment and its resident Claude SDK query as one
ThreadSession. That forced an idle query and Claude child process to remain alive until core released the entire attachment after 30 minutes; closing the combined object earlier also removed routing state, so the nextturn/startfailed withNo active session.What changed
SdkSessionand query.idleQueryReleaseEnabled, defaulted off for the bake period. Changes apply on the next start, resume, or turn command.session/replaced→ identity →session.resetordering.thread/stopstill deletes the attachment, allowing core's existing 30-minute cleanup to retire the bridge worker.thread/resumerequests before constructing a query.Enable the bake with:
This is Claude-provider policy only. The option travels in the existing opaque provider-options bag and old host daemons already forward that bag, so the server/daemon wire contract and
HOST_DAEMON_PROTOCOL_VERSIONare unchanged. Immediate auth-failure eviction and credential-store startup serialization remain separate follow-up PRs (#2804 and #2807).How you verified
The fake-clock regressions fail before the implementation and cover:
Commands run after rebasing onto current
origin/main:CI=1 pnpm exec turbo run test typecheck --filter=bb-plugin-provider-claude-code --force— 24 files, 349 tests passed; typecheck passedCI=1 pnpm exec turbo run test typecheck --filter=@bb/templates --force— 43 tests passed; typecheck passedCI=1 pnpm exec turbo run test --filter=@bb/server --force -- test/skills/builtin-skills-copy.test.ts test/skills/shipped-skills-quality.test.ts— 14 tests passedCI=1 pnpm exec turbo run test --filter=@bb/server --force -- test/threads/thread-runtime-config.test.ts— 30 tests passedgit diff --check origin/main...HEADLive dev CLI QA confirmed the setting schema reports
default: false, setting it totrueis reflected immediately, and unsetting it restores the effective value tofalse.