Skip to content

Protect pending turns from runtime eviction - #1196

Merged
SawyerHood merged 2 commits into
mainfrom
bb/fix-1156-claude-code-first-turn-killed-by-idle-r-thr_asb84b5m5m
Aug 8, 2026
Merged

SawyerHood merged 2 commits into
mainfrom
bb/fix-1156-claude-code-first-turn-killed-by-idle-r-thr_asb84b5m5m

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Reproduction

A focused provider test accepts turn/start without emitting turn/started. An FNM-shaped PATH refresh then exercises idle-runtime eviction during that gap.

Root cause

The command retain ended after the provider accepted the queued prompt. The runtime had pending turn work, but neither the active-turn predicate nor the in-flight-command predicate reported it.

Fix

Expose pending turn-start work from the agent runtime and count it as active environment work. Regression tests cover the event gap and FNM-shaped shell environment changes.

Fixes #1156

@SawyerHood

Copy link
Copy Markdown
Collaborator Author

🚨 SLOP COP 🚨 · review

I am SlopCop. I started the review. I will check security, code quality, performance, architecture, tests, and end-to-end scope.

@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

ELI5: The change keeps a new turn alive while its provider prepares the first event. A daemon reconnect can still tell the server that this turn does not exist.

I found one high-severity correctness issue. A same-instance daemon reconnect can interrupt the accepted turn before its first lifecycle event.

The inline comment gives the full failure path and a specific fix. Use one shared live-thread query for eviction and reconnect reports.

I found no new security issue. The possible long retention matches the existing behavior for a started active turn.

The architecture scan found no other duplicate implementation. The new separate boolean does expose split definitions of live work across eviction and reconnect code.

Validation passed:

  • git diff --check
  • 831 agent-runtime tests
  • 493 host-daemon tests
  • Turbo type checks for both packages
  • All GitHub checks, including both package smoke checks

A browser test does not apply because this pull request has no UI path. Add a daemon and server reconnect integration test instead.

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

Comment thread apps/host-daemon/src/runtime-manager.ts Resolved
@SawyerHood
SawyerHood force-pushed the bb/fix-1156-claude-code-first-turn-killed-by-idle-r-thr_asb84b5m5m branch from be8d41e to ff8c3a5 Compare August 8, 2026 17:00
@SawyerHood

Copy link
Copy Markdown
Collaborator Author

Reconnect check after the rebase:

I confirmed that listActiveThreads must include a thread after the provider accepts turn/start and before turn/started arrives.

reconcileDaemonReportedThreads uses each reported id with the saved thread status. It does not inspect provider event rows.

  • An active row stays active and avoids a false restart interruption.
  • A starting or idle row receives run.started. This is correct because the provider accepted the turn.
  • A stopping or deleted row still requests a stop.

A different daemon instance cannot retain this in-memory turn state. The new report only changes the same-instance reconnect path that preserves the runtime.

The branch now uses protocol version 85, after version 84 from PR #1197.

@SawyerHood
SawyerHood merged commit 3e77578 into main Aug 8, 2026
10 checks passed
@SawyerHood
SawyerHood deleted the bb/fix-1156-claude-code-first-turn-killed-by-idle-r-thr_asb84b5m5m branch August 8, 2026 17:08
amadad pushed a commit to amadad/bb that referenced this pull request Aug 14, 2026
## Reproduction

A focused provider test accepts `turn/start` without emitting
`turn/started`. An FNM-shaped `PATH` refresh then exercises idle-runtime
eviction during that gap.

## Root cause

The command retain ended after the provider accepted the queued prompt.
The runtime had pending turn work, but neither the active-turn predicate
nor the in-flight-command predicate reported it.

## Fix

Expose pending turn-start work from the agent runtime and count it as
active environment work. Regression tests cover the event gap and
FNM-shaped shell environment changes.

Fixes get-bb#1156
ymichael added a commit that referenced this pull request Aug 17, 2026
…gences

- 87 protocol bumps (26->121), not 92; turn-settlement fixes are #1196/#1234/#1321/#1432
- #75 is a pre-GitHub ticket id; cite commit 1a5620b
- ProviderAdapter has 18 members, not 16; corrected per-provider line counts
- The outbound vocabulary is a shared 7-method core with real divergences
  (acp lacks fork; codex maps stop/discard/compact/skills to different
  methods and has 4 methods no bb bridge speaks) - phase 1 must pick
  canonical mappings; codex bridge is a mapping layer, not a passthrough
- Canonical PendingInteractionPayload union lives in @bb/domain, not
  shared/pending-interaction-normalization.ts (codex-only helper)
- classify split is claude-vs-rest; normalizeExecutionOptions is claude-only

Co-Authored-By: Claude Fable 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

1 participant