Skip to content

test: keep the launch capture's default-home pin over its cleared env - #20673

Merged
buluoray merged 1 commit into
mainfrom
fix/admission-test-home-pin-20324
Oct 15, 2026
Merged

buluoray merged 1 commit into
mainfrom
fix/admission-test-home-pin-20324

Conversation

@buluoray

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The ACP launch capture can no longer let another thread resolve the real data home, so test_both_physical_spawn_expressions_obey_admission stops failing at random.

Seen on #18015 (Backend Tests (3.12, 3), gw3): test/test_windows_cleanup_capacity.py::test_both_physical_spawn_expressions_obey_admission[False-client] errors at teardown with this test resolved the operator's REAL default data home (/home/runner/.kiro/crew). It passes locally, alone and with its whole file.

Why it matters

Any PR whose shard happens to schedule this test after one that leaves a thread behind goes red on a check unrelated to its diff. The capture is shared by 17 test files, so every capture test can hit the same failure, and a real home-resolution guard firing for an unrelated reason teaches people to re-run it.

Not a goal

  • Naming or fixing the background thread that landed in the window on CI. The job log holds no stack, and a thread reading the home at call time is legal; the capture's own window is what this PR closes.
  • Changing config_dir(), data_home() or the conftest guard.
  • Exporting KIROCREW_HOME into the capture's fixed parent environment: the delta-from-parent goldens depend on it staying absent.
  • A thread that reads the environment inside the capture and is then descheduled until after the pin lifts. config_dir() reads the variable and the resolver at two moments; that gap is inside production code, much narrower than the window closed here, and left as is.

What changed (motivation → approach → change)

  • Symptom: the conftest teardown check _refuse_a_resolved_real_default_home fires on a capture test, meaning paths._resolved_home held the real ~/.kiro/crew. That global is written only by _resolve_default_home(), i.e. a lookup with no valid KIROCREW_HOME.
  • Root cause: capture() and _capture_runtime_served() in test/acp_launch_capture.py build their patch stack as [patch.dict(os.environ, parent_env, clear=True), <stubs...>, <default-home pin>, <breadcrumb stub>]. Entered in order and exited in reverse, the cleared environment (no KIROCREW_HOME) is live both BEFORE the pin is entered and AFTER it is exited, with the real resolver behind it. During the test the floor pin keeps every other moment safe, so these two edges are the only instants in this test where a lookup can reach the real default; a thread an earlier test on the same worker left running that calls config_dir() there resolves the real home. Under xdist that is ordering-dependent, which matches "passes locally".
  • Change: the two pins move into one helper, _default_home_pins(tmp_path), and both capture paths enter it ahead of the environment patch, so they unwind after it. The resolver is now pinned for every instant KIROCREW_HOME is absent. The stubs themselves, and so every golden answer, are unchanged.
  • Ruled out: test(crew-container): scope the vanish race with monkeypatch.context() #18015 only mentions this issue (it is where the failure was seen); it changes one container test file, not the capture, and does not fix it. test: join the metrics consent worker before a test's home pin lifts #20199 joined the metrics consent worker; it is a different caller and is already merged.

Backwards compatibility

Compatible: test-only change; the same two stubs are applied, only earlier and for longer.

Removes nothing: no stub, key, file or behaviour is dropped; the pins now span a strictly larger interval.

Tests

  • test/test_acp_launch_goldens.py::test_the_default_home_stays_pinned_while_the_capture_environment_is_installed[client|runtime] (new): wraps unittest.mock's dict patcher and, at both edges of the os.environ patch (just after it is installed, just before it is restored), records whether KIROCREW_HOME is absent while paths._resolve_default_home is still the real resolver. It probes rather than calls the resolver, so it never creates a home. Both arms are red on origin/main's acp_launch_capture.py (2 failed) and green with this change (2 passed).
  • Targeted files run with -n0, all green: test_acp_launch_goldens.py (44), test_windows_cleanup_capacity.py (33), test_acp_deepseek_backend.py (154), test_browser_cli_launch.py (44), test_acp_pod_home_remap.py (41).

Manual verification

Traced every _resolve_default_home() call that found the cache empty, and every home lookup made with KIROCREW_HOME absent, across test_windows_cleanup_capacity.py. Locally, every unpinned lookup happens inside the capture on threads the capture owns, and none resolves the real home. The CI flake itself was not reproduced on this host: it needs another test's surviving thread to land in the window, so it is stated here as the mechanism the source allows, not as a reproduced run.

Related Issues

Closes #20324

Pattern harvest

Rule candidate: review-prompt
Pattern: a patch.dict(os.environ, ..., clear=True) that removes a pin variable must be entered after, and exited before, every stub that stands in for that variable; otherwise a concurrent reader sees neither.

Decision for the owner

The decision is whether this flake is fixed by closing the launch capture's own unpinned window, without naming the CI thread that landed in it. This draft closes the window in the shared capture, because it is the only point in this test where a real-home lookup is possible, and it leaves hunting the stray thread to the conftest guard's next stack-recording change.

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

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

…ed environment

The ACP launch capture installs a fixed parent environment with no
KIROCREW_HOME and pins the default data-home resolver so nothing it drives
resolves the operator's real home. The pin was entered AFTER the environment
patch and exited BEFORE it, so at both edges the cleared environment was live
with the real resolver behind it. A thread an earlier test on the same xdist
worker left running reads the home at call time; landing in that window it
resolved the real ~/.kiro/crew, and the conftest teardown check failed
whichever capture test happened to be running.

Enter the two default-home pins ahead of the environment patch in both the
client and the runtime capture, so they unwind after it, and pin the ordering
with a test that probes both edges of the environment patch.

Closes #20324
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 96b76e73d9190b44987626e8af350e2d10d34fee touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ⏭️ skipped

Revision 96b76e73d9190b44987626e8af350e2d10d34fee ships no reviewable capability (docs, tests or generated files only), so there is nothing to inventory. Advisory — does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Verify before merge: the CI flake was never reproduced, so "Closes #20324" stands on an inferred race window. Reopen the issue if the guard fires again.

[DESIGN-REVIEWED] 96b76e7

Description read

[DESCRIPTION-READ] 1b064f961939cd81542efd53eef0dccd4e60e2e564291c9b7adf542fc2855329

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 96b76e73d9190b44987626e8af350e2d10d34fee — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 96b76e7

Verdict parsed from the review's SHA-scoped output markers for commit 96b76e73d9190b44987626e8af350e2d10d34fee.

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

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 96b76e73d9190b44987626e8af350e2d10d34fee and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 96b76e7

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

@buluoray
buluoray marked this pull request as ready for review October 15, 2026 07:24
@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners October 15, 2026 07:24
@buluoray
buluoray enabled auto-merge (squash) October 15, 2026 07:24
@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 15, 2026

@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 (2 files). 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: test-only: moves the default-home and breadcrumb pins in the ACP launch capture so they stay in force while the cleared environment is installed, and adds a test that probes both edges.

@buluoray
buluoray merged commit 294121f into main Oct 15, 2026
103 checks passed
@buluoray
buluoray deleted the fix/admission-test-home-pin-20324 branch October 15, 2026 09:04
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 15, 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.

Flaky: test_both_physical_spawn_expressions_obey_admission resolves the real data home

2 participants