Skip to content

fix(test): credit busy-helper callers in the slot-reader tripwire - #12718

Merged
bolichen97 merged 1 commit into
mainfrom
fix/slot-reader-enumeration-drift
Sep 22, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/slot-reader-enumeration-drift

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

What is the problem?

test/test_pending_boundary_consumer_semantics.py::test_running_and_turn_running_slot_readers_are_enumerated fails on plain main, with no pull request involved. Verified on a clean worktree at origin/main 0a80050938: 1 failed, 8 passed.

The test is a source-scanning tripwire. It walks every .py under src/kiro_crew/dashboard/, uses ast to find every function that reads slot.running or slot.turn_running, builds {(file, symbol): frozenset(predicates)}, and asserts that equals a hardcoded expected map. Its enumeration only saw a predicate named directly inside a function body, with one exception already carved out for _destructive_history_busy.

Two changes that were each green alone produced a red union:

So the enumeration diff on main is exactly four stale entries and one unexpected one:

direction entry predicate
unexpected chat_handlers.py::_switch_target_busy reservation (running)
stale chat_handlers.py::api_chat_slot_agent reservation
stale chat_handlers.py::api_chat_slot_model reservation
stale chat_handlers.py::api_chat_slot_reasoning_effort reservation
stale chat_handlers.py::api_chat_slot_workspace reservation

The publishers assertion in the same test is unaffected and already matches.

Why this issue matters to the user

Every pull request in the repository is blocked. The test runs in shard 4, so Backend Tests (3.12, 4) and Backend Tests (Windows) (4) go red on any head based on current main, whatever the change touches. Confirmed on three unrelated pull requests whose diffs do not go near src/kiro_crew/dashboard/ at all, which is the only tree this test reads, so none of them can alter its enumeration. Pull requests on older bases still show both lanes green.

Nobody can land anything, including the fix for whatever they were actually working on, until this is repaired.

How our fix solves it

Chaining back from the symptom: the red lane is one failing assertion; the assertion fails because actual != expected; actual changed because #11425 moved a guard from four callers into one helper; the enumeration treated that move as four readers disappearing, because it credits a reader only where the attribute is named.

The straightforward repair would be to delete the four handlers from the table and add the helper. That restores green and is wrong in a way that matters: those four handlers still refuse a switch on the basis of reservation state, so dropping them stops the table from recording that dependency. Worse, it removes the tripwire's teeth for the next person, because a new handler wired to _switch_target_busy would name no predicate, add no entry, and trip nothing.

Instead, the helper's callers inherit what the helper reads. The test already did this for _destructive_history_busy; this change turns that one-off carve-out into a small declared map and adds the second helper to it:

_BUSY_HELPERS: dict[str, frozenset[str]] = {
    "_destructive_history_busy": frozenset({"running", "turn_running"}),
    "_switch_target_busy": frozenset({"running"}),
}

The four handlers therefore stay in the table with their reservation declaration intact, and expected gains exactly one line for the helper itself. Net change to the table is one added entry.

frozenset({"running"}) is the correct declaration for _switch_target_busy, not a transcription of what it happens to read. Its own docstring gives the reason: slot.running is set at dispatch, before the multi-second provider.start() registers a session, so a cold-starting first turn dispatched through that slot is visible in the reservation and in neither of the helper's other two signals. A pre-commit refusal on a switch wants the reservation. No reader was found using the wrong predicate, so #11425 is referenced here as the origin of the drift and not as a defect.

No production code changes. No assertion was skipped, xfailed, deleted or loosened; the rglob was not narrowed; no allowlist was added.

What tests we did

test/test_pending_boundary_consumer_semantics.py, run with an explicit -n0, on a clean worktree cut from origin/main 0a80050938:

  • Before, on plain main with no edits: 1 failed, 8 passed. The failure is test_running_and_turn_running_slot_readers_are_enumerated.
  • After, with this change: 9 passed.
  • Gates on the changed file: flake8 clean, isort --check-only clean, black --check unchanged.

Because a fix to a tripwire can quietly disarm it, the tripwire was also confirmed to still trip, by appending a throwaway function to chat_handlers.py and reverting it afterwards:

  • a new function reading slot.turn_running directly: test fails, as it should.
  • a new function whose only reference is a call to _switch_target_busy: test fails, as it should. This is the case a plain table update would have let through silently.

Any other suggestions on the work

This class of failure is worth addressing at its root, because the tripwire cannot see it coming. A table of expected source facts is a semantic merge conflict: two pull requests touch no common line, so git merges them without complaint, each one's CI is green against its own base, and the contradiction appears only in the union. Git's textual conflict detection is the wrong instrument, and adding more tables makes the exposure larger.

Three options, cheapest first:

  1. Re-run required checks against an up-to-date merge ref. The immediate hole is that a pull request can satisfy required checks on a merge commit computed against a stale base. Requiring branches to be current before merge, or re-running the affected shard on the real merge ref at merge time, would have caught this specific pair. Cheap, and catches the whole class, not just tables.
  2. Make the table derivable. Let the test write the observed map to a checked-in fixture under a flag, and assert the fixture matches. The drift then shows up as a conflict in a file both pull requests edit, which git can see, instead of as a passing test on each side.
  3. Move the declaration next to the reader. A small decorator or a structured comment on each reader, with the test asserting only that every reader carries one and that it matches what the function reads. Then a reader and its declaration cannot drift, because they move together. Largest change, and it removes the failure mode rather than detecting it.

Option 1 is worth doing regardless of the other two, since nothing about it is specific to this test.

Pattern harvest

Rule candidate: CI policy, not a code pattern. Re-run required checks against an up-to-date merge ref, or require a branch to be current before merge.

Pattern: a test that asserts a hardcoded table of facts derived from other source files can be satisfied by two pull requests independently and by neither of them together. One side changes the scanned population, the other side writes the table, the two share no line, git reports no conflict, and each side is green against its own base. Merge order decides nothing, so re-running the failing side is not a fix; the contradiction exists only in the union.

The narrower lesson for anyone adding such a test: an enumeration that credits a reader only where it names the attribute makes ordinary refactoring look like deletion. Credit the callers of a guard helper, so extracting a guard does not silently empty the table.

Not reachable by lint: the defect is an agreement between two files with no shared syntax, so there is no single code shape to match on.

@chenmingwei23
chenmingwei23 requested review from a team and smeyffret September 22, 2026 05:37
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 22, 2026
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 28fe81804e0b04b8e59523d552937e218485e508 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 28fe818

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

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Verify shard 4 (Linux and Windows) is green on this PR's merge ref, since the failure it fixes only exists in a union of branches.

Suggestions

  • Add a one-line cross-check that each _BUSY_HELPERS value equals the helper's own enumerated entry in actual, so a helper whose reads change cannot leave its callers credited with a stale predicate set.

[DESIGN-REVIEWED] 28fe818

@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 28fe818

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

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

@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 Sep 22, 2026
The reader enumeration in test_pending_boundary_consumer_semantics only
saw a slot predicate named directly inside a function, so extracting a
guard into a shared helper dropped every caller out of the table. #11425
extracted _switch_target_busy out of the agent, model, reasoning-effort
and workspace switch handlers; #11454 later added the tripwire with the
table describing the pre-#11425 reader set. Each was green alone, so main
holds the union and the test fails there, taking Backend Tests (3.12, 4)
and Backend Tests (Windows) (4) red on every pull request.

Credit a busy-helper's callers with the state the helper reads, rather
than removing the four handlers from the table: they still depend on the
reservation, and a naive table update would also stop the tripwire firing
for the next handler wired to the same helper.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving over #12715/#12716: those two drop the four switch handlers from the enumeration, which weakens the tripwire (a new handler wired through _switch_target_busy would go unenumerated) and breaks the precedent already set for _destructive_history_busy. This PR generalizes that precedent into a table and keeps every caller credited. Test passes locally on current main (9 passed).

amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…rodotdev#12718)

The reader enumeration in test_pending_boundary_consumer_semantics only
saw a slot predicate named directly inside a function, so extracting a
guard into a shared helper dropped every caller out of the table. kirodotdev#11425
extracted _switch_target_busy out of the agent, model, reasoning-effort
and workspace switch handlers; kirodotdev#11454 later added the tripwire with the
table describing the pre-kirodotdev#11425 reader set. Each was green alone, so main
holds the union and the test fails there, taking Backend Tests (3.12, 4)
and Backend Tests (Windows) (4) red on every pull request.

Credit a busy-helper's callers with the state the helper reads, rather
than removing the four handlers from the table: they still depend on the
reservation, and a naive table update would also stop the tripwire firing
for the next handler wired to the same helper.
wknight1 pushed a commit to wknight1/KiroCrew that referenced this pull request Oct 5, 2026
…rodotdev#12718)

The reader enumeration in test_pending_boundary_consumer_semantics only
saw a slot predicate named directly inside a function, so extracting a
guard into a shared helper dropped every caller out of the table. kirodotdev#11425
extracted _switch_target_busy out of the agent, model, reasoning-effort
and workspace switch handlers; kirodotdev#11454 later added the tripwire with the
table describing the pre-kirodotdev#11425 reader set. Each was green alone, so main
holds the union and the test fails there, taking Backend Tests (3.12, 4)
and Backend Tests (Windows) (4) red on every pull request.

Credit a busy-helper's callers with the state the helper reads, rather
than removing the four handlers from the table: they still depend on the
reservation, and a naive table update would also stop the tripwire firing
for the next handler wired to the same helper.
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