forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Epic: Subagent State Handoff & Context Boundary Resilience
Overview
This epic addresses the fundamental architectural weakness in how OpenCode handles context boundaries between parent agents and subagents, as well as during session compaction. Currently, when context transfers occur between different execution scopes, critical information can be lost, leading to silent failures, stuck states, and incomplete recovery.
Problem Statement
Context Boundary Fragility: Both subagent delegation and session compaction represent context transfers where:
- State Loss: Critical working context, rules, and progress can be lost
- Failure Visibility: Parents cannot detect when subagents fail or get stuck
- Recovery Failure: Insufficient information for agents to continue work after context reset
- Permission Blindness: Parent agents cannot see subagent permission requests
Related Issues
Subagent State Handoff Issues
- Subagent results not always properly handled anomalyco/opencode#3173 - Subagent results not always properly handled
- Feature request: let subagents inherit context anomalyco/opencode#2588 - Feature request: let subagents inherit context
- Sub-agent's request for permission is not shown in the primary agent's view anomalyco/opencode#4078 - Sub-agent's request for permission is not shown in primary agent's view
- Feature: Subagents should support auto compaction anomalyco/opencode#3153 - Feature: Subagents should support auto compaction
- [FEATURE]: Improve Subagent Invocation Documentation anomalyco/opencode#3715 - Improve Subagent Invocation Documentation
Compaction Context Issues
- Agent no follow rules after compact session anomalyco/opencode#3099 - Agent no follow rules after compact session
- Model in BUILD mode does not have enough context to continue after compaction anomalyco/opencode#3031 - Model in BUILD mode does not have enough context to continue after compaction
- Session automatically compacted, destroying the entire working context anomalyco/opencode#2945 - Session automatically compacted, destroying the entire working context
Solution Areas
1. Enhanced State Handoff Protocol
- Bidirectional State Sync: Continuous state synchronization between parent and subagent
- Progress Indicators: Real-time visibility into subagent execution state
- Failure Detection: Parent agents can detect when subagents are stuck or failed
- Recovery State: Sufficient context for agents to recover and continue work
2. Context Inheritance & Preservation
- Context Forking: Subagents inherit relevant parent context (configurable)
- Rule Persistence: Agent rules and AGENTS.md survive context transfers
- Working State: Current task state, file changes, and progress preserved
- Selective Context: Intelligent filtering of what context to inherit
3. Permission & Notification Bridge
- Permission Forwarding: Subagent permission requests visible to parent
- Status Broadcasting: Real-time status updates across context boundaries
- Error Propagation: Clear error communication between contexts
- Progress Events: Detailed progress information for long-running tasks
4. Resilient Recovery Mechanisms
- Handoff Documents: AI-generated context handoff documents for recovery
- State Snapshots: Periodic state snapshots for recovery points
- Rollback Capability: Ability to rollback to known good states
- Continuation Prompts: Rich context for agents to continue work
Success Criteria
- No Silent Failures: Parents always know subagent status (working, stuck, failed, completed)
- Complete Context Recovery: Agents can fully recover work after any context transfer
- Permission Transparency: All permission requests visible to appropriate users
- Rule Persistence: Agent rules survive all context boundaries
- State Continuity: Working state preserved across compaction and subagent calls
This epic represents a fundamental improvement to OpenCode's reliability and user experience when dealing with long-running, complex tasks that span multiple context boundaries.
prophet1906
Metadata
Metadata
Assignees
Labels
No labels