Skip to content

test(dashboard): isolate the eager-spawn semaphore in the default-model tests - #22815

Merged
KiroCrewCaptain merged 1 commit into
kirodotdev:mainfrom
rnoack1:fix/eager-spawn-sem-test-isolation
Nov 4, 2026
Merged

KiroCrewCaptain merged 1 commit into
kirodotdev:mainfrom
rnoack1:fix/eager-spawn-sem-test-isolation

Conversation

@rnoack1

@rnoack1 rnoack1 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Stop TestEagerSpawnDefaultModel from failing for reasons that have nothing to do with the model it is asserting on.

_eager_spawn stands down when the module-global _eager_spawn_sem is already held:

if _eager_spawn_sem.locked():
    logger.info("Eager spawn: concurrency cap reached, skipping slot %s", slot.key)
    return

src/kiro_crew/dashboard/chat_turn/eager_spawn.py:558, reached from the real _eager_spawn the test calls directly.

TestEagerSpawnDefaultModel isolates the debounce but not the semaphore, so it only passes while no sibling pre-warm holds a permit in the same xdist worker. When one does, _eager_spawn returns having registered no session and the test fails at test/test_chat_send_agent_model_default.py:156 with AttributeError: 'NoneType' object has no attribute 'kwargs' — a failure that names nothing about the real cause.

test/test_chat_runner_composition_contract.py:551 already lists _eager_spawn_sem under _RUNNER_STATE, whose comment says the single shared binding "holds only while no owner keeps a copy". This test keeps no copy.

Why it matters

An intermittent failure whose message points at a None return rather than at a held semaphore costs an investigation every time it fires, and the obvious readings are both wrong: it looks like a defect in the model-default path, or like an ordinary flake. It took measuring the semaphore directly to attribute it. Left alone, each recurrence pays that cost again, and a test that fails for an unrelated reason erodes trust in a red run.

Not a goal

  • Changing _eager_spawn's concurrency behaviour. The locked() stand-down is deliberate and stays exactly as it is.
  • Auditing every other test that drives _eager_spawn for the same gap. This PR fixes the one class whose dependence was measured.
  • Any production code change. The diff is one line in one test file.

What changed (motivation → approach → change)

Observed symptom: test_eager_session_starts_on_the_global_default fails with AttributeError: 'NoneType' object has no attribute 'kwargs' when a sibling pre-warm holds the eager-spawn permit.

Root cause: the class's _no_debounce autouse fixture replaces _EAGER_SPAWN_DEBOUNCE_SECS but leaves _eager_spawn_sem shared, so the assertion depends on worker-wide state the test does not own.

Change: the same fixture now also installs a fresh semaphore, copying the idiom already used at test/test_session_capabilities.py:223:

monkeypatch.setattr(chat_runner, "_eager_spawn_sem", asyncio.Semaphore(1))

Patched on chat_runner rather than on eager_spawn, because that is where the name actually resolves. eager_spawn.py imports it only under TYPE_CHECKING; at runtime chat_runner._eager_spawn.__globals__ is chat_runner's module dict, and eager_spawn carries no _eager_spawn_sem attribute at all. Verified by probing both module objects. asyncio was already imported in the file.

Backwards compatibility

Compatible: the change is confined to one test class's own fixture and rejects, renames and removes nothing.

Removes nothing: the diff adds a single monkeypatch.setattr line and deletes nothing, so no caller or reader loses a path.

Tests

No new test. The change makes an existing assertion mean what it says, so the evidence is a control rather than a new case.

A negative control was loaded as a throwaway pytest plugin that installs asyncio.Semaphore(0) on chat_runner (so locked() is True), standing in for a sibling pre-warm holding the only permit:

run before this change after
no control (today's CI shape) 1 passed 1 passed
sibling holds the permit 1 failed 1 passed

The control is not in the diff. Without it the test passes either way, which is exactly why the gap survived.

Suites run in parallel on this branch, with the repo's default xdist settings: test_chat_send_agent_model_default.py, test_chat_runner_composition_contract.py, test_session_capabilities.py, test_eager_spawn.py — 323 passed.

Blocking gates: mypy src/kiro_crew/ → Success: no issues found in 3445 source files; black, isort, flake8 all clean.

Manual verification

N/A — the control above exercises the only behaviour that changed, and it fails for the intended reason before the fix.

Related Issues

None. Found while driving #12702, which a maintainer has since closed as no longer applicable; this fix is independent of that PR's design and is raised on its own.

Pattern harvest

Rule candidate: review-prompt

Pattern: a test monkeypatching one module-global of a group leaves its siblings shared, so the assertion silently depends on worker-wide state. _RUNNER_STATE in test_chat_runner_composition_contract.py already enumerates that group, which makes the gap checkable: a test that patches any member and drives a function reading another is suspect.

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

…el tests

_eager_spawn returns early when the module-global _eager_spawn_sem is already
held, so this class silently depended on no sibling pre-warm being in flight in
the same xdist worker.
@github-actions github-actions Bot added readiness: checking Automated validation is still running fork Pull request from a fork (external contributor) labels Oct 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ⏭️ skipped

Revision 79386fc454f88a235c8f73956db8837722bebc00 ships no reviewable capability (docs, tests or generated files only), so there is nothing to inventory. Does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 79386fc454f88a235c8f73956db8837722bebc00 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 79386fc454f88a235c8f73956db8837722bebc00 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: it is a test-only change that gives the class its own copy of shared worker state, using the idiom test_session_capabilities.py already uses.

[DESIGN-REVIEWED] 79386fc

Description read

[DESCRIPTION-READ] 9bd9c9798aae123d9a5f04a1c121381f081f2d677997e36fd33b3e4390a5ffe2

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 79386fc454f88a235c8f73956db8837722bebc00 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 79386fc

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 79386fc454f88a235c8f73956db8837722bebc00 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 79386fc

@rnoack1
rnoack1 marked this pull request as ready for review November 4, 2026 13:34
@rnoack1
rnoack1 requested review from a team and KiroCrewCaptain as code owners November 4, 2026 13:34
@rnoack1
rnoack1 requested a review from buluoray November 4, 2026 13:34
@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 Nov 4, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 4, 2026 14:06

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Tier 1 auto-approve: test (1 file). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: gives the eager-spawn default-model test class its own semaphore, so those tests no longer share that state with other tests.

@KiroCrewCaptain
KiroCrewCaptain merged commit c9c076f into kirodotdev:main Nov 4, 2026
104 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 4, 2026
@rnoack1
rnoack1 deleted the fix/eager-spawn-sem-test-isolation branch November 9, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants