Skip to content

feat: Context reset with structured handoff artifacts for long-running sessions #906

@ryaneggz

Description

@ryaneggz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestharness-designHarness design feature set (v0.9-v0.10)phase-2Phase 2: Quality & resilience

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions