Skip to content

fix(agents): keep a default its workspace checkout still declares - #16562

Merged
bolichen97 merged 1 commit into
mainfrom
fix/healer-project-backed-default
Oct 3, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/healer-project-backed-default

Conversation

@bolichen97

@bolichen97 bolichen97 commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: the default-agent healer never resets a default that the alias's workspace checkout still declares.

Repro (#16555), now test_a_default_its_workspace_still_declares_is_not_reset:

  • Setup: alias pkg runs reviewer in workspace proj and is the default. Both ~/.kiro/agents/reviewer.json and proj/.kiro/agents/reviewer.json declare reviewer.
  • The global spec is uninstalled.
  • The owner's next healing refresh (a complete scan) rewrites default_agent to default in config.json. On origin/main the test fails with 'default' == 'pkg'.

Cause: reset_dangling_default_agent (config/loader.py) takes its removal evidence (_MATERIALIZED_SEEN minus the current snapshot) from the user-level agents directory only. kiro-cli resolves --agent against the session's project directory first (config.paths.project_agents_dir), so the default still dispatches in that workspace. The healer cannot see that.

Why it matters

A durable, silent change to the owner's setting, for a default that still works. Nothing puts it back.

Not a goal

  • No change to the evidence set or to dispatch.
  • Project specs in workspaces other than the alias's own are not consulted. The alias binds one workspace, and dispatch uses that one.

What changed (motivation → approach → change)

  • _alias_workspace_dir places the alias's workspace the way dispatch does: the named entry, else default_workspace, through workspace_dir_from_entry. That is the one placement rule, so a relative dir lands under the data home and not the gateway's cwd.
  • _workspace_declares(template, workspace_dir) scans <workspace>/.kiro/agents with the same scan as the snapshot (_scan_materialized_index). That directory, in both spec forms, is the only project location the backend activates; the legacy .agent-spec.json files are not counted. Using the same scan also tells it whether the scan was complete.
  • The reset is declined in each of these cases:
    • the checkout still declares the template;
    • the scan was partial (a spec it could not read or parse);
    • the listing raised;
    • the workspace path is sensitive, in which case it is never read.
  • A workspace with no .kiro/agents declares nothing.
  • Inside the locked config write, _locked_workspace_dir re-derives the row's workspace from the document it holds. The write is declined if that differs from the workspace that was checked.

Backwards compatibility

Compatible. A default whose template is gone from both the user-level directory and its workspace is still reset; the test also covers that step.

Tests

New in test/test_config_loader.py::TestDanglingDefaultAgentReset, each paired with the targeted mutation that fails it:

Test Fails when
test_a_default_its_workspace_still_declares_is_not_reset (also resets once the checkout drops it) the check is removed
test_a_relative_workspace_is_placed_under_the_data_home the path is placed with Path(dir).expanduser()
test_a_workspace_spec_that_cannot_be_read_is_not_evidence_either completeness is ignored
test_a_row_repointed_at_another_workspace_inside_the_locked_write_is_kept the in-lock re-check is removed

Regression proof on this branch: with loader.py reverted to the release/0.8.0 tip, the 4 new tests fail.

Gates:

  • test_config_loader.py, test_agent_execution_catalog.py and test_config_api.py: 723 passed.
  • Every related file plus test/integration: 20786 passed. The 2 failures are the test_chat_runner_composition_contract.py ones that fail identically on origin/main.
  • The baselined black and subprocess-encoding gates, isort, flake8, mypy (2080 files), comment-history, agent-SDK boundary and docs-lint gates all pass.

Manual verification

N/A. The tests drive real refreshes over a real agents directory, a real project checkout and a real config.json.

Related Issues

Fixes #16555. Follow-up to #16410, #16455 and #16512. A release/0.8.0 backport follows, on top of #16385.

Pattern harvest

Rule candidate: review-prompt
Pattern: "X is gone" evidence must come from every place the consumer resolves X. A self-healing write keyed on one directory is wrong when the resolver also searches another.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • 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

@bolichen97
bolichen97 requested a review from a team as a code owner October 3, 2026 17:02
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 3, 2026
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — 🟡 CONCERNS

Design-level review of b0c503bd136163e0e46c9afbead2170abe093511 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

The description describes a different implementation than the one in the diff, so reviewers are checking claims the code doesn't make.

Watch

  • The description is out of date.
    • It says the check uses "agent_discovery.list_agents(agents_dir=..., project_dir=...), so project .kiro/agents and .kiro/*.agent-spec.json count exactly as they do in the picker".
    • The diff calls _scan_materialized_index(project_agents_dir(workspace_dir)) instead. Its own docstring calls that "the only project location the backend activates".
    • Effect: the picker and the healer can now disagree about the same workspace. A spec at .kiro/*.agent-spec.json shows in the picker, but the healer still resets a default pointing at it.
    • The test it cites, test_a_workspace_listing_that_fails_is_not_evidence_either, does not exist. The mutation claim is built on it.
    • The diff adds behaviour the description never mentions: the locked-write workspace re-check (_locked_workspace_dir(data, row) != workspace_dir), the is_sensitive_path refusal, the torn-spec check, and relative-workspace placement.
    • Clears when: you either rewrite ## What changed and ## Tests to match the scan-based design and the tests that exist, without touching the frozen Goal sections, or switch the code to list_agents. Whichever you choose, state whether .kiro/*.agent-spec.json counts as evidence for the healer.

[DESIGN-REVIEWED] b0c503b

Description read

[DESCRIPTION-READ] b1b7b79f231415c94d68c55847cf072b8102b9094866914cfbe6722046f6c101

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 3, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of b0c503bd136163e0e46c9afbead2170abe093511 — 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/CONCERNS are advisory.

First-Principles-Verdict: PASS

The What changed section is out of date: it describes agent_discovery.list_agents and a test named test_a_workspace_listing_that_fails_is_not_evidence_either, but the diff ships _scan_materialized_index and four different tests.

Not justified as shipped

  • Item 2 — undeclared: the description never mentions this check. The diff adds if is_sensitive_path(str(workspace_dir)): return True. It only ever keeps the setting the owner chose.
  • Item 4 — undeclared: the description never mentions the locked-write check _locked_workspace_dir(data, row) != workspace_dir. It follows the race guard the function already has (_dangling_template(...) != template).

What this change ships

Inventory (5 items) — 3 justified

Intent: the owner's default agent stays put while the alias's own workspace still declares its template. This is a FIX (#16555, with a test that fails on base).

  1. The healer keeps a default when <workspace>/.kiro/agents still declares the template — justified
  2. The healer keeps the default, without reading, when the workspace is a sensitive path — undeclared
  3. The healer keeps the default when the project scan is partial, unparseable or raises — justified
  4. The healer keeps the default when the alias's workspace changes while it waits for the config lock — undeclared
  5. A relative workspace dir is resolved under the data home through workspace_dir_from_entry — justified

[FIRST-PRINCIPLES-REVIEWED] b0c503b

Description read

[DESCRIPTION-READ] f7da9ba689f867a187453913dcd06d147e46634b82662877f8dafc81902296cd

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 3, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] b0c503b

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable b0c503bd136163e0e46c9afbead2170abe093511: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] b0c503b

False positive or not applicable? A repository writer can comment:
/ai-review override gpt b0c503bd136163e0e46c9afbead2170abe093511: <one-sentence reason>

The default-agent healer takes its removal evidence from the user-level agents
directory only. kiro-cli resolves --agent against the session's project
directory first, so a global spec uninstalled while the alias's workspace
checkout still declared a same-named spec left the default dispatching there,
yet the healer read it as removed and durably reset default_agent to
"default".

Before resetting, the healer now scans the alias's workspace, placed by
workspace_dir_from_entry (the named entry, else default_workspace, as dispatch
does). The scan covers <workspace>/.kiro/agents, the only project location the
backend activates, and uses the same scan as the snapshot, so it knows whether
it was complete. The healer declines when that checkout still declares the
template, when the scan was partial, when the listing fails, and when the
workspace path is sensitive (never read). The locked config write re-derives
the row's workspace from the document it holds and declines if it changed.

Fixes #16555
@bolichen97
bolichen97 force-pushed the fix/healer-project-backed-default branch from 0e37389 to b0c503b Compare October 3, 2026 17:48
@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 3, 2026
@bolichen97
bolichen97 merged commit f027885 into main Oct 3, 2026
148 of 152 checks passed
@bolichen97
bolichen97 deleted the fix/healer-project-backed-default branch October 3, 2026 18:37
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

default-agent healer resets a project-backed default when a same-named global spec is removed

1 participant