Skip to content

fix(pod): wait out a brief sharing violation in pod down - #16124

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/pod-down-sharing-violation
Oct 2, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/pod-down-sharing-violation

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: pod down on Windows does not fail just because another process is briefly still reading the pod's task wrapper.

Pod Boot Canary (Windows) failed on #16102, a PR that touches no pod code: pod down returned [WinError 32] The process cannot access the file because it is being used by another process: '...\env\kcboot....KiroCrew.cmd'. HOME and remaining task/run evidence were preserved; this pod is NOT proven zero-residue.

Why it matters

The canary is a required Windows lane, so this reds unrelated PRs at random. For a real operator the same hold makes pod down refuse and leave the pod's HOME behind, although the pod is fully stopped.

Not a goal

  • Any change to how stop proves the pod's processes are gone (Job drain, publisher retirement, receipt) or to its fail-closed answer.
  • Retrying any other error, or any other file.

What changed (motivation → approach → change)

By the time stop deletes the .cmd, the pod's own processes are already drained through the boot-contained Job. What can still hold the wrapper open is a process the backend does not own: the Task Scheduler service finishing with the action file, an indexer or AV scanner. Those holds last milliseconds to seconds, and a bare unlink reads one as a leak.

  • src/kiro_crew/pod/windows.py: _unlink_waiting_out_sharing(path) retries PermissionError with winerror == 32 (ERROR_SHARING_VIOLATION) every 0.1s for up to 10s, then re-raises it unchanged; every other error raises at once. stop deletes the wrapper through it.
  • docs/system-specs/common/platform-compat.md: the paragraph on retrying ERROR_SHARING_VIOLATION for opens gains the delete case and the rule (that one error only, with a deadline).

Backwards compatibility

Compatible: a delete that succeeded before succeeds the same way; one that failed for any reason other than a sharing violation fails the same way and as fast. A sharing violation now waits up to 10s before the same failure.

Tests

test/test_pod_windows_stop_race.py, with an injected clock so nothing waits for real:

  • a wrapper held for three attempts is deleted on the fourth;
  • a hold past the ceiling still raises and leaves the file, at the deadline;
  • a plain access denial is not retried (one attempt, no sleep);
  • stop reaches the wrapper only through the retrying delete.

On Windows: the stop-race, run and liveness pod files plus the 35 tree-scan pin files pass (3042 passed); flake8, mypy and the comment-history gate are clean. The real canary runs on CI.

Manual verification

N/A — unit coverage plus the CI canary; reproducing an outside process's transient hold on demand on a real Task Scheduler host is not practical.

Related Issues

Seen on #16102 (Pod Boot Canary (Windows)).

Pattern harvest

Rule candidate: review-prompt — on Windows, a teardown unlink/rmdir of a file another process may just have used must retry ERROR_SHARING_VIOLATION (only) under a deadline instead of treating the first failure as residue.

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

@bolichen97
bolichen97 requested a review from a team as a code owner October 2, 2026 09:36
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Confirm the required Windows Pod Boot Canary lane is green on this run — it is the only live reproduction of the hold being fixed.

[DESIGN-REVIEWED] 80c1eeb

Description read

[DESCRIPTION-READ] 6beff1b45825443bb84a79b4014447d3850b90c7910f5c5a9d60bec372c82c05

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

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 80c1eeb9668db73c8e607ff7b98b7cf753d64f49 and found no blocking issues.

This comment is updated in place on each push.

Review details

FINDING -- src/kiro_crew/pod/windows.py:162 -- "sleep(interval)" can overshoot the deadline and allow a late unlink to succeed -> Fix: sleep only for the remaining budget and re-check the deadline before retrying.
[GPT-REVIEWED] 80c1eeb

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

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 80c1eeb9668db73c8e607ff7b98b7cf753d64f49 — 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 fix covers one of the two deletes of this wrapper: _rollback_start (windows.py:701) runs the identical schtasks-/Delete-then-unlink on the same just-written .cmd bare.

Not justified as shipped

  • Item 1 — symptom-level: a point patch — grepped task_script_path(cfg, name).unlink: 2 sites on base, 1 fixed. _rollback_start (src/kiro_crew/pod/windows.py:701) deletes the same wrapper right after its own schtasks /Delete, on a file written moments earlier — exactly the just-written-file hold the repo already records (history.py:1541, "a just-written … file can be transiently unopenable while an indexer or AV scanner holds it"); a hold there turns a clean pod up rollback into "startup rollback incomplete". The ## Not a goal carve-out excludes "any other file", not the other call site of this file.
    Subtraction: replace the bare task_script_path(cfg, name).unlink(missing_ok=True) in _rollback_start with the already-shipped _unlink_waiting_out_sharing.
    Clears when: the rollback site routes through _unlink_waiting_out_sharing, or a recorded rebuttal that rollback's delete is not exposed to the hold.

What this change ships

Inventory (4 items) — 3 justified

Intent: pod down on Windows (and the required canary) must not fail because an outside process briefly holds the pod's task wrapper — a FIX.

  1. pod down deletes the task wrapper through a retry that waits out a brief outside hold (≤10s) — symptom-level: the same delete stays bare in startup rollback (windows.py:701)
  2. A wrapper held past the ceiling still fails pod down as before, now up to 10s later — justified
  3. The platform-compat spec gains the delete-retry rule — justified
  4. Tests pin the retry's bounds and that stop deletes only through it — justified

[FIRST-PRINCIPLES-REVIEWED] 80c1eeb

Description read

[DESCRIPTION-READ] 06f9d72e3914f94455f39863ae759a1277c6118938034e86fd56ca944cf65214

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 added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 2, 2026
…e task wrapper

On Windows the pod's .cmd wrapper can still be open in a process the backend does not own (Task Scheduler finishing with the action file, an indexer or AV) right after the pod's own processes are drained, so pod down failed with WinError 32 and reported the pod as not zero-residue. Retry only ERROR_SHARING_VIOLATION under a bounded deadline; any other error, or a hold past the deadline, still fails closed.
@bolichen97
bolichen97 force-pushed the fix/pod-down-sharing-violation branch from 208590a to 80c1eeb Compare October 2, 2026 09:45
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed 80c1eeb9668db73c8e607ff7b98b7cf753d64f49 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 80c1eeb

Verdict parsed from the review's SHA-scoped output markers for commit 80c1eeb9668db73c8e607ff7b98b7cf753d64f49.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 80c1eeb9668db73c8e607ff7b98b7cf753d64f49: <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 2, 2026
@chenmingwei23
chenmingwei23 merged commit 455ba72 into main Oct 2, 2026
97 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/pod-down-sharing-violation branch October 2, 2026 16:06
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 2, 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