Repository navigation
fix(agents): heal a default agent only after a scan that read every spec - #16512
Conversation
Design Review (Opus 5.5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS One spec that never parses, such as a stray backup or a half-written Watch
[DESIGN-REVIEWED] b126725 Description read[DESCRIPTION-READ] 0196fa83b37fd3f4460b43a49b620eeaa9025751f4684ae0ac07f201d7028e8d 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 Not justified as shipped
What this change shipsInventory (5 items) — 4 justifiedIntent: stop a passing read failure of the default's spec from permanently resetting the owner's
[FIRST-PRINCIPLES-REVIEWED] b126725 Description read[DESCRIPTION-READ] 4ce444edde7b766875e583781c3a4ef417e8d44ba61c4ac8fedd096dc9f9b8ba That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Review detailsOne advisory finding; nothing blocks the merge. FINDING — src/kiro_crew/config/loader.py:5585 — a plain markdown file with no [OPUS-REVIEWED] b126725 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
3194275 to
087cd29
Compare
The agents-directory scan skips a spec it cannot read or parse, so a spec caught mid-write or briefly unreadable during the owner's catalog fetch left its agent out of that snapshot while the file was still on disk. The healer took that absence as a removal and durably reset default_agent to "default". The scan now records, in thread-local state beside its unchanged (names, stems) return, whether it read every candidate, and the refresh publishes that flag with the snapshot it installs, under the same lock. The healer reads the installed snapshot, its removals and its completeness in one lock hold, and re-reads them inside the locked config write, so a partial snapshot another refresh installed in between is never taken as evidence that an agent was removed. A real removal still resets on the next complete scan. Part of #16409
087cd29 to
b126725
Compare
…/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 never resets the owner's
default_agentbecause of a scan that could not read every spec._scan_materialized_index(config/loader.py) skips a spec it cannot read or parse: theexcept (ValueError, OSError): continue. If the owner's catalog fetch lands while the default's spec is mid-write, briefly unreadable (EACCES, EMFILE) or hand-edited into invalid JSON, that agent is missing from the snapshot even though its file is still on disk. The healer (#16410, #16455) compares the snapshot against what it has seen and treats the missing name as a removal. It then durably resetsdefault_agenttodefault, and nothing points it back once the file reads again. Found by review of the release/0.8.0 backport (#16385).Why it matters
A transient read failure becomes a lasting change to the owner's settings.
Not a goal
(names, stems)return, or to dispatch during a partial scan.What changed (motivation → approach → change)
_SCAN_STATE.complete. A failed directory listing or a skipped spec sets it to false. The(names, stems)return contract is unchanged, because the scan has other callers and tests that stub it with 2-tuples.refresh_materialized_agentsreads the flag on the thread that ran the scan. It publishes the flag as_MATERIALIZED_COMPLETEtogether with the snapshot it installs, under_MATERIALIZED_AGENTS_LOCK, and heals only whenheal_defaultis set and its own scan was complete.reset_dangling_default_agenttakes the installed snapshot, its removals and its completeness in one lock hold (_removal_evidence). It declines when the installed snapshot is partial. It reads all three again inside the locked config write, so a partial snapshot that another refresh installed in between stops the reset. This covers the overlap where a complete refresh's healer would otherwise read a later partial refresh's snapshot._MATERIALIZED_COMPLETEbetween boots and checks it in its residue witness.Backwards compatibility
Compatible. A real removal resets the default on the next complete scan, exactly as before.
Tests
test/test_config_loader.py::TestDanglingDefaultAgentReset::test_a_scan_that_could_not_read_every_spec_is_not_evidence_of_a_removal. The default's spec is torn: the owner's refresh skips it and does not reset. The spec is repaired, and still nothing changes. The spec is deleted, and the default resets. On origin/main it fails ('default' == 'pkg').test_a_partial_snapshot_installed_after_a_complete_scan_is_not_evidenceandtest_a_partial_snapshot_installed_inside_the_locked_write_stops_it(the overlap case, with the partial refresh landing inside the locked write).scan_completegate fails the torn-spec test, and so does removing the flag set in the scan'sexcept._MATERIALIZED_COMPLETE = Trueunconditionally fails both overlap tests.test_config_loader.py,test_agent_execution_catalog.pyandtest_config_api.py: 720 passed. The wider set, every file referencing the refresh, the healer, dispatch or the snapshot plustest/integration, gives 20775 passed. Its 2 failures are thetest_chat_runner_composition_contract.pyones that fail identically on origin/main.Manual verification
N/A: the test drives a real refresh over a real agents directory and
config.json.Related Issues
Part of #16409. Follow-up to #16410 and #16455. Found on the backport #16385.
Pattern harvest
Rule candidate: review-prompt
Pattern: a durable write that acts on "X is absent from this scan" must first establish that the scan was complete. A read that skips failures silently has to report that it skipped.
Checklist