Skip to content

fix(skill-projection): compare skill-view ownership by resolved data-home path - #17846

Merged
cruisercohen merged 1 commit into
mainfrom
fix/skill-view-ownership-resolved-home
Oct 8, 2026
Merged

cruisercohen merged 1 commit into
mainfrom
fix/skill-view-ownership-resolved-home

Conversation

@cruisercohen

@cruisercohen cruisercohen commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Clean up skill-view aliases even when a data home is reached under more than one path spelling, so they stop piling up in the agents directory.

A skill view's ownership is recorded as the data home's path, and the reclaim, prune, and drain paths decide whether a view is theirs to clean up by comparing that recorded path against the current data home. The comparison was literal string equality on a path that is not symlink-resolved. When one data home reaches disk under two spellings — /home/<user> is commonly a symlink to /local/home/<user> — a view recorded under one spelling and read under the other looks like it belongs to a different home, so nothing ever reclaims it and the aliases accumulate.

Why it matters

Every leaked alias is a file kiro-cli enumerates on every session start, so the backlog is a growing per-session cost, not just clutter. A launch that uses the other spelling, or a pod that shares ~/.kiro, trips this bug, and once a view is stranded no later run can recover it. (A home that moved is only reunified while its old spelling still resolves to the new location — e.g. a residual symlink — since the fix matches by resolved path, not by relocation.)

Not a goal

  • Changing the stored ownership value, the alias name, or the view-name hash — no existing file is renamed or re-hashed.
  • Adding a file-count ceiling to view publication (a separate change).
  • Reworking any other path comparison in the module.

What changed (motivation → approach → change)

Skill views leaked because the ownership-home check compared raw path strings, and one home has two spellings when /home is a symlink to /local/home.

The fix compares home identities by their resolved path instead of by spelling. A new _same_crew_home(recorded, current) helper in src/kiro_crew/acp/skill_projection.py resolves both sides with os.path.realpath on POSIX and, on a resolution failure (such as a symlink loop), falls back to the old exact-string comparison so the check never widens what counts as this home. The two-spelling problem is a POSIX phenomenon, and the recorded value is untrusted sidecar content, so on Windows the helper does not resolve at all — it keeps the pre-fix literal comparison, which never touches the filesystem for an unequal value and so cannot be steered into opening a UNC/network target.

Every ownership-home comparison in the module now goes through that one helper — the ledger prefetch, the orphan-sidecar sweep, the three reclaim gates, the read-only census diagnostic, and the current-publication check. The value stored in each ownership record and the alias name hash are untouched, so a view published before this change is matched by its existing record and no alias is rewritten.

Backwards compatibility

Compatible: the stored ownership value and the alias name hash are unchanged, so existing aliases and sidecars keep their names and keep being matched. The only behavior change is that two spellings of one home now compare equal; a genuinely different home still resolves to a different path and stays foreign.

Removes nothing: no path is hidden, no record or alias is deleted by this change, and no validator is tightened — a view that was reclaimable before stays reclaimable, and some that were wrongly stranded now become reclaimable.

Tests

Added to test/test_native_skill_projection.py:

  • _same_crew_home treats /home-style and /local/home-style spellings of one home as the same, in both directions, using a real temporary symlink.
  • A genuinely different home, and a non-string recorded value, stay foreign.
  • When path resolution raises, the helper falls back to literal string comparison (identical strings still match; different strings stay foreign).
  • End to end: a dead alias whose ownership record names the symlink spelling of this home is reclaimed by the prune, where before it was left as another home's.

The two tests that assert the resolved-path match run only on POSIX (that match is a POSIX phenomenon); the others run on every OS. Because the new helper reaches os.path.realpath, the link-screen baseline in test/link_screen_sites.py now also declares _is_current_publication as a known screen-then-resolve site — it re-validates the alias path itself, and the resolve is of unrelated home-identity strings, so it is a baseline entry, not a hold site.

Manual verification

N/A — unit coverage sufficient; the behavior is fully exercised by the symlink-based tests above.

Related Issues

Fixes #13362

Pattern harvest

Not generalizable: this is a single ownership comparison that must be identity-based rather than spelling-based; the module's other path checks already resolve or pin their targets.

@cruisercohen
cruisercohen requested a review from a team as a code owner October 7, 2026 20:45
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

One check before merge: the alias hash still uses the unresolved crew_home_id ("home": crew_home_id in the digest). Each spelling still publishes its own alias; the fix only makes the duplicates reclaimable.

Suggestions

  • The "Why it matters" section says a moved data home "trips the same bug". realpath only matches a moved home while the old path still resolves to the new one, so either drop that example or note that limit.

[DESIGN-REVIEWED] 216adab

Description read

[DESCRIPTION-READ] 3e277a511c4ad63502be3db718aceeeb98096b3695461be5acd64d8ffee27000

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 216adaba9c179fb7434ac211e52621bd996d5ff5 — 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: PASS

Check that test_prune_reclaims_an_alias_recorded_under_a_symlinked_home_spelling fails on base. It is the only check that the fix removes #13362.

What this change ships

Inventory (6 items) — 6 justified

Intent: stop skill-view aliases piling up when one data home is reached under two path spellings. This is a FIX.

  1. Aliases whose ownership record names a symlinked spelling of this home are now reclaimed, pruned and drained. — justified
  2. The census diagnostic stops counting other-spelling records as foreign_home. — justified
  3. The current-publication check treats a view recorded under the other spelling as this home's. — justified
  4. Windows keeps the old literal comparison and never resolves the recorded path. — justified
  5. If path resolution fails, the comparison falls back to the old exact-string behaviour. — justified
  6. The link-screen baseline in test/link_screen_sites.py declares _is_current_publication. — justified

Sibling count: I grepped _MANAGED_CREW_HOME and crew_home_id comparisons in src/kiro_crew. There are 8 comparison sites, all 8 go through _same_crew_home, and none is left unfixed. The only other path-equality helper is the private _same_path in apps/builtins/dev_fleet/repository.py:912. It lives in an app package, so it is not a shared mechanism for acp/.

[FIRST-PRINCIPLES-REVIEWED] 216adab

Description read

[DESCRIPTION-READ] 46fb1593570608d2ef89e5bbd84e5b036ff734c1d7551bc86fb45a3e30216e67

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 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 216adaba9c179fb7434ac211e52621bd996d5ff5 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 216adab

Verdict parsed from the review's SHA-scoped output markers for commit 216adaba9c179fb7434ac211e52621bd996d5ff5.

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

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 216adaba9c179fb7434ac211e52621bd996d5ff5 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 216adab

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

@cruisercohen
cruisercohen force-pushed the fix/skill-view-ownership-resolved-home branch from a26ebd6 to c40eccf Compare October 7, 2026 21:07
@cruisercohen

Copy link
Copy Markdown
Contributor Author
  • span=5ddc75f4e72f fixed

Fixed in c40eccf. The description claimed the helper "resolves both sides with os.path.realpath"; the What changed section now states the Windows branch explicitly: resolution runs only on POSIX (where the /home -> /local/home two-spelling problem is), and on Windows the helper keeps the pre-fix literal comparison and does not resolve, so an untrusted recorded value cannot be steered into opening a UNC/network target.

@cruisercohen

Copy link
Copy Markdown
Contributor Author
  • span=ec1e446e86e9 rebutted

Keeping as-is. On POSIX the extra per-candidate cost is one os.path.realpath(current) on a fixed string -- a single lstat-class syscall against the multiple file reads (alias bytes + ownership sidecar) each candidate already performs in the prune/sweep/drain loops, so it is noise on an I/O-bound path, and the per-run work is already bounded by the reclaim/scan caps. On Windows the helper returns before realpath, so there is no lookup to cache. Caching current would require threading a pre-resolved value through all seven ownership comparison sites, widening a diff deliberately confined to the ownership comparison so it stays trivial to rebase against the sibling file-count PR touching the same file. Advisory suggestion, outside the frozen goal; not taken.

@cruisercohen
cruisercohen force-pushed the fix/skill-view-ownership-resolved-home branch from c40eccf to 4eece9b Compare October 7, 2026 21:34
@cruisercohen

Copy link
Copy Markdown
Contributor Author
  • span=204cf49153d6 fixed

Fixed in 4eece9b. Correct: both tests assert the RESOLVED-path match, which _same_crew_home only performs on POSIX (on Windows it keeps the literal comparison and does not resolve), so on a Windows runner with symlink privilege they created the link, took the Windows branch, and failed the equality assertion. @requires_symlinks only skips when a symlink cannot be CREATED, not when the asserted behaviour is OS-specific. Both POSIX-behaviour tests now also carry skipif(platform_compat.IS_WINDOWS); the OS-agnostic helper tests (genuinely-different, never-resolves-on-windows, falls-back) still run everywhere. Verified by forcing IS_WINDOWS at collection: the two skip, the other three pass.

@cruisercohen
cruisercohen force-pushed the fix/skill-view-ownership-resolved-home branch from 4eece9b to 609d67c Compare October 7, 2026 22:05
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

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

@cruisercohen

Copy link
Copy Markdown
Contributor Author

The two failing Windows Backend Tests — test_http_server_bind_ratchet (16 vs recorded 15) and test_session_control_doc (tabulated refusal code remote_target_unsupported) — are inherited from main, not introduced by this PR. Both reproduce on fresh main with none of this diff applied, and are tracked by #17900 (fixes in flight: #17906, #17907). This PRs own review lanes (GPT, Opus, Design, First Principles) all pass; it will go green once main is fixed and this branch is rebased onto it.

@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 7, 2026
…home path

Skill-view ownership was recorded and compared as data_home().absolute(),
which is not symlink-resolved. On cloud desktops /home/<u> is a symlink to
/local/home/<u>, so a launch using the other spelling, a pod sharing ~/.kiro,
or a moved data home produced views the reclaim/prune/drain paths treated as
another home's, so nothing ever cleaned them up.

Add _same_crew_home() comparing home identities by os.path.realpath with a
literal-string fallback on resolve failure, and route every ownership-home
comparison through it. The stored value and the view-name hash are unchanged,
so no existing alias is renamed or re-hashed.
@cruisercohen
cruisercohen force-pushed the fix/skill-view-ownership-resolved-home branch from 609d67c to 216adab Compare October 8, 2026 00:11
@cruisercohen

Copy link
Copy Markdown
Contributor Author

Rebased: main moved. The two inherited reds (http_server_bind_ratchet 16-vs-15 and session_control_doc remote_target_unsupported, tracked by #17900) are now fixed on main (#17906/#17907 landed, #17900 closed), so I rebased this branch once onto fresh origin/main (1ad2d6d). Single commit, no conflicts (change is confined to _same_crew_home); scoped backend tests pass (215), both former-red ratchets now green on the new base. New head 216adaba9. Letting CI re-run.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 8, 2026
@cruisercohen

cruisercohen commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

span=56828ee357a2 — fixed. Tightened the "Why it matters" prose: the moved-data-home example now notes the limit — a relocated home is reunified only while its old spelling still resolves to the new location (e.g. a residual symlink), since the fix matches by resolved path, not by relocation. The leak scenarios the fix actually addresses (alternate spelling, pod sharing ~/.kiro) are unchanged. Prose-only; no code change.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 8, 2026
@github-actions github-actions Bot added the readiness: passed Eligible automated validation passed for the current revision label Oct 8, 2026

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at 216adaba9c. The fix is correct and stays fail-closed.

Coverage. Every read of _MANAGED_CREW_HOME in skill_projection.py now goes through _same_crew_home: the ledger window, the orphan-sidecar sweep, the legacy-sidecar branch in reclaim, the metadata check and its pre-delete revalidation, the census, and _is_current_publication. No literal home comparison is left, and no other module reads the key.

Fail-closed.

  • A realpath match only happens when both strings land on the same real directory, i.e. the same home. A pod's data home is a separate directory and stays foreign (test_prune_never_touches_another_homes_alias still passes).
  • Planting a sidecar whose recorded path symlinks to this home needs write access to ~/.kiro/agents, which already allows deleting the aliases directly, so nothing is gained.
  • Liveness is unaffected: leased aliases are in the skip set before any ownership check runs.
  • Resolution errors fall back to "foreign"; Windows keeps the literal compare and never resolves the untrusted value.

Link-screen baseline. Declaring _is_current_publication is justified: the realpath runs on the home strings, not on the alias_path the function screens with lstat, so it is not a new TOCTOU.

Upgrade impact. No stored value, alias name or hash changes. The default (same-spelling) path takes the unchanged literal fast path; only mixed-spelling POSIX hosts see new behaviour, which is the fix.

Tests. test_native_skill_projection.py plus the link-screen gate: 229 passed. Reverting the helper to == reddens test_same_crew_home_matches_across_symlinked_home_spellings and test_prune_reclaims_an_alias_recorded_under_a_symlinked_home_spelling; removing the Windows guard reddens test_same_crew_home_never_resolves_an_untrusted_path_on_windows. Windows was checked by monkeypatch only, not on a Windows host.

Non-blocking follow-ups

  1. Changing the orphan-sidecar sweep, census, ledger window, legacy-sidecar branch or _is_current_publication back to a literal compare leaves every test green. An end-to-end test for the sweep and census under a symlinked spelling would pin them.
  2. The alias name is still hashed on the literal home spelling, so a mixed-spelling host still mints one alias per spelling; this change makes the other spelling's copies reclaimable, so growth is bounded rather than stopped. Reasonable (canonicalizing would rename every alias on upgrade), but worth saying in the body.
  3. os.path.realpath(current) is constant per process and could be cached; realpath on a recorded value pointing at a stale automount can block while the publication lock is held. Low risk since sidecars are same-user.

@cruisercohen
cruisercohen merged commit 385e55c into main Oct 8, 2026
113 of 115 checks passed
@cruisercohen
cruisercohen deleted the fix/skill-view-ownership-resolved-home branch October 8, 2026 02:05
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 8, 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

3 participants