Repository navigation
fix(agent-discovery): retry a Windows sharing violation on an agent spec read - #29915
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS The retry is pulled out of the loop What this change shipsInventory (5 items) — 5 justifiedIntent: on Windows, keep an agent's configured MCP servers listed while the dashboard rewrites
[FIRST-PRINCIPLES-REVIEWED] b6f0e70 Description read[DESCRIPTION-READ] 971e4a9505cc4e7d4bd6d11e18f28ddfd9f502033543c508fa82934cd7d3c606 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. The fix reuses the existing Windows read-retry loop around the pinned open, so it fixes the cause without changing the Notes
[DESIGN-REVIEWED] b6f0e70 Description read[DESCRIPTION-READ] b22afcb94b2b49018c79ea393f1234fa030aebdd61e4b2b2ad104f550edc660a 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 |
Opus 5.5 Review — ✅ no blocking findingsReviewed Review detailsNo findings. Notes:
[OPUS-REVIEWED] b6f0e70 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
5aa092c to
b6f0e70
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Approving b6f0e70. I read the full diff at this head.
retry_read_sharing_windowis the existing loop fromread_bytes_with_retry, lifted out to take a callable.read_bytes_with_retrynow calls it, so its budget, backoff, Windows-only and off-event-loop rules are unchanged.- The spec reader retries the whole pinned open and read inside
read_once, so the fence check runs again on every attempt instead of reusing a descriptor from before the replace. - A fence refusal is not caught by the new branch:
_SpecReadRefusedsubclassesOSError, notPermissionError, so it is not retried and its ownexcepthandles it first. - Past the budget the per-file contract stays
None, now with one WARNING on Windows only. POSIX keeps the single attempt and the DEBUG line. - Tests cover WinError 32 and 33, a lock for most of the budget, a lock past it (one warning), the event loop keeping one attempt, POSIX, an absent spec, and the strict reader.
No regex, glob or case-blind matching is added. All 97 checks pass.
Problem / Motivation
Goal: On Windows, an agent's configured MCP servers stay listed while the dashboard rewrites
kirocrew.json, instead of briefly reading as "no servers configured".On Windows, a read of
~/.kiro/agents/kirocrew.jsonthat overlaps a replace of that file fails withPermissionError(WinError 32 or 33)._read_agent_specfolded that error intoNonewith a DEBUG line, and_load_agent_configtreatsNoneas absent. For that one read the capabilities view drops the agent's MCP servers, anddiscover_servers_to_synccomparesmcp.jsonagainst an empty set. The reporter measured 1 to 3 misses per 200 reads with a writer looping. POSIX allows the read, so only Windows is hit.Why it matters
A configured server that reads as never configured can't be told apart from a real absence. A sync check in that window can offer to sync servers that are already configured. No log line above DEBUG shows the miss.
Not a goal
None-on-unreadable contract of_read_agent_spec. Callers depend on it (_read_agent_spec's unreadable-spec degradation is logger.debug-silent, hiding whole failure classes #6727)._load_agent_config.rebuild_agent_configis agent: a Windows sharing violation while rebuild_agent_config reads kirocrew.json rebuilds it from defaults and writes that back, erasing user edits #15515).What changed (motivation → approach → change)
The bug: the spec read opened the file once and treated a Windows lock as "not a spec". Now a locked spec is read again after the replace.
atomic_write.pyretry_read_sharing_windowread_bytes_with_retryalready ran, split out so a caller with its own open can reuse it. Same budget (_REPLACE_MAX_ATTEMPTS,_REPLACE_BACKOFF_SECONDS), Windows only, never sleeps on the event loop.read_bytes_with_retrycalls it unchanged.agent_discovery_parts/spec_reads.py_read_spec_bytes_read_agent_specPermissionErrorthat outlasts the budget logs one WARNING naming the spec with%r, then returnsNoneas before. POSIX keeps the DEBUG line.agent_discovery.pyread_agent_spec_strictreads through_read_spec_bytesas well, so it gets the same retry. A contended read off the loop waits at most about 0.45 s. A caller on the event loop still makes one attempt.Known overlapping PR: #10107 (fork, folder-scoped agent picker) rewrites much of
spec_reads.pyand conflicts with main. This change touches about 20 lines there and is independent of it.Backwards compatibility
Compatible: a spec that is missing, oversized, non-UTF-8, linked, hardlinked, sensitive or UNC still returns
Nonewith the same log lines and audit events. Only a Windows sharing violation is retried.Removes nothing: the change adds a retry and one WARNING. No path, key, function or record is removed.
Tests
test/test_agent_spec_read_sharing_violation.pypatchesopen_fenced_for_readto raisePermissionErrorwithwinerror32 or 33, then open the real file:_load_agent_config;Noneand logs exactly one WARNING naming the spec;Nonewith no WARNING;read_agent_spec_strictgets the same retry.Determinism: 5 repeats green, and green with the 8 node ids in reverse order. 651 targeted tests pass at
-n 2(spec readers, facade, atomic write, retry sites, flake ratchet).Proof: PROVEN test/test_agent_spec_read_sharing_violation.py::test_spec_locked_mid_replace_still_lists_its_servers[32], test/test_agent_spec_read_sharing_violation.py::test_spec_locked_mid_replace_still_lists_its_servers[33], test/test_agent_spec_read_sharing_violation.py::test_spec_locked_for_most_of_the_budget_is_still_read, test/test_agent_spec_read_sharing_violation.py::test_spec_locked_past_the_budget_warns_and_reads_as_none (head 5aa092c)
Manual verification
N/A: the defect needs a Windows sharing violation, which the seam test simulates. The
Backend Tests (Windows)lane runs the same tests on Windows.Related Issues
Closes #27905
Sibling sweep
Swept: git grep -n "open_fenced_for_read(" -- src/
Sibling: src/kiro_crew/agent_discovery_parts/spec_reads.py:539 -- not affected -- head probe returns False on failure, so the caller keeps raising
Sibling: src/kiro_crew/agent_discovery_parts/dir_revision.py:65 -- not affected -- an unhashable entry makes the memo re-read the spec through the fixed reader
Sibling: src/kiro_crew/artifacts_disk.py:194 -- not affected -- artifact store files, not an agent spec, different writer
Sibling: src/kiro_crew/knowledge/readers.py:215 -- not affected -- asciidoc include under a jail, no product writer replaces it
Pattern harvest
Rule candidate: review-prompt
Pattern: an
except OSErrorthat returns a sentinel for "absent" also swallows a WindowsPermissionErrorfrom a concurrent replace; retry it or report it apart fromFileNotFoundErrorChecklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)