Skip to content

fix: keep the default crew in the startup crewmate prune - #15360

Closed
buluoray wants to merge 1 commit into
mainfrom
fix/crewmate-prune-chatted-or-created
Closed

buluoray wants to merge 1 commit into
mainfrom
fix/crewmate-prune-chatted-or-created

Conversation

@buluoray

@buluoray buluoray commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The startup crewmate prune never deletes the default crew.

The scan skips the default row as the merged config reads it, but the delete's in-lock re-check read neither document's default_agent. A row made the default between the scan and the delete -- kirocrew config set default_agent <name> in config.json, or --local in config.local.json -- was removed.

Why it matters

Deleting the default crew's row leaves the default pointing at a name with no record, so every surface that falls back to the default crew lands on nothing.

Not a goal

  • Changing which generated rows the prune keeps. The keep rule stays RFC crewmates-launch §03 as accepted: a generated row the owner edited (model, avatar, triggers, colour, star, workspace, store), a row bound to a runtime-owned spec, a private copy or an uninstalled spec, and every kirocrew or app-stamped row are kept.
  • Hiding kept-but-unused rows on the Crewmates page. feat: hide unused crewmate rows on the Crewmates page #15363 does that: it lists a row unasked only when its DM thread holds a message, it was created on the dashboard, or it is the default crew.

What changed

  • remove_never_chatted resolves the default from the fresh base document (held under the base lock) and the overlay (read under its sidecar lock) as the loader merges them: the overlay's default_agent key when present, else the base's, falling back to default, else the first row, when that names no row. That row is refused.
  • crew-mode.md states the locked re-check covers both documents' default_agent.

Backwards compatibility

Compatible: the pass refuses one more case and removes nothing it did not remove before. The marker name is unchanged.

Tests

  • TestCandidates::test_a_base_default_selected_under_the_lock_refuses_the_delete and ::test_an_overlay_default_selected_under_the_lock_refuses_the_delete: and ::test_a_fallback_default_under_the_lock_refuses_the_delete: dropping each check fails its test (1 failure each).
  • Disabling the edited-row keep (_is_fresh_sync_shape answering true) fails 34 tests, so the §03 keep rule stays pinned.
  • 95 tests pass in test/test_crewmate_prune_migration.py.

Manual verification

N/A: the pass runs once at startup against config.json, and the unit test drives it against real temp config and overlay files.

Related Issues

Follows #14897 and #15103. Hiding is #15363.

Pattern harvest

Not generalizable: a default-row check missing from one migration's locked re-check.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • 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

Contribution License Agreement

@buluoray
buluoray requested a review from a team as a code owner September 30, 2026 08:31
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Sep 30, 2026
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Verify _default_agent_candidates stays in step with the loader's default resolution — nothing ties the two, and drift re-opens this bug class.

Suggestions

  • Add a parity test driving the loader and _default_agent_candidates over the same base/overlay documents, so a future change to loader.py:4290-4297's fallback fails a test here instead of silently diverging.

[DESIGN-REVIEWED] 4d2206e

Description read

[DESCRIPTION-READ] dd5e2da51f6f41ed2c8b94dd340874892acbe772de865381482f2208e2f477b1

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 Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 4d2206eeee7d9e6acc732aa4a74c5b12bb85295d — 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

Nothing to check.

What this change ships

Inventory (4 items) — 4 justified

Intent: FIX — the startup crewmate prune must never delete the row the loader would select as the default crew, including one made the default between the scan and the delete.

  1. A row made the default in config.json after the scan is refused, not deleted — justified
  2. A row made the default in config.local.json (--local) after the scan is refused — justified
  3. The loader's fallback row (invalid stored default, no default row → first row) is refused — justified
  4. crew-mode.md's locked re-check prose now covers both documents' default_agent — justified

[FIRST-PRINCIPLES-REVIEWED] 4d2206e

Description read

[DESCRIPTION-READ] c28fa1b299be96d80e28c630fa20896990aaa0863d671d6a92e478effba04009

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 Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — 🔴 changes requested (blocking)

GPT 5.6 found at least one blocking issue that must be resolved before merging 4d2206eeee7d9e6acc732aa4a74c5b12bb85295d. 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

This comment is updated in place on each push.

BLOCKING -- src/kiro_crew/crewmate_prune_migration.py:322 -- Invalid agent records distort default resolution
names: list[str] = list(coerce_dict_section(dict(base), "agents"))
Overlay nulls selected row -> loader removes it and falls back to first valid row -> prune deletes that active default row.
Anchor: residual/crash-data-loss-corruption
Fix: Derive names from deep-merged agents and exclude non-dict entries.
[BLOCK-MERGE] 4d2206e
[GPT-REVIEWED] 4d2206e

Adjudication (Opus 5) — is blocking on each finding proportionate?

Harm: UNBOUNDED-class (silent rebinding of the default crew's workspace/memory store plus loss of its config.agents row) — the delete-time guard _default_agent_candidates (crewmate_prune_migration.py:322-332) builds names from the raw base/overlay sections, while the loader drops any non-dict row (config/loader.py:3990-3992) and then falls back to default/next(iter(cfg.agents)) (config/loader.py:4290-4297), so the two disagree exactly when the default_agent-named row is non-dict.
Conditions confirmed: the scan-time filter name in ("default", cfg.default_agent) (crewmate_prune_migration.py:384-385) already protects the loader's answer, so harm needs the row to go non-dict between the scan's load (:940) and the re-check inside the config lock (:751); a non-dict agents.<name> is producible by the product's own writer with no type gate on the overlay path (cli_config.py:271-292, :802-820), and _deep_merge replaces the base row with it (config/resolution.py:305-310); recovery is partial — the spec and transcripts are untouched (module docstring :133-135) and the removal is recorded in the marker (:805-810), but the default-crew re-resolution is persisted silently (config/loader.py:4290-4298) with no warning.
Real fix is small and local: derive names from the merged documents keeping only dict-valued rows, the same filter the loader applies — no new state, no new ordering contract, no mechanism beyond the guard that already exists; the rarity argument fails the FLAG prongs (the input is writable by the shipped CLI, and the timing window is the very window this guard was added to close).

[ADJUDICATION] 4d2206e total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] 4d2206e
[ADJUDICATION-FENCED] 4d2206e fenced=1 flagged=0
UPHOLD-FENCED F1 src/kiro_crew/crewmate_prune_migration.py:322 -- The guard diverges from the loader's own row-validity rule, the triggering non-dict row is writable by the shipped config set --local path rather than being an input no writer can produce, and the fix is a local change to the same expression, so the residual risk is not extreme enough to pre-draft an override.
[GPT-ADJUDICATED-FENCED] 4d2206e

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

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

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

Review details

No findings.

FINDING — src/kiro_crew/crewmate_prune_migration.py:657 — remove_never_chatted's docstring closes its refusal-cause list at "an overlay leaf appeared, or a team lists the name -- is newer evidence and is refused" and the module docstring's "A refused delete is not a commit" bullet (line 116) enumerates the same four causes, while _mutate now has a fifth (if _name in _default_agent_candidates(doc, overlay): return None) that only crew-mode.md records → Fix: add the default-crew re-check to both enumerations, matching the wording added to the spec.

[OPUS-REVIEWED] 4d2206e

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

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

@buluoray
buluoray force-pushed the fix/crewmate-prune-chatted-or-created branch from 636c76a to ceef710 Compare October 1, 2026 03:04
@buluoray

buluoray commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Review dispositions for ceef710213 (rebased onto current main):

GPT 5.6 BLOCKING (crewmate_prune_migration.py:305) and Opus 5 BLOCKING (:306) — fixed. Both are right: a pre-member_id crewmate created on the built-in spec (kirocrew agent create defaults --kiro-agent kirocrew; the dashboard create path does the same) is byte-identical to a sync-written kirocrew row. _is_owners_row now keeps every non-sync source, kirocrew included; CORE_RUNTIME_AGENT_NAMES is gone. New/rewritten tests pin it (test_a_kirocrew_row_bound_to_a_core_runtime_spec_is_kept[*], test_a_kirocrew_stamp_keeps_whatever_it_is_bound_to[*]); reinstating the old branch reddens 7 of them.

Opus 5 FINDING (feature-map:119, "the roster hides those") — fixed. Confirmed matchesSource returns true for the default all filter. Feature map, RFC §03 and crew-mode spec now say an app-stamped row is listed under the package origin and only the opt-in origin filter excludes it.

First Principles BLOCK (RFC §03 amendment ships in this diff) — needs a maintainer. The fix above narrows the reversal (kirocrew rows are kept again, matching base §03), but rows bound to helper specs / private copies / uninstalled specs / edited rows are still newly removed, which base §03 keeps. That is the product decision recorded as "narrowed on 2026-09-29"; it clears by an /ai-review override first-principles <sha>: <decision> from the owner, or by landing the §03 amendment first.

Design CONCERNS (edited rows with triggers / non-default memory_store are removed) — advisory, needs the same owner call. This is the decided narrowing ("a model, a picture, triggers, a colour, a star, a workspace or a store is not a claim"); whether triggers/store should join the keep set is part of that decision, not something to change unilaterally here.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 1, 2026
@buluoray
buluoray force-pushed the fix/crewmate-prune-chatted-or-created branch from ceef710 to cfed64d Compare October 1, 2026 05:35
@buluoray buluoray changed the title fix: prune only unclaimed rows the retired agent sync stamped fix: keep an overlay-selected default crew in the crewmate prune Oct 1, 2026
@buluoray

buluoray commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Review dispositions for cfed64d10f (rebased onto current main). The owner decided: keep owner-edited rows per RFC crewmates-launch §03 as accepted; hiding unused rows belongs to #15363.

First Principles BLOCK (§03 amendment reversed accepted keep rules): fixed. The §03 amendment, the feature-map edit and the widened rule are gone; the keep rule, its docs and its marker are main's. Disabling the edited-row keep (_is_fresh_sync_shape answering true) fails 34 tests.
Design CONCERNS (rows with triggers / non-default memory_store): fixed. Either makes the row a non-fresh shape, so it is kept.

Hiding kept-but-never-chatted rows is #15363's: its roster lists a row unasked only when its DM thread holds a message, it was created on the dashboard, or it is the default crew, so a kept sync row nobody chatted with is hidden there.

@buluoray

buluoray commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Review dispositions for cfed64d10f (rebased onto current main). The owner decided: keep owner-edited rows per RFC crewmates-launch §03 as accepted; hiding unused rows belongs to #15363.

GPT 5.6 F2 (edited sync rows deleted with their workspace): fixed by the same revert: a row whose shape differs from a fresh sync row is not a candidate. GPT 5.6 F1 (overlay default_agent not checked under the lock): fixed. The locked re-check refuses a row the overlay names as default_agent; test_an_overlay_default_selected_under_the_lock_refuses_the_delete fails without it.

Hiding kept-but-never-chatted rows is #15363's: its roster lists a row unasked only when its DM thread holds a message, it was created on the dashboard, or it is the default crew, so a kept sync row nobody chatted with is hidden there.

@buluoray

buluoray commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Review dispositions for cfed64d10f (rebased onto current main). The owner decided: keep owner-edited rows per RFC crewmates-launch §03 as accepted; hiding unused rows belongs to #15363.

Opus 5 BLOCKING (private-fork row deleted, orphaning the fork): fixed. Private copies are excluded from candidates and re-checked under the spec lock, as on main. Opus 5 FINDINGs (RFC launch criterion; docstrings naming kiro_agent): fixed. Both texts were part of the reverted rewrite; main's text is accurate for main's rule.

Hiding kept-but-never-chatted rows is #15363's: its roster lists a row unasked only when its DM thread holds a message, it was created on the dashboard, or it is the default crew, so a kept sync row nobody chatted with is hidden there.

@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 1, 2026
@buluoray
buluoray force-pushed the fix/crewmate-prune-chatted-or-created branch from cfed64d to bfaac01 Compare October 1, 2026 06:50
@buluoray buluoray changed the title fix: keep an overlay-selected default crew in the crewmate prune fix: keep the default crew in the startup crewmate prune Oct 1, 2026
@buluoray

buluoray commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Dispositions for bfaac018d9.

Design CONCERNS and First Principles CONCERNS (base default_agent not re-checked under the lock; description overclaimed): fixed. Both are right: the scan skipped the merged default, but _mutate read neither document's default_agent. The locked re-check now refuses a row the fresh base document names as default_agent (alongside the overlay check). test_a_base_default_selected_under_the_lock_refuses_the_delete fails without it (1 failure); 92 tests pass. The PR description and crew-mode.md now describe both checks.

GPT 5.6 and Opus 5 reported no blocking findings on cfed64d10f.

@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 1, 2026
@buluoray
buluoray force-pushed the fix/crewmate-prune-chatted-or-created branch from bfaac01 to d5617ce Compare October 1, 2026 07:53
@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 1, 2026
@buluoray
buluoray force-pushed the fix/crewmate-prune-chatted-or-created branch from d5617ce to 27f0f64 Compare October 1, 2026 08:05
@buluoray

buluoray commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

GPT 5.6 disposition for 27f0f64398.

BLOCKING (crewmate_prune_migration.py:685, an empty/unknown default makes the loader select a row the literal checks miss): fixed. The locked re-check now refuses every row the loader could select as the default from the two documents read under their locks (_default_agent_candidates): default, either document's default_agent, and, when the merged value is empty or names no row and no default row exists, the first row (the loader's fallback at loader.py:4290-4298). The set is a superset of the loader's choice, so a doubtful ordering keeps rather than deletes. test_a_fallback_default_under_the_lock_refuses_the_delete fails without the fallback branch (1 failure); 93 tests pass. crew-mode.md describes the rule.

@buluoray

buluoray commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

First Principles disposition for 27f0f64398.

CONCERNS (early base-default guard at crewmate_prune_migration.py:706-710 is subsumed by _default_agent_candidates): accepted, not pushed. Correct: the candidate set always holds default and any non-empty base default_agent, and every path between the two checks refuses, so the early guard never decides alone. It is redundant, not wrong; removing it is a no-behaviour-change cleanup. I'm holding it rather than pushing, because a push now restarts every check for an advisory finding. If any real finding forces another push on this PR, the early guard goes in that same commit.

The scan skips the default row as the merged config reads it, but the
delete's in-lock re-check read neither document's default_agent. A name made
the default between the scan and the delete -- `kirocrew config set
default_agent <name>` in config.json, or `--local` in config.local.json --
was removed. The re-check now resolves the default from the two documents read under
their locks exactly as the loader merges them -- the overlay's
default_agent key when it carries one, else the base's, falling back to
`default`, else the first row, when that names no row -- and refuses that
row.

The keep rule is RFC crewmates-launch section 03 as accepted: a generated
row the owner edited (a model, avatar, triggers, colour, star, workspace,
store), a row bound to a runtime-owned spec, a private copy or an
uninstalled spec, and any kirocrew or app-stamped row stay.
@buluoray
buluoray force-pushed the fix/crewmate-prune-chatted-or-created branch from 27f0f64 to 4d2206e Compare October 1, 2026 08:55
@buluoray

buluoray commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Dispositions for 4d2206eeee.

GPT 5.6 BLOCKING (crewmate_prune_migration.py:327, an empty overlay default_agent makes the loader fall back to the first row while the helper used the base value) and Opus 5 FINDING (:325, the base value was kept even when the overlay replaced it, so that row was refused on every boot and the marker never written): fixed. Both are right, and they are the same bug from two sides: the helper unioned both documents' values instead of merging them. _default_agent_candidates now resolves the default as _deep_merge does: the overlay's default_agent key when the overlay carries one (empty or not), else the base's; when that names no row, default if present, else the first row. The early base-default guard is removed (First Principles' CONCERNS), so one spelling decides. Two new tests pin each side: test_an_empty_overlay_default_selects_the_fallback_row fails when a blank overlay value falls through to the base, and test_a_base_default_the_overlay_replaces_is_still_removed fails when the replaced base value is kept. 95 tests pass.

First Principles CONCERNS (duplicate early guard): fixed in the same commit.

@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 1, 2026
@buluoray
buluoray marked this pull request as draft October 1, 2026 16:05
@iamwhatever

Copy link
Copy Markdown
Contributor

Thanks for this, @buluoray! Closing because this draft has had no activity for over two weeks and main has moved on since. You are welcome to reopen it or open a fresh PR whenever you are ready.

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 19, 2026
@bolichen97
bolichen97 deleted the fix/crewmate-prune-chatted-or-created branch November 6, 2026 07:21
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.

2 participants