Skip to content

fix: context overflow sentinel and coordinator size reduction#1035

Draft
obit91 wants to merge 5 commits intobradygaster:devfrom
obit91:obit91/1017-context-overflow-sentinel
Draft

fix: context overflow sentinel and coordinator size reduction#1035
obit91 wants to merge 5 commits intobradygaster:devfrom
obit91:obit91/1017-context-overflow-sentinel

Conversation

@obit91
Copy link
Copy Markdown

@obit91 obit91 commented Apr 23, 2026

Summary

Fixes #1017 — Squad coordinator silently drops in long sessions due to context overflow.

Problem

When sessions grow long, the ~84KB squad.agent.md coordinator file can be silently dropped from <available_skills> due to context budget pressure. The session degrades to a vanilla Copilot agent with no safety rails and no warning — no agent routing, no PRs, no branch protection.

Solution (two complementary fixes)

  1. Canary token sentinel in copilot-instructions.md — a deterministic <!-- SQUAD_COORDINATOR_CANARY_a8f3 --> token at the end of squad.agent.md. The always-loaded copilot-instructions.md checks for this exact token. If missing (coordinator dropped or truncated), it warns loudly and refuses to proceed silently. This replaces the earlier semantic self-inspection approach per reviewer feedback.

  2. Size reduction of squad.agent.md from ~84KB → ~57KB (32% smaller) by extracting detailed reference content into on-demand files that agents load only when needed:

    • after-agent-reference.md — post-work checklist, Scribe spawn template
    • casting-reference.md — universe table, selection algorithm, state schemas
    • client-compatibility-reference.md — platform detection, VS Code adaptations
    • model-selection-reference.md — 4-layer model hierarchy, role mapping
    • ralph-reference.md — work-check cycle, idle-watch, board format
    • spawn-reference.md — full spawn template, lightweight template
    • worktree-reference.md — lifecycle management, dependency setup

Validation

  • Template sync: 164/164 tests pass ✅ (byte-for-byte parity across all 4 mirror locations)
  • Build: Pre-existing failures on upstream/dev (unrelated FSStorageProvider SDK export) — our changes are template-only
  • Content fidelity: Extracted content verified identical to original — extraction only, no content modifications
  • Branch rebased on latest upstream/dev (ec07f38)

Review feedback addressed

  • ✅ Canary token (per @tamirdresher) — replaces semantic self-inspection with deterministic exact-match check
  • ✅ Removed hardcoded ~80KB size references (per Copilot reviewer)
  • ✅ Default branch detection in worktree-reference.md (per Copilot reviewer)
  • ✅ Cross-worktree safety guidance preserved (per Copilot reviewer)

Closes #1017

obit91 and others added 5 commits April 23, 2026 22:56
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>
…-only

Content validation revealed that ralph-reference.md and casting-reference.md
contained newly authored sections not present in the original squad.agent.md.

ralph-reference.md: Removed Board Format state machine, Idle-Watch Mode,
Activation Triggers, and Work-Check Termination sections (newly authored).
Restored original Step 3 priority ordering bullet that was simplified.
Kept only content that was inline in the original.

casting-reference.md: Added note clarifying this is new specification material
that fills a gap (the original referenced this file but never had the content
inline). Universe table, selection algorithm, and JSON schemas are additive.

Closes bradygaster#1017

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Squad coordinator silently drops in long sessions (context overflow)

1 participant