Repository navigation
fix(context): send a conductor's prompt once on kas - #39654
Conversation
A shipped conductor's [AGENT SYSTEM PROMPT] block is its spec prompt plus the widget pointer, so it never matched the wire prompt KAS records and the whole contract reached the model twice. When the block starts with the recorded prompt, it now carries only the part after it: the resolved widget sections. Any other text, and the turn after a compaction, keep the full block.
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the prefix-strip removes only text the harness already holds natively, and a revert would undo it cleanly. Notes
[DESIGN-REVIEWED] ee680a8 Description read[DESCRIPTION-READ] 1c298d9b12822ad9d7bcca34bf5979913cfe6a22d781e39a5de1b613975b99ee That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix works on the comparison that failed (exact match → prefix match at a line break), and the issue (#39605) and a new test back the defect. Notes
What this change shipsInventory (3 items) — 2 justifiedIntent: a shipped conductor on KAS gets its contract only once per session. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] ee680a8 Description read[DESCRIPTION-READ] ce96efb98f334290cfb344610381ca9b747e0902763f0030b3d0a71faece0ed9 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
This review checked head ee680a8 against the current main.
- The block is cut down only when the rendered prompt starts with the recorded
template://<agent>#prompttext and the rest is empty or starts at a line break. An exact match still sends no block. - After a compaction or a resume, the full block still comes back.
- Run on an extracted copy of this head, all 7 tests in
test/test_context_native_prompt_once.pypass. With the baseturn_message.pyswapped in, only the new conductor test fails.
Well done: the new test has a real control. With nothing recorded it asserts the full prompt plus the widget section, so the trimmed case cannot pass for the wrong reason.
Optional:
- Three specs still describe the old exact-match-only rule. These are
docs/architecture/context-management.md:66,docs/system-specs/modules/providers.md:1576andsrc/kiro_crew/docs/agent-spec-fields.md:627. The test module docstring does too. A follow-up could update them to the new prefix rule. - No test pins the line-break guard at
turn_message.py:415. A case where the recorded prompt ends in the middle of a word would cover it. - The comment at
turn_message.py:408describes the trim as conductor-only. The condition applies to any agent, so the comment could state the general rule and give the conductor as the example.
Problem / Motivation
Goal: A shipped conductor on KAS gets its contract once per session, not twice.
On KAS with kiro-cli >= 2.33.1, the five shipped conductors (
crew_mode.CONDUCTOR_TEMPLATES) receive their spec prompt natively from the agent definition and again inside the first message's[AGENT SYSTEM PROMPT]block. That is about 7K to 26K duplicated characters on every request for the life of the session, and it comes back after each compaction.Why it matters
Conductors are the long-lived, high-request-count sessions. The duplicate costs tokens on every request (patrol wakes usually pay the cache-write price) and fills the context window, so conductors compact sooner.
Not a goal
file://app-persona double delivery tracked in Persona delivered twice: native spec-prompt read overlaps the context.py injection #13305.What changed (motivation → approach → change)
_render_contract(context_assembly/agent_spec.py) appends{{WIDGET_BLOCK}}for every conductor, so the rendered block is the recorded wire prompt plus the widget sections. The dedupe incontext_assembly/turn_message.pywithholds the block only on a byte-for-byte match withtemplate://<agent>#prompt, so it never fires for a conductor.Backwards compatibility
Compatible: only the session-start block on a KAS session that recorded the agent's wire prompt changes, and only by dropping text the harness already holds. This applies to any agent whose rendered block extends that recorded prompt at a line break, not only the five conductors; for each, the dropped prefix is the exact text KAS already delivers as the system prompt.
Removes nothing: the model still receives the full contract (natively) and the widget pointer (in the block).
Tests
test/test_context_native_prompt_once.py::test_a_conductor_handed_its_prompt_gets_only_the_widget_pointer(new): with nothing recorded the conductor block holds the prompt and the pointer; with the wire prompt recorded, the prompt is not repeated and the block holds only the Inline Widgets section.[AGENT SYSTEM PROMPT],template://, the session head, the widget block orCONDUCTOR_TEMPLATES: 2500 passed, 1 failed. The failure istest_markdown_agent_specs.py::TestParser::test_the_strict_listing_raises_where_the_glob_reads_an_empty_directory, which also fails alone on this machine; it monkeypatchesos.scandir, which the local Python'sglobdoes not route through, and this diff does not touch that code.mypyonturn_message.py: clean.ruffwas not available locally; CI lint covers it.Proof: PROVEN test/test_context_native_prompt_once.py::test_a_conductor_handed_its_prompt_gets_only_the_widget_pointer (head ee680a8)
Manual verification
N/A — unit coverage drives the real
ContextBuilder.build_messagepath with a KAS provider double that records the wire prompt, as the existing tests in this file do.Real-machine verification
Not run: this changes prompt assembly only, and the unit test exercises the same
build_messagepath a KAS session uses. A maintainer can confirm by opening akirocrew-conductorchat on KAS (kiro-cli >= 2.33.1) and checking that the first message's[AGENT SYSTEM PROMPT]block holds only the Inline Widgets / Artifacts sections.Related Issues
Fixes #39605
Sibling sweep
Swept:
git grep -n "template://" -- src/Sibling: src/kiro_crew/context_assembly/member.py -- not affected -- compares the raw essentials body, which carries no widget pointer
Sibling: src/kiro_crew/acp/runtime_session_create.py -- not affected -- writes the record this fix reads
Sibling: src/kiro_crew/session_head.py -- not affected -- only the default agent's head, which gets no widget append
Pattern harvest
Not generalizable: the dedupe itself is general (any agent whose rendered block extends its recorded wire prompt at a line break now sends only the remainder), but today the conductor widget pointer in
_render_contractis the one renderer that appends after that prompt, so there is no wider defect class to lint for.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commitsContribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.