The context handler consumed the handoff marker after the first turn (and
agent_end cleared all markers), so every subsequent turn fell through to the
fast path and re-sent the full, ever-growing history. Across a task chain the
context grew monotonically instead of resetting per task, defeating the handoff
and eventually overrunning the model's context window.
Track a single activeHandoffId that is never consumed and is overwritten when a
later handoff supersedes it, so truncation re-applies on every turn and the
context stays pinned to the carry-over prompt for the whole task. Add a pure,
testable resolveHandoffContext helper and a multi-turn regression test.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- session-handoff/index.ts: core session handoff logic
- session-handoff/state.ts: state management for handoff
- tests/session-handoff.test.ts: test suite for session handoff