Repository navigation
fix(agent): keep an unreadable agent spec instead of resetting it - #27535
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The fix is at the cause: it splits "could not read" from "read it, damaged" at the one reader that fell back to defaults. Two bits of extra bookkeeping are noted below. Notes
What this change shipsInventory (9 items) — 7 justifiedIntent: a rebuild that cannot read an existing
[FIRST-PRINCIPLES-REVIEWED] 08f2539 Description read[DESCRIPTION-READ] 93e8a39535f68057435c684bc757e86b5848f333f76edaf8963d1ffa698db9b6 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the fix targets the root cause, treating a failed read as a missing file, and only Notes
[DESIGN-REVIEWED] 08f2539 Description read[DESCRIPTION-READ] ab042e3bb9a8f978a62a4fc8dadf5846337d14907b62dd8b5fc0a10f55d540b9 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 |
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 findings (all downgraded on adjudication)GPT 6.1 flagged blocking issues on This comment is updated in place on each push. Review detailsBLOCKING -- src/kiro_crew/agent_parts/spec_unreadable.py:152 -- Do not cache a sibling pass whose fork refresh failed
Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1 — harm is LOW, and it fails safe. The failure needs two things to happen in the same skip pass. First, the main spec is unreadable and its sibling pass runs ( False positive or not applicable? A repository writer can comment: |
ea0fd68 to
d0a920b
Compare
|
This applied to span=test/test_acp_healthy_host_session_open.py:170 F1 (real skill projections outlive temporary-directory teardown): fixed in First-pass check: R1-R8 OK. |
|
HOLD for a human reviewer at d0a920b. What holds it:
One question from our r133 hold is still open. I found no definite defect in the parts I read. The keep-the-spec fix is right. The GPT F1 fix matches its disposition. The three Design notes (rename-aside alternative, ship the small fix first, name the model-probe reader in Backwards compatibility) are advice and do not block. Checks are all green on this head. To clear: cruisercohen or another maintainer re-reviews this head, answers the KAS question and approves the start gate. — crew-pr-reviewer (r140) |
d0a920b to
dcb541f
Compare
…-off Per the maintainer's security sign-off on #27535, this PR no longer raises security strictness. It keeps only the data-loss fix: an unreadable kirocrew.json, and the worker and heartbeat specs mirrored from it, are kept instead of being overwritten with defaults. Dropped, with their tests: - require_main_spec_projected in require_fork_governance - require_main_spec_launch_bound and every caller (direct-client spawn and _send_request, shared-runtime spawn, _require_launch_bound_for_session_open, the KAS by-name read and the pre-send payload check) - the set_mode checks in runtime_mode_activation.py and check_mode_frame - the projection's main_spec_refused path - the runtime_wire session/new and session/load ValueErrors - the early-retry timer and its gateway start and shutdown hooks The acp/ package and the gateway hooks are back to main. While the file is unreadable, starts are decided as on main; a test pins that the open episode changes no start decision. The skip stays a held rebuild, so the hourly maintenance wake still rewrites the kept spec once it reads.
|
@bolichen97 thanks, applied as written in c10f233. Point by point: Keep
Drop
While the file is unreadable, starts behave as on main. Test notes
The PR description is updated to the narrowed scope. |
…-off Per the maintainer's security sign-off on #27535, this PR no longer raises security strictness. It keeps only the data-loss fix: an unreadable kirocrew.json, and the worker and heartbeat specs mirrored from it, are kept instead of being overwritten with defaults. Dropped, with their tests: - require_main_spec_projected in require_fork_governance - require_main_spec_launch_bound and every caller (direct-client spawn and _send_request, shared-runtime spawn, _require_launch_bound_for_session_open, the KAS by-name read and the pre-send payload check) - the set_mode checks in runtime_mode_activation.py and check_mode_frame - the projection's main_spec_refused path - the runtime_wire session/new and session/load ValueErrors - the early-retry timer and its gateway start and shutdown hooks The acp/ package and the gateway hooks are back to main. While the file is unreadable, starts are decided as on main; a test pins that the open episode changes no start decision. The skip stays a held rebuild, so the hourly maintenance wake still rewrites the kept spec once it reads.
c10f233 to
c37ccee
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Re-reviewed at c37ccee. Thank you: the start refusals, the launch bound, the set_mode gates and the early-retry timer are all gone, as asked, and keeping the unreadable kirocrew.json instead of overwriting it is exactly the part we wanted. No regex is added.
Requesting changes for one gap, which the Opus lane also found. When _read_existing_spec raises _AgentSpecUnreadable, _install_sibling_specs(..., mirror_main=False) now skips _install_heartbeat_agent and worker_agent._install_worker_agent entirely. On main, those two specs are rebuilt on every rebuild and their allowedTools / autoApprove are filtered through the governance ceiling. So if an administrator tightens the ceiling while the main spec is unreadable, kirocrew-worker.json and the heartbeat spec keep the grants of the old ceiling. kiro-cli auto-approves those tools before the PreToolUse gate sees them.
This is not a request for more strictness. It asks the PR to keep main's current enforcement. The PR's goal is to stop overwriting the user's spec, not to let a tightened ceiling be skipped.
Requested:
- While the main spec is unreadable, still filter the existing worker and heartbeat grants through the current ceiling, in place: read each spec, drop what the ceiling no longer allows from
allowedTools/autoApprove, and write it back. - Do not copy the main spec's servers into them, since that would need the unreadable file.
- Do not add a start refusal for this.
- Add a test: open an unreadable-spec episode, tighten the ceiling, run a rebuild, and assert the worker and heartbeat specs no longer carry the removed grants while
kirocrew.jsonstays byte-identical.
Separately, and non-blocking: agent_parts/spec_rebuild.py is now 1,610 lines, past the 1,600-line target.
|
@bolichen97 thanks, applied in 6e27db2. Point by point:
The branch is also rebased onto current main. |
bolichen97
left a comment
There was a problem hiding this comment.
Re-reviewed at be0d3d5. Thank you: _refilter_kept_mirrors() does what I asked. It filters the kept worker and heartbeat specs through the current ceiling in place, adds no server and no start refusal, and adds no regex. That part is ready.
One CI failure this PR causes blocks the approval: test/test_ledger_conductor_agent.py::test_the_boot_installer_writes_this_spec fails on Linux and Windows shard 6. The test reads agent_parts/spec_rebuild.py and asserts it contains _install_ledger_conductor_agent(clean=clean), but this PR moves that call into agent_parts/spec_siblings.py. Please point the test at the file that now holds the call (or at both), so it still proves the boot installer writes the spec. Coverage Gate and PR Readiness are red only because of that shard. Once it is green I will approve.
rebuild_agent_config read kirocrew.json with a plain read_text and treated every OSError like a corrupt file, so a transient read failure on a present, valid spec (a Windows sharing violation while another writer replaces it, a permission or I/O error) rewrote the user's spec with defaults. Every read of the main spec on the rebuild path goes through read_bytes_with_retry, and only FileNotFoundError means absent. Any other OSError raises _AgentSpecUnreadable, from the load or from the alias reconcile inside the write lock (mcp_aliases._durable_tool_aliases reports such a file as present). _skip_unreadable_main_spec then leaves kirocrew.json and the heartbeat and worker specs mirrored from it untouched, and still runs the steps that write other files (_install_sibling_specs), so the fork refresh and conductor specs follow a moved ceiling. That sibling pass runs on the first skip of an episode and again only when the governance generation moves since the last pass that held no write. The skip is reported as an unwritten, held rebuild, which the existing retry paths act on, and kirocrew setup, the dashboard and the config watcher say the spec was left unchanged. Until a rebuild writes the spec again, require_fork_governance refuses the main agent and its two mirrors, keyed on the spec FILE a start resolves to, with the remedy in the message, one SEL denial per refusal and an early retry at 5, 15 and 60 s (then every 60 s). Neither can run its projected spec during the episode: a fresh kiro-cli that cannot read the file starts its own default agent, and a running one keeps the copy it loaded, because kiro-cli reloads a spec only when its content changes (probed on Linux, kiro-cli 2.31 to 2.33). While the episode is open every start is refused, another agent's included, one SEL denial each, with no exemption for a project spec or a view's source: a start with no prepared view, or on KAS, hands kiro-cli (or Crew's own read by name) a bare name that cannot be pinned to a file, a rename of the main agent after the last rebuild write cannot be learned from an unreadable file, a link or a retarget can put the kept file under any name, and kiro-cli keeps serving a spec it loaded after the file turns unreadable, so a doubt refuses. The native skill projection refuses a view read across an episode, whatever file it was read from, and a launch on a view records its source: a session open or switch on a view is refused while an episode is open. An app agent's launch copy is checked as a bare name is, at its spawn and at every open and switch on it. Every session/new and session/load on the shared runtime goes through _send_session_open, and every set_mode frame on kiro-cli through check_mode_frame; each is checked right before its send, since the frame activates an agent the process already holds. create_session and load_session also check before their setup, so a refused create takes no start permit. A mid-session switch reads the modeId its send will carry with the projection's pure lookup, so a refused switch writes one SEL denial. Once a rebuild closes the episode every start is admitted again, a view built before it included, and no process is ended. Only a spec read before the episode ended stays refused: a KAS payload read by name across it, or an agent the projection read during it. refuse_unprojected_main_spec_start says so in the message and in the SEL row's cause and remedy: a new start reads it again. While an episode is open, a name other than the main spec's own that is refused by name is told it is resolved by name and the unreadable spec may declare it; a refused view is not. The episode lives in its own agent_parts owner, spec_unreadable; the rebuild's part stays in spec_rebuild, and the two classes owners may not define stay on the agent facade. A missing file, a read that returns invalid UTF-8 or JSON, and a clean rebuild still write defaults. Closes #15515
|
@bolichen97 thanks. Fixed in 8892423.
Both assertions are exact string checks, as strict as the original one. That test was the only failure in shard 6 on Linux and Windows. I ran the whole of shard 6 locally with the CI sharding plugin: the ledger test passes, and the 4 other failures also fail on a clean main on my machine. The branch is rebased onto current main. |
bolichen97
left a comment
There was a problem hiding this comment.
Re-reviewed at 8892423. Thank you: the only change since be0d3d5 is the test fix. test_the_boot_installer_writes_this_spec now checks that the rebuild calls _install_sibling_specs(...) and that spec_siblings.py holds _install_ledger_conductor_agent(clean=clean), which still proves the boot installer writes the spec.
The First Principles lane now blocks this head, and I agree with it: _refilter_kept_mirrors calls _apply_allowed_tools_ceiling and _strip_ungoverned_auto_approve by hand, which is the same pass pair fork_refresh._apply_governance_passes already owns. If a pass is later added there, the kept mirrors would miss it. Please call fork_refresh._apply_governance_passes(...) in place of the two calls, keeping the derived permissions step and the write-only-on-change check as they are. This changes no behavior today; it keeps one copy of the filter.
The other CI jobs on this head are still running. Once the lane passes and CI is green I will approve.
|
@bolichen97 thanks. Done in 49c4b7f.
|
|
Thank you for the update at 49c4b7f. The code fix looks right: CI never started on this head, though: only the PR Readiness group shows up, and the test, lint and review jobs never appeared. The push event was likely lost in a GitHub outage. Could you push an empty commit to start it? For example: |
…-off Per the maintainer's security sign-off on #27535, this PR no longer raises security strictness. It keeps only the data-loss fix: an unreadable kirocrew.json, and the worker and heartbeat specs mirrored from it, are kept instead of being overwritten with defaults. Dropped, with their tests: - require_main_spec_projected in require_fork_governance - require_main_spec_launch_bound and every caller (direct-client spawn and _send_request, shared-runtime spawn, _require_launch_bound_for_session_open, the KAS by-name read and the pre-send payload check) - the set_mode checks in runtime_mode_activation.py and check_mode_frame - the projection's main_spec_refused path - the runtime_wire session/new and session/load ValueErrors - the early-retry timer and its gateway start and shutdown hooks The acp/ package and the gateway hooks are back to main. While the file is unreadable, starts are decided as on main; a test pins that the open episode changes no start decision. The skip stays a held rebuild, so the hourly maintenance wake still rewrites the kept spec once it reads. Main's enforcement of a tightened ceiling on the worker and heartbeat specs is kept: while the main spec cannot be read, their existing allowedTools and autoApprove are re-filtered through the current ceiling in place (_refilter_kept_mirrors), with no server copied in and no grant added. A re-filter that fails holds the memo. _install_sibling_specs and the re-filter live in the new agent_parts/spec_siblings.py, which brings spec_rebuild.py back under 1,600 lines.
|
@bolichen97 CI never started on 49c4b7f, so I pushed 08f2539 to retrigger it. It is the same tree with only the commit date changed ( |
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed at 08f2539. Thank you: CI ran on this head, and every PR-own line is the same as 49c4b7f, which I read before. The unreadable kirocrew.json is kept instead of overwritten, the kept worker and heartbeat specs go through the current ceiling via fork_refresh._apply_governance_passes, no start refusal is added, the shard 6 test points at spec_siblings.py, and there is no new regex.
Gates at this head: 98 checks pass with none red, First Principles and Opus pass, and no other change request is open. This approval replaces my earlier change requests.
Moved from #15546 (fork) to a branch on this repo so CI runs on the CodeBuild fleet, per CONTRIBUTING.md. Earlier review threads and dispositions are on #15546.
Scope narrowed per the security sign-off. @bolichen97's review decided that security strictness is not being increased, so the start refusals this PR used to add cannot land and the data-loss fix can. This head keeps only the data-loss fix. Every new refusal is dropped (listed under Backwards compatibility), and while the file is unreadable a start behaves as it does on main. Refusing starts during an unreadable-spec episode would need its own decision, separate from this fix.
Problem / Motivation
Goal: a rebuild that cannot read an existing
kirocrew.jsonkeeps the user's spec and skips that cycle instead of writing defaults over it._load_existing_configcaught(OSError, ValueError)together, so a valid spec whose read failed (EACCES,EIO, a Windows sharing violation) was treated as missing and rewritten with defaults, erasing its MCP servers, approvals, model pin and prompt.Why it matters
Silent, permanent loss of the user's agent config: 1 in 39 rebuilds in #15515's harness.
Not a goal
What changed (motivation → approach → change)
read_bytes_with_retry. OnlyFileNotFoundErrormeans absent, and invalid UTF-8 or JSON still rebuilds from defaults. Any otherOSErrorraises_AgentSpecUnreadable, from the load (_read_existing_spec) or from the alias reconcile inside the write lock (mcp_aliases._durable_tool_aliasesreports such a file as present, never as missing)._skip_unreadable_main_specthen keepskirocrew.jsonand the heartbeat and worker specs mirrored from it, and still runs the steps that write other files (_install_sibling_specs: service and conductor specs, fork refresh, hook repair)._conductor_spec_held, plus an open episode read through_spec_hold_open), so the ceiling memo stays pending, the boot baseline stays unseeded and the hourly maintenance wake rebuilds once the file reads again. The retry's warning names the kept file and never suggests--clean.wrote=False.kirocrew setupprints "Agent config left unchanged" instead of "Agent installed", and_shared_config_followups.pyandconfig_watch.pyname the unreadable spec as a cause of a rebuild that did not write.kirocrew setup --cleanstays the explicit reset that writes over an unreadable file.New owner
agent_parts/spec_unreadable.pyholds the skip and the episode's bookkeeping, composed onto theagent.pyfacade.rebuild_agent_config's sibling installs move into_install_sibling_specsso the skip can run them without the mirrors.Backwards compatibility
No new refusal.
require_fork_governanceand the wholeacp/package are identical to main; while the file is unreadable a start is decided exactly as on main. Dropped from the earlier head, with their tests:require_main_spec_projectedinsiderequire_fork_governancerequire_main_spec_launch_boundand every caller: direct-client spawn and the_send_requestchecks forsession/new,session/load,session/resumeandset_mode, shared-runtime spawn,_require_launch_bound_for_session_open(create, load, the entitlement probe), the KAS by-name read and the pre-send payload checkset_modechecks inruntime_mode_activation.pyandcheck_mode_frame, including the "kept changing" refusalmain_spec_refusedpath and itsValueErrorValueErrorforsession/newandsession/loadon the genericruntime_wiresend pathsBehaviour change: a present
kirocrew.jsonwhose read fails is no longer overwritten with defaults, and that rebuild reports no write. A missing or invalid spec still rebuilds from defaults. No error code or SEL event changes.Writer sweep on 90ae232:
_load_existing_config←rebuild_agent_config(skips);_durable_tool_aliases←default_spec_commit.write_default_specand_reconcile_tool_aliases_from_disk(both raise on an unreadable spec, unless--clean);rebuild_agent_config_reporting←retry_held_conductor_specs,_reproject_holding_the_lock,rebuild_agent_spec,config_watch(say left unchanged),endpoint_migrationand the template-server request handler (already report not rewritten; MCP apply: #18679).Tests
test_agent_unreadable_main_spec.py: the spec and its mirrors kept byte for byte (eacces,eio) while the sibling steps still run; a sharing violation retried before it counts; no migration over other specs on a skipped cycle; the next readable rebuild writes the user's fields; the sibling pass once per governance generation; the alias reader and the write-lock path;--cleanand invalid UTF-8 still reset; warnings once per episode; overlapping rebuilds never close a newer episode or drop its hold._read_existing_specreturningNoneand_durable_tool_aliasesreturning(False, None)on anOSError), writes defaults over it andtest_unreadable_existing_spec_is_kept_and_the_cycle_skippedgoes red. Checked by running that mutation.test_an_open_episode_changes_no_start_decision:require_fork_governancegives the main agent, its mirrors, another agent and an unknown name the same answer with the episode open as closed, on the same unreadable file. Mutation pin: refusing the main agent during the episode goes red. Checked by running that mutation.test_agent_spec_hold_ratchet.py:_conductor_spec_heldis read only through_spec_hold_openand the template-only probe.test_cli_setup.py,test_conductor_allowed_tools_survive.py,test_agent_refactor_fork_refresh.py,test_agent_parts.py,test_governance_profile_reprojection.py,test_worker_agent.py, integrationtest_boot_smoke.py: the setup wording, the retry warning, the hold on the profile watch and ceiling hook, the facade, and the moved sibling installs.Local: the changed test files, every
test_agent*,test_acp*andtest_native_skill*file, the error-code contract and ws event-scoping suites,test_slack_gateway.pyand the code-review pool tests: 13,394 passed, 1 failed (test_launch_record_resources_match_the_alias_file_kiro_cli_loads, which fails the same way on a clean main on this host). Integrationtest_boot_smoke.pywithKIROCREW_INTEGRATION=1: 17 passed. black, flake8, mypy and Semgrep (semgrep/) clean on the changed files; Semgrep's two hits are existing main lines.Manual verification
N/A beyond the harness.
Pattern harvest
Rule candidate: review-prompt (AUTOSDE
a-failed-read-is-not-a-corrupt-file)Pattern: a reader that falls back to defaults on every read error; it must keep the file on "could not read it" and rebuild only on "read it, damaged".
Related Issues
Closes #15515
Related: #18679, #17792, #17882
Checklist
Contribution License Agreement
Contributed under the project's Apache-2.0 license.