Skip to content

fix(agents): keep a default its workspace checkout still declares (release/0.8.0) - #16568

Merged
bolichen97 merged 1 commit into
release/0.8.0from
backport/0.8.0-healer-project-backed-default
Oct 3, 2026
Merged

bolichen97 merged 1 commit into
release/0.8.0from
backport/0.8.0-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)

Backport of #16562 to release/0.8.0, which carries the healer through #16385. It is a clean cherry-pick -x, and its patch-id equals the source's.

  • _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.
  • 252 related files plus test/integration: 17792 passed. The failures are the parallel-run spawn tests in test_acp_runtime.py and test_subagent_shared_scratch.py, which fail the same way on the untouched release tip.
  • The baselined black and subprocess-encoding gates, isort, flake8, mypy (1864 files), comment-history and docs-lint pass. The agent-SDK boundary gate reports only the pre-existing session_agent_selection.py offender.

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

Part of #16555. Backport of #16562; the healer reached release/0.8.0 with #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:22
@bolichen97
bolichen97 requested review from dodgeblaster and removed request for a team October 3, 2026 17:22
@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

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 69aed43257cfb5a1dffae9abd4ddcfb8aeb0b7e7 — 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

Verify the backport claim — that this branch's patch-id equals #16562 as merged on main — since the review environment cannot run git patch-id.

What this change ships

Inventory (4 items) — 4 justified

Intent: FIX — stop the default-agent healer from silently resetting a default that still dispatches via the alias's workspace checkout (#16555, test fails on base).

  1. A default whose alias's workspace checkout still declares the template is no longer reset — justified
  2. An unreadable, torn, or partially scanned workspace checkout declines the reset instead of counting as removal evidence — justified
  3. A sensitive workspace path is never read and declines the reset — justified
  4. A row repointed to a different workspace while the healer waited for the config lock declines the write — justified

Lens-4 check: project_agent_names (agent_discovery.py:929) yields an empty set on unreadable/sensitive checkouts with no completeness flag, which fails toward the reset this fix prevents — meaningfully different, not a duplicate. Lens-6: _removal_evidence grep = 1 consumer (reset_dangling_default_agent); 0 unfixed siblings.

[FIRST-PRINCIPLES-REVIEWED] 69aed43

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Confirm git patch-id --stable equality with source commit b0c503b — the trailer is present but I could not run the comparison.

[DESIGN-REVIEWED] 69aed43

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 69aed43257cfb5a1dffae9abd4ddcfb8aeb0b7e7 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 69aed43

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

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

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

Review details

The in-lock workspace re-derivation reads a different document than the pre-lock one, so the heal can be silently disabled — advisory, nothing blocks.

FINDING — src/kiro_crew/config/loader.py:6472 — _locked_workspace_dir(data, row) != workspace_dir compares a base-document-only answer against workspace_dir, which came from cfg.workspaces (the config.local.json-merged, _migrate_workspaces-normalized table), so on an install whose workspaces entry lives in the overlay (kirocrew config set --local workspaces.proj.dir …, which _dict_set_create accepts unvalidated) or whose base document holds a flat-string/"dir": null/non-dict entry, _locked_workspace_dir returns the base-dir value or None, the comparison never matches, _reset returns None on every call, and a default_agent whose template file is gone is never repaired — every new chat keeps failing "Agent mode … is not available" with only a silent False → Fix: derive the in-lock side from the same shape rule, e.g. _alias_workspace_dir(_migrate_workspaces(raw), …) instead of the strict per-entry walk, and re-compare against a value taken from the same document (or drop the raw re-derivation in favour of re-reading the row's workspace name only).

FINDING — src/kiro_crew/config/loader.py:6449 — workspace_dir = _alias_workspace_dir(cfg.workspaces, row.workspace, cfg.default_workspace) sits outside every try in a function documented "Never raises", and workspace_dir_from_entry ends in Path(dirname).expanduser(), which _migrate_workspaces feeds unchecked (WorkspaceConfig(dir=value.get("dir", "workspace"))), so a workspaces entry with a truthy non-string dir (TypeError) or a ~unknownuser/... dir (RuntimeError) — the two inputs cli_config._refuse_missing_workspace_dirs and onboarding_apply._write_workspace both catch explicitly around this same call — propagates out of reset_dangling_default_agent and refresh_materialized_agents into the owner's GET /api/agents/catalog, whose blanket except Exception turns every fetch into 503 agent_catalog_unavailable and leaves the dangling default unrepaired → Fix: wrap lines 6449-6451 in try: … except Exception: return False, matching the KiroCrewConfig.load() guard directly above, or move the placement call inside _workspace_declares, which already has the catch-all.

[OPUS-REVIEWED] 69aed43

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable 69aed43257cfb5a1dffae9abd4ddcfb8aeb0b7e7: <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

(cherry picked from commit b0c503b)
@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 force-pushed the backport/0.8.0-healer-project-backed-default branch from 6b98c04 to 69aed43 Compare October 3, 2026 17:57
@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 3, 2026
@bolichen97
bolichen97 merged commit e1c2bd3 into release/0.8.0 Oct 3, 2026
24 of 31 checks passed
@bolichen97
bolichen97 deleted the backport/0.8.0-healer-project-backed-default branch October 3, 2026 18:37
@github-actions github-actions Bot removed the readiness: checking Automated validation is still running 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.

1 participant