fix: add context overflow sentinel and reduce coordinator size#1016
fix: add context overflow sentinel and reduce coordinator size#1016obit91 wants to merge 4 commits intobradygaster:devfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves Squad’s resilience to context-budget truncation by adding a “coordinator missing” sentinel to Copilot instructions and by reducing the size of the coordinator prompt via extraction of large sections into on-demand reference files.
Changes:
- Add a coordinator-presence check to
copilot-instructions.md(and this repo’s.github/copilot-instructions.md) to prevent silent fallback to an unsafe “vanilla agent” mode. - Extract detailed coordinator guidance into new on-demand reference files (spawn templates, model selection, client compatibility, post-work steps, worktrees) and update the coordinator template to point to them.
- Register the new reference files in the CLI template installation manifest.
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| templates/worktree-reference.md | Adds extracted worktree lifecycle + pre-spawn reference content. |
| templates/squad.agent.md.template | Replaces large inline sections with on-demand reference pointers to reduce coordinator size. |
| templates/spawn-reference.md | New on-demand reference containing full + lightweight spawn templates. |
| templates/model-selection-reference.md | New on-demand reference with full model selection hierarchy + fallback chains. |
| templates/copilot-instructions.md | Adds coordinator overflow sentinel instructions. |
| templates/client-compatibility-reference.md | New on-demand reference for platform detection + VS Code adaptations. |
| templates/after-agent-reference.md | New on-demand reference for post-work steps + Scribe spawn template. |
| packages/squad-sdk/templates/worktree-reference.md | Mirrors templates/worktree-reference.md for SDK template distribution. |
| packages/squad-sdk/templates/squad.agent.md.template | Mirrors coordinator template updates for SDK distribution. |
| packages/squad-sdk/templates/spawn-reference.md | Mirrors spawn reference for SDK distribution. |
| packages/squad-sdk/templates/model-selection-reference.md | Mirrors model selection reference for SDK distribution. |
| packages/squad-sdk/templates/copilot-instructions.md | Mirrors coordinator overflow sentinel for SDK distribution. |
| packages/squad-sdk/templates/client-compatibility-reference.md | Mirrors client compatibility reference for SDK distribution. |
| packages/squad-sdk/templates/after-agent-reference.md | Mirrors after-agent reference for SDK distribution. |
| packages/squad-cli/templates/worktree-reference.md | Mirrors templates/worktree-reference.md for CLI template distribution. |
| packages/squad-cli/templates/squad.agent.md.template | Mirrors coordinator template updates for CLI distribution. |
| packages/squad-cli/templates/spawn-reference.md | Mirrors spawn reference for CLI distribution. |
| packages/squad-cli/templates/model-selection-reference.md | Mirrors model selection reference for CLI distribution. |
| packages/squad-cli/templates/copilot-instructions.md | Mirrors coordinator overflow sentinel for CLI distribution. |
| packages/squad-cli/templates/client-compatibility-reference.md | Mirrors client compatibility reference for CLI distribution. |
| packages/squad-cli/templates/after-agent-reference.md | Mirrors after-agent reference for CLI distribution. |
| packages/squad-cli/src/cli/core/templates.ts | Adds new reference files to TEMPLATE_MANIFEST so squad init/upgrade installs them. |
| .squad-templates/worktree-reference.md | Canonical template source for worktree reference (synced to mirrors). |
| .squad-templates/squad.agent.md | Canonical coordinator prompt updated to use on-demand references. |
| .squad-templates/spawn-reference.md | Canonical spawn reference source. |
| .squad-templates/model-selection-reference.md | Canonical model selection reference source. |
| .squad-templates/copilot-instructions.md | Canonical coordinator overflow sentinel source. |
| .squad-templates/client-compatibility-reference.md | Canonical client compatibility reference source. |
| .squad-templates/after-agent-reference.md | Canonical after-agent reference source. |
| .github/copilot-instructions.md | Adds coordinator overflow sentinel to this repo’s Copilot instructions. |
| .github/agents/squad.agent.md | Updates checked-in coordinator prompt to use on-demand references. |
| .changeset/context-overflow-sentinel.md | Changeset documenting the sentinel + coordinator-size reduction. |
|
@obit91 few things:
@bradygaster @diberry can you also take a look please? |
|
Thanks for the thorough review @tamirdresher! Addressing each point: 1. Issue #76 / 30K GHE hard cap Good call. The user's reported issue was specifically about context budget pressure in long CLI sessions (large session summary crowding out the ~84KB coordinator), not the GHE 30K hard cap from #76. This PR helps both — we went from 84KB → ~60KB — but you're right that we're still ~2x over the 30K GHE limit. That's a different (harder) problem requiring deeper structural changes beyond extraction. I've noted the relationship in #1017. The extraction here is still net-positive for the CLI context overflow case. 2. Canary token — implemented ✅ Great suggestion. Replaced the semantic self-inspection with a deterministic canary token approach in 6ae2d29:
3. Tests / CI Template sync tests pass locally (164/164) — these validate byte-for-byte parity across all 4 mirror locations and verify the manifest entries resolve. CI didn't run because this is a fork PR — the fork doesn't have the repo's CI workflows configured. Happy to help get CI triggered if there's a way to do that from the upstream side, or I can rebase onto a branch in the upstream repo if that's preferred. 4. Process notes — acknowledged
|
When sessions grow long, the ~84KB squad.agent.md coordinator file can be silently dropped from context, causing Squad to degrade to a vanilla Copilot agent with no safety rails (no PRs, no branch protection, no agent routing). Solution 1 — Sentinel: Add a coordinator-presence check to copilot-instructions.md (always loaded, ~3KB). When the coordinator is missing, the agent warns loudly and refuses to work silently. Solution 2 — Size reduction: Extract detailed content from squad.agent.md into 5 on-demand reference files, reducing it from ~84KB to ~55KB (33% smaller). Extracted sections: model selection, client compatibility, spawn templates, after-agent-work steps, and worktree lifecycle. New template files: - model-selection-reference.md - client-compatibility-reference.md - spawn-reference.md - after-agent-reference.md - worktree-reference.md Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Remove hard-coded ~80KB size estimate from copilot-instructions.md sentinel (size will change over time, keep description generic) - Add ralph-reference.md to .squad-templates/ and TEMPLATE_MANIFEST (was referenced by squad.agent.md but missing from template distribution) - Replace hard-coded 'main' branch in worktree-reference.md with default branch detection via git symbolic-ref - Add cross-worktree safety warning to squad.agent.md inline (main-checkout strategy not safe for concurrent sessions) Closes bradygaster#1017 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add response mode exemplars back inline (Direct/Lightweight/Standard/Full) - Expand ralph-reference.md with full work-check cycle details (gh commands, categorization table, periodic check-in, watch mode, three layers, board format, integration with follow-up work) - Add cross-worktree considerations to worktree-reference.md (worktree-local vs main-checkout strategy details) - Restore cross-worktree safety guidance inline in squad.agent.md Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Per review feedback from @tamirdresher: semantic self-inspection ('do you see coordinator instructions?') is unreliable for LLMs. Replace with deterministic canary token approach: - Add <!-- SQUAD_COORDINATOR_CANARY_a8f3 --> at end of squad.agent.md - copilot-instructions.md checks for exact token string - Catches both missing coordinator AND truncation (token at EOF) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
6ae2d29 to
5af088c
Compare
|
Superseded by #1035 — same content, proper branch naming convention (obit91/1017-...) per review feedback, plus content fidelity fixes. |
Problem
When sessions grow long, the ~84KB
squad.agent.mdcoordinator file can be silently dropped from<available_skills>due to context budget pressure. This causes Squad to degrade to a vanilla Copilot agent with no safety rails:mainSolution
1. Context Overflow Sentinel (Safety Net)
Added a coordinator-presence check to
copilot-instructions.md(always loaded at ~3KB, survives context pressure). When the coordinator is missing, the agent:Added to both:
.squad-templates/copilot-instructions.md(template for user projects).github/copilot-instructions.md(this repo's own)2. Coordinator Size Reduction (Root Cause)
Reduced
squad.agent.mdfrom ~84KB to ~55KB (33% smaller) by extracting detailed content into on-demand reference files, following the existing extraction pattern used by 11 other sections.Extracted sections:
New reference files:
model-selection-reference.md— 4-layer hierarchy, fallback chains, model catalogclient-compatibility-reference.md— platform detection, VS Code adaptations, degradation tablespawn-reference.md— full and lightweight spawn templatesafter-agent-reference.md— post-work steps, Scribe spawn templateworktree-reference.md— worktree lifecycle, pre-spawn setupAll reference files are created in
.squad-templates/(canonical source), synced to all mirror targets, and registered inTEMPLATE_MANIFESTfor installation viasquad init.Testing
Design Decisions