-
Notifications
You must be signed in to change notification settings - Fork 9
fix: harden coordinator prompt against context compression #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jflowers
merged 3 commits into
unbound-force:main
from
jflowers:opsx/coordinator-prompt-hardening
Aug 10, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| schema: unbound-force | ||
| created: 2026-08-02 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| ## Context | ||
|
|
||
| The coordinator agent prompt at `internal/agentkit/content/agents/coordinator.md` is a 22-line embedded markdown file that defines the coordinator's behavioral contract. Analysis of all four agent prompt files in the project reveals a clear robustness hierarchy: | ||
|
|
||
| | File | Structure | Compression Resilience | | ||
| |------|-----------|----------------------| | ||
| | `coordinator.md` | Single "Rules" section, 6 bullets | Fragile | | ||
| | `worker.md` | Checklist + Constraints sections | Moderate | | ||
| | `background-worker.md` | Constraints-first, capability negations | Moderate | | ||
| | `SKILL.md` (forge-coordination) | Multi-section, MUST/NEVER keywords, numbered protocols | Reference standard | | ||
|
|
||
| The coordinator prompt is the most fragile. Its single critical negative constraint ("Never reserve files") sits at line 14 of 22 — 64% through the file — where a 50% truncation would drop it entirely. | ||
|
|
||
| ## Goals / Non-Goals | ||
|
|
||
| ### Goals | ||
| - Restructure `coordinator.md` so critical constraints survive context compression (DCP, summary, truncation) | ||
| - Adopt patterns proven in `worker.md`, `background-worker.md`, and the forge coordination skill | ||
| - Enforce explicit ordering: `forge_review` MUST precede `forge_complete` | ||
| - Maintain behavioral parity for existing rules; make the implicit `forge_review` → `forge_complete` ordering explicit | ||
|
|
||
| ### Non-Goals | ||
| - Changing the coordinator's actual behavioral contract (no removed rules — the `forge_review` → `forge_complete` ordering and the `NEVER edit code directly` prohibition are codifications of existing implicit behavior: the forge coordination skill defines review-before-complete ordering, and the coordinator's identity as a non-coding orchestrator implies it should not edit code directly) | ||
| - Hardening other agent prompts (`worker.md`, `background-worker.md`) — those are separate changes | ||
| - Adding runtime enforcement of constraints (e.g., tool-level guards blocking out-of-order calls) | ||
| - Modifying the forge coordination skill (`SKILL.md`) — it already follows the reference pattern | ||
|
|
||
| ## Decisions | ||
|
|
||
| ### 1. Identity-first opening with embedded constraints | ||
|
|
||
| The first sentence of the file will state who the coordinator is AND what it must not do. Compressors prioritize opening content — an identity statement like "You are a coordinator. You orchestrate workers but NEVER reserve files or edit code directly." survives any reasonable summarization. | ||
|
|
||
| **Rationale**: The forge coordination skill (`SKILL.md`) demonstrates this pattern at scale with its multi-section design. `background-worker.md` places constraints before capabilities, which is structurally sound though it does not embed constraints in the identity opening itself. | ||
|
|
||
| ### 2. Dedicated "Critical Constraints" section before workflow | ||
|
|
||
| Negative constraints (NEVER reserve files, NEVER edit code directly) and mandatory ordering (MUST review before complete) move to a dedicated section with a strong header, positioned before the workflow protocol. | ||
|
|
||
| **Rationale**: Position matters for compression. Content appearing earlier in a document is more likely to survive truncation. The forge coordination skill (`SKILL.md`) uses this pattern with its "File Reservation Rules" section. | ||
|
|
||
| ### 3. Uppercase severity keywords (MUST/NEVER/ALWAYS) | ||
|
|
||
| All constraints use RFC 2119-style uppercase keywords for severity signaling. This matches the convention established in the forge coordination skill and the project constitution. | ||
|
|
||
| **Rationale**: Uppercase keywords serve as compression-resistant markers. A compressor summarizing "NEVER reserve files" is more likely to preserve the prohibition than one summarizing "Never reserve files" in lowercase. | ||
|
|
||
| ### 4. Numbered protocol replacing unordered bullet list | ||
|
|
||
| The current 6-bullet unordered list becomes a numbered checklist with explicit ordering. This makes the `forge_review` → `forge_complete` dependency visible and enforceable. | ||
|
|
||
| **Rationale**: `worker.md` uses a 7-step numbered checklist that clearly conveys ordering. The forge coordination skill uses numbered protocols for both coordinator and worker flows. | ||
|
|
||
| ### 5. Preserve YAML front matter and "Available Tools" section | ||
|
|
||
| The existing YAML front matter (`name`, `description`, `mode`) and the "Available Tools" footer remain unchanged. These are structural elements consumed by the agent framework. | ||
|
|
||
| **Rationale**: Composability First — the file's interface with the agentkit embed system must not change. | ||
|
|
||
| ## Risks / Trade-offs | ||
|
|
||
| ### Longer prompt consumes more context window | ||
|
|
||
| The restructured prompt will be approximately 30-40 lines (up from 22). This adds ~18 lines of context to every coordinator session. | ||
|
|
||
| **Mitigation**: The added lines are structural (section headers, numbered steps) rather than new information. The constraint count grows from 6 to 7 (adding the explicit "NEVER edit code directly" prohibition, which codifies the coordinator's existing non-coding role). The trade-off is acceptable: 18 lines of context is trivial compared to the risk of a coordinator that silently drops quality gates. | ||
|
|
||
| ### Compression-resistance is heuristic, not guaranteed | ||
|
|
||
| No prompt structure can guarantee survival under all possible compression strategies. The patterns used here (identity-first, constraints-before-workflow, uppercase keywords) are empirically effective but not provably optimal. | ||
|
|
||
| **Mitigation**: This is a defense-in-depth measure. The forge coordination skill (`SKILL.md`) provides a redundant statement of the same constraints. Even if the coordinator prompt is compressed, the skill's constraints may survive in a separate part of the context. | ||
|
|
||
| ### No runtime enforcement | ||
|
|
||
| This change relies on prompt engineering, not code-level guards. A sufficiently degraded context could still produce constraint violations. | ||
|
|
||
| **Mitigation**: Runtime enforcement (e.g., blocking `forge_complete` if `forge_review` wasn't called) is a valid follow-up but is explicitly out of scope for this change. The prompt hardening provides immediate value with zero runtime risk. If the restructured prompt causes behavioral regression, the fix is to revert `coordinator.md` to its previous version — a single-file modification with no runtime dependencies, making rollback trivial. | ||
| <!-- scaffolded by uf vdev --> |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| ## Why | ||
|
|
||
| The coordinator agent prompt (`internal/agentkit/content/agents/coordinator.md`) is 22 lines with all behavioral constraints expressed as 6 bullet points in a single "Rules" section. When tools like DCP compress session context, critical constraints — particularly the prohibition on file reservation and the mandatory review-before-complete ordering — are likely to be lost or weakened. | ||
|
|
||
| This is the same class of vulnerability identified in [unbound-force/unbound-force#346](https://github.com/unbound-force/unbound-force/issues/346). A coordinator that silently drops constraints under compression could reserve files (causing deadlocks with workers), skip reviews (bypassing quality gates), or call `forge_complete` before `forge_review` (circumventing verification). | ||
|
|
||
| Fixes [#46](https://github.com/unbound-force/replicator/issues/46). | ||
|
|
||
| ## What Changes | ||
|
|
||
| Restructure the coordinator agent prompt to survive context compression by applying patterns already proven in the project's other agent files (`worker.md`, `background-worker.md`) and the forge coordination skill (`SKILL.md`). | ||
|
|
||
| Specific changes: | ||
| 1. Add an opening identity statement that embeds key constraints inline, ensuring compressors retain them in any summary's opening sentence. | ||
| 2. Create a dedicated "Critical Constraints" section with uppercase severity keywords (MUST/NEVER) positioned before the workflow section. | ||
| 3. Add an explicit ordered protocol (numbered checklist) that enforces `forge_review` before `forge_complete`. | ||
| 4. Separate boundary rules (what the coordinator must NOT do) from procedural steps (what it does). | ||
|
|
||
| ## Capabilities | ||
|
|
||
| ### New Capabilities | ||
| - None — this change modifies an existing embedded asset, not runtime code. | ||
|
|
||
| ### Modified Capabilities | ||
| - `coordinator agent prompt`: Restructured for compression resilience with explicit ordering, identity reinforcement, and prominent negative constraints. | ||
|
|
||
| ### Removed Capabilities | ||
| - None. | ||
|
|
||
| ## Impact | ||
|
|
||
| - **File**: `internal/agentkit/content/agents/coordinator.md` (single file change) | ||
| - **Embedded asset**: The file is embedded via `go:embed` into the binary; changes take effect at next build. | ||
| - **Behavioral**: No runtime code changes. The coordinator's behavioral contract is preserved — this change makes existing constraints more explicit, not different. | ||
| - **Testing**: The agent prompt is an embedded text asset. Existing parity tests and embed tests cover the file's inclusion. No new test infrastructure needed, though a structure validation test could verify constraint positioning. | ||
|
|
||
| ## Constitution Alignment | ||
|
|
||
| Assessed against the Replicator constitution (`.specify/memory/constitution.md`), which extends the Unbound Force org constitution v1.1.0. | ||
|
|
||
| ### I. Autonomous Collaboration | ||
|
|
||
| **Assessment**: PASS | ||
|
|
||
| The coordinator prompt defines how the coordinator collaborates with workers through well-defined MCP tools and comms messaging. This change reinforces that contract by making the separation of concerns (coordinator orchestrates, workers reserve files and edit code) more explicit and compression-resistant. | ||
|
|
||
| ### II. Composability First | ||
|
|
||
| **Assessment**: N/A | ||
|
|
||
| This change modifies an embedded text asset. It does not affect standalone functionality or introduce dependencies. | ||
|
|
||
| ### III. Observable Quality | ||
|
|
||
| **Assessment**: PASS | ||
|
|
||
| The restructured prompt explicitly requires the coordinator to call `forge_review` for every worker completion before `forge_complete`, strengthening the quality gate. The use of uppercase MUST/NEVER keywords aligns with the severity signaling convention used in the forge coordination skill. | ||
|
|
||
| ### IV. Testability | ||
|
|
||
| **Assessment**: PASS | ||
|
|
||
| The change affects a single embedded markdown file. The file is already covered by embed tests. A structural test MUST be added to verify that critical constraints appear before workflow steps, ensuring the compression-resilience property is maintained over time. |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.