Repository navigation
fix(frontend): let both static/dist readers see the link this module creates - #9062
Conversation
GPT 5.6 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 4.8 Review (fork) — ✅ no blocking findingsReviewed |
Design Review (Fable 5, fork) — ✅ PASSDesign-level review of All three changed sites route through the repo's pre-existing canonical helper pair ( Design-Verdict: PASS Root-cause fix routed through the repo's existing canonical junction helpers, exactly where platform-compat convention says it belongs, with red-before evidence on Windows. [DESIGN-REVIEWED] 30a6bd0 |
First Principles Review (Fable 5, fork) — ✅ PASSPremise-level review of All three fixed sites verified against base ( First-Principles-Verdict: PASS Verify the Windows-only red-before claims on a real Windows shard — every measurement backing this fix comes from a platform this repo's Linux CI review cannot reproduce. What this change shipsInventory (4 items) — 4 justifiedIntent: make
[FIRST-PRINCIPLES-REVIEWED] 30a6bd0 |
|
CI attribution for Both failing children ( The run checked out
Already repaired upstream. This branch touches Not rerunning and not rebasing: the next run against current |
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]: This PR has been inactive for 7+ days with failing CI. I've assessed the blockers and they appear resolvable — I'll push fixes directly to this branch as a co-author. Assessment: The only CI red ( If you'd prefer I don't touch this PR, add the |
…reates frontend._ensure_tree_dist publishes static/dist through platform_compat.symlink_or_junction, which falls back to a directory JUNCTION on unelevated Windows. Three readers of that path decide what occupies it with is_symlink(), which reports False for a junction: - pod.provision.build_dist: a dangling junction answers False to is_symlink(), is_file() AND is_dir(), falls through every removal branch, and the copytree crashes with FileExistsError [WinError 183]. - frontend._discard_path: a live junction reaches the rmtree branch, whose refusal ignore_errors=True swallows, so .dist.previous.* entries are never reclaimed; a dangling one falls through every branch. - frontend._stage_dist_locked: a dangling junction answers False to both is_symlink() and exists(), so the move-aside is skipped and the os.replace publish lands on the surviving entry — the same "Could not stage static/dist" failure class. All three now route through the canonical platform_compat.is_link_or_junction / unlink_link_or_junction pair, link-first so a dangling entry is still handled, rmdir for a junction so nothing behind the link is deleted. Tests create links with the product's own symlink_or_junction helper so each platform exercises the shape it actually produces: three positive cases (live link detached without touching its target, dangling link removed, dangling static/dist moved aside and the fresh bundle staged) plus negative controls pinning that real trees and plain files keep their existing handling. Original fix by Leon (leonlaiyc); _stage_dist sibling fix and rebase by Kiro Crew. Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
261837a to
30a6bd0
Compare
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca] Drive-to-green changes on this push ( 1. Rebased onto current 2. Extended the fix to the third reader ( 3. One pinning test, 4. One comment reword in 5. Squashed to one commit, Leon preserved as author, Local gates on this head: targeted files 519 passed / 1 skipped; isort, flake8, mypy, black-formatting, subprocess-encoding, comment-history, brand-name, and the other structural gates all exit 0. The scoped backend run's 160 unrelated failures reproduce byte-identical on pristine Disposition records for the Design / First Principles Watch and Suggestion items follow once the lanes stamp this head. |
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca] Closing the loop on the advisory items both whole-design lanes raised on the previous head (
|
iamwhatever
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (4 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, SAST annotations clean, security checklist all-NO, AI reviewers green. Category: is_symlink()/is_file() missed a Windows directory junction, so static/dist link removal fell through every branch and left the entry on disk -- replaced with platform_compat.is_link_or_junction/unlink_link_or_junction in frontend._discard_path, frontend._stage_dist_locked and pod.provision.build_dist, plus four regression tests. CodeQL is not applicable on this fork PR (default-setup emits no check-run); SAST coverage is Semgrep only, latest run success with 0 annotations.
Audit of the is_symlink()-based link guards that PR #9062's First Principles Review lane deferred (issue #10737). A directory junction -- the shape platform_compat.symlink_or_junction and any unelevated Windows writer produce -- answers False to is_symlink(), and when dangling also to exists()/is_file()/is_dir(), so each of these guards was blind to exactly the link that can occur on Windows. Converted (junction-aware oracle, one pinning test per site built with the product's own link helper plus a simulated-junction test so POSIX shards pin it too): - seed.py dangling-$KIROCREW_HOME guard: now pinned_fs.is_reparse_point, the oracle the sibling guardrails in the same function already use. A dangling junction fell through every exists()-gated guard into the raw copytree FileExistsError the guard exists to prevent. - deploy/__init__.py link migration: is_link_or_junction / unlink_link_or_junction. <home>/skills/<name> is also published by apps/bridges.py through symlink_or_junction, so a live junction reached the exists() branch where rmtree_force refused it and gateway startup aborted; a dangling one crashed copytree. - pod/runtime.py orphan_homes, cleanup_home (pre- and post-check), _rmtree_bounded, write_pod_config: is_link_or_junction. On unelevated Windows a junction is the only link a same-user writer can plant under pod_root, so the planted alias was listed as an orphan, resolved to its live sibling, passed containment, and its refusal was reported as "something is still writing there" after the full retry window. Annotated, not converted: stop_pod's systemd drop-in check is Linux-only. Semgrep rule proposed in #9062 (symlink_or_junction writer + is_symlink reader in one module): evaluated and declined -- the writer and reader live in different modules at every site in this audit (bridges.py vs deploy, frontend.py vs pod/provision.py, or no product writer at all), so the rule would have matched none of them, while a module-agnostic is_symlink() rule would need a 166-site allowlist. Closes #10737
Audit of the is_symlink()-based link guards that PR #9062's First Principles Review lane deferred (issue #10737). A directory junction -- the shape platform_compat.symlink_or_junction and any unelevated Windows writer produce -- answers False to is_symlink(), and when dangling also to exists()/is_file()/is_dir(), so each of these guards was blind to exactly the link that can occur on Windows. Converted (junction-aware oracle, one pinning test per site built with the product's own link helper plus a simulated-junction test so POSIX shards pin it too): - seed.py dangling-$KIROCREW_HOME guard: now pinned_fs.is_reparse_point, the oracle the sibling guardrails in the same function already use. A dangling junction fell through every exists()-gated guard into the raw copytree FileExistsError the guard exists to prevent. - deploy/__init__.py link migration: is_link_or_junction / unlink_link_or_junction. <home>/skills/<name> is also published by apps/bridges.py through symlink_or_junction, so a live junction reached the exists() branch where rmtree_force refused it and gateway startup aborted; a dangling one crashed copytree. - pod/runtime.py orphan_homes, cleanup_home (pre- and post-check), _rmtree_bounded, write_pod_config: is_link_or_junction. On unelevated Windows a junction is the only link a same-user writer can plant under pod_root, so the planted alias was listed as an orphan, resolved to its live sibling, passed containment, and its refusal was reported as "something is still writing there" after the full retry window. Annotated, not converted: stop_pod's systemd drop-in check is Linux-only. Semgrep rule proposed in #9062 (symlink_or_junction writer + is_symlink reader in one module): evaluated and declined -- the writer and reader live in different modules at every site in this audit (bridges.py vs deploy, frontend.py vs pod/provision.py, or no product writer at all), so the rule would have matched none of them, while a module-agnostic is_symlink() rule would need a 166-site allowlist. Closes #10737
…1136) Audit of the is_symlink()-based link guards that PR #9062's First Principles Review lane deferred (issue #10737). A directory junction -- the shape platform_compat.symlink_or_junction and any unelevated Windows writer produce -- answers False to is_symlink(), and when dangling also to exists()/is_file()/is_dir(), so each of these guards was blind to exactly the link that can occur on Windows. Converted (junction-aware oracle, one pinning test per site built with the product's own link helper plus a simulated-junction test so POSIX shards pin it too): - seed.py dangling-$KIROCREW_HOME guard: now pinned_fs.is_reparse_point, the oracle the sibling guardrails in the same function already use. A dangling junction fell through every exists()-gated guard into the raw copytree FileExistsError the guard exists to prevent. - deploy/__init__.py link migration: is_link_or_junction / unlink_link_or_junction. <home>/skills/<name> is also published by apps/bridges.py through symlink_or_junction, so a live junction reached the exists() branch where rmtree_force refused it and gateway startup aborted; a dangling one crashed copytree. - pod/runtime.py orphan_homes, cleanup_home (pre- and post-check), _rmtree_bounded, write_pod_config: is_link_or_junction. On unelevated Windows a junction is the only link a same-user writer can plant under pod_root, so the planted alias was listed as an orphan, resolved to its live sibling, passed containment, and its refusal was reported as "something is still writing there" after the full retry window. Annotated, not converted: stop_pod's systemd drop-in check is Linux-only. Semgrep rule proposed in #9062 (symlink_or_junction writer + is_symlink reader in one module): evaluated and declined -- the writer and reader live in different modules at every site in this audit (bridges.py vs deploy, frontend.py vs pod/provision.py, or no product writer at all), so the rule would have matched none of them, while a module-agnostic is_symlink() rule would need a 166-site allowlist. Closes #10737
…reates (kirodotdev#9062) frontend._ensure_tree_dist publishes static/dist through platform_compat.symlink_or_junction, which falls back to a directory JUNCTION on unelevated Windows. Three readers of that path decide what occupies it with is_symlink(), which reports False for a junction: - pod.provision.build_dist: a dangling junction answers False to is_symlink(), is_file() AND is_dir(), falls through every removal branch, and the copytree crashes with FileExistsError [WinError 183]. - frontend._discard_path: a live junction reaches the rmtree branch, whose refusal ignore_errors=True swallows, so .dist.previous.* entries are never reclaimed; a dangling one falls through every branch. - frontend._stage_dist_locked: a dangling junction answers False to both is_symlink() and exists(), so the move-aside is skipped and the os.replace publish lands on the surviving entry — the same "Could not stage static/dist" failure class. All three now route through the canonical platform_compat.is_link_or_junction / unlink_link_or_junction pair, link-first so a dangling entry is still handled, rmdir for a junction so nothing behind the link is deleted. Tests create links with the product's own symlink_or_junction helper so each platform exercises the shape it actually produces: three positive cases (live link detached without touching its target, dangling link removed, dangling static/dist moved aside and the fresh bundle staged) plus negative controls pinning that real trees and plain files keep their existing handling. Original fix by Leon (leonlaiyc); _stage_dist sibling fix and rebase by Kiro Crew. Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
…rodotdev#11136) Audit of the is_symlink()-based link guards that PR kirodotdev#9062's First Principles Review lane deferred (issue kirodotdev#10737). A directory junction -- the shape platform_compat.symlink_or_junction and any unelevated Windows writer produce -- answers False to is_symlink(), and when dangling also to exists()/is_file()/is_dir(), so each of these guards was blind to exactly the link that can occur on Windows. Converted (junction-aware oracle, one pinning test per site built with the product's own link helper plus a simulated-junction test so POSIX shards pin it too): - seed.py dangling-$KIROCREW_HOME guard: now pinned_fs.is_reparse_point, the oracle the sibling guardrails in the same function already use. A dangling junction fell through every exists()-gated guard into the raw copytree FileExistsError the guard exists to prevent. - deploy/__init__.py link migration: is_link_or_junction / unlink_link_or_junction. <home>/skills/<name> is also published by apps/bridges.py through symlink_or_junction, so a live junction reached the exists() branch where rmtree_force refused it and gateway startup aborted; a dangling one crashed copytree. - pod/runtime.py orphan_homes, cleanup_home (pre- and post-check), _rmtree_bounded, write_pod_config: is_link_or_junction. On unelevated Windows a junction is the only link a same-user writer can plant under pod_root, so the planted alias was listed as an orphan, resolved to its live sibling, passed containment, and its refusal was reported as "something is still writing there" after the full retry window. Annotated, not converted: stop_pod's systemd drop-in check is Linux-only. Semgrep rule proposed in kirodotdev#9062 (symlink_or_junction writer + is_symlink reader in one module): evaluated and declined -- the writer and reader live in different modules at every site in this audit (bridges.py vs deploy, frontend.py vs pod/provision.py, or no product writer at all), so the rule would have matched none of them, while a module-agnostic is_symlink() rule would need a 166-site allowlist. Closes kirodotdev#10737
Problem / Motivation
frontend._ensure_tree_distpublishessrc/kiro_crew/static/distitself:symlink_or_junctiontriesos.symlinkfirst and falls back to a directoryjunction on Windows, because a directory symlink there needs
SeCreateSymbolicLinkPrivilegethat an ordinary unelevated process does not hold.So on a normal Windows dev box, KiroCrew's own writer puts a junction at that
path — this is not a planted or adversarial shape, it is the product's default
output. Measured on an unelevated Windows shell:
Three readers of that same path ask
is_symlink(), which is False for a junction.1.
pod.provision.build_dist— the link check runs ahead ofis_dir()/is_file()on purpose, so a dangling link is still replaced. Adangling junction answers False to all three:
Every branch is skipped and
shutil.copytree(src_dist, dst)lands on a directoryentry that still exists. Measured:
FileExistsError: [WinError 183], and nothingup the provisioning chain handles it —
provision()and itspodcallers surfacea traceback instead of the
FATAL:line every other failure there produces.2.
frontend._discard_path— its own docstring already explains the mechanism:…and then tests
is_symlink(), 170 lines below thesymlink_or_junctioncall thatcreates the junction. A live junction therefore reaches the
rmtreebranch,whose refusal
ignore_errors=Trueswallows; a dangling one matches no branch atall. Either way the entry survives.
3.
frontend._stage_dist_locked— the move-aside before publication decideswhether an occupant exists with
is_symlink() or exists(). A dangling junctionanswers False to both, so the move-aside is skipped and the
os.replacepublishlands on the surviving entry — the same "Could not stage static/dist" failure
the handler below it exists to prevent. The
publishedcheck inside that handlerreads the same blind pair.
Why it matters
build_distis the crash:pod up/provision(build=True)on a checkout whosestatic/distlink has gone dangling — the linked tree was cleaned, or the worktreeit pointed into was removed — dies with an unhandled
FileExistsErrorrather thanrestaging. The identical situation with a symlink recovers cleanly, so this is a
Windows-only failure of an already-implemented recovery path.
_discard_pathis the leak, and it has a caller-visible tail:_stage_distcalls_discard_path(backup)to clear.dist.previous.<pid>and thenos.replaces theserved bundle onto that name. A surviving entry makes that replace fail, which the
except OSErrorturns into "Could not stage static/dist" — a refused publicationwhose cause is an entry that was supposed to have been reclaimed. The sweep over
.dist.previous.*at the end has the same blind spot, so the entries accumulate._stage_dist_lockedis the refused publish with no leak needed at all: onedangling junction at
static/distis enough to make every subsequent stagingattempt fail on this box until someone removes the entry by hand.
Graded honestly: no data loss and no containment escape.
rmtreerefuses ajunction rather than deleting through it, so nothing behind the link is ever
destroyed. What breaks is availability of the provisioning/publication path.
What changed (motivation → approach → change)
Symptom: a junction at
static/distcrashesbuild_dist, is never reclaimed by_discard_path, and blocks_stage_dist's move-aside.Root cause: all three readers spell "is this a link?" as
is_symlink(), whichdoes not see the junction this very module writes.
Change: all three route through the repo's canonical pair.
In
_stage_dist_lockedthe fix is the predicate alone — the move-aside'sis_symlink() or exists()becomesis_link_or_junction(...) or exists()at bothreads, ordering preserved, so a dangling entry is moved aside exactly like a
dangling symlink already is.
The symlink path is behaviour-preserving:
unlink_link_or_junctioncallsos.unlinkfor a symlink — exactly what both removal sites already did — andrmdironly for a junction. The link branch stays first so the dangling casekeeps working.
The unlink half matters as much as the predicate. The obvious "fix" once a
junction is detected — reach for
shutil.rmtree— would delete through it anddestroy the linked tree. Detaching with
rmdiris what keeps the target intact,and that property is asserted rather than asserted-in-prose.
Both files already import
platform_compat; no import path grew. Nothing else ineither module is touched.
Why all three sites in one PR: they are three readers of a single link,
written by a single call, and the fix is the same substitution. Fixing a subset
leaves the remaining reader looking at the same path with the same blind
predicate.
Tests
test/test_pod.py(TestProvisionBuildPaths) andtest/test_frontend_edition_build.py, 6 tests:test_build_dist_restages_over_a_dangling_dist_linkFileExistsErrorcasetest_build_dist_still_short_circuits_on_a_LIVE_dist_linkhas_distand no build runstest_discard_path_detaches_a_live_dist_link_without_deleting_its_targettest_discard_path_removes_a_dangling_dist_linktest_discard_path_still_removes_a_real_tree_and_a_plain_filetest_stage_dist_moves_a_dangling_dist_link_aside_and_publishesstatic/distis moved aside, the fresh bundle is staged, and the occupant is reclaimedEvery link is created with the product's own
platform_compat.symlink_or_junction,not a bare
os.symlink— so each test exercises whichever shape the runningplatform actually produces, and the Windows shards get the junction.
Guard-the-guard. Each test asserts the planted shape through oracles outside
the module under test before touching the code under test:
platform_compat.is_link_or_junction(...)is true, and for the dangling casesnot .is_dir()(plusprov.has_dist(co) is Falsewherehas_distcouldshort-circuit the path under test).
Red-before, measured.
build_dist, against an unpatched tree:FileExistsError: [WinError 183]._discard_path, with the production hunkreverted and everything else in place:
2 failed(assert not True— the link wasstill there), the negative control still passing. The
_stage_distcase isPOSIX-green by construction — a dangling symlink already answers
is_symlink()True, so both predicates agree there — and reds on the Windowsshard without the production change, where only the junction exposes the gap.
Gates on this head:
flake8,isort --check-only,mypy, black,subprocess-encoding, comment-history, and the scoped backend suite all pass
locally; the affected test files report
519 passed.Manual verification
N/A — unit coverage sufficient: all three defects are decided entirely by which
branch a link matches, and the tests build real links with the product's own
helper on the affected platform rather than mocking the predicate.
Screenshots / video
N/A — backend-only; no rendered surface changes.
Related Issues
no linked issue: found by inspection while auditing
is_symlink-based guards forthe Windows junction blind spot, the same family as #7881.
Pattern harvest
Rule candidate:
semgrepPattern: a module that creates a directory link with
platform_compat.symlink_or_junctionand then reads that same path back withis_symlink()/os.path.islink(). The writer emits a junction on unelevatedWindows and the reader cannot see one, so a guard fails against the product's own
default output rather than against an adversary. Worth flagging mechanically:
symlink_or_junctionandis_symlinkappearing in one module is the signal.Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)