Summary
Orchestra's CompactingMiddleware summarizes history in-place, but this is insufficient for models exhibiting "context anxiety" — agents start wrapping up prematurely as the context window fills. Full context resets with structured handoff artifacts give the next agent a clean slate.
This feature introduces:
ContextResetMiddleware — monitors context utilization and triggers resets when a configurable threshold (default 80%) is exceeded
HandoffArtifact schema — standardized structured output capturing completed work, in-progress tasks, remaining tasks, key decisions, files modified, and a state summary
- Per-assistant
context_strategy — configurable as compact, reset, or auto (model-aware default: compact for Opus-class, reset for Sonnet-class)
- Session tracking — threads track session boundaries with metadata for UI rendering
- Frontend UX — visual dividers at reset boundaries, expandable handoff summaries, session navigator for long threads
- Planner/evaluator integration — plan files, evaluator configs, and sprint contract state persist through resets
Key Files
| File |
Status |
Description |
backend/src/schemas/entities/handoff.py |
New |
HandoffArtifact Pydantic schema |
backend/src/utils/context_reset.py |
New |
ContextResetMiddleware implementation |
backend/src/schemas/entities/llm.py |
Modify |
Add context_strategy field to Assistant schema |
backend/src/utils/middleware.py |
Modify |
Register ContextResetMiddleware |
frontend/src/components/chat/SessionDivider.tsx |
New |
Visual divider at session boundaries |
frontend/src/components/chat/HandoffSummary.tsx |
New |
Expandable handoff artifact display |
Spec & Plan
Risks
- Handoff quality: If the agent produces a poor summary, the next session starts with bad context. Mitigation: structured schema forces completeness; add validation.
- Token overhead: Producing the handoff costs tokens. Mitigation: handoff prompt is short and structured.
- Race conditions: User message during reset could be lost. Mitigation: queue incoming messages during reset, deliver to new session.
Summary
Orchestra's
CompactingMiddlewaresummarizes history in-place, but this is insufficient for models exhibiting "context anxiety" — agents start wrapping up prematurely as the context window fills. Full context resets with structured handoff artifacts give the next agent a clean slate.This feature introduces:
ContextResetMiddleware— monitors context utilization and triggers resets when a configurable threshold (default 80%) is exceededHandoffArtifactschema — standardized structured output capturing completed work, in-progress tasks, remaining tasks, key decisions, files modified, and a state summarycontext_strategy— configurable ascompact,reset, orauto(model-aware default: compact for Opus-class, reset for Sonnet-class)Key Files
backend/src/schemas/entities/handoff.pybackend/src/utils/context_reset.pybackend/src/schemas/entities/llm.pycontext_strategyfield to Assistant schemabackend/src/utils/middleware.pyfrontend/src/components/chat/SessionDivider.tsxfrontend/src/components/chat/HandoffSummary.tsxSpec & Plan
/.claude/specs/context-reset-handoff.md/.claude/plans/context-reset-handoff.mdRisks