feat(coordinator): add compaction recovery via session-state.md#682
feat(coordinator): add compaction recovery via session-state.md#682tamirdresher wants to merge 1 commit intodevfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds coordinator guidance for recovering from conversation compaction by persisting a compact, overwrite-on-each-batch checkpoint in .squad/session-state.md, and reinforces “restraint after dispatch” behavior.
Changes:
- Adds a new “Coordinator Restraint” section to reduce mid-flight intervention and post-hoc narration of agent output.
- Extends “After Agent Work” with a new step to write
.squad/session-state.mdplus a “Compaction Recovery” procedure. - Updates routing principles and the source-of-truth hierarchy to include
.squad/session-state.mdas derived/overwritten.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
.squad/routing.md |
Adds an explicit routing principle about coordinator restraint after dispatch. |
.github/agents/squad.agent.md |
Documents session-state checkpointing + compaction recovery flow; adds coordinator restraint guidance; updates hierarchy table. |
|
|
||
| 2. **Don't intervene while an agent is still running.** Once dispatched, let the agent complete. Don't spawn a "helper" or "clarifier" agent mid-flight. Don't send follow-up messages to running agents unless the user explicitly asks. Wait for `read_agent` to return before acting on that agent's work. | ||
|
|
||
| 3. **Don't summarize or rephrase agent output.** Present agent results directly. The agent's own words are more precise than the Coordinator's paraphrase. Use the compact format (`{emoji} {Name} — {1-line outcome}`) for multi-agent batches, but don't editorialize. |
There was a problem hiding this comment.
This reads a bit self-contradictory: it says “Don’t summarize or rephrase agent output,” but then permits a coordinator-written {emoji} {Name} — {1-line outcome} for multi-agent batches. Consider clarifying that a minimal 1-line outcome is allowed while additional paraphrase/interpretation is not, so coordinators know what’s permitted.
| 3. **Don't summarize or rephrase agent output.** Present agent results directly. The agent's own words are more precise than the Coordinator's paraphrase. Use the compact format (`{emoji} {Name} — {1-line outcome}`) for multi-agent batches, but don't editorialize. | |
| 3. **Don't summarize or rephrase agent output beyond a minimal label.** Present agent results directly; the agent's own words are more precise than the Coordinator's paraphrase. For multi-agent batches you may add a neutral 1-line outcome label in the compact format (`{emoji} {Name} — {1-line outcome}`), but keep it strictly minimal and non-interpretive — no extra detail, analysis, or commentary beyond what the agent already said, and don't editorialize. |
| 7. **Write session state** to `.squad/session-state.md` (overwrite, not append). This is the coordinator's compaction recovery checkpoint. Format: | ||
|
|
There was a problem hiding this comment.
This new step adds a required filesystem write, but earlier in this section it states the post-work turn should be lean and include "no heavy file I/O." To avoid confusing coordinators, update that earlier guidance to explicitly carve out the session-state checkpoint as a small/required write (and/or clarify what qualifies as "heavy" I/O).
| 7. **Write session state** to `.squad/session-state.md` (overwrite, not append). This is the coordinator's compaction recovery checkpoint. Format: | |
| 7. **Write session state (lightweight, required I/O)** to `.squad/session-state.md` (overwrite, not append). This single small-text checkpoint is **exempt** from the "no heavy file I/O" guidance for post-work turns. | |
| - Keep this file a brief summary (typically ≤ ~10KB). | |
| - **Do NOT** add any other I/O here: no large/binary files, repo-wide scans, bulk history rewrites, extra logs/metrics, or git operations. Those count as **heavy** I/O and must be done in dedicated tooling/agents, not the post-work turn. | |
| This file is the coordinator's compaction recovery checkpoint. Format: |
| ## Agents Spawned | ||
| - {Name}: {outcome emoji} {1-line outcome} | ||
|
|
There was a problem hiding this comment.
Since .squad/session-state.md is overwritten after each batch, it’s ambiguous whether “Agents Spawned / Key Decisions / Files Modified” should be cumulative for the whole session or only the latest batch. For compaction recovery to work after multiple batches, the doc should specify that this file reflects the full session-to-date (or that the coordinator rolls forward the previous file contents before overwriting).
| When the coordinator detects that conversation context was compacted (prior messages are missing or summarized): | ||
|
|
There was a problem hiding this comment.
“Detects that conversation context was compacted (prior messages are missing or summarized)” isn’t a very actionable signal for the coordinator. Consider documenting concrete indicators to key off of (e.g., presence of a compaction/system notice in the transcript, the user explicitly saying compaction happened, or the coordinator observing missing earlier agent outputs/IDs) so the recovery behavior triggers consistently.
| When the coordinator detects that conversation context was compacted (prior messages are missing or summarized): | |
| Treat the conversation as **compacted** and enter recovery mode when **any** of the following are true: | |
| - The system or platform injects an explicit compaction/truncation notice into the transcript. | |
| - The user explicitly says that earlier messages were truncated, summarized, or otherwise lost. | |
| - You observe references in `.squad/session-state.md` (e.g., coordinator turns, agent run IDs, or outputs) that do not appear in the currently visible conversation transcript, indicating missing prior messages. | |
| When any of the above indicators are present: |
|
🔄 Ralph PR status
Adds compaction recovery via session-state.md. Coordinator prompt change only. Needs rebase onto current dev. |
After each agent batch, the coordinator now writes a compact session summary to .squad/session-state.md. When context compaction triggers, the coordinator re-reads this file to recover agent outcomes, task status, decisions, and next steps — preventing total context loss. Also adds session-state.md to the Source of Truth Hierarchy table. Refs #653 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🚀 Full Squad Review — feat(coordinator): compaction recovery via session-state.mdDomain: coordinator/compaction
All 21 squad members reviewed and approved. |
08195ea to
340642d
Compare
🚀 Squad Team Review — PR #682Adds compaction recovery via session-state.md. Coordinator writes compact session summary after each agent batch; reads it back after compaction. 2 files, +60/-0. |
|
📋 PR Lifecycle: Team review complete. Labeled \squad:pr-reviewed. Waiting for Dina's review. Add \squad:pr-dina-approved\ when ready to proceed. |
…gaster#666, bradygaster#676) (bradygaster#682) * docs(ai-team): CLI UI Polish PRD finalized — 20 issues created Session: 2026-03-01T20-13-00Z-ui-polish-prd Requested by: Brady Changes: - Created 6 orchestration logs (.squad/orchestration-log/2026-03-01T20-24-57Z-*.md) - Created session log (.squad/log/2026-03-01T20-13-00Z-ui-polish-prd.md) - Merged 5 decision files into decisions.md (PRD strategy, cast confirmation, processing state, Brady directives) - Deleted inbox files after merge (deduplication complete) - Updated team history files (Cheritto, Kovash, Redfoot, Marquez, Keaton, Fenster) - PRD created (docs/prd-cli-ui-polish.md) with 20 discrete issues (bradygaster#662-681) for alpha-1 release - Pragmatic alpha-first strategy: P0 blockers (blank screens, spinner, banner) + P1 quick wins, defer grand redesign Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(tui): consolidate separators, fix empty space, add info hierarchy and breathing room (bradygaster#655, bradygaster#670, bradygaster#671, bradygaster#677) - Create shared Separator component in components/Separator.tsx (bradygaster#677) All inline separator rendering (box.h.repeat) replaced across App.tsx, AgentPanel.tsx, and MessageStream.tsx - Remove flexGrow={1} from MessageStream outer Box (bradygaster#655) This was pushing content to bottom of viewport with empty space above - Bold primary CTAs in dim contexts (bradygaster#670) Header: @agent and /help now bold within dimColor usage line First-run: 'Try:' prompt bolded AgentPanel empty state: 'Send a message' and '/help' bolded - Add whitespace breathing room (bradygaster#671) Header wrapper gets marginBottom={1} Turn separators get marginTop={1} AgentPanel bottom separators upgraded from marginTop={0} to marginTop={1} Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * docs: update Cheritto history and add separator decision Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: wire onPermissionRequest handler in CLI session creation (bradygaster#651) Add approveAllPermissions handler to all 4 client.createSession() calls in the CLI shell. The handler was defined in SDK adapter types but never wired, causing a raw SDK error for users. - Add approve-all handler in shell/index.ts (CLI runs locally with user trust) - Export SquadPermissionHandler types from @bradygaster/squad-sdk/client - Add clear error guidance in adapter/client.ts for missing handler Closes bradygaster#651 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix(tui): bump secondary text contrast and wire table wrapping (bradygaster#666, bradygaster#676) - Replace dimColor with color="gray" for secondary text (system messages, italic markdown, duration labels, agent activity feed) — higher contrast than dim on dark terminals - Add GRAY ANSI constant and secondary() helper to output.ts - Add wrapTableContent() + truncateTableColumns() to MessageStream — tables exceeding terminal width are column-truncated with ellipsis - Wire table wrapping into both message history and streaming content paths Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
What
Add compaction recovery behavior to the coordinator's "After Agent Work" flow in squad.agent.md.
Why
When context compaction triggers during long sessions, the coordinator loses all agent context — outcomes, decisions, pending work — and cannot continue effectively (Refs #653). This is a known platform limitation with no runtime fix yet.
How
Testing
Docs
Exports
None — no public API changes.
Breaking Changes
None — additive behavior only. Existing sessions without a session-state.md will simply skip the recovery step.
Waivers
None required.