Skip to content

fix(context): send a conductor's prompt once on kas - #39654

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
crew/issue-radar/fix-39605-conductor-prompt-once
Nov 20, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
crew/issue-radar/fix-39605-conductor-prompt-once

Conversation

@kyleseaman

@kyleseaman kyleseaman commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

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

What changed (motivation → approach → change)

  • Symptom: the block repeats the conductor's whole contract.
  • Cause: _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 in context_assembly/turn_message.py withholds the block only on a byte-for-byte match with template://<agent>#prompt, so it never fires for a conductor.
  • Change: when the rendered block starts with the recorded wire prompt and the remainder begins at a line break, the block now carries only that remainder (the resolved widget sections). A full match still sends nothing, as before. Any other text sends the full block, as before. This follows the first fix the issue suggests, and keeps both merged intents: fix: give every conductor the widget pointer and offer widgets unasked #31345 (every conductor gets the widget pointer, resolved per surface) and fix(context): send a custom agent's prompt once on kas #31875 (the block is withheld when it would repeat the recorded prompt).

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.
  • Existing tests in that file still pass (exact match withheld, other text kept, compaction restores the full block).
  • Ran the 39 test files that touch [AGENT SYSTEM PROMPT], template://, the session head, the widget block or CONDUCTOR_TEMPLATES: 2500 passed, 1 failed. The failure is test_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 monkeypatches os.scandir, which the local Python's glob does not route through, and this diff does not touch that code.
  • mypy on turn_message.py: clean. ruff was 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_message path 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_message path a KAS session uses. A maintainer can confirm by opening a kirocrew-conductor chat 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_contract is the one renderer that appends after that prompt, so there is no wider defect class to lint for.

Checklist

  • A Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license.

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.
@kyleseaman
kyleseaman requested review from a team and KiroCrewCaptain as code owners November 19, 2026 22:40
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision ee680a8be43edfb9a799ac8198150b2ad29a0a13 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of ee680a8be43edfb9a799ac8198150b2ad29a0a13 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the prefix-strip removes only text the harness already holds natively, and a revert would undo it cleanly.

Notes

  • The prefix rule now applies to any agent whose rendered block extends its recorded wire prompt, not just conductors. The comment and the "Not generalizable" claim undersell that. That is fine, but the comment should state the general rule.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of ee680a8be43edfb9a799ac8198150b2ad29a0a13 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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

  • Item 1 — symptom-level: the turn builder now trims away a suffix that _render_contract (context_assembly/agent_spec.py:841) adds just before it. That trim is a second place that knows the widget pointer sits after the prompt text. Subtraction: have the contract renderer hand back the widget sections on their own and delete the startswith/rest slicing in turn_message.py:411-415.

What this change ships

Inventory (3 items) — 2 justified

Intent: a shipped conductor on KAS gets its contract only once per session. This is a FIX.

  1. A conductor's first-message [AGENT SYSTEM PROMPT] block on KAS now holds only the Inline Widgets/Artifacts sections — symptom-level (strips the renderer's suffix after the fact)
  2. Any agent whose rendered prompt extends the prompt KAS recorded at a line break now sends only the remainder — justified
  3. A new test checks the conductor block with and without a recorded prompt — justified

[FIRST-PRINCIPLES-REVIEWED] ee680a8

Description read

[DESCRIPTION-READ] ce96efb98f334290cfb344610381ca9b747e0902763f0030b3d0a71faece0ed9

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed ee680a8be43edfb9a799ac8198150b2ad29a0a13 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] ee680a8

Verdict parsed from the review's SHA-scoped output markers for commit ee680a8be43edfb9a799ac8198150b2ad29a0a13.

False positive or not applicable? A repository writer can comment:
/ai-review override fable ee680a8be43edfb9a799ac8198150b2ad29a0a13 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of ee680a8be43edfb9a799ac8198150b2ad29a0a13 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] ee680a8

False positive or not applicable? A repository writer can comment:
/ai-review override gpt ee680a8be43edfb9a799ac8198150b2ad29a0a13 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 19, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 20, 2026 00:07

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>#prompt text 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.py pass. With the base turn_message.py swapped 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:1576 and src/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:408 describes 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.

@KiroCrewCaptain
KiroCrewCaptain merged commit 1593665 into main Nov 20, 2026
105 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the crew/issue-radar/fix-39605-conductor-prompt-once branch November 20, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conductor-family agents receive their full system prompt twice: WIDGET_BLOCK append defeats the native-prompt dedupe

2 participants