Skip to content

fix(loop): consumed steers no longer re-inject into a new run's first turn - #467

Merged
huichen merged 2 commits into
mainfrom
claude/loop-steer-consumed
Sep 2, 2026
Merged

huichen merged 2 commits into
mainfrom
claude/loop-steer-consumed

Conversation

@huichen

@huichen huichen commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Found while auditing the actual run history from the loop-driven sessions.

Bug: the steer injection cursor (last_steer_ts) was per-run in-memory state, but ledger replay keeps pending_steer forever (latest-wins). A NEW run client resets its cursor to 0 → the stale supervisor instruction re-injects into the first turn of the next run, even though the previous run already consumed it.

Fix: after draining a steer into a turn envelope, the run client appends a new SteerConsumed ledger event BEFORE the turn executes (a mid-turn death still leaves the consumption durable). Replay clears pending_steer only for the same episode (ts + agent_id match), preserving latest-wins for newer steers.

Bonus (same audit): the live tee now carries the tool_start phase field — the agent emits TWO starts per tool call (phase=input when the provider stream opens, phase=execution when it actually runs); a real run showed 10 starts vs 5 session tool_calls. Consumers (tail rendering, idle detection) can now dedup correctly.

Tests: steer_consumed.rs (consumption clears pending; episode-match guard keeps newer steers). 67 future-loop suites green, clippy --all-targets -D warnings, fmt.

… turn

Found auditing the actual run history for steering behavior. The run loop's
injection cursor (last_steer_ts) was per-run in-memory state, but the ledger
replay keeps pending_steer forever (latest-wins) — so a NEW run client
(cursor reset to 0) re-injected the stale instruction into its first turn.

Fix: after draining a steer into a turn envelope, the run client appends a
SteerConsumed event (before the turn runs, so a mid-turn death still leaves
the consumption durable); replay clears pending_steer only for the SAME
episode (ts + agent_id match), latest-wins preserved for newer steers.

Also: the live tee now carries tool_start 'phase' (input vs execution — one
tool call emits both; observed 10 starts vs 5 session tool_calls in a real
run), enabling correct start-counting in tail/idle detection.

Tests: steer_consumed.rs (clear-on-consume, episode-match guard). 67
future-loop suites green; clippy --all-targets -D warnings; fmt.
@huichen
huichen enabled auto-merge (squash) September 2, 2026 14:02
@huichen
huichen merged commit 7443573 into main Sep 2, 2026
12 checks passed
@huichen
huichen deleted the claude/loop-steer-consumed branch September 2, 2026 14:32
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