Skip to content

fix(context): send a custom agent's prompt once on kiro-cli and KAS - #17172

Closed
ianlenora wants to merge 1 commit into
kirodotdev:mainfrom
ianlenora:fix/13305-persona-once
Closed

ianlenora wants to merge 1 commit into
kirodotdev:mainfrom
ianlenora:fix/13305-persona-once

Conversation

@ianlenora

@ianlenora ianlenora commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On kiro-cli and KAS, a custom agent's persona reaches the model once instead of twice.

Every custom agent that runs on kiro-cli or KAS gets its persona twice. The harness loads the spec's prompt itself, and Crew adds the same text again as its AGENT SYSTEM PROMPT block, at session start and after every compaction. That covers app agents (a file:// prompt), user and third-party specs with an inline prompt, and Crew's own conductor and worker agents. A regression test reproduced it on main at c6bfd72 for both an inline prompt and an app's file:// prompt.

Why it matters

An affected session carries a second copy of its persona in context for the rest of its life, and every sub-agent a kiro-cli conductor spawns starts with its worker instructions twice: context space and input tokens spent on every turn for nothing. #13257 removed the same doubling for Crew's default prompt; custom agents still have it.

Not a goal

  • Changing how kiro-cli or KAS load a spec's prompt, or rewriting specs that apps, other tools or users install. Crew does not own those files.
  • Deduplicating prompts that use Crew's placeholders ({bot_name}, {{MAX_SUBAGENTS}}). The harness copy is unfilled, so both copies stay and the one Crew fills keeps the persona correct.
  • Crew Members. A member's persona already arrives once, through member essentials.
  • Harnesses other than kiro-cli and KAS. They read no kiro spec, so the block stays their only copy.

What changed (motivation → approach → change)

Crew drops its copy of a custom persona only when a snapshot proves the harness loaded exactly that text; every other case gets the block.

Where Change
agent_sdk/backends_mcp.py (re-exported by agent_sdk/backends.py), acp_backends.py ACP_BACKENDS_NATIVE_SPEC_PROMPT (kiro-cli, KAS: they deliver a spec's own prompt); ACP_BACKENDS_NATIVE_SPEC_PROMPT_ACROSS_COMPACTION (kiro-cli alone) and its release floor NATIVE_SPEC_PROMPT_ACROSS_COMPACTION_MIN_KIRO_CLI_VERSION = 2.28.0 (a floor, not a list)
the session providers, providers/base.py, agent_sdk/context.py native_spec_prompt_across_compaction, True for kiro-cli at or above the floor (read off agentInfo.version), False otherwise (block sent, a duplicate at worst); a recorded copy is itself the report of native delivery
member_essential_context.py the shape rule (user-level spec, inline or absolute file:// no sandbox may hide), the key template://<agent>#prompt, and native_spec_prompt_copy(agent, transport=, work_dir=): reads the spec kiro-cli is given: its skill-view alias when one was prepared (a copy, so a later source edit leaves the snapshot on what kiro-cli runs), else the plain name as kiro-cli resolves it (a same-named checkout spec records nothing)
acp/runtime_mode_activation.py (bound on acp/runtime_class.py), acp/runtime_spawn_launch.py, acp/runtime_session_create.py, acp/runtime_session_load.py one read right before each moment kiro-cli reads a spec: the translated --agent spec before the launch, the id session/set_mode names before each attempt (an app's launch copy is not a skill-view alias, so a session it runs records nothing and keeps the block); _record_native_persona_snapshot is the map's one writer on session/new and session/load; a KAS host records only its wire payload's prompt
sandbox_argv.py sandbox_may_hide_path, read through the sandbox.py facade: may any tier's masks (links resolved) deny a child the path; reads only, errs toward hidden
context_assembly/agent_spec.py (bound on kiro_crew/context.py), context_assembly/turn_message.py, context_assembly/turn.py no block only when the shape qualifies, a snapshot exists, Crew's text equals it and filling placeholders changes nothing; a conductor's block (it also carries #23139's widget pointer) keeps only that pointer when its spec text matches; after a compaction only where the provider reports retention
context-management.md, two system-spec modules, agent-spec-fields.md which side carries a persona on each harness, the read moments, the alias, the sandbox case, the post-compaction rule

kiro-cli reads a spec at spawn and session/set_mode only, never at a plain session/new, so the copy is read right before those two reads; an edit landing after that read leaves the file different from the snapshot, so the block is sent. KAS stays out of the compaction set: nothing says its summarization keeps the spec prompt. A wrong guess drops the persona instead of repeating it, so every unproven case sends.

Backwards compatibility

Compatible: nothing main accepts is rejected, renamed or removed. A loaded copy is recorded only on kiro-cli and KAS, so a provider without one keeps the block, as does a turn with no provider. The block is withheld in proven sessions and the handle's document map gains one key; readers:

  • acp/kas_agents.py:resolve_prompt -- KAS still gets the prompt on session/new; test_custom_persona_reaches_real_native_harness_once
  • context_assembly/turn_message.py:build_message (ContextBuilder.build_message) -- sub-agent and cron turns build through it; its native_documents hand-off to member essentials blanks a body the harness holds, prompt key included (test_native_envelope_blanks_the_persona_recorded_under_the_prompt_key)
  • context_assembly/turn.py:post_compaction_parts -- same rule after a compaction, default prompt restored; test_post_compaction_reinjection_applies_the_same_rule
  • context_blocks.py:split_blocks -- sizes the blocks a prompt carries
  • acp/session_handle.py:native_context_documents -- the key sits beside a member launch's template resources; the owner persona travels once; test_owner_persona_is_untouched_by_the_native_spec_prompt_rule

Tests

  • test_context_agent_prompt.py (TestLoadAgentPrompt, moved whole from test_context.py so both stay under the 2,000-line cap): once on kiro-cli and KAS; the block kept for ten unprovable shapes (two sandbox-masked) and an edited spec; the alias read (an edited source sends the edited persona once) and a checkout-shadowed name; after a compaction kiro-cli withholds at the floor, KAS and a kiro-cli below it send once.
  • test_acp_persona_snapshot_moments.py: the recorder stores the spawn copy, not the file at session start; the bracket reads the alias it sends and never writes the map; the spawn read precedes the launch; the recorder prefers the set_mode pair; an app's launch copy records nothing at spawn or at set_mode.
  • test_acp_spawn_offload.py: a member's persona is recorded once on create and resume; four bracket tests unpack its (alias, persona) return.
  • test_context_widget_block.py: a conductor whose spec prompt kiro-cli holds gets a block of only the widget pointer on the dashboard and no block elsewhere; a conductor spec edited after activation keeps its whole block.
  • test_essential_delivery.py (real session/new and session/load; create-then-resume on one transport: one record each, withheld next turn; after a compaction withheld at 2.28.0, sent once at 2.27.1), test_member_essential_context.py (the native envelope), test_native_spec_prompt.py (both sets, the floor table, both providers at, below and without a version), test_agent_spec_hardened_reads.py (the hardened reader), test_sandbox_plan.py (the predicate covers every tree each plan masks), test_runtime_bindings.py (the persona methods in the runtime's member inventory).

Manual verification

Real kiro-cli 2.28.0 running this branch. Positive case (user-level spec, token-free absolute file:// persona): one native document at session/new, 0 blocks at start, on resume and after a forced compaction, the same role answer throughout. Negative case (a persona with Crew's placeholders): no snapshot, block kept. Transcript and driver. Not proven live: a file://~/ prompt (host policy blocks that write) and a sandbox-masked one; tests keep the block for both.

A security scan of the changed files: no Critical findings, and no Semgrep, secret or CVE findings.

Related Issues

Follows #13257 (the same doubling for Crew's default prompt).

Part of #13305, which stays open for the three cases this PR leaves doubled: personas that use Crew's placeholders, a capability-materialized owned member whose spec still carries the managed file:// pointer, and an app agent kiro-cli runs from a launch copy (#21867).

Pattern harvest

Rule candidate: review-prompt
Pattern: a block Crew injects must first ask the live provider whether the harness already delivers it and compare against the copy the harness loaded, read from the spec it is given, not the file at turn time

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • 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

@ianlenora

Copy link
Copy Markdown
Contributor Author

Intent: On kiro-cli and KAS, a custom agent's persona reaches the model once: Crew drops its own copy only when it can show that copy is identical to the one the harness already delivered.
Not a goal: changing how harnesses load a spec's prompt, rewriting specs Crew does not own, deduplicating prompts that use Crew's placeholders, or changing Crew Member or other-harness delivery.

@dwu96

dwu96 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Oct 5, 2026
@dwu96

dwu96 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

2 similar comments
@dwu96

dwu96 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@dwu96

dwu96 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@ianlenora
ianlenora marked this pull request as ready for review October 6, 2026 12:44
@ianlenora
ianlenora requested a review from a team as a code owner October 6, 2026 12:44
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of a5defa303a295687d00eedfc0dab52263e63607e via the fork AI-review pipeline — 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

Every item traces back to the doubled persona tracked in #13305, which the description says was reproduced on main. The extra machinery decides when the block can be withheld without the persona going missing.

What this change ships

Inventory (8 items) — 7 justified

Intent: on kiro-cli and KAS, a custom agent's persona reaches the model once instead of twice. This is a FIX.

  1. At session start on kiro-cli and KAS, a custom agent's [AGENT SYSTEM PROMPT] block is no longer sent when it would repeat word for word the copy the harness loaded — justified
  2. After a compaction, the block is withheld only on kiro-cli 2.28.0 or later; KAS, and kiro-cli below that release, still get it once — justified
  3. A conductor whose spec prompt the harness already holds gets a block carrying only the widget pointer — justified
  4. The runtime records the persona text kiro-cli loads, read right before the spawn and before session/set_mode, from the alias or checkout spec that kiro-cli actually resolves — justified
  5. A resumed session (session/load) now records the persona too, on KAS as well as kiro-cli — justified
  6. A file:// persona that some sandbox tier may hide always keeps the block (sandbox_may_hide_path, read-only, one consumer) — justified
  7. Two new backend capability sets, the 2.28.0 release floor, and a native_spec_prompt_across_compaction provider property — justified
  8. TestLoadAgentPrompt moved as a whole from test_context.py to a new file, to stay under the line cap — rides along

[FIRST-PRINCIPLES-REVIEWED] a5defa3

Description read

[DESCRIPTION-READ] 13af22b45d83a75dbabd34299b9a3ed796b5b1933e49c6ad836ba325d85dd704

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

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of a5defa303a295687d00eedfc0dab52263e63607e via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the persona block is only withheld when a recorded snapshot proves the harness holds the same text, and every case it can't prove still sends the block, so the worst outcome is a duplicate.

Notes

  • Two separate snapshot moments (spawn and set_mode) plus a separate sandbox-hide check is a lot of machinery for saving tokens. It can be walked back later, because removing the recorder brings back today's behaviour.

[DESIGN-REVIEWED] a5defa3

Description read

[DESCRIPTION-READ] 81d6fed544b4f3abcbb7b19f0b7fa14123b8b0075ff1dd5c9adf5152db7b6a8f

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

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed a5defa303a295687d00eedfc0dab52263e63607e via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] a5defa3

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed a5defa303a295687d00eedfc0dab52263e63607e via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] a5defa3

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 6, 2026
@ianlenora
ianlenora force-pushed the fix/13305-persona-once branch from c9a073d to 47b3907 Compare October 7, 2026 03:54
@ianlenora

Copy link
Copy Markdown
Contributor Author
  • BLOCKING: the scratch-home fixture patches HOME only, so ~ does not resolve into it on Windows span=5834cf773e6d — fixed in 47b3907

Fixed: the fixture now sets USERPROFILE beside HOME (a two-line change), so ntpath.expanduser resolves ~ into the scratch home on Windows exactly as posixpath.expanduser does elsewhere, and the file://~/ case exercises the ~ exclusion on every CI shard instead of the runner's real profile.
Verified in the parent session by calling ntpath.expanduser with USERPROFILE patched to the scratch home; the Windows shard on 47b3907 is the authoritative check.
Provenance: the two-line change was written by a repair sub-agent (gpt-5.6-sol) and verified by the parent session (claude-fable-5.1). The local lane briefs were worked as a parent self-review because both reviewer sub-agents died to the gateway's provider-shutdown bug, so CI's gpt and opus lanes remain the authoritative review.

@ianlenora

Copy link
Copy Markdown
Contributor Author
  • W1: no live check on real kiro-cli that the persona still reaches the model when the block is withheld span=b18a40907da2 — fixed in 47b3907

Fixed with measured runs of this PR's code against real kiro-cli 2.28.0, driven through the worktree's own AcpRuntime and AcpProvider (a pod could not run on this host: Dev Fleet has no checkout configured, and the worktree has no built dist/; the PR body records this).
Positive case, a user-level spec with a token-free absolute file:// persona: at session/new the handle carried one native document, template://<agent>#prompt, 2,106 characters (the persona file's size), and the built turn had zero AGENT SYSTEM PROMPT blocks and no copy of the persona text. A real turn asking the agent its role answered with the persona's role. After a real compact() (completed, 923-character summary) the snapshot was still on the handle, the post-compaction build through the turn.py reinjection path again had zero blocks, and the same question got the same role answer. The load_session resume leg also recorded the snapshot and built zero blocks.
Negative case, a spec whose persona carries {bot_name} and {{...}} placeholders: no snapshot, and exactly one block kept (38,967 bytes of agent instructions).
Not proven live: the file://~/ shape of a user-level spec. Creating a user-level agent is policy-blocked for the agent on this host; workspace-local specs reject both absolute and ~ prompts with PromptFileError, and the shape rule plus the home-file test keep the block for that shape regardless.
Provenance: the live check and this disposition were done in the parent session (claude-fable-5.1); both review sub-agents died to the gateway's provider-shutdown bug, so CI's lanes remain the authoritative review.

@ianlenora

Copy link
Copy Markdown
Contributor Author
  • W2: the identical-copy check compares today's spec file, not the copy kiro-cli loaded at activation span=6d3d97bb297b — fixed in 47b3907

Fixed with an activation snapshot. AcpRuntime._record_native_persona_snapshot records, at session/new and at session/load, the persona text the harness loaded under the key template://<agent>#prompt in the handle's native_context_documents: for kiro-cli only what the user-level spec's absolute file:// prompt resolved to through the hardened, size-capped reader, and for a KAS host only what its payload carried (kas_agents is None records nothing). The identical-copy check in member_essential_context.py and the post-compaction path in turn.py compare against that snapshot, never against the file on disk at turn time.
A spec edited, renamed or made unreadable after activation therefore differs from the snapshot and keeps the block, so the new text reaches the model at the next session start or compaction exactly as on main; native_spec_prompt defaults to False and the three callers that build a turn with no provider keep the block too.
Guards: 19 new tests (11 in test_context.py, 4 in test_essential_delivery.py, 4 in test_native_spec_prompt.py), including resume tests for kiro-cli and KAS load_session, a wire-host test that the KAS payload is the only source, and a spec-edited-after-resume test. Mutation checks were run and restored: removing the kas_agents is None guard fails the wire-host test; removing the session/load snapshot call fails both resume tests.
Provenance: designed, implemented and verified in the parent session (claude-fable-5.1) after the repair sub-agents died to the gateway's provider-shutdown bug; the live runs recorded under W1 exercise this snapshot on real kiro-cli 2.28.0.

@ianlenora

Copy link
Copy Markdown
Contributor Author

Note on the test_source_pin_budget red seen on the earlier head c9a073d4d: that failure was main's own. The owner-dm module's source-pin budget was raised to three reads by #17290 (ea7e91c8e) and returned to one read by #17339 (merge commit 334335182, 6 Oct). The current head 47b39079ffa6d3474a48345685c0c40851b287bd is a single commit rebased onto origin/main at 5b2aee24e, which includes #17339, so the red does not apply to this PR's commit. Nothing in this PR touches that module or its test.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Oct 7, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Reviewed, not approving (crew-pr-reviewer). This is a large change (+1126) to how a custom agent's prompt is sent on kiro-cli and KAS. It needs a maintainer's review.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision readiness: action required A blocking check or review needs attention labels Oct 7, 2026

@cruisercohen cruisercohen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Delta review at head 21ecbc4 (rebased since my last review at 1d50497). The earlier blocker is addressed: native_spec_prompt_shape now rejects an absolute file:// persona whenever sandbox_may_hide_path says a sandbox tier on this host can mask it, and that check fails closed (an unreadable host reports the path hidden), so the block is kept rather than lost. The targeted context, persona-snapshot, essential-delivery, member-context and sandbox-plan suites pass locally on this head (801 passed). One blocker remains:

  1. test/test_context.py:2055 adds a new pytest.skip("symlinks unavailable on this host") in the sandbox-masked-link case, which the GPT review lane blocks under the repo's rule that a ratchet may only tighten. On a host without symlink privilege, the masked-link assertions would silently not run. Please make the link case run everywhere, or split it into a separately gated test so the existing file gains no skip. Note that the make_dir_link helper the lane suggests is not in test/conftest.py on this head.

Also, since this head now changes the sandbox module (sandbox.py), the Sensitive Change Review lane needs a maintainer's sign-off on top of review approval.

@ianlenora
ianlenora force-pushed the fix/13305-persona-once branch from 21ecbc4 to 5f30d35 Compare October 10, 2026 18:14
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 10, 2026
@ianlenora

Copy link
Copy Markdown
Contributor Author

@cruisercohen thanks for the delta review. On 5f30d3539, rebased on current main:

The skip is gone. The sandbox-masked-link case now builds its link with make_dir_link (re-exported by test/conftest.py from kiro_crew.testing.links): a directory link into the masked tree, a junction on Windows, which needs no symlink privilege. So the case runs on every host, and prompts/persona.md still reaches the masked file only through the link. test_context.py gains no skip.

The rebase picked up main's new relocated .vault mask. sandbox_may_hide_path now counts it the way the planner does. The pin test that checks the predicate against plan_confinement for every tier caught the gap on the rebase. That is also the answer to the Design note about keeping that second list in step with the planner: it can drift, and the pin turns drift into a red test. Building the plans at read time instead would create the voice-runtime directories and run ssh -V on each read; happy to switch if you'd rather pay that.

Still open, both maintainer calls:

  • Sensitive Change Review: this changes sandbox.py from a fork, which that gate refuses outright. I'm glad for a maintainer to take it over on a branch here (Co-authored-by: / Supersedes #17172), or to say if you'd rather I move it some other way.
  • The 2.28.0 post-compaction floor from your first review: one floor at the verified release, no version list, and the block is sent below it (a duplicate, never a lost persona). It still needs a maintainer's explicit OK.

@iamwhatever the Design Watch item you held on (a file:// persona read outside the sandbox) is answered by failing open: any target a sandbox may hide keeps the block, which cruisercohen confirmed on 21ecbc4c3.

@ianlenora

Copy link
Copy Markdown
Contributor Author
  • Item 5 — sandbox_may_hide_path for an unreported dropped-persona case span=4339af87cacb — kept; a maintainer's call

The function exists because a human review asked for it: the Design lane raised the sandbox-masked file:// persona as a Watch item, and cruisercohen's review 5474912687 marked it blocking. Their delta review 5478137912 accepts the fix.
There is no live reproduction, and the PR body says so. The guard fails open: for a target a sandbox may hide, Crew records nothing and sends its block, so the worst case is today's duplicate, never a lost persona.
The second list is pinned to the planner: test_sandbox_plan.py checks every tree each tier's plan masks, and that pin caught main's new relocated .vault mask on the rebase.
Deleting the function reopens the case the reviewer blocked on. If the maintainers prefer that trade, removing it and its use in native_spec_prompt_shape is a small follow-up.

@ianlenora
ianlenora force-pushed the fix/13305-persona-once branch from 5f30d35 to a2892eb Compare October 12, 2026 13:44
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 12, 2026

@cruisercohen cruisercohen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed at dac76b6. My remaining point from the review on 21ecbc4 is addressed: the sandbox-masked-link case in test/test_context.py now builds its link with make_dir_link, which test/conftest.py re-exports on this head, so the case runs on every host and the file gains no skip. My change request is resolved on the code.

I am not approving, because this still needs the following:

  • Merge conflict with main: the branch needs a rebase.
  • Backend Tests (3.12, 2) and macOS Tests (2) fail in test_provider_spawn_off_loop_18172.py::test_cancellation_during_the_spawn_still_reaps. That test was fixed on main after this run (#19358), so a rebase should clear it, and Coverage Gate (failing closed on that lane) with it.
  • Sensitive Change Review is red because the head changes sandbox.py from a fork. The new sandbox_may_hide_path only reads paths and fails closed, but that gate and the post-compaction version floor both need a maintainer's sign-off.

@ianlenora

Copy link
Copy Markdown
Contributor Author

@cruisercohen thanks. Rebased onto current main as one commit, 2790a9032. That base includes #19358, and on this run the test_cancellation_during_the_spawn_still_reaps reds on Backend Tests (3.12, 2) and macOS (2) are gone: both shards and the Coverage Gate pass. The conflicts were main's switched-model reset beside the set_mode bracket call (create and resume, runtime.py) and its new prompt_timeout_for_deadline and stream(timeout=) next to this PR's provider property (both providers); the change itself is the same as dac76b6ed. The Sensitive Change Review and the post-compaction 2.28.0 floor stay with a maintainer, as you say.

@iamwhatever

Copy link
Copy Markdown
Contributor

This PR stops a custom agent's persona reaching the model twice on kiro-cli and KAS. Crew withholds its [AGENT SYSTEM PROMPT] block only when a snapshot shows the harness loaded the same text: read right before spawn and before each session/set_mode, from the skill-view alias when one exists, and recorded by one writer on create and resume. I re-read the production diff at 2790a90. The blocker from our earlier hold is fixed: native_spec_prompt_shape now refuses any absolute file:// target that sandbox_may_hide_path says any tier's masks may hide. That check compares both the given and resolved spellings against every tier's trees, and it fails closed to "hidden" on any error, so a file the sandboxed harness cannot read keeps the block instead of leaving no persona. I tried edited-after-spawn specs, checkout-shadowed names, relative, ~ and managed prompts, placeholders, and KAS file:// payloads. Each mismatch keeps the block, and I found no path that drops the persona. I am holding on hard blockers, not a defect. First, the branch is now CONFLICTING/DIRTY against main and needs another rebase. Second, Sensitive Change Review is red because a fork PR changes sandbox.py, which that gate refuses outright, so a maintainer has to take the change over on an in-repo branch (as the author offered) or sign it off. Third, the maintainer also needs to answer the question still open from cruisercohen's first review: do you accept the static kiro-cli >= 2.28.0 floor for withholding the persona after a compaction, or do you want a verified-version list? — crew-pr-reviewer (deep re-check)

@ianlenora

Copy link
Copy Markdown
Contributor Author

@cruisercohen thanks for approving the runs. Two reds on 70328a049 are not from this change and need a re-run, which a fork account can't trigger here:

Everything else is green, and the GPT, Opus and First Principles lanes report no blocking findings; the Sensitive Change Review still needs a maintainer, as noted above.

@ianlenora

Copy link
Copy Markdown
Contributor Author

@cruisercohen @iamwhatever rebased onto main as one commit, 07a696782. #20584 carved sandbox.py into owner modules while this was open, so one resolution choice on the sensitive path is worth a look:

  • sandbox_may_hide_path stays in sandbox.py, byte-for-byte as reviewed, next to wrapped_by_crew_sandbox and the other spawn predicates the carve left in the facade. It reads two names the carve moved and the facade only forwards (_pod_os_home_targets, _VOICE_RUNTIME_LEAF), so the facade now binds both by import, as it does for the other moved names its own code reads, and test_sandbox_refactor_facade.py lists them in _BOUND_HERE. Without those bindings the read raises NameError, the function's except reports every path hidden, and the dedup silently turns off; the test_sandbox_plan pins fail if either binding is dropped.
  • sandbox.py grows 8,084 → 8,137 lines against its line-cap row (reported, not failed). If you'd rather it live in an owner, sandbox_staging is the one that reaches every input without a new import edge; happy to move it.
  • test: split four oversized test files under the line cap #20531 moved the bracket AST test to test_worker_agent_load_bracket.py, and its return-names assertion moved with it.

The persona logic is otherwise the same as 70328a049.

@cruisercohen cruisercohen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-review at 8dd4a97923, answering your note on the sandbox side of the rebase.

The resolution checks out. sandbox_may_hide_path is byte-for-byte the function we reviewed. The two names it reads now live in owner modules, and the facade serves them only as attributes of the module object, which a global lookup inside sandbox.py never goes through, so the explicit imports are required. I checked that locally: with those two imports removed, test_sandbox_may_hide_path_leaves_readable_trees_visible and test_sandbox_may_hide_path_changes_nothing_and_asks_no_ssh fail (every path reports hidden). With them in place, the sandbox_may_hide_path tests and all of test_sandbox_refactor_facade.py pass. Keeping the function next to wrapped_by_crew_sandbox reads fine to me. Whether it should move to an owner module is a maintainer's call.

The other changes are re-homes too. The bracket AST assertion moved with its test into test_worker_agent_load_bracket.py, and native_spec_prompt_across_compaction gets its row in the frozen AcpProvider member inventory. The persona logic is unchanged.

The red Backend Tests (3.12, 5), (Windows) (5) and (macOS) (1) all fail only in test_acp_bindings.py, on approval_withdrawable and the new approve_tool signature. That comes from the main commit this branch sits on, which predates #20902. A rebase onto current main should clear those and Coverage Gate. Sensitive Change Review still needs a maintainer, because this touches the sandbox.

cruisercohen
cruisercohen previously approved these changes Oct 19, 2026
@ianlenora

Copy link
Copy Markdown
Contributor Author

@cruisercohen @iamwhatever rebased onto main as one commit, d3a75addb. Since cac3eb132, main has split six of the files this PR edits, so most of the work is moving the PR's hunks to where main put the code. The persona logic is the same as feb02c27b. After the rebase notes, this answers the Design lane's two items on this head and asks for one CI job to be re-run.

What moved:

  • refactor: split agent_sdk/backends.py into vocabulary owner modules #21616 split agent_sdk/backends.py into owners. The two sets, the 2.28.0 floor and spec_prompt_retention_verified now live in backends_mcp.py beside ACP_BACKENDS_SPEC_SERVERS_OFF_WIRE, since that owner answers which spec fields and levels a host reads. The facade re-exports all four, so every import path and object is unchanged. The block is byte-for-byte the one on the previous head, and the disposition rows stay in the facade's docstring table.
  • refactor(context): bind ContextBuilder methods from owner modules #21049 moved ContextBuilder's method bodies into context_assembly. The PR's changes to _load_agent_prompt and _resolve_agent_prompt moved with them into agent_spec.py; apart from main's own ctx. reads and its new browser= argument, both functions match the previous head line for line. _native_prompt_snapshot also lives in agent_spec.py and is bound on the kiro_crew.context facade, which turn.py and turn_message.py read at call time, so the patch seam is the same. build_message, now in turn_message.py, passes the snapshot at session start as before.
  • test: split four oversized test files by behaviour under test #21784 split test_context.py. Adding this PR's tests would take it to 2,226 lines, past the 2,000-line cap, so TestLoadAgentPrompt moved whole into test_context_agent_prompt.py: main's class plus this PR's tests, unchanged.
  • test: split four oversized test files into topic siblings #21906 split test_member_essential_context.py. The native-envelope test stays in the main file.
  • refactor(acp): bind AcpRuntime spawn, kill and session-start owners #22085 moved AcpRuntime's spawn and session-start bodies into owner modules. The PR's hunks moved with them: the spawn-time persona read into runtime_spawn_launch.py, the recorder calls into runtime_session_create.py and runtime_session_load.py. _spawn_persona_snapshot is declared under TYPE_CHECKING, the way main declares the other fields a bound member writes first, and the recorder reads it with a None default, so a runtime that never spawned still records nothing. The three persona methods stay on AcpRuntime in runtime.py, beside _activate_mode_bracketed, which main also kept there; test_runtime_bindings.py gets their inventory rows and the bracket's new signature digest (its handle= parameter). Happy to move the three into an owner module instead.

Also new since cac3eb132:

sandbox_may_hide_path. One change from cac3eb132 that no comment here has explained yet: it lives in sandbox_argv, read through the sandbox.py facade. #20866 left that facade with no code of its own, and argv already imported 9 of the 11 names the function reads; the other two come over edges argv already has, so _CARVED_IMPORTS is unchanged. I chose argv over sandbox_staging because staging materialises mask targets and this function only reads. Happy to move it.

The Design lane suggests it read the planner's mask output instead of keeping its own list of masked trees. I've kept the list. Reading the planner's output means building plans, and a plan answers a narrower question: _spawn_plan builds one spawn's plan for one renderer and one tier, and building it is not read-only. _live_plan_host primes the voice runtime (prime_voice_runtime_sandbox_paths creates it) and, on the namespace renderer, runs ssh -V. This function has to hold for every tier and renderer a later spawn may get, and it runs while Crew loads an agent's prompt (native_spec_prompt_shape, from context_assembly/agent_spec.py and the member essentials), so it must change nothing. test_sandbox_may_hide_path_changes_nothing_and_asks_no_ssh pins that it creates nothing and runs no ssh.

The two lists cannot drift apart unnoticed. test_sandbox_may_hide_path_covers_every_tree_a_plan_masks builds the plan for each tier, renderer and home layout (24 cases) and requires every tree the plan denies (its sensitive_files and ~/.ssh), and a file inside each, to be reported hidden. A tree the planner starts denying without this list fails that test. That catches the error that matters, a wrong "visible", which would lose the persona; an extra entry costs one repeated block. One source of truth would be a side-effect-free "every tree any tier masks" helper in the planner that both read. That is a refactor of the sandbox planner, so I'd rather leave it to a follow-up than widen this PR.

Two things on this head are maintainer calls:

  • Sensitive Change Review is red because this PR changes sandbox.py and sandbox_argv.py. The gate refuses any fork PR that touches a sensitive path, whatever approvals it has, and asks a maintainer to take the change over on a branch here. It failed the same way on the earlier heads.

  • The 2.28.0 post-compaction floor. The Design lane's Watch item ("The version floor is open-ended") and the First Principles lane's one ask both say the floor trusts every release from 2.28.0 up on one 2.28.0 transcript. That is accurate: NATIVE_SPEC_PROMPT_ACROSS_COMPACTION_MIN_KIRO_CLI_VERSION is (2, 28, 0), spec_prompt_retention_verified is True for every release at or above it, and nothing re-checks retention when kiro-cli changes. In the transcript, the forced compaction completes, the post-compaction build has 0 AGENT SYSTEM PROMPT blocks and no persona copy, and the agent follows its persona before and after ([persona] followed before=True after=True). test_essential_delivery.py covers both sides of the floor (withheld after a compaction at 2.28.0, sent once at 2.27.1). No release after 2.28.0 has a transcript. packaging/kiro-cli-version pins 2.27.1, below the floor, so the bundled kiro-cli is sent the block once after each compaction today; the withhold applies only where kiro-cli 2.28.0 or later is installed. The ways to clear it, and their costs:

    • (a) Add an upper bound at the newest release a transcript covers, so spec_prompt_retention_verified checks min <= version <= max. This follows the PR's own rule that an unverified case sends the block: a newer release gets one duplicate block per compaction, which is main's behaviour today, until someone re-runs the driver from the transcript comment and moves the bound. Cost: one transcript and a one-line bump for each release that should keep the withhold.
    • (b) A check that re-proves retention when kiro-cli changes, such as re-running that driver as part of each kiro-cli bump. It needs a logged-in kiro-cli, so it would be a release step rather than a unit test.
    • (c) Accept the open-ended floor. Every newer release keeps the saving, at the risk the Design lane names: a kiro-cli whose summary drops the spec prompt loses the persona without a word.

    I recommend (a), with the upper bound set by a fresh run of the same driver on a current kiro-cli (2.32.0), so current releases keep the saving. If a maintainer picks (a), I'll push it on this branch with a test on each side of both bounds. If (c), a maintainer saying so here is what clears the Watch item.

One red on this head is a timeout rather than a failure: Backend Tests (3.12, 2) stopped test_facade_mirror_guards.py::test_every_name_the_test_trees_patch_through_a_facade_reaches_its_readers at pytest's 120 s limit, and Coverage Gate fails because it requires that job. The test passes alone in 88 s on this head and in 92 s on its base b92a9c3a7, and the same timeout appears in 20 of the 24 most recent failed fork-PR CI runs I checked, from 10:07 to 12:59 UTC today. Could a maintainer re-run that job?

cruisercohen
cruisercohen previously approved these changes Oct 21, 2026
@ianlenora

ianlenora commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@cruisercohen @iamwhatever rebased onto main as one commit, a04f8dc1b, to clear the conflicts with #22358 and #21867. The push dismissed the approval on d3a75addb. Everything that changed since that head is listed below. The persona logic is the same as on d3a75addb, apart from one adjustment #21867's app launch copies need:

One correction to my last note: _spawn_persona_snapshot was declared under TYPE_CHECKING, but main keeps that block for fields a bound member assigns first, and __init__ assigns this one. It is now annotated in __init__, as main does for _derived_spec_snapshot, and the recorder's getattr default still covers a runtime built with __new__. Behaviour is unchanged.

Checked before the push. On this commit, all 48 gate commands I ran exit 0, among them Fast Gate's new flake-pattern ratchet against the merge-base, and 15,993 tests pass in 294 test files: this PR's own, every test that imports or names one of the five modules main's newest commits changed alongside this PR (acp/runtime_class.py, acp/runtime_session_create.py, agent_sdk/backends_mcp.py, sandbox.py and sandbox_argv.py), and the tests those commits changed that name a module this PR changes. On the same change rebased onto an earlier main (d0622d088), 42,612 tests passed across 991 test files: this PR's tests, every suite that imports or names a module both this PR and main changed, and #21867's launch-copy tests. The 10 that failed there are doctor tests that fail the same way on main. Not run locally: the full backend suite and an AI review, which CI covers.

@ianlenora

ianlenora commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi Matt, PR #17172 (send a custom agent's prompt once on kiro-cli and KAS) is rebased onto current main to clear the conflicts with #23139 and #23010, and it needs your approval: #17172

On the new head, e111245:

What still needs a maintainer:

  1. Approving the workflow runs on e111245.
  2. Sensitive Change Review is red because the PR changes sandbox.py and sandbox_argv.py: that's the sandbox_may_hide_path check you asked for on 9 Oct. The gate refuses any fork PR touching those paths, so a maintainer has to take the change over on a branch in kirodotdev/KiroCrew.
  3. The 2.28.0 post-compaction floor is still open-ended, which your 9 Oct review said a maintainer should accept or replace. My comment from 21 Oct sets out three options, and I recommend adding an upper bound.
  4. Your approval of e111245.

Thanks!

kiro-cli reads a custom agent spec's prompt when it activates the
agent, and KAS receives it on session/new. Crew also injected the same
text as its AGENT SYSTEM PROMPT block, so on those two harnesses a
custom persona reached the model twice: at session start, and again
after every compaction.

The runtime records the harness's copy of the prompt only for the
backends in ACP_BACKENDS_NATIVE_SPEC_PROMPT (kiro-cli, KAS); that
recorded copy is the whole report, and the prompt builder withholds its
block only when one exists and the text it would send is word for word
that copy: a user-level spec's inline prompt or absolute file:// prompt
that Crew's placeholder pass leaves unchanged. The managed default
prompt, relative and home-relative (~) file:// paths, project-level
specs and every other harness keep the block. So does a file:// target
that a Kiro Crew sandbox on the host may hide (sandbox_may_hide_path:
every tier's masked trees, files and ~/.ssh, links resolved): Crew reads
the file from the gateway, outside the sandbox, while a sandboxed
harness may be denied it and drop it silently.

The harness's copy is recorded at the moments kiro-cli reads the spec,
from the spec kiro-cli is given -- its skill-view alias when a view was
prepared, a copy taken at preparation, else the plain name as kiro-cli
resolves it from the process cwd (a checkout spec declaring the name records
nothing, so the block is sent; otherwise the user-level spec) -- read
once, immediately before the request: the runtime reads the translated
--agent spec before its process spawns, and the session/set_mode
bracket reads the alias it sends and returns the pair. An edit landing
after that read leaves the file different from the snapshot, so the
block is sent, never withheld. A plain session/new reads nothing, so the
file as it reads at session start is never the source: a persona edited
between the spawn and the session keeps its block, because kiro-cli does
not hold the edited text. One recorder writes the
session's document map, after the bracket and after every merge, so a
member launch whose sources already carry the persona gets no second
record of the same text. A KAS host is recorded from its wire payload.

Reinjection after a compaction withholds the block only on a harness
shown to keep the spec prompt through its own compaction,
ACP_BACKENDS_NATIVE_SPEC_PROMPT_ACROSS_COMPACTION, reported by the
providers as native_spec_prompt_across_compaction, and only from the
kiro-cli release that transcript was taken on,
NATIVE_SPEC_PROMPT_ACROSS_COMPACTION_MIN_KIRO_CLI_VERSION (2.28.0), read
off the agentInfo.version the process reported at initialize. A floor,
not a list of releases: below it, and when no version was reported, the
block is sent, a duplicate of a prompt the harness may still hold, which
costs tokens and nothing else. KAS is not in the set, so a KAS session
is sent the block once after a compaction even when the recorded copy
still matches. Session start is unchanged on both.

Closes kirodotdev#13305
@iamwhatever

Copy link
Copy Markdown
Contributor

Holding a5defa3 for a maintainer; I found no defect.

The persona block is withheld only when a snapshot proves kiro-cli or KAS loaded the same text, and every unproven case still sends it. sandbox_may_hide_path only reads and reports "hidden" on any error, so a file a sandboxed harness cannot read keeps the block. The AI lanes have no findings on this head and the branch now merges cleanly into main.

What still blocks:

  1. Sandbox change from a fork. The PR adds new logic to sandbox_argv.py and a re-export in sandbox.py. Sensitive Change Review refuses this from a fork, so a maintainer has to take it over on a branch of this repository and sign off on the sandbox read.
  2. Open decision on the 2.28.0 floor. NATIVE_SPEC_PROMPT_ACROSS_COMPACTION_MIN_KIRO_CLI_VERSION trusts every kiro-cli release from 2.28.0 up on the strength of one 2.28.0 transcript. A maintainer needs to accept that open-ended floor or choose one of the bounded options in the author's 21 Oct comment.

The cases left doubled are tracked in #13305.

— crew-pr-reviewer (r128)

@bolichen97

Copy link
Copy Markdown
Contributor

[operator: bolichen97] Continuing this in #31875; thanks for the start.

@iamwhatever

Copy link
Copy Markdown
Contributor

Thank you for this work! As noted in the thread, it continued in #31875, which has now merged. Closing this one as superseded by #31875.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants