Epic-Bound Session Architecture Specification
Version: 1.1.0 Status: DRAFT Created: 2025-12-28 Supersedes: MULTI-SESSION-SPEC.md (partial)RFC 2119 Conformance
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174].Executive Summary
This specification defines the Epic-Bound Session architecture for CLEO, replacing the optional session model with a mandatory Epic-scoped session system. Every session is bound to an Epic (or parent task with subtasks), enabling structured work tracking, multi-agent coordination, and automatic session note aggregation on Epic completion.Key Principles
| Principle | Description |
|---|---|
| Epic-Bound | Every session MUST be scoped to an Epic or parent task |
| Session-Required Writes | Add, update, complete operations REQUIRE active session |
| Agent-Per-Task Focus | One agent per focused task, session-bound locking |
| Informative Outputs | All errors include context, suggestions, blockers |
| Registry-Based Discovery | Agents browse available sessions before starting |
| 4-State Lifecycle | Active → Suspended → Ended → Closed |
Part 1: Session Lifecycle
1.1 State Diagram
1.2 State Transitions
| From | To | Command | Requirements |
|---|---|---|---|
| (none) | Active | session start --epic T001 | Epic exists, no active session for scope |
| Active | Suspended | session suspend | Focus tasks updated with progress |
| Active | Ended | session end --note "..." | Session notes REQUIRED |
| Suspended | Active | session resume <id> | Session exists, scope valid |
| Ended | Active | session resume <id> | Session exists, scope valid |
| Active/Ended | Closed | session close | ALL tasks in scope completed |
| Closed | (none) | N/A | NOT reversible |
1.3 State Definitions
ACTIVE- Agent is working on tasks within session scope
- Focus locks can be acquired
- Write operations (add, update, complete) are enabled
lastActivitytimestamp updated on every operation
- Work paused temporarily
- Focus locks released (other agents can claim)
- Session resumable with same context
- Use case: “stepping away”, “waiting for review”
- No session notes required (quick pause)
- Work session formally concluded
- Session notes REQUIRED (handoff to next agent)
- Focus locks released
- Session resumable by same or different agent
- Use case: “end of day”, “completed my portion”
- Session permanently completed
- All tasks in scope MUST be complete
- Session notes aggregated to Epic/parent task
- Epic automatically completed
- Session archived to history
- NOT resumable
Part 2: Session Binding
2.1 Binding Requirements
Every session MUST be bound to one of:- Epic (type: “epic”)
- Main Task with Subtasks (type: “task” with children)
- Standalone tasks without children
- Subtasks (they belong to parent’s session)
2.2 Session Start Flow
2.3 Nested Session Hierarchy
When an Epic contains child Epics:- T001 can have a session
- T003 can have a NESTED session (child of T001’s session)
- T003’s session is formally linked to T001’s session via
parentSessionId - When T001’s session closes, all nested sessions MUST be closed first
Part 3: Focus Locking
3.1 Focus Within Sessions
Focus is session-scoped, not global:3.2 Focus Lock Rules
| Rule | Behavior |
|---|---|
| One agent per task | If T005 focused by agent A, agent B cannot focus T005 |
| Session-bound | Lock releases when session suspended/ended |
| Blocked task check | Cannot focus task blocked by dependencies |
| Scope validation | Cannot focus task outside session scope |
3.3 Focus Attempt Outcomes
3.4 Parallel Focus (Multiple Agents)
Multiple agents can work on the same Epic session, each focusing different tasks:- Each agent MUST have unique focus
- No two agents can focus the same task
- All agents share session context and notes
Part 4: Session Registry
4.1 Registry Structure
4.2 Registry Commands
Part 5: Write Operation Enforcement
5.1 Operations Requiring Session
| Operation | Session Required | Reason |
|---|---|---|
add | YES | New tasks MUST belong to session scope |
update | YES | Task modifications tracked to session |
complete | YES | Completion requires focus lock |
focus set | YES | Focus is session-scoped |
delete | YES | Destructive ops need accountability |
list | NO | Read-only, but shows session context |
show | NO | Read-only, but shows session context |
analyze | NO | Read-only analysis |
phases | NO | Read-only |
5.2 Enforcement Behavior
5.3 Context-Aware Read Operations
Read operations show session context when available:Part 6: Session Notes & Epic Completion
6.1 Note Types
| Type | When | Required |
|---|---|---|
progress | During work | Encouraged |
blocker | When blocked | Required if setting blocked status |
handoff | On session end | REQUIRED |
completion | On session close | Auto-generated |
6.2 Note Requirements
On Task Complete (within session):- Notes REQUIRED via
--notesflag or interactive prompt - Notes attached to task’s
notesarray
- Full session handoff notes REQUIRED
- Command:
cleo session end --note "Summary of work done" - Notes stored in session registry
- All session notes aggregated
- Notes appended to Epic’s
notesarray - Session archived to history
6.3 Auto-Completion Flow
When all tasks in session scope are completed:6.4 Epic Notes Aggregation
On session close, Epic receives:Part 7: Error Codes
| Code | Name | Exit | Description |
|---|---|---|---|
| 30 | E_SESSION_EXISTS | 30 | Session already active for scope |
| 31 | E_SESSION_NOT_FOUND | 31 | Session ID not found |
| 32 | E_SCOPE_CONFLICT | 32 | Scope overlaps with another session |
| 33 | E_SCOPE_INVALID | 33 | Invalid scope (no epic, empty, etc.) |
| 34 | E_TASK_NOT_IN_SCOPE | 34 | Task not in session scope |
| 35 | E_TASK_CLAIMED | 35 | Task focused by another agent |
| 36 | E_SESSION_REQUIRED | 36 | Operation requires active session |
| 37 | E_SESSION_CLOSE_BLOCKED | 37 | Cannot close, tasks incomplete |
| 38 | E_FOCUS_REQUIRED | 38 | Operation requires focused task |
| 39 | E_NOTES_REQUIRED | 39 | Session notes required for operation |
Part 8: Command Reference
8.1 Session Commands
8.2 Focus Commands (Session-Aware)
Part 9: Migration Path
Since this is the new DEFAULT behavior:9.1 Existing Projects
For projects with existing.cleo/ directory:
- On first
session start, migrate to new schema - Create sessions.json with enhanced structure
- Existing
_meta.activeSessionmigrated to full session entry - Config updated with
session.requireSession: true
9.2 Backward Compatibility
- Read operations remain unchanged
- Existing todo.json structure preserved
- Session enforcement can be disabled via
session.requireSession: false(NOT RECOMMENDED, only for legacy compatibility)
Part 10: Configuration
| Setting | Default | Description |
|---|---|---|
requireSession | true | Write ops require session |
requireNotesOnEnd | true | Notes required on session end |
requireNotesOnComplete | true | Notes required on task complete |
warnOnNoFocus | true | Warn if session started without focus |
allowNestedSessions | true | Child epics can have sub-sessions |
allowParallelAgents | true | Multiple agents in same session |
sessionTimeoutHours | 72 | Hours before stale session warning (was 24h, now 72h) |
autoDiscoveryOnStart | true | Show available sessions on session start |
| Setting | Default | Description |
|---|---|---|
autoEndActiveAfterDays | 7 | Auto-end active sessions after N days of inactivity |
10.1 Stale Session Handling
Sessions can legitimately run for extended periods (72+ hours) when agents work across multiple Claude conversations or during long-running development work. The stale session handling system balances this flexibility with automatic cleanup. Session Timeout Warning (72 hours) AftersessionTimeoutHours (default: 72) of inactivity:
- Session remains active but displays warning on status checks
- Agent can continue working normally
- No automatic state change occurs
- Warning helps identify potentially abandoned sessions
retention.autoEndActiveAfterDays (default: 7) of inactivity:
- Active sessions are automatically transitioned to ended state
- A system note is added documenting the auto-end
- Focus locks are released
- Session remains resumable (not closed)
- Epic is NOT auto-completed
| Inactivity | Status | Warning | Auto-Action | Resumable |
|---|---|---|---|---|
| < 72h | Active | None | None | N/A |
| 72h - 7d | Active | Yes | None | N/A |
| > 7d | Ended | N/A | Auto-end | Yes |
- Work on complex epics over multiple days
- Wait for external dependencies (reviews, deployments)
- Hand off between agent sessions
- Resume after weekends or breaks
Part 11: Implementation Gaps (Current State)
11.1 What Exists
| Component | Status | Location | Notes |
|---|---|---|---|
| Library | ✅ Implemented | lib/sessions.sh | Full multi-session functions |
| Schema | ✅ Complete | schemas/sessions.schema.json | Ready for use |
| This Spec | ✅ Draft | EPIC-SESSION (MDX) / docs/archive/specs-md/EPIC-SESSION-SPEC.md (archived) | Vision document |
| Old Spec | ⚠️ Partial | docs/archive/specs-md/MULTI-SESSION-SPEC.md (archived) | Predecessor, needs merge |
11.2 What’s Missing
| Gap | Current State | Required Action |
|---|---|---|
| Config Template | No multiSession section | Add to templates/config.template.json |
| Init Script | No sessions.json creation | Update scripts/init.sh |
| Default Enabled | multiSession.enabled: false | Change default to true |
| Session Commands | Use old single-session logic | Wire to lib/sessions.sh |
| Write Enforcement | Operations don’t check session | Add guards to add/update/complete |
| Auto-Complete | Immediately completes Epic | Change to prompt agent |
| Focus Lock | Global in todo.json | Move to sessions.json per-session |
11.3 Files Requiring Changes
Config Template (templates/config.template.json):
scripts/init.sh):
- Add
init_sessions_file()call - Create
.cleo/sessions.jsonwith initial structure - Set
multiSession.enabled: truein config
scripts/session.sh):
- Replace single-session logic with
lib/sessions.shcalls - Implement discovery mode for
session start - Add
session closecommand (4th state) - Enhance error messages with context
scripts/add.sh, scripts/update.sh, scripts/complete.sh):
- Add session check at start
- Error if no active session (E_SESSION_REQUIRED)
- Log operations with session context
scripts/complete.sh):
- Check if all tasks in scope complete
- Prompt agent instead of auto-completing Epic
- Trigger session close flow
11.4 Migration for Existing Projects
When user runs any cleo command on existing project:- Detect: Check if
.cleo/sessions.jsonexists - Migrate: If not, check for
_meta.activeSessionin todo.json - Create: Initialize sessions.json with migrated session (if any)
- Config: Add
multiSessionsection to config.json if missing - Warn: Inform user of migration on first use
Appendix A: Example Workflows
A.1 Solo Agent Workflow
A.2 Multi-Agent Workflow
Appendix B: Informative Error Examples
All errors MUST be informative, not generic:Revision History
| Version | Date | Author | Changes |
|---|---|---|---|
| 1.0.0 | 2025-12-28 | Claude/User | Initial specification |
| 1.1.0 | 2026-01-26 | Claude/User | Session timeout increased from 24h to 72h; added stale session handling (autoEndActiveAfterDays); added Part 10.1 |
