Skip to content

fix(agents): let an enrolled crewmate reach the crew roster - #15920

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/enroll-invalidates-registry-inrepo
Oct 1, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/enroll-invalidates-registry-inrepo

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Replaces #12831 by @leonlaiyc (reopened in-repo so the fork-only CI gates can run). Original author's commit is carried verbatim; credit preserved via the commit author and Co-Authored-By.

Why no screenshot: This is a cache-invalidation behavior change in the enroll mutation's onSuccess — it adds two invalidateQueries calls. The AgentTemplatesTab markup it touches is byte-identical before and after; a before/after of that tab would be the same pixels. The observable effect is that a different surface (the Crews tab / Crew Members roster) refreshes immediately instead of serving a stale cache entry — a freshness/timing behavior, not a visual delta — and it is proven by the added regression test rather than a static image.

Problem / Motivation

Goal: an enrolled crewmate shows up on the Crews tab and the Crew Members roster right away, instead of being absent from the list the enroll just reported adding it to.

"Enroll as crewmate" on the Custom agents tab (formerly Agent templates) creates a crewmate, says so, and the crewmate is missing from the list it was added to.

The enroll POSTs /api/agents — the same crew registry write the Crews tab's own create makes — but the mutation invalidated only ['agent-templates']. The registry's own readers were left holding the pre-write roster: the Crews tab (this tab's sibling on the same rail, CapabilitiesPage) and the Crew Members roster under the same ['kirocrew-agents'] prefix (api/membersQuery.ts).

Nothing else refreshes them while that cache entry is live. The dashboard's QueryClient sets staleTime: Infinity ("queries never go stale on their own. Freshness is driven exclusively by WebSocket push"), so a remount serves the cached roster, and POST /api/agents pushes no refresh frame (the only push_refresh("agents") is the MCP capability install). Opening Agent Capabilities on Crews, switching here, enrolling and going back is inside that entry's gcTime, so the just-enrolled crewmate is absent.

Why it matters

The action reports success and the roster contradicts it on the next click, on the same page. The user's reasonable reading is that the enroll silently failed, and the obvious recovery — enroll again — hits name_taken from the server for a crewmate the UI is refusing to show. There is no affordance on either tab that forces the refetch; a full reload is the only way out. The window is bounded by React Query's gcTime on ['kirocrew-agents'], so it is a wrong state for exactly as long as the user is likely to still be looking.

Not a goal

  • No change to the backend write, the refresh-frame plumbing, or the staleTime: Infinity policy. This is purely the client naming the keys its own write already invalidates for the Crews-tab create path.
  • No new WebSocket push for POST /api/agents; the fix is bounded to the enroll mutation's onSuccess.

What changed

The enroll now invalidates the registry prefix — which carries the members roster with it — and ['kirocrewConfig'] alongside it, the pairing #12740 established for a member write (the same write lands in config.json, whose masked read ships the agent records):

invalidate()
void queryClient.invalidateQueries({ queryKey: ['kirocrew-agents'] })
void queryClient.invalidateQueries({ queryKey: ['kirocrewConfig'] })

['kirocrew-agents'] is invalidated as a prefix, which is how the members roster (['kirocrew-agents', 'members-roster']) comes along. ['kirocrewConfig'] is the pairing #12740 established for the same backend write.

Tests

Added a regression test that mounts the Crews tab's own ['kirocrew-agents'] query beside the tab under the production staleTime: Infinity (the suite's per-test client uses the library default, where a remount would refetch and hide the bug). It asserts the enrolled crewmate appears on the roster after enroll.

Local run on this branch (rebased onto current main):

  • vitest run src/test/AgentTemplatesTab.test.tsx — 28/28 pass (incl. the new test)
  • tsc --noEmit — clean
  • eslint on the two changed files — clean

Pattern harvest

A client-side write that fans out to more than one read model must invalidate every key that reads it, not just the one the originating tab renders — especially under staleTime: Infinity, where no background refetch will paper over a missed key. The members roster rides the ['kirocrew-agents'] prefix and ['kirocrewConfig'] carries the same records by design, so a crew registry write has to name all three.

Rule candidate: When a React Query mutation writes a resource that several queries read (here a crew registry write read by ['agent-templates'], the ['kirocrew-agents'] prefix, and ['kirocrewConfig']), invalidate every reader's key in onSuccess; under staleTime: Infinity a missed key leaves a stale UI with no self-correcting refetch.

Enrolling a template POSTs /api/agents -- the same crew registry write the
Crews tab's own create makes -- but the mutation invalidated only
['agent-templates']. The registry's own readers were left holding the
pre-write roster: the Crews tab beside this one on the same rail, and the
Crew Members roster that lives under the ['kirocrew-agents'] prefix.

Nothing else refreshes them while that cache entry is live. The dashboard's
QueryClient sets staleTime: Infinity ("queries never go stale on their own.
Freshness is driven exclusively by WebSocket push"), so a remount serves the
cached roster instead of asking again, and POST /api/agents pushes no refresh
frame -- the only push_refresh("agents") in the backend is the MCP capability
install. Opening Agent Capabilities on Crews, switching here, enrolling and
going back is inside that entry's gcTime, so the crewmate this tab has just
reported as enrolled is absent from the list it was added to.

The enroll now invalidates the registry prefix, which carries the members
roster with it, and ['kirocrewConfig'] alongside it -- the pairing #12740
established for a member write, because the same write lands in config.json
and its masked read ships the agent records.

The regression test mounts the Crews tab's own query beside the tab and runs
it under the production staleTime, because the suite's per-test QueryClient
uses the library default, where a remount would refetch and hide this.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@iamwhatever
iamwhatever requested a review from a team October 1, 2026 15:50
@iamwhatever
iamwhatever requested a review from a team as a code owner October 1, 2026 15:50
@iamwhatever
iamwhatever requested a review from bolichen97 October 1, 2026 15:50
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] 2ffd45a

Description read

[DESCRIPTION-READ] 99e0a1d8706f4632dbf8a64866948f6dbf55ad7232c0d644c774e1b735007452

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

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 2ffd45ac6173d19b345bc94f8582aa43e1d830a0 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 2ffd45a

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

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

UX Review (Fable 5) — ✅ PASS

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

UX-Verdict: PASS

Verify in the running app that switching back to the Crews tab shows the enrolled crewmate without a manual reload.

[UX-REVIEWED] 2ffd45a

Description read

[DESCRIPTION-READ] cf57c263818860009e7316d4490907f88aa9d83372d851f9cd6fdaafeb81055b

That sha256 names everything this verdict read: the PR description, plus the 3 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 1, 2026

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 2ffd45ac6173d19b345bc94f8582aa43e1d830a0 — 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: CONCERNS

The PR's own rule — "a crew registry write has to name all three" keys — leaves one counted violator: MeetCrewmatesFlow invalidates the registry prefix but not ['kirocrewConfig'].

Not justified as shipped

  • Item 2 — symptom-level: the harvest sentence "a crew registry write has to name all three" has 4 production writers of POST /api/agents (grep createKirocrewAgent); after this PR, 3 pair both keys and MeetCrewmatesFlow.tsx:429 still invalidates only ['kirocrew-agents'], so a crewmate created there leaves the same stale config snapshot (memory row "unavailable", per KiroCrewAgentsPage.tsx:947-951) until an unrelated refresh frame heals it. Accepted-and-deferred, not a demand on this frozen Goal.
    Clears when: the ['kirocrewConfig'] invalidation lands beside MeetCrewmatesFlow.tsx:429 in any PR, or a maintainer records the deferral.

What this change ships

Inventory (3 items) — 2 justified

Intent: FIX — a crewmate enrolled from the Custom agents tab appears on the Crews tab and Crew Members roster immediately, instead of being absent from the list the enroll reported adding it to.

  1. An enrolled crewmate now shows on the Crews tab and Crew Members roster right away — justified
  2. The enroll also refreshes the cached config snapshot, so the new member's memory-store record reads current — symptom-level: point patch; 1 of 4 writers of the same endpoint still misses this key
  3. New regression test pins the roster refresh under the production never-stale cache — justified

[FIRST-PRINCIPLES-REVIEWED] 2ffd45a

Description read

[DESCRIPTION-READ] d291d02e8b36aa579dd19c1b11331d7369eb2fbf61d3069c13472ba3bc19e7c1

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 1, 2026

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

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

Review details

Two newly added comments assert facts the repository contradicts; nothing blocks the merge.

FINDING — website/src/pages/overview/AgentTemplatesTab.tsx:450 — the stated justification for the added invalidation, (the only push_refresh("agents") is the MCP capability install) (restated at website/src/test/AgentTemplatesTab.test.tsx:684), is false: push_refresh("agents") fires from 18 sites, including handlers/agents.py:1585,1621,1667,1696,1760,1817,3158,3519,3932,5999,6704 and handlers/agent_templates.py:657,981, so the one true premise — api_kirocrew_agents_create (handlers/agents.py:4930) returns {"ok": True, …} with no push on any path — is buried under a claim a reader disproves in one grep → Fix: narrow the parenthetical to the handler, e.g. (`api_kirocrew_agents_create` is one of the agent writes that pushes no `refresh` frame), in both places.

FINDING — website/src/test/AgentTemplatesTab.test.tsx:691 — exactly as KiroCrewAgentsPage.tsx:810-813 spells it points at the crew-card line-clamp-2 description block, not the useQuery({ queryKey: ['kirocrew-agents'] }) at KiroCrewAgentsPage.tsx:932-935, so the only pointer tying CrewsRosterProbe to the production consumer it stands in for leads to unrelated markup → Fix: cite the symbol (KiroCrewAgentsPage's agentsData query) or correct the range to 932-935.

[OPUS-REVIEWED] 2ffd45a

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

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

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 1, 2026
@chenmingwei23
chenmingwei23 merged commit 11df8d8 into main Oct 1, 2026
102 of 104 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/enroll-invalidates-registry-inrepo branch October 1, 2026 17:18
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 1, 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.

3 participants