Repository navigation
fix(agents): harden the default-agent healer and the file-name map - #16455
Conversation
Design Review (Opus 5.5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS Healing is now opt-in, so an owner who disables an app or deletes a template keeps a dangling Watch
Suggestions
[DESIGN-REVIEWED] 61ea746 Description read[DESCRIPTION-READ] e2c82e31bbd3f051b131bdfeac3462023753d360b921bb0601ddf6edf8444cc2 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) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The drop-count warning and its Not justified as shipped
What this change shipsInventory (6 items) — 5 justifiedIntent: stop people other than the owner from rewriting the owner's default agent, stop local files from hijacking edition agents, and bound the state the agents-directory scan keeps for the process. FIX.
[FIRST-PRINCIPLES-REVIEWED] 61ea746 Description read[DESCRIPTION-READ] dfb950f72d4e950e57091a237205c433df628a6692610c585a4bb1f1896676cc That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Review detailsNo findings block the merge; the one advisory finding is below. FINDING — src/kiro_crew/config/loader.py:5615 — Changing the default to [OPUS-REVIEWED] 61ea746 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
…/0.8.0) Backport of #16323, #16410 to release/0.8.0, cherry-picked in main's merge order. * fix(agents): let an installed agent become the default agent (#16323) (cherry picked from commit 5c6268a) Backport adaptation: test/integration/conftest.py conflicted only on context; the source's added reset lines (config_loader import, docstring bullet, the three _MATERIALIZED_* resets and checks) were applied, nothing else. Every other file applied cleanly. * fix(agents): reset a default agent only when its template was removed (#16410) (cherry picked from commit f16fa23) Backport adaptation: test/integration/conftest.py conflicted on context only (a main-only updates-loop entry next to it); only this change's _MATERIALIZED_SEEN lines were applied. Every other file applied cleanly. * Also carries the follow-up proposed on main in #16455 (found by review of this backport): the healer's removal evidence is bounded at 4096 entries, evicting the oldest stale removals first, and a name longer than 256 characters is not recorded; the agent_runtime_policy docstring and its spec row name the key as the dispatched agent.
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: |
3983197 to
496808e
Compare
Follow-ups to #16323 and #16410, found by review of their release/0.8.0 backport. - Heal on request only. refresh_materialized_agents now defaults to heal_default=False, so a refresh reached from someone other than the owner (an app token's turn, a lookup, an app registration) can no longer write the owner's config.json. Only the owner's catalog fetch opts in. A refresh that does not heal still records the removals it sees. - An edition agent cannot be redirected. dispatch_kiro_agent no longer applies the stem map to a name the edition contributes, so a user-level "<edition-agent>.json" that declares another name cannot turn a binding to the edition agent into a dispatch of that other agent. - Bounded retained maps. _MATERIALIZED_SEEN is an insertion-ordered dict used as a set, capped at 4096 entries; each scan moves the still-declared names to the end, so the oldest stale removals are evicted first. _MATERIALIZED_STEMS is bounded the same way where it is built. A name longer than 256 characters is kept in neither. What a bounded write drops is reported in one aggregate warning, written only when the count changes; a landed snapshot records its names and its file-name bindings in one call, so it is counted and reported once. - The agent_runtime_policy docstring and its spec row now name the key as the agent the member runs (its kiro_agent through dispatch_kiro_agent).
496808e to
61ea746
Compare
…/0.8.0) Backport of #16323, #16410, #16455 to release/0.8.0, cherry-picked in main's merge order. * fix(agents): let an installed agent become the default agent (#16323) (cherry picked from commit 5c6268a) Backport adaptation: test/integration/conftest.py conflicted only on context; the source's added reset lines (config_loader import, docstring bullet, the three _MATERIALIZED_* resets and checks) were applied, nothing else. Every other file applied cleanly. * fix(agents): reset a default agent only when its template was removed (#16410) (cherry picked from commit f16fa23) Backport adaptation: test/integration/conftest.py conflicted on context only (a main-only updates-loop entry next to it); only this change's _MATERIALIZED_SEEN lines were applied. Every other file applied cleanly. * fix(agents): harden the default-agent healer and the file-name map (#16455) (cherry picked from commit 4a11ed2)
…/0.8.0) Backport of #16323, #16410, #16455, #16512 to release/0.8.0, cherry-picked in main's merge order. * fix(agents): let an installed agent become the default agent (#16323) (cherry picked from commit 5c6268a) Backport adaptation: test/integration/conftest.py conflicted only on context; the source's added reset lines (config_loader import, docstring bullet, the three _MATERIALIZED_* resets and checks) were applied, nothing else. Every other file applied cleanly. * fix(agents): reset a default agent only when its template was removed (#16410) (cherry picked from commit f16fa23) Backport adaptation: test/integration/conftest.py conflicted on context only (a main-only updates-loop entry next to it); only this change's _MATERIALIZED_SEEN lines were applied. Every other file applied cleanly. * fix(agents): harden the default-agent healer and the file-name map (#16455) (cherry picked from commit 4a11ed2) * fix(agents): heal a default agent only after a scan that read every spec (#16512) (cherry picked from commit 4576a29)
…/0.8.0) (#16385) * fix(catalog): restore companion runtime_policy on member rows (#12686) Co-authored-by: Premshay <28099628+Premshay@users.noreply.github.com> (cherry picked from commit fa1b47d) * fix(agents): let an installed agent become the default agent (release/0.8.0) Backport of #16323, #16410, #16455, #16512 to release/0.8.0, cherry-picked in main's merge order. * fix(agents): let an installed agent become the default agent (#16323) (cherry picked from commit 5c6268a) Backport adaptation: test/integration/conftest.py conflicted only on context; the source's added reset lines (config_loader import, docstring bullet, the three _MATERIALIZED_* resets and checks) were applied, nothing else. Every other file applied cleanly. * fix(agents): reset a default agent only when its template was removed (#16410) (cherry picked from commit f16fa23) Backport adaptation: test/integration/conftest.py conflicted on context only (a main-only updates-loop entry next to it); only this change's _MATERIALIZED_SEEN lines were applied. Every other file applied cleanly. * fix(agents): harden the default-agent healer and the file-name map (#16455) (cherry picked from commit 4a11ed2) * fix(agents): heal a default agent only after a scan that read every spec (#16512) (cherry picked from commit 4576a29) --------- Co-authored-by: Premshay <premshay@gmail.com> Co-authored-by: Premshay <28099628+Premshay@users.noreply.github.com>
Problem / Motivation
Goal: the default-agent healer writes the owner's config only on the owner's own request, a local file cannot redirect a binding to an edition agent, and every map the agents-directory scan keeps for the process is bounded where it is kept.
Review of the release/0.8.0 backport of #16323 and #16410 (#16385) found four defects in code that is already on main:
refresh_materialized_agents(*, heal_default=True)(config/loader.py) healed on every caller that did not opt out. Two such callers can be reached from someone other than the owner:schedule_materialized_agents_refresh(app registration, which a turn for an unresolved app slot can trigger) andside_readonly_spec's refresh. So a non-owner's action could set the owner'sdefault_agenttodefault. The value is fixed and the template had to be gone already, but the write is still the owner's.dispatch_kiro_agentapplies the stem map to any name not declared on disk. An edition-contributed agent is never declared on disk. So a user-levelcaptain.jsondeclaringpilotturned a binding to the edition agentcaptaininto a dispatch ofpilot._MATERIALIZED_STEMSkept every mismatched stem -> declared-name pair from the user-writable directory, with no count or length bound._MATERIALIZED_SEEN(fix(agents): reset a default agent only when its template was removed #16410) only grew: no count bound, no name-length bound, no report of what it drops.The
ProviderRegistry.agent_runtime_policydocstring (platform/interfaces.py) and its spec row also said the key is the member'skiro_agent. Since #16323 the catalog passesdispatch_kiro_agent(kiro_agent).Why it matters
1 lets a non-owner trigger a write to the owner's config. 2 lets a file in a user-writable directory change which agent a binding runs. 3 and 4 are process-lifetime state that a writable directory can grow without limit. The docstring is the companion's contract.
Not a goal
What changed (motivation → approach → change)
refresh_materialized_agentsdefaults toheal_default=False. Only the owner's catalog fetch passesTrue(heal_default=owner, unchanged). A refresh that does not heal still records the removals it sees, so the next owner fetch acts on them.dispatch_kiro_agentreturns a name the edition contributes verbatim. The edition is asked (_edition_agent_names) only when a stem mapping exists, so the common path stays in memory._MATERIALIZED_SEENis an insertion-ordered dict used as a set, written through_remember_seen. Each scan or publish moves the names still declared to the end. Past_MATERIALIZED_SEEN_MAX(4096) the oldest entries are evicted, and those are the removals seen longest ago._scan_materialized_indexbounds the stem map where it is built: the same 4096-entry cap, and no stem or name longer than_MATERIALIZED_SEEN_NAME_MAX_CHARS(256). A name past the length bound is kept in neither map. A binding to it dispatches verbatim, and a default bound to it is never reset._report_droppedwrites one aggregate warning per bounded map per scan or publish, and only when the dropped count changes. A landed snapshot records its declared names and its file-name bindings in a single_remember_seencall, so its eviction is counted, and its warning written, once.agent_runtime_policydocstring andplatform-contextspec row name the key as the dispatched agent.Backwards compatibility
apps.bridges._deregister_agents->schedule_materialized_agents_refresh) and template delete. These paths still record the removal, but the default is repointed only on the owner's next picker open, not inside the removal. The reason is that these refreshes also run from paths that do not establish an owner caller (a turn's re-registration, for one). Until that fetch, the dangling default fails visibly ("Agent mode ... is not available"), as it did before fix(agents): let an installed agent become the default agent #16323.a-bound-bounds-every-field-it-retainsrequires overflow to be counted and reported once per snapshot, and the review on this PR's previous head enforced that.Tests
New in
test/test_config_loader.py::TestDanglingDefaultAgentReset, each proven by mutating the code it guards:test_a_refresh_heals_only_when_its_caller_asksheal_default=Truetest_a_local_file_cannot_redirect_a_binding_to_an_edition_agenttest_the_file_name_map_is_bounded_where_it_is_built_and_reported_oncetest_the_removal_evidence_is_bounded_and_evicts_the_oldest_removals_firsttest_a_name_past_the_length_bound_is_not_kept_as_evidencetest_an_unchanged_oversized_directory_reports_its_evidence_drop_onceThe existing healer tests now opt in with
heal_default=True, which is what they test.Gates:
test_config_loader.py,test_agent_execution_catalog.pyandtest_config_api.py: 717 passed.default_agent, the catalog, dispatch or the snapshot, plustest/integration: 20772 passed. The 2 failures are intest_chat_runner_composition_contract.py, which fails identically on origin/main.Manual verification
N/A. The tests run real refreshes over a real agents directory and a real
config.json.Related Issues
Part of #16409. Follow-up to #16323 and #16410. Found on the backport #16385.
Pattern harvest
Rule candidate: review-prompt
Pattern: a refresh helper that performs an owner-scoped write must default to not writing, with each owner-authorized caller opting in. A name-to-target map built from a user-writable directory must not shadow a namespace it does not own (here, edition agents).
Checklist