Skip to content

fix(test): bind the real sel before the cron tests replace it - #40124

Merged
Zedmor merged 1 commit into
mainfrom
fix/test-cron-auto-pause-sel-leak
Nov 20, 2026
Merged

Zedmor merged 1 commit into
mainfrom
fix/test-cron-auto-pause-sel-leak

Conversation

@Zedmor

@Zedmor Zedmor commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Two cron test files no longer leave a test's stand-in for kiro_crew.sel.sel bound in a module for the rest of the process, so the tests that run after them in the same process pass.

test/test_cron_auto_pause_limit.py and test/test_cron_remove_deletes_history.py replace kiro_crew.sel.sel for a test. CronService.add_job then imports kiro_crew.dashboard.chat_folders_paths for the first time (cron_service/fields.py, resolve_project_path), and that module does from kiro_crew.sel import sel, so it keeps the stand-in after monkeypatch has restored kiro_crew.sel.sel. The next first import of the kiro_crew.dashboard.chat_folders facade in the process checks that its owners agree on every shared name and raises:

RuntimeError: kiro_crew.dashboard.chat_folders: names bound to different objects across the family are ['sel'], but the facade declares []

Every later test in that process that imports the dashboard fails at that import.

Why it matters

Main is green only because an xdist worker has usually imported chat_folders_paths at collection, before any test runs. Run either file with a few neighbours and it fails: a developer running pytest test/test_cron_auto_pause_limit.py test/test_power.py, a leaf-scope CI run that repeats a small set of changed files, or any change to how files are grouped into processes. Draft #39738 hit it on its first full run: 15 tests red in one process (shard 7 of run 44661146070).

Not a goal

  • Changing the chat_folders facade's import-time check or any isolation floor.
  • A general guard against a test's stand-in being bound by a module imported during that test; only the two proven files are changed.
  • The four files that fail when run alone with ImportError: cannot import name '_PHASE_EMOJIS' from 'kiro_crew.slack.handler' (listed under Sibling sweep); that is a different defect.

What changed (motivation → approach → change)

Symptom: tests after these files fail at the chat_folders import. Cause: a module first imported while kiro_crew.sel.sel is replaced binds the replacement by name. Change: both files import kiro_crew.dashboard.chat_folders_paths at module level, before any test patches, so the name it binds is the real accessor. Six lines each, test files only.

Backwards compatibility

Compatible: test files only; nothing that runs in the product changes.

Removes nothing: two imports are added to two test modules.

Tests

Proof: not provable -- test-only change

  • Before, on main 380b086: python -m pytest -n0 --no-cov -q -p no:cacheprovider test/test_cron_auto_pause_limit.py test/test_power.py -> 3 failed, 86 passed (the three test_should_prevent_sleep_* tests, each with the RuntimeError above); ... test/test_cron_remove_deletes_history.py test/test_power.py::test_should_prevent_sleep_no_sessions -> 1 failed, 10 passed.
  • After, on this branch: the same two commands -> 89 passed and 11 passed; the three files together -> 99 passed.
  • test/test_flake_pattern_ratchet.py, test/test_process_cache_floor_ratchet.py, test/test_conftest_import_budget.py -> 79 passed. Black, isort, flake8, comment-history, brand and file-line-cap gates pass.

Manual verification

N/A — the reproduction above is the whole behaviour, and it is a pytest command.

Real-machine verification

Machine: own development host (EC2, AMD EPYC 9R14), Amazon Linux 2023, x86_64, 32 vCPU / 123 GiB
Before (main 380b086): python -m pytest -n0 --no-cov -q -p no:cacheprovider test/test_cron_auto_pause_limit.py test/test_power.py -> 3 failed, 86 passed, RuntimeError: kiro_crew.dashboard.chat_folders: names bound to different objects across the family are ['sel']
After (head 4d08c3d): the same command -> 89 passed
Cleanup: own computer

Related Issues

Related: #39702

Sibling sweep

Swept: grep -rlE 'setattr\([a-zA-Z_.]*sel, "sel"|setattr\("kiro_crew\.sel\.sel"|patch\("kiro_crew\.sel\.sel"|patch\.object\([a-zA-Z_.]*sel, "sel"' test src/kiro_crew/apps/builtins (154 test files replace kiro_crew.sel.sel; 333 modules under src/kiro_crew bind it with from kiro_crew.sel import), then each of the 154 run in its own process followed by test/test_power.py::test_should_prevent_sleep_no_sessions, which imports the dashboard and its facades.
Sibling: test/test_cron_auto_pause_limit.py -- changed here
Sibling: test/test_cron_remove_deletes_history.py -- changed here
Sibling: test/test_cron_origin_injection.py -- not affected -- fails alone on main with a different error (_PHASE_EMOJIS import), no family error
Sibling: test/test_send_message_per_part.py -- not affected -- fails alone on main with the _PHASE_EMOJIS import error, no family error
Sibling: test/test_send_message_session_link.py -- not affected -- fails alone on main with the _PHASE_EMOJIS import error, no family error
Sibling: test/test_send_message_targeted.py -- not affected -- fails alone on main with the _PHASE_EMOJIS import error, no family error

The other 148 files left the dashboard import clean. The sweep proves only what that one canary import catches: a stand-in kept by a module outside the facades it imports would not show.

Pattern harvest

Rule candidate: review-prompt
Pattern: a test replaces a module attribute that other modules bind with from x import name, and the code under test imports such a module for the first time inside the test, so the stand-in outlives the test

Checklist

  • A Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits
  • 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

Contributed under the project's Apache-2.0 license.

AI-assisted, opened by Claude Code

test_cron_auto_pause_limit.py and test_cron_remove_deletes_history.py
replace kiro_crew.sel.sel for a test. CronService.add_job then imports
kiro_crew.dashboard.chat_folders_paths for the first time, and that
module binds sel by name at import, so the test's stand-in stays bound
after the test ends. The next first import of the chat_folders facade
in the same process refuses a family whose owners disagree on sel, and
every later test that needs the dashboard fails at that import.

Under xdist a worker has usually imported the module at collection, so
main is green; either file followed by test_power.py in one process
fails. Both files now import chat_folders_paths before any test
patches.

Related: #39702
@Zedmor
Zedmor requested review from a team and KiroCrewCaptain as code owners November 20, 2026 20:15
@Zedmor
Zedmor requested a review from buluoray November 20, 2026 20:15
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 4d08c3d7a994603974562147fd89085898c64e1b 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

First Principles Review (Opus 5.5) — ⏭️ skipped

Revision 4d08c3d7a994603974562147fd89085898c64e1b 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

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 4d08c3d7a994603974562147fd89085898c64e1b — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Test-only change. It fixes two proven leaks without touching the product, so nothing blocks.

Notes

  • This fixes only two of the files that can cause the problem. Any other test that replaces kiro_crew.sel.sel while a module binding sel loads for the first time would leak the same way. Your own sweep can't see that case outside the chat_folders facades. A follow-up could make the root conftest import the dashboard facades before any test runs, so no test file has to remember to do it.

[DESIGN-REVIEWED] 4d08c3d

Description read

[DESCRIPTION-READ] b59a2326db72f0b405610d3ccd085a0beffcce4417acc013bdf332434b93f0aa

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 — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 4d08c3d

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable 4d08c3d7a994603974562147fd89085898c64e1b false-positive: <reason, 20 to 500 characters>

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 4d08c3d7a994603974562147fd89085898c64e1b and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 4d08c3d

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 4d08c3d7a994603974562147fd89085898c64e1b false-positive: <reason, 20 to 500 characters>

@Zedmor
Zedmor enabled auto-merge (squash) November 20, 2026 20:25
@github-actions github-actions Bot added the readiness: passed Eligible automated validation passed for the current revision label Nov 20, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider estimates a 4% chance that this change introduces a defect, within the 12% limit for approving on its own, but it is held at tier 2: reviewer-finding: Design Review.

Test-only fix. CronService.add_job lazily imports kiro_crew.dashboard.chat_folders_paths (cron_service/fields.py:67), which binds sel by name (chat_folders_paths.py:25). The two test files replace kiro_crew.sel.sel (lines 253/464/626 and the fixture at line 40), so the first import during a test captured the stand-in and broke the chat_folders facade's family check for later tests. Importing chat_folders_paths at module level, before any patch, binds the real accessor. This follows the leak described in testing-conventions.md:753. Product code is untouched and CI is green.

Tier: 2, held for a person: reviewer-finding: Design Review.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit 4d08c3d7a9 · 12 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@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.

Approving. On this head, the review traced the cause through the code: the lazy chat_folders_paths import in resolve_project_path binds sel by name, and the tests' monkeypatch of kiro_crew.sel.sel gets captured by that binding until the chat_folders facade family check refuses it. The review also reran the before and after commands from the body. On base: 3 failed (with test_power.py) and 1 failed (with the power canary). On head: 89, 11 and 99 passed. The change is test-only and adds no clocks, sleeps, ports, env changes or file writes.

Done well: the comment explains the full failure chain, so a reader can see why the unused import must stay.

Optional:

  • Other cron test files patch sel and call add_job in the same way. A follow-up could preload chat_folders_paths once in test/conftest.py, and then the per-file imports would not be needed.
  • Nothing pins the ordering import yet. A teardown that asserts chat_folders_paths.sel is kiro_crew.sel.sel would make a test fail if someone deletes the import.
  • #39738 has the same hunk in test/test_cron_auto_pause_limit.py. It can drop that hunk when it rebases after this PR merges.

@Zedmor
Zedmor merged commit b1a29dd into main Nov 20, 2026
99 of 100 checks passed
@Zedmor
Zedmor deleted the fix/test-cron-auto-pause-sel-leak branch November 20, 2026 21:28
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 20, 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.

2 participants