fix(orchestrator): bootstrap-token discipline + SQLite agent-channel queries#9
Open
evannadeau wants to merge 1 commit into
Open
fix(orchestrator): bootstrap-token discipline + SQLite agent-channel queries#9evannadeau wants to merge 1 commit into
evannadeau wants to merge 1 commit into
Conversation
…queries Two related fixes to PA/SA bootstrap skills (recipes only; no source changes): 1. Bootstrap token discipline — getting-started step 1 adds `sections:` filter to briefing() and pa-bootstrap step 5.5/5.6 add `output_mode: "summary"` to all five lookups. Empirically validated: PA bootstrap drops from 204KB persisted tool-results to 56KB (72% reduction); SA bootstrap drops to 60KB. Per-session savings compound across multi-agent workdays. 2. SQLite agent-channel queries — pa-bootstrap steps 2/3/6 replace `cat sessions.json` / `cat state.json` with Python sqlite3 queries against `agent_channel.db`. The JSON state files no longer exist (migrated to SQLite WAL); the recipe was never updated. Also: switch path env var from `$CLAUDE_PROJECT_DIR` (unset in PA sessions on Claude Code 2.1.142) to `$ORCHESTRATOR_PROJECT_ROOT` (set by the launchers).
This was referenced May 15, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two related fixes to the PA/SA bootstrap skill recipes. Recipe-only changes — no MCP server / source code modifications, no
dist/rebuild required.Fix 1 — Bootstrap token discipline
getting-started/SKILL.mdstep 1 andpa-bootstrap/SKILL.mdsteps 5.5/5.6 currently instruct the agent to callbriefing()and fivelookup()calls in full-content mode without any output narrowing. On a representative Quayline workspace this consumes ~204KB of persisted tool-results per PA bootstrap (~50K tokens of context, roughly 10% of a Max 5x plan's 5-hour rolling window — and every fresh SA pays its own cost).Changes:
getting-startedstep 1: addsections: ["work_items","open_threads","decisions","checkpoint","user_model","cross_session"]to thebriefing()call. Default rendering includesneglected_areas(large tag soup),drift, andcuration_candidates— useful for explicit maintenance turns (orchestrator:reflect) but inflates routine bootstrap by 5-15K tokens.pa-bootstrapsteps 5.5 + 5.6: addoutput_mode: "summary"to all five enumeration lookups (user_pattern,architecture,decision,convention,anti_pattern). The skill's own stated intent — "Skim each. You don't need to memorize content - you need to know WHAT exists so you can surface specific notes by ID" — exactly matches summary mode's one-line-per-result rendering. Agents can still drill into full content vialookup({id: "<id8>"})when an SA's task intersects a specific note.Empirical validation (Quayline workspace, 2026-05-15):
The largest individual lookup persisted at 84KB in full mode and disappears entirely under summary mode (the response fits inline at ~1-2KB and is never persisted to disk). Across a multi-session workday (1 PA + N SAs), savings compound linearly with N.
The
sectionsfilter change is independently needed because operators who try to workaround at the project level cannot — the upstream skill callsbriefing()before the project'sCLAUDE.mdis read, so a project-side override has no chance to apply. Only the upstream skill can claim that ~5-15K savings.Fix 2 — SQLite agent-channel queries
pa-bootstrap/SKILL.mdsteps 2, 3, and 6 instruct the agent tocat sessions.jsonandcat state.jsonin$CLAUDE_PROJECT_DIR/.orchestrator-state/agent-channel/. Neither file exists in current plugin versions — agent-channel was migrated to SQLite (WAL-modeagent_channel.db) with thesessions,global_pause, andsa_pausetables replacing the JSON files. The recipe was never updated.Compounding the issue,
$CLAUDE_PROJECT_DIRis not propagated to PA sessions in Claude Code 2.1.142 (verified empirically viaenv); the recipe's bash commands silently expand to/.orchestrator-state/...(root-anchored) and report "missing" even when state exists. The launchers DO set$ORCHESTRATOR_PROJECT_ROOT.Changes:
cat sessions.jsonwith a Python stdlibsqlite3query againstagent_channel.db. The query joins role/heartbeat/name/current_task in one call and powers both steps (Step 2 looks for the agent's own row; Step 3 lists rows whererole=subordinateand heartbeat age < 90s).cat state.jsonwithSELECT * FROM global_pause WHERE active=1.$CLAUDE_PROJECT_DIRto$ORCHESTRATOR_PROJECT_ROOT.The Python stdlib approach avoids requiring
sqlite3CLI to be installed (it isn't on a fresh Ubuntu-24.04 WSL workstation).Failure mode without these fixes
A fresh PA running
/pa-bootstrapon current plugin code:sessions.json missing(the file doesn't exist).Test plan
pa-bootstrap/SKILL.mdandgetting-started/SKILL.mddirectly frommain@cb407712before drafting the diff (no rebase risk; the fork was in sync).sqlite3query empirically: it returns the running session's row withrole=prime, fresh heartbeat, and current_task on Quayline workspace369009bc/a29491cd. Output matches whatcat sessions.jsonwould have produced in pre-migration plugin versions.$ORCHESTRATOR_PROJECT_ROOTis set in Claude Code 2.1.142 PA sessions viaenv | grep ORCHESTRATOR.briefing({sections: [...]})empirically — returns the requested sections only, suppressesneglected_areas/drift/curation_candidates(saves ~10-15K tokens on this workspace).lookup({type:..., output_mode:"summary"})empirically — returns one-line-per-result rendering with id8 + type + truncated content. Disk persistence threshold not triggered for limit=15 results.Out of scope (separate upstream PR candidates)
The Quayline workspace's KB tracks several other upstream-PR candidates touching
plugins/orchestrator/mcp/server.ts(path-hashing leading-dash strip; version-driftVersion: ...line bug at server.ts:655; agent-channel filewatcher silently truncating PA-to-SA multi-paragraph addresses at the first colon-after-blank-line; concurrent stop-hook deadlock between parallel Claude Code sessions). These are MCP server source changes and would requiredist/rebuild — they should ship as a separate PR (or PRs) to keep this skill-recipe-only change reviewable in isolation.References
For SpawnBox-dev maintainers: this PR was developed against the operator's local orchestrator KB notes (anti-patterns
b1cc1bc2ande2239a05for the two fixes respectively, plus the empirical-confirmation appends from sessiona29491cd). Happy to share the full note bodies if useful — they include diff shapes verbatim from the operator's investigation.🤖 Generated with Claude Code (Admiral PA orchestrating a meta-team-cleanup batch)