Skip to content

fix(portability): keep the export archive inside the crew directory - #9070

Merged
iamwhatever merged 2 commits into
kirodotdev:mainfrom
leonlaiyc:fix/portability-export-junction-containment
Sep 7, 2026
Merged

iamwhatever merged 2 commits into
kirodotdev:mainfrom
leonlaiyc:fix/portability-export-junction-containment

Conversation

@leonlaiyc

@leonlaiyc leonlaiyc commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

portability.create_export_zip walks workspace/, plan_memory/ and skills/ with
rglob("*") and writes each file into an archive the user downloads and hands on.
The walk skipped an entry that is a symlink — but rglob descends a
directory link, and the file on the far side is an ordinary one, so that skip never
fired for it. Measured: workspace/memory/linked/not-ours.md, living outside the
crew directory entirely, appeared in the export's namelist.

Correction to this PR's earlier description. It said _is_excluded and
is_sensitive_path "both read the LEXICAL path". That is wrong about the second one,
and a reviewer was right to flag it: is_sensitive_path → _path_in_home_dirs →
_candidate_forms builds _resolved_forms_bounded(expanded), so it does resolve
links — a linked ~/.aws really was caught. The accurate statement is narrower and
different in kind: neither filter is a containment test at all. _is_excluded is
a rule about the archive name; is_sensitive_path asks whether a path is a
protected location, never whether it is inside the crew directory. An ordinary
file of the user's — notes, documents, anything under a link somebody dropped in the
workspace — was neither, and went into the archive.

A resolve-and-compare is not enough, and the first commit here only did that.
ZipFile.write takes a name and opens it itself, so the file that was checked and
the file that is read are two separate lookups. Measured against the shape main
ships:

by-name containment check at validation time: True  (accepts it)
archived bytes: b'private notes'
VULNERABLE: True

And a refusal computed after the open is already too late on Windows — the
third finding. _open_inside called os.open(candidate, ...) and only then asked
fd_real_path where the descriptor had landed. Opening a path whose ancestor is a
link to a UNC share is itself an outbound SMB authentication as this process, so
the containment, sensitivity and hardlink checks were all correct and all ran one
syscall too late. This is the ordering hooks.validate_file_path states as its own
contract — the Windows UNC and linked-ancestor gates run before any resolution,
"because realpath on a UNC path is itself the outbound SMB probe".

And a pathname screen could not fix it — the fourth finding, which is what this
revision answers.
The previous head refused a candidate whose ancestor was a
reparse point, checked with lstat. A reviewer was right that this is still
raceable: any check of a name is a check-to-open window, and an adversary who can
plant the link chooses when. Measured, not conceded — the same racing writer,
run at the same instant, against both builds:

ARM A: previous head be3caf39b (lstat screen, then os.open by name)
  attacker      : rename SUCCEEDED, junction planted
  os.open called: keep.md                    <- the outbound probe
  bytes archived: None                       <- containment refused it, too late

ARM B: this revision (pinned ancestor walk)
  attacker      : rename REFUSED (PermissionError winerror=32)
  bytes archived: b'ours'

Arm A is the finding in three lines: the guard worked — nothing was archived — and
the probe went out anyway.

And the ENUMERATION was still probing before any of that ran — the fifth finding,
which this revision answers.
Pinning the candidate's ancestors closed the swap
race, but a junction already sitting in the workspace when the export starts was
never raced for: rglob descended it, and is_file() and is_sensitive_path()
resolved what it yielded, before _open_inside was ever reached. Measured by
wrapping every resolving call and exporting a workspace holding one planted junction:

head 5663dd30a (pinned read, rglob enumeration)
  resolving calls through the junction : 14   (os.path.realpath, ntpath._getfinalpathname)
  loot archived                        : False

this revision (pinned walk)
  resolving calls through the junction : 0
  loot archived                        : False

Both builds archive nothing from behind the junction, which is exactly why the
archive cannot be the oracle. If the junction names \\host\share, those 14
resolutions are the outbound SMB authentication, and return None afterwards
cannot recall them. The previous revision disclosed this as an unclosed residual; it
is closed here.

Why it matters

An export is a file the user deliberately hands to someone else — another machine, a
support thread, a backup. Content that was never theirs to share leaves the host with
no recovery once the archive has left.

The race is not theoretical here: a running gateway gives agent tools write access to
the same workspace the export walks, and an export can be triggered while they are
working. Under the race the harm is also strictly worse than under the plain blind
spot, because the sensitivity gate is one of the checks the swap gets to skip — the
name is validated, and something else is read.

The ordering finding is a different kind of harm rather than more of the same: a leaked
NTLM exchange is not something a later return None can take back, and it costs the
attacker nothing but a junction in a directory their tools can already write to.

What changed (motivation → approach → change)

Root cause: the check and the use are two lookups of one name, and no lookup was
asking about containment in the first place.

Approach: resolve once, open once, address everything downstream through the
descriptor — the discipline pinned_fs already exists for in this repo. This change
consumes its fd_real_path rather than adding a second mechanism.

  • _open_verified(target, root_real) — opens with O_NOFOLLOW where it
    exists, rejects a non-regular file on the descriptor's own fstat, then asks the
    kernel where the open descriptor actually is (/proc/self/fd, F_GETPATH, or
    GetFinalPathNameByHandleW) and compares that against the crew root.
    is_sensitive_path is re-asked about that real path, so the protected-location
    rule is not the one check the swap defeats. Every failure route — unreadable,
    non-regular, unknowable real path — returns None, never a fallback to the
    pathname.
  • _add_from_fd streams the entry from that descriptor instead of letting
    ZipFile.write reopen the name. Streaming rather than reading whole is deliberate:
    a workspace file has no size bound here and the export used to copy one of any
    size. This is also why hooks.safe_read_file_bytes_nolink — which performs exactly
    the right validation — was not reused: its 50 MB cap would silently drop a large
    workspace file from the export.
  • The entry's timestamp and mode come from the same fstat, so hand-building the
    ZipInfo does not quietly lose what write used to record.
  • The crew root is resolved once, before the walk (os.path.realpath(mc)), since
    $KIROCREW_HOME may itself legitimately be a link and the test must not reject the
    whole export because of it.
  • The by-name filters stay as cheap pre-filters that avoid opening what is already
    known to be unwanted, with a comment saying what each one actually decides.

Three things the descriptor alone does not settle, all raised in review and all fixed
here:

  • A hardlink defeats every path-based guard, including this one. It shares its
    target's inode, so there is no symlink for O_NOFOLLOW to refuse, is_symlink()
    is False, and fd_real_path reports the path the descriptor was opened by — the
    innocent workspace alias — not a canonical one. is_sensitive_path is then asked
    about the alias and answers "not sensitive" while the bytes behind it are a
    credential file's. Only the link COUNT, read off the descriptor, sees it, so
    st_nlink > 1 is refused. Same rule and same reasoning as
    pinned_fs.refuse_hardlink_alias and hooks.safe_read_file_bytes_nolink; the cost
    is honest and small — a workspace file that legitimately has a second link is left
    out of the export.
  • force_zip64=True on the streamed entry. ZipFile.write stat'd the source and
    turned ZIP64 on by itself; a streamed entry does not know its size when the header
    is written, so without this a source over zipfile.ZIP64_LIMIT raises
    RuntimeError part-way through and the export endpoint answers 500. A multi-GiB
    file under workspace/ is ordinary — a dataset, a model artifact — and it used to
    archive fine, so leaving this off would trade one defect for a regression.
  • The walk descends and verifies in one motion. _walk_contained /
    _walk_pinned replace rglob. A directory is PINNED with
    platform_compat.pin_directory before it is listed, and each child is then
    classified from the listing itself (_entry_is_link) rather than by a call that
    resolves it: on Windows FindFirstFileW returns the attributes and the reparse tag
    inline, so a child's type and link-ness cost no lookup THROUGH that child. A child
    directory is descended only by pinning it in turn, so the path the kernel walks to
    reach component n runs entirely through components already opened and verified —
    starting at the crew root itself, which the kernel walks to reach every candidate.
    pin_directory supplies both halves on Windows: its handle omits
    FILE_SHARE_DELETE, so a held directory can be neither renamed nor deleted — nor
    can anything above it — and its open refuses to follow a reparse point, so a
    junction sitting at the name fails there instead of being traversed. This is not
    a new mechanism
    : aws_control/backend/storage.py already pins root-then-child for
    exactly this reason — "a watcher can no longer rename the directory away and plant a
    junction at its name between our create and the CLI's open".
  • _pin_ancestors and _open_inside are deleted rather than kept beside it. The
    walk holds the same chain, for a whole subtree instead of re-walking it once per
    file, so keeping both would be two mechanisms doing one job. _entry_is_link
    refuses every reparse point rather than only link-shaped ones — which is precisely
    what pin_directory and open_file_no_reparse already refuse, so it classifies
    what the opens would reject anyway: a cheap skip, never the enforcement.
    DirEntry.is_symlink() alone would not do: a junction's tag is
    IO_REPARSE_TAG_MOUNT_POINT, not IO_REPARSE_TAG_SYMLINK, so that method answers
    False for one — which is how rglob came to descend it in the first place.
  • is_sensitive_path is no longer asked about the PATHNAME. That call was the
    probe — 12 of the 14 measured resolutions. It is removed, not relocated: the same
    question is still asked in _open_verified, of the descriptor's real path, which
    was always the load-bearing one because a name can be re-pointed and a descriptor
    cannot.
  • The leaf is opened and judged in one operation. New
    platform_compat.open_file_no_reparse opens with FILE_FLAG_OPEN_REPARSE_POINT, so
    a reparse point at the final name is opened as itself and refused (ELOOP) rather
    than followed — Windows has no O_NOFOLLOW, so os.open follows one. The attribute
    is read off the descriptor, which makes it a fact about what was opened rather than
    a prediction about what a later open will find. It shares the CreateFileW wiring
    with pin_directory via one private helper, so the two do not carry separate copies
    of the same security-critical flags. On POSIX it is the O_NOFOLLOW open the code
    already had, named.

Three deliberate boundaries, each stated because getting one wrong is worse than the
defect:

  • The walk starts at the RESOLVED root. pin_directory refuses a reparse point at
    a name, so pinning the configured spelling of $KIROCREW_HOME would fail on a host
    where the crew directory is itself a link — and return an empty archive rather
    than a safer one. A silently empty backup is worse than the leak. Resolving first
    means the chain that gets pinned is the real one; the crew root's own ancestors are
    configuration this export has already read through.
  • POSIX is not handed Windows semantics. The walk pins on both platforms, but
    only half the property is real there: pin_directory on POSIX is
    O_RDONLY | O_DIRECTORY | O_NOFOLLOW, whose refusal of a symlinked directory is
    genuine and is exactly what rglob already did — so the exported set is unchanged —
    while the anti-rename half has no POSIX equivalent and nothing here claims it. The
    Windows-only tests say so in their skip reason. Containment on POSIX rests where it
    always did, on _open_verified checking the descriptor's real path; resolving a
    symlink there is local and leaks nothing, so there is no outbound probe to prevent.
  • No lexical UNC screen. A candidate here is the configured root joined with
    components the export itself enumerated, so it is UNC-shaped only when the root is —
    and refusing on that would break a deliberately configured UNC home for nothing.

What it costs, stated exactly. Nothing outside the crew directory is newly
dropped — containment already refused that. Content still inside it is either walked
under its own name anyway, or, if it lives in a part of the crew directory the export
does not walk, is left out on Windows — which is already the behaviour on POSIX, where
rglob never descends a directory link. The walk holds one descriptor per directory
for as long as that directory's subtree is being produced — depth, not breadth, bounds
how many are open at once, and it is strictly fewer opens than the previous revision,
which re-pinned the whole ancestor chain once per file. Each is released in a
finally that also runs if the consumer abandons the walk; a test pins that they are
released even when a component mid-chain refuses, because a handle leak here would
exhaust a large export rather than merely look untidy.

The exported set is unchanged by the walk rewrite, measured rather than argued:
on a tree covering nesting, EXCLUDE_DIRS, EXPORT_EXCLUDE, .pid and
skills/auto, the archive namelist and manifest counts were byte-identical to the
ones the previous walk produced. The exclusion fix below then deliberately CHANGES
that set on Windows — see the next section.

The Windows exclusion bypass — disclosed here first, then fixed here. An earlier
revision of this description scoped this out as a separate defect. A security review
disagreed and was right, so it ships in this PR.

_keep_for_export asked _is_excluded(PurePosixPath(str(rel))). On Windows
str(rel) is backslash-separated, so PurePosixPath parses the whole relative path
as a SINGLE component: .name becomes workspace otes\.env and .parts has
length one, so the EXPORT_EXCLUDE basename set and the EXCLUDE_DIRS walk both
stop matching. workspace/notes/.env — a credential file this export exists to keep
out — went into the archive the user downloads and hands on.

Fixed with PurePosixPath(*rel.parts) for the filter and rel.as_posix() for the
archive name. Measured on the same fixture tree as the parity run above:

before: workspace/notes/.env, workspace/__pycache__/x.pyc, workspace/snapshots/s.md
        all EXPORTED   (7 files)
after : excluded        (4 files)

So the exported set does change on Windows, and that is the fix: every nested
.env, .local_secret, sel_hmac.key, telemetry_salt, *.pid, and everything
under snapshots/, outbox/, uploads/ and __pycache__/ now stays out. POSIX is
unaffected — str(rel) and parts already agreed there.

On the archive name: ZipInfo rewrites os.sep today, so that half fixes no live
bug; it stops the member name depending on that behaviour, next to a filter that must
not.

Tests

TestTheAncestorSwapIsRefusedNotDetected (new — replaces the screen's tests):

  • test_a_racing_writer_cannot_swap_a_pinned_ancestor — the blocking finding's own
    scenario, executed rather than described.
    The swap is performed from inside
    pin_directory, immediately after the targeted component has been verified and
    pinned and before the next filesystem call — the precise instant a real racing
    writer would aim for, rather than a thread that has to get lucky. Two assertions,
    both load-bearing: the rename must fail, because that is the property (the
    export no longer depends on nobody having swapped the directory, but on nobody being
    able to); and the descriptor must still come back on the genuine bytes, because a
    guard that closed the race by refusing everything would pass the first assertion and
    be useless.
  • test_the_same_rename_succeeds_once_nothing_is_pinned — guards that guard: the
    refusal above is the pin, not a filesystem that could never have done the rename.
  • test_a_reparse_point_at_the_leaf_is_refused_without_being_followed —
    open_file_no_reparse refuses the link, and the guard-the-guard then proves that
    exact name
    is traversable by an ordinary os.open, so the refusal cannot be
    mistaken for the link being unopenable.
  • test_an_ordinary_file_still_opens_through_the_no_follow_open — the descriptor is
    the one _add_from_fd streams from, and on Windows it is now a CreateFileW handle
    wrapped in a CRT descriptor. The test exercises st_nlink (the hardlink rule reads
    it off this handle), lseek and dup+fdopen — exactly the operations a shallow
    test would miss and the archive would break on.
  • test_every_pin_is_released_even_when_a_component_refuses — a component mid-chain
    is made to refuse and every pinned descriptor must still be closed.

TestNothingIsProbedThroughAPlantedReparsePoint (new — the fifth finding):

  • test_a_pre_planted_junction_is_never_resolved_during_an_export — the assertion
    is on the CALLS, not on the archive.
    A junction is planted under workspace/
    before the export runs; every resolving call (os.stat, os.open, os.listdir,
    os.scandir, os.path.realpath / isfile / isdir / exists / getsize, and
    ntpath._getfinalpathname) is wrapped, and the test fails if any of them names the
    junction or anything beneath it. os.lstat and os.path.islink are deliberately
    not in that set — they do not follow the final component, so naming the link with
    one traverses nothing. An audit hook covers os.scandir / os.listdir as well,
    because pathlib binds scandir at import time and patching os.scandir does not
    see rglob's own descent — the single most important call to catch. Two negative
    controls sit beside it: the genuine workspace/keep.md must still be archived (a
    guard that refused the whole tree would otherwise pass), and the loot must still be
    absent.
  • test_the_recorder_actually_catches_a_probe — guards that guard. It performs the
    three calls the previous build made on that exact path (is_file(),
    realpath(), rglob) and asserts the recorder saw both a realpath and the
    scandir descent. An oracle that can never fire proves nothing, and this one is
    the whole test.
  • Guard-the-guard on the fixture itself, through oracles outside the module:
    is_symlink() must be False (it really is a junction, which is why rglob
    walked in), is_link_or_junction must be True, and the far side must really be
    readable through the link.

Red-before for these two: with only portability.py reverted to 5663dd30a and
the new tests kept, test_a_pre_planted_junction_is_never_resolved_during_an_export
fails with AssertionError: the export resolved a path through the planted junction (14 calls), listing os.path.realpath and ntpath._getfinalpathname on the junction
path. The recorder test passes on both builds, as it must — it tests the oracle, not
the fix.

The tests that depend on the rename lock are marked Windows-only with the reason
stated: the walk pins on both platforms, but the anti-rename half is a share-mode
property (FILE_SHARE_DELETE omitted) that POSIX has no equivalent of.

TestALinkedCrewRootStillExports:

  • test_a_crew_root_reached_through_a_link_still_packages_its_workspace — drives the
    public create_export_zip with $KIROCREW_HOME on a real link. This is the
    regression the resolved-root rule exists to avoid, and it would otherwise be silent.

TestTheArchivedBytesAreTheValidatedBytes (same assertions, retargeted from
_open_inside to _open_verified now that the pins live in the walk):
test_retargeting_the_link_after_validation_cannot_change_what_is_archived (the
descriptor race, with the swap at the crew root — the one component outside the pins),
test_a_sensitive_target_is_refused_on_the_descriptor,
test_a_file_reached_through_a_directory_link_gets_no_descriptor,
test_a_real_file_inside_the_crew_dir_gets_a_descriptor_on_its_own_bytes,
test_a_hardlinked_alias_gets_no_descriptor (+ its single-link control),
test_a_streamed_entry_larger_than_the_zip64_limit_still_exports (+
test_the_zip64_guard_can_actually_fail),
test_containment_fails_closed_when_the_real_path_is_unknowable,
test_a_directory_never_yields_a_descriptor.

TestExport: test_export_does_not_package_files_reached_through_a_directory_link
(Windows-marked, with its guard-the-guard walking from the root the production walk
starts at), test_export_preserves_the_mtime_of_what_it_packages,
test_export_still_packages_a_real_nested_workspace_file.

Red-before is the A/B in Problem / Motivation, run against be3caf39b loaded
side-by-side with this build and driven by the identical attacker: on the previous
head the racing rename succeeded, the junction was planted, and os.open was still
called on the candidate; on this head the rename is refused with WinError 32 and the
genuine bytes come back. The same swap, injected through the shipped test, is
test_a_racing_writer_cannot_swap_a_pinned_ancestor.

Gates. test/test_portability.py 78 passed / 4 skipped on Windows against real
junctions. pin_directory's existing consumers re-run clean:
test_platform_compat.py, test_aws_control_storage.py, test_pinned_staging.py =
383 passed / 72 skipped, the single failure being
TestFindPythonInterpreterReal::test_version_gate_ignores_a_sitecustomize_decoy_on_pythonpath,
reproduced with this branch's production files reverted to be3caf39b — it is an
artefact of the PYTHONPATH override this Windows box needs to run the suite at all,
which is the very thing that test is about. mypy --platform linux reports 0 errors
in portability.py (the 4 it finds are pre-existing in dashboard/state.py and one
other, reached by import following). black --check clean on portability.py;
test/test_portability.py is in the repository's black baseline (1164 known-
unformatted files) and scripts/check_black_formatting.py passes, so it is
deliberately not reformatted — doing so would bury this diff under an unrelated
rewrite of its SQL fixtures. flake8 and isort --check-only clean on both;
scripts/scrub-lint.sh --no-history passes.

Manual verification

N/A — unit coverage sufficient: the whole defect is the relationship between the
containment decision and the archive read, and the tests drive both against a real
junction rather than a mock, including through the public create_export_zip. The
ordering property is asserted on the syscall itself rather than on an observable
side effect, which is what a manual run could not have shown either.

Related Issues

None — found by inspection while auditing is_symlink-based containment guards for
the Windows junction blind spot, the same family as #7881.

Pattern harvest

Rule candidate: review-prompt
Pattern: a containment guard that validates a path and then reopens it. Two
distinct failures ride together — a recursive walk descends a directory link and the
leaf beyond it carries no mark (a Windows junction carries none anywhere), and
resolve()-then-open(name) is a check-to-use window. Where a walk feeds something
that reads, writes, moves or executes the result, the fix is not a stricter name
check: open once and address the descriptor. A second lesson for review prompts:
"filter X already resolves links" does not mean filter X answers containment — ask
which question each filter actually answers before crediting it with an unrelated one.

Third lesson, and the one this PR was blocked twice to learn: on Windows a correct
refusal computed after the open is still a leak, and no pathname check can fix it.

Touching an untrusted path is the outbound probe, so the sequence must be
open-and-judge in one operation, with the ancestors held rather than inspected —
lstat-then-open and is_symlink()-then-open are the same defect wearing different
clothes. The repository already had the primitive (platform_compat.pin_directory)
and already had the pattern (aws_control/backend/storage.py); the review prompt
worth writing is "if this guard checks a name and then opens that name, what holds the
name still in between?".

Fourth: when reusing an ancestor-walking guard, ask what it is scoped to. A walk
that runs to the drive root fails closed on everything when the configured root is
itself a link — which would have turned a leak fix into a silently empty backup.

Fifth, and the one this revision cost: guarding the read does not guard the walk.
Four revisions hardened what the export was allowed to OPEN while the enumeration in
front of it kept resolving untrusted names for free. The review prompt worth writing
is "before the guard runs, what has already touched this path?" — and the test that
catches it must assert on the calls, because every build here archived the right
thing. rglob, glob, os.walk and Path.iterdir are all guard-free surface. The
enumeration primitive that is safe was already available: os.scandir hands back a
child's type and reparse tag from the directory listing, so a walk can decide about a
child without ever addressing it.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|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

🤖 Generated with Claude Code

`create_export_zip` walks `workspace`, `plan_memory` and `skills` with
`rglob("*")` and skips an entry that `is_symlink()`, so that an export never
carries bytes from outside the crew directory. That skip is blind to the escape
that costs the most: `rglob` DESCENDS a directory link, and the file on the far
side is an ordinary one — `is_symlink()` false — so it is written straight into
the archive. On Windows the link is typically a junction, which `is_symlink`
does not report at all, and a junction needs none of the privilege a directory
symlink needs there.

The two filters below the skip do not catch it either. `_is_excluded` and
`is_sensitive_path` both read the LEXICAL path, which runs through the link's
own name and therefore looks like ordinary crew content — so a sensitive file
behind a link passes the sensitivity check that exists to stop exactly this.

Measured on unpatched main with a real junction: `workspace/memory/linked/
not-ours.md` appeared in the export's namelist, sourced from outside the crew
directory. The consequence class is content the user then hands to someone else,
since an export archive is made to be moved off the host.

Fixed by requiring the RESOLVED path to stay under the resolved crew directory —
the repo's existing idiom (`apps/backend.py:651`). Resolving is what covers both
shapes at once: it follows every reparse point on the way down and answers where
the bytes actually live. `mc` is resolved once so a legitimately linked
`$KIROCREW_HOME` does not reject the whole export. The `is_symlink()` skip is
kept as-is; this adds a layer rather than replacing one.

The import side of this module is untouched.

`test_export_skips_symlinks` cannot cover this — it plants a link that IS the
entry, and it `pytest.skip`s where symlinks cannot be created, i.e. on the
platform where the junction spelling lives. The new tests use
`conftest.make_dir_link` and need no privilege.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@leonlaiyc
leonlaiyc requested review from a team and krishdhasmana September 6, 2026 16:53
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 6, 2026
@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5.1, fork) — 🟡 CONCERNS

Design-level review of 82700d56276fe2c6ff6820e53cee09ba0dc9b606 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

Sound fix on a real boundary (workspace-writable-by-agent + Windows SMB probe), reusing existing pinned-fd primitives — but the description contradicts the shipped diff on a security-relevant hunk.

Watch

  • The "still out of scope" claim is false, and it hides a second security fix. The PR body states the Windows separator bug — _is_excluded(PurePosixPath(str(rel))) collapsing a nested path to one component, so workspace/notes/.env exports on Windows — is "untouched by this PR." The diff does fix it: the old call site (portability.py:168) is replaced by _keep_for_export using PurePosixPath(*rel.parts), plus a whole new TestExclusionsSurviveAWindowsSeparator. A reviewer trusting the description would not vet the new credential-exclusion logic. Consequence: the fold-in is fine and welcome, but the "byte-identical export set" parity claim cannot hold on Windows (a credential file that used to export no longer does) — reconcile the description with what shipped so the parity assertion isn't relied on as-is.

Suggestions

  • platform-compat.md's helper table documents pin_directory as the "hold a dir in place" primitive; add a row for the new sibling open_file_no_reparse so the leaf-open counterpart is discoverable next to it.

[DESIGN-REVIEWED] 82700d5

@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

Reviewed 82700d56276fe2c6ff6820e53cee09ba0dc9b606 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 82700d5

@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed 82700d56276fe2c6ff6820e53cee09ba0dc9b606 via the fork AI-review pipeline; updated in place on each push.

Review details

FINDING -- src/kiro_crew/platform_compat.py:3853 -- "Refuses a directory" contradicts the POSIX branch, which returns a directory descriptor -> Fix: document that POSIX callers must reject directories.
[GPT-REVIEWED] 82700d5

@github-actions

github-actions Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5.1, fork) — 🟡 CONCERNS

Premise-level review of 82700d56276fe2c6ff6820e53cee09ba0dc9b606 via the fork AI-review pipeline — 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

Every item traces to a named harm on a real boundary (export leak, agent-tool write race, Windows UNC auth probe) — but a second defect fix and a one-caller keep parameter ride along.

What this change ships

Intent: stop create_export_zip from packaging files that live outside the crew directory. FIX.

  1. Files reached through a directory junction/symlink are no longer exported — justified (measured leak: workspace/memory/linked/not-ours.md).
  2. A hardlinked file (st_nlink>1) is now dropped from the export — justified (credential-alias leak; matches pinned_fs.refuse_hardlink_alias).
  3. A concurrent directory swap mid-walk is refused, not just detected (Windows pins) — justified (running-gateway write race is a named boundary).
  4. The walk never resolves through a planted junction (no outbound SMB probe) — justified (Windows UNC auth = platform fact).
  5. Excluded basenames (.env, …) now excluded for nested Windows paths — rides along; separate pre-existing defect (old PurePosixPath(str(rel)) at portability.py:168), justified and tested.
  6. New platform_compat.open_file_no_reparse + _win_open_without_following extraction — 1 consumer, justified leaf twin of pin_directory.
  7. Entries hand-built/streamed from fd with force_zip64, mtime/mode from fstat — justified (avoids large-file 500 regression).
  8. Crew root resolved once before the walk — justified (linked $KIROCREW_HOME).

Watch

  • Item 5 is a distinct Windows credential-leak fix riding in a link-containment PR; its zero option DOES cost Windows users, so it belongs, but a human should note two defects land together.

Subtractions

  • Drop the keep: Callable parameter from _walk_contained/_walk_pinned and inline _keep_for_export: exactly one production caller passes it (create_export_zip, patch line 418); the lambda _rel: True callers are tests, which don't count. Take the concrete filter.

[FIRST-PRINCIPLES-REVIEWED] 82700d5

@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: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 6, 2026
@leonlaiyc

Copy link
Copy Markdown
Contributor Author

Addressing the exact-head [BLOCK-MERGE] on 78232262f, and the finding beside it, at 3325f5fca.

F1 — TOCTOU at portability.py:182. Accepted as stated. zf.write(str(fpath), ...) takes a name and opens it again, so the check and the read were two lookups. Validation now happens on an open descriptor (_open_inside → pinned_fs.fd_real_path) and _add_from_fd streams the entry from that descriptor. is_sensitive_path is re-asked about the descriptor's real path, so the protected-location rule is not the one check the swap gets to skip.

Reproduced against the shape main ships before fixing it:

by-name containment check at validation time: True  (accepts it)
archived bytes: b'private notes'   VULNERABLE: True     <- zf.write reopens the name
archived bytes: b'ours'            VULNERABLE: False    <- streamed from the descriptor

Streaming rather than reading whole is deliberate — a workspace file has no size bound here. That is also why hooks.safe_read_file_bytes_nolink, which performs exactly the right validation, was not reused: its 50 MB cap would silently drop a large workspace file from the export. The entry's timestamp and mode come from the same fstat, so the hand-built ZipInfo does not lose what write recorded (test_export_preserves_the_mtime_of_what_it_packages).

FINDING — the is_sensitive_path claim. You are right and the description was wrong. _path_in_home_dirs → _candidate_forms builds _resolved_forms_bounded(expanded), so it does resolve links; a linked ~/.aws really was caught. Both changed comments and the PR body are corrected. The accurate statement is narrower and different in kind: neither filter is a containment test — _is_excluded is a rule about the archive name, and is_sensitive_path asks whether a path is a protected location, never whether it is inside the crew directory. An ordinary file of the user's was neither, which is what leaked.

One more thing that was green for the wrong reason. The walk-descent test guarded itself with link.rglob("*") — a walk starting at the link, which descends on every platform — so on Linux it proved nothing about whether the export's own walk from workspace/ ever gets there. It now guards from the production walk's root, and is marked for Windows: pathlib's ** does not descend a POSIX directory symlink. Measured both ways.

@leonlaiyc
leonlaiyc force-pushed the fix/portability-export-junction-containment branch from 3325f5f to 8a74e97 Compare September 7, 2026 06:15
@leonlaiyc

Copy link
Copy Markdown
Contributor Author

Both exact-head [BLOCK-MERGE] findings on 3325f5fca are accepted and fixed at 8a74e97ad. Neither is argued down — both are the reviewer's own prescribed fix.

F1 — hardlinked alias. Correct, and it is the sharper version of the point I only half-made. fd_real_path returns the path the descriptor was opened by, so for a hardlink it reports the innocent workspace alias and is_sensitive_path is asked about the wrong name entirely. There is no symlink for O_NOFOLLOW to refuse and is_symlink() is False, so only the link count sees it. _open_inside now refuses st_nlink > 1, matching pinned_fs.refuse_hardlink_alias and hooks.safe_read_file_bytes_nolink rather than inventing a rule.

F2 — ZIP64. Confirmed against CPython's zipfile before fixing it: a streamed entry has no size at header time, and crossing the limit raises RuntimeError: File size unexpectedly exceeded ZIP64 limit from zipfile.py. force_zip64=True fixes it, which restores what ZipFile.write was doing implicitly. This was a regression my own streaming change introduced, not a pre-existing gap.

Red-before, measured against 3325f5fca with only the production file reverted and the new tests kept:

FAILED ...::test_a_hardlinked_alias_gets_no_descriptor
  AssertionError: assert 14 is None          <- the alias was handed a descriptor
FAILED ...::test_a_streamed_entry_larger_than_the_zip64_limit_still_exports
  RuntimeError: File size unexpectedly exceeded ZIP64 limit   (zipfile.py:1168)

Both pass on this head; test/test_portability.py is 70 passed / 4 skipped locally.

The hardlink test guards itself through four oracles outside the module — the alias is not a symlink, its realpath is itself, is_sensitive_path accepts it, and it really does read back the target's bytes — so it fails for the reason it names and not an unrelated one. The ZIP64 test lowers zipfile.ZIP64_LIMIT instead of inflating the fixture (the branch is selected by size > ZIP64_LIMIT, and a multi-gigabyte artifact would buy nothing but minutes), and test_the_zip64_guard_can_actually_fail proves the lowered limit really selects that branch so the test cannot pass vacuously.

Design and First Principles also name sibling check-to-open sites elsewhere in this module. They are advisory and I have deliberately left them — widening this PR to silence advisory comments is how a bounded security fix stops being reviewable. Happy to take them as a follow-up.

Amended rather than stacked, to stay inside the two-commit rule; the PR body is re-synced to what actually ships.

@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 Sep 7, 2026
@leonlaiyc
leonlaiyc force-pushed the fix/portability-export-junction-containment branch from 8a74e97 to 4f5e14d Compare September 7, 2026 06:19
@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 Sep 7, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 7, 2026
@leonlaiyc

Copy link
Copy Markdown
Contributor Author

The exact-head security [BLOCK-MERGE] on be3caf39b is accepted and fixed at 5663dd30a. The prescribed fix is what shipped: pin each verified ancestor before inspecting the next, then open and reject the leaf reparse point atomically. No further pathname check was added — the previous one was removed.

The finding was right, and here is the measurement rather than a concession. Same racing writer, same instant (the swap fires from inside the walk immediately after the targeted component is verified and before the next filesystem call), run against both builds:

ARM A: be3caf39b (lstat screen, then os.open by name)
  attacker      : rename SUCCEEDED, junction planted
  os.open called: keep.md                    <- the outbound probe
  bytes archived: None                       <- containment refused it, too late

ARM B: 5663dd30a (pinned ancestor walk)
  attacker      : rename REFUSED (PermissionError winerror=32)
  bytes archived: b'ours'

Arm A is the whole finding in three lines: the guard worked — nothing was archived — and the probe went out anyway.

The primitive already existed; this reuses it rather than inventing one. platform_compat.pin_directory opens with FILE_FLAG_OPEN_REPARSE_POINT and a share mode that omits FILE_SHARE_DELETE. Measured on Windows 11 before writing any code:

Probe Result
rename / rmdir a pinned directory refused, WinError 32
rename an ancestor of a pinned directory refused, WinError 5
the same rename once the handle is released succeeds — so the refusal is the pin
pin_directory on a junction NotADirectoryError, at the open
CreateFileW(OPEN_REPARSE_POINT) on a junction handle identity is the reparse point itself, not the target — it did not traverse
plain os.open through that junction succeeds — the probe being removed

_pin_ancestors therefore opens and holds every directory from the resolved root down to the candidate's parent, pinning each before naming the next, so the only path the kernel walks to reach component n runs through components already opened and verified. This is the pattern aws_control/backend/storage.py already uses to hold the path a sandboxed CLI writes through — "a watcher can no longer rename the directory away and plant a junction at its name between our create and the CLI's open".

The leaf. Windows has no O_NOFOLLOW, so os.open follows a reparse point at the final name and no by-name check can close that. platform_compat.open_file_no_reparse is new and small: it opens with FILE_FLAG_OPEN_REPARSE_POINT and reads the attribute off the descriptor, so the refusal and the open are one operation — a fact about what was opened, not a prediction about what a later open will find. It shares the CreateFileW wiring with pin_directory through one private helper, so the two do not carry separate copies of the same security-critical flags. On POSIX it is exactly the O_NOFOLLOW open the code already had, given a name.

Three boundaries, stated because getting one wrong is worse than the defect. The walk starts at the resolved root — pin_directory refuses a reparse point at a name, so pinning the configured spelling of $KIROCREW_HOME would return an empty archive on a host where the crew directory is a link, and a silently empty backup is worse than the leak. It is Windows-only, because a POSIX pin cannot block a rename and there is no outbound probe there to prevent. And no lexical UNC screen is added: a candidate here is the configured root joined with components the export itself enumerated, so it is UNC-shaped only when the root is.

Coverage is on the property, not the mechanism. test_a_racing_writer_cannot_swap_a_pinned_ancestor performs the swap from inside pin_directory at that exact instant and asserts both that the rename failed and that the genuine bytes still came back — a guard that closed the race by refusing everything would pass the first assertion and be useless. test_the_same_rename_succeeds_once_nothing_is_pinned proves the refusal is the pin. test_a_reparse_point_at_the_leaf_is_refused_without_being_followed refuses the link and then proves that exact name is traversable by an ordinary os.open. test_an_ordinary_file_still_opens_through_the_no_follow_open exercises st_nlink, lseek and dup+fdopen on the new descriptor, since on Windows it is now a CreateFileW handle in a CRT wrapper and the archive path depends on all three. test_every_pin_is_released_even_when_a_component_refuses covers the handle-leak failure mode, which would exhaust a large export rather than merely look untidy.

test/test_portability.py 76 passed / 4 skipped on Windows against real junctions. pin_directory's existing consumers re-run clean (test_platform_compat.py, test_aws_control_storage.py, test_pinned_staging.py = 383 passed / 72 skipped); the one failure there is test_version_gate_ignores_a_sitecustomize_decoy_on_pythonpath, reproduced with this branch's production files reverted to be3caf39b — an artefact of the PYTHONPATH override this box needs to run the suite, which is the very thing that test is about. mypy --platform linux: 0 errors in either changed file. black --check: clean on both.

What this still does not close, so it is not read as more than it is. The pins cover the read. They do not cover the enumeration: rglob descends a junction in order to yield what is beyond it, and is_sensitive_path/is_file() resolve by name before _open_inside is reached, so a junction already planted when the export starts is still traversed by the walk itself. That is main's behaviour, unchanged here; closing it means replacing rglob with a prunable walk, a separate change with its own regression surface. The description is re-synced to what ships.

🤖 Generated with Claude Code

@leonlaiyc
leonlaiyc force-pushed the fix/portability-export-junction-containment branch from 5663dd3 to 651241f Compare September 7, 2026 09:43
@leonlaiyc

Copy link
Copy Markdown
Contributor Author

The exact-head security [BLOCK-MERGE] on 5663dd30a is accepted and fixed at 651241f72. Not argued down — the finding is right, and the answer to the question it forces ("can the export enumerate these trees without resolving through an unverified component?") is yes, using a primitive the repository already had.

The finding, reproduced before anything was changed. Every resolving call was wrapped and an export run over a workspace holding one pre-planted junction:

head 5663dd30a (pinned read, rglob enumeration)
  resolving calls through the junction : 14   (4x os.path.realpath, 8x ntpath._getfinalpathname,
                                               2x os.scandir seen via audit hook)
  loot archived                        : False

head 651241f72 (pinned walk)
  resolving calls through the junction : 0
  loot archived                        : False

Both builds archive nothing from behind the junction. That is exactly why "the file was not archived" cannot be the test: if the junction names \\host\share those 14 resolutions are the outbound SMB authentication, and the refusal that follows cannot recall them. rglob descended it; is_sensitive_path(str(fpath)) and fpath.is_file() resolved what it yielded — all before _open_inside ran. This is the residual the previous body disclosed and scoped out; it is closed here rather than disclosed again.

The ordering you prescribed is what shipped. _walk_contained / _walk_pinned replace rglob:

  1. the crew root is pinned first — the kernel walks that name to reach every candidate, so leaving it out would hang the whole export off a swappable component;
  2. a directory is pinned with platform_compat.pin_directory before it is listed;
  3. children are classified from the listing itself, never by a call that resolves them;
  4. a child directory is descended only by pinning it in turn;
  5. the leaf is opened with platform_compat.open_file_no_reparse;
  6. bytes are streamed from that descriptor.

The measurement that made step 3 possible, since it is the load-bearing one and I did not want to assert it from documentation:

probe result
DirEntry.is_symlink() on a junction False — tag is IO_REPARSE_TAG_MOUNT_POINT, not ..._SYMLINK. This is why rglob walked in
DirEntry.is_dir(follow_symlinks=False) on a junction True — it looks like an ordinary directory
DirEntry.stat(follow_symlinks=False).st_reparse_tag 0xa0000003, from the listing, 0 calls naming the junction
pin_directory on a junction NotADirectoryError, 0 calls naming the junction
open_file_no_reparse on a junction OSError, 0 calls naming the junction

So _entry_is_link reads the reparse attribute off FindFirstFileW data Windows has already returned — a child's type and link-ness cost no lookup through that child. It refuses every reparse point rather than only link-shaped ones, which is precisely what pin_directory and open_file_no_reparse already refuse: it classifies what the opens would reject anyway, so it is a cheap skip and never the enforcement.

is_sensitive_path on the pathname is removed, not relocated — that call was 12 of the 14 probes. The same question is still asked in _open_verified, of the descriptor's real path, which was always the load-bearing one because a name can be re-pointed and a descriptor cannot.

_pin_ancestors and _open_inside are deleted rather than kept beside the walk. The walk holds the same chain for a whole subtree instead of re-walking it per file, so keeping both would be two mechanisms doing one job — and strictly fewer opens than before.

The regression asserts on the calls, not the archive. test_a_pre_planted_junction_is_never_resolved_during_an_export wraps os.stat, os.open, os.listdir, os.scandir, os.path.realpath/isfile/isdir/exists/getsize and ntpath._getfinalpathname, and fails if any names the junction or anything below it. os.lstat and os.path.islink are deliberately excluded — they do not follow the final component. An audit hook covers scandir/listdir as well, because pathlib binds scandir at import time and patching os.scandir cannot see rglob's own descent. Red-before, with only portability.py reverted to 5663dd30a and the new tests kept:

FAILED ...::test_a_pre_planted_junction_is_never_resolved_during_an_export
  AssertionError: the export resolved a path through the planted junction (14 calls):
  [('os.path.realpath', '...\workspace\trap'), ('ntpath._getfinalpathname', '...\workspace\trap'), ...]

test_the_recorder_actually_catches_a_probe guards that guard by making the three calls the previous build made on that exact path; it passes on both builds, as an oracle test must.

Everything you listed as preserved is pinned and green: hardlink refusal, ZIP64 streaming, descriptor-bound archive bytes, ancestor-swap protection (test_a_racing_writer_cannot_swap_a_pinned_ancestor, retargeted to the walk), the linked crew-root regression, and pin release on failure. test/test_portability.py is 78 passed / 4 skipped; pin_directory's existing consumers are 383 passed / 72 skipped with the one failure being this box's PYTHONPATH sitecustomize artefact, which does not touch platform_compat.py in this diff.

POSIX is not handed Windows semantics. The walk pins on both platforms, but only half the property is real there: pin_directory on POSIX is O_RDONLY | O_DIRECTORY | O_NOFOLLOW, whose refusal of a symlinked directory is genuine and is exactly what rglob already did — so the exported set is unchanged — while the anti-rename half has no POSIX equivalent and nothing here claims it.

The exported set is byte-identical, measured rather than argued: on a tree covering nesting, EXCLUDE_DIRS, EXPORT_EXCLUDE, .pid and skills/auto, the namelist and the manifest counts match the previous walk's exactly.

One pre-existing defect found while measuring that, and deliberately NOT fixed here. _is_excluded(PurePosixPath(str(rel))) — on Windows str(rel) uses backslashes, so PurePosixPath parses the whole relative path as a single part, and EXCLUDE_DIRS / the EXPORT_EXCLUDE basename set never match for a nested file there (workspace/notes/.env is exported on Windows). That line is untouched by this PR and the behaviour is identical on both sides of it. It is a different defect on a different path, and folding it into a security fix that has been blocked four times would make this unreviewable; it wants its own change. Flagging it rather than leaving it to be found.

Amended rather than stacked, to stay inside the two-commit rule; the PR body is re-synced to what actually ships, and the residual paragraph it used to carry is gone because the residual is.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 7, 2026
@leonlaiyc
leonlaiyc force-pushed the fix/portability-export-junction-containment branch from 651241f to f1dc774 Compare September 7, 2026 12:59
@leonlaiyc

Copy link
Copy Markdown
Contributor Author

Backend Tests (3.12, 3) and Backend Tests (Windows) (3) were red on 651241f72, and it is branch-caused — my own test, not a flake and not inherited. Fixed at f1dc7745a.

FAILED test/test_portability.py::TestTheArchivedBytesAreTheValidatedBytes::test_the_zip64_guard_can_actually_fail
  E  RuntimeError: File size too large, try using force_zip64
  AssertionError: Regex pattern did not match.

The cause is not a typo, and it is worth stating precisely because it hid from every local gate: CPython reworded this exception between the versions in play. 3.10 raises File size unexpectedly exceeded ZIP64 limit; 3.12 raises File size too large, try using force_zip64. My match="ZIP64" pinned the 3.10 spelling, and the only interpreter on my machine is 3.10 — so the suite was green locally and red on CI's 3.12. The test itself was always correct about the branch; it was wrong to assert on a stdlib message's wording.

The repair is one line plus the reason: match="(?i)zip64", which matches both spellings on the single token they share, keeping the assertion specific to the ZIP64 branch without pinning wording the stdlib may reword again.

'ZIP64'      -> [True, False]   # 3.10 msg, 3.12 msg
'(?i)zip64'  -> [True, True]

test/test_portability.py is 78 passed / 4 skipped; flake8 and scripts/check_black_formatting.py clean. The diff is 8 lines in that one test file — no production file touched, so nothing about the pinned-walk behaviour changed. Coverage Gate was derivative of this failure.

GPT's advisory on open_file_no_reparse's docstring is deliberately still not actioned: it carries no [BLOCK-MERGE], and touching the branch for an advisory would churn the SHA and supersede four clean exact-head reviews for nothing.

Amended rather than stacked, to stay inside the two-commit rule.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 7, 2026
`create_export_zip` walked `workspace/`, `plan_memory/` and `skills/` with
`rglob("*")`, which DESCENDS a directory link while the file on the far side
is an ordinary one, so the walk's own `is_symlink()` skip never fired for it.
Neither by-name filter below that skip is a containment test either:
`_is_excluded` is a rule about the archive name, and `is_sensitive_path` asks
whether a path is a PROTECTED location -- it does resolve links, so a linked
`~/.aws` was caught -- never whether it is inside the crew directory. An
ordinary file of the user's, reached through a link dropped in the workspace,
was sensitive to none of them and went into an archive the user hands on.

A resolve-and-compare would answer that for an instant only: `ZipFile.write`
takes a NAME and opens it again, so the file that was checked and the file
that is read are two separate lookups, and a running gateway gives agent
tools write access to that workspace while an export can be triggered.

`_open_verified` inverts the order -- open first, then ask the kernel where
the open thing is via `pinned_fs.fd_real_path` -- and `_add_from_fd` streams
the entry from that descriptor, so check and use address one object. A
hardlink alias, which no path-based guard can see, is refused on the
descriptor's link count; `force_zip64=True` keeps a source over `ZIP64_LIMIT`
archiving as `ZipFile.write` used to.

That settles what may be ARCHIVED. It does not settle what may be TOUCHED,
and on Windows those are different questions: resolving a path whose
component is a link to a UNC share IS an outbound SMB authentication, so a
refusal computed afterwards has already paid the cost it exists to prevent.
No pathname check fixes it -- every by-name check is a check-to-open window
and an adversary that can plant the link chooses when. The names have to be
held rather than inspected.

The enumeration was the last place that still inspected them. Pinning the
candidate's ancestors closed the swap race, but `rglob` had already descended
a PRE-PLANTED junction, and `is_file()` and `is_sensitive_path()` had already
resolved what it yielded, before any of it ran. Measured on this module,
exporting a workspace holding one planted junction: 14 resolving calls went
out through it -- `os.path.realpath` and `ntpath._getfinalpathname` -- while
the export correctly archived nothing from behind it. Nothing being archived
was never the question.

So the walk descends and verifies in one motion instead. `_walk_pinned` pins
a directory with `platform_compat.pin_directory` before listing it -- the
handle omits `FILE_SHARE_DELETE`, so a held directory can be neither renamed
nor deleted, nor can anything above it, and the open refuses to follow a
reparse point, so a junction at the name fails there instead of being
traversed -- then classifies each child from the listing Windows already
returned, where the attributes and reparse tag arrive inline and cost no
lookup THROUGH the child. A child directory is descended only by pinning it
in turn, so the path the kernel walks to reach any component runs entirely
through components already opened and verified, starting at the crew root
itself. This is the pattern `aws_control/backend/storage.py` already uses to
hold the path a sandboxed CLI writes through. The leaf goes through the new
`platform_compat.open_file_no_reparse`, which opens a reparse point AS ITSELF
rather than following it, so the refusal and the open are one operation;
POSIX keeps the `O_NOFOLLOW` open it already had, named.

`_pin_ancestors` and `_open_inside` are gone rather than kept alongside this:
the walk holds the same chain, for the whole subtree instead of re-walking it
per file, so keeping them would be two mechanisms doing one job.

The walk starts at the RESOLVED root, since `$KIROCREW_HOME` may itself be a
link and `pin_directory` refuses a reparse point at a name -- pinning the
configured spelling would return an empty export on such a host.

The exported set is unchanged: on a tree covering nesting, `EXCLUDE_DIRS`,
`EXPORT_EXCLUDE`, `.pid` and `skills/auto`, the archive is byte-identical to
the one the previous walk produced.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@leonlaiyc
leonlaiyc force-pushed the fix/portability-export-junction-containment branch from f1dc774 to 82700d5 Compare September 7, 2026 14:06
@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 Sep 7, 2026
@leonlaiyc

Copy link
Copy Markdown
Contributor Author

The exact-head security [BLOCK-MERGE] on f1dc7745a is accepted and fixed at 82700d562. Not argued down — and worth saying plainly: this PR disclosed that defect and scoped it out, and that call was wrong.

The body argued it was a separate defect on a separate path that would make a five-times-blocked security fix unreviewable. The reviewer's answer is the better one: in a change whose entire subject is "stop the export packaging bytes it should not", shipping a known path that puts workspace/.env into the archive on Windows is not a scope boundary, it is the same bug wearing a different hat. The measurement was already in the body; only the conclusion was wrong.

The defect. _keep_for_export asked _is_excluded(PurePosixPath(str(rel))). On Windows str(rel) is backslash-separated, so PurePosixPath parses the whole relative path as ONE component: .name becomes workspace\notes\.env and .parts has length one. Both exclusion rules then stop matching.

PurePosixPath(str(PureWindowsPath("workspace/notes/.env"))).parts  -> 1 component
PurePosixPath(str(PureWindowsPath("workspace/notes/.env"))).name   -> 'workspace\notes\.env'
PurePosixPath(*PureWindowsPath("workspace/notes/.env").parts).name -> '.env'

The fix is the reviewer's, verbatim: PurePosixPath(*rel.parts) for the filter, and rel.as_posix() for the archive name. Measured end to end on the same fixture tree as the parity run in the body:

before: workspace/notes/.env, workspace/__pycache__/x.pyc, workspace/snapshots/s.md  ALL EXPORTED  (7 files)
after : excluded                                                                     (4 files)

On the archive name specifically: ZipInfo happens to rewrite os.sep today, so that half is not a live bug — it stops the member name depending on that behaviour, next to a filter that must not.

Correction to the body, since it now says something false. It claimed the exported set was "byte-identical" before and after this PR. That was true of the walk rewrite and is no longer true of the PR: on Windows this change now removes files from the archive — every nested .env, .local_secret, sel_hmac.key, telemetry_salt, *.pid, and everything under snapshots/, outbox/, uploads/, __pycache__/. That is the point of the fix, and the body has been re-synced to say so rather than leaving the old claim standing.

Regression, and it is platform-independent. TestExclusionsSurviveAWindowsSeparator drives _keep_for_export with PureWindowsPath instead of staging a real Windows export, so parts and str() differ on every host and the tests fail everywhere if the old spelling returns — this does not depend on the Windows shards to have teeth. It parametrises every EXPORT_EXCLUDE basename and every EXCLUDE_DIRS entry, keeps negative controls so the rebuild cannot start excluding everything, pins the skills/auto rule that also reads parts, and carries a guard-the-guard that reproduces the one-component parse directly.

Red-before with only portability.py reverted to f1dc7745a: 8 failed, 5 passed. Green after: test/test_portability.py 91 passed / 4 skipped. flake8, isort, mypy --platform linux (0 errors) and scripts/check_black_formatting.py clean.

Amended rather than stacked, to stay inside the two-commit rule.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 7, 2026
@iamwhatever
iamwhatever merged commit ea9b6da into kirodotdev:main Sep 7, 2026
74 of 75 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 7, 2026
jingchaodev pushed a commit to jingchaodev/KiroCrew that referenced this pull request Sep 9, 2026
agent_skill_globs re-read and re-security-validated every agent spec
(77 files, ~115 ms) on every call, and it sits on the session-context
build path — paid at every session start, subagent spawn, and
full-context cron/monitor wake, plus the dashboard prompts listing.

Cache the result per (agents_dir, agent) against the same stat-only
directory signature the list_agents cache already uses, caching []
misses too; clear_list_agents_cache() drops both caches. Measured on a
77-agent dir: 115 ms -> 0.5 ms per call; warm build_session_context
87 ms -> ~14 ms.

fix(bench): warm real embedder before KB evaluation (#9295)

Wait for the configured in-process embedding backend in one-shot KB benchmark runs instead of refusing during a cold model load. Preserve non-blocking availability for normal Knowledge traffic and cover blocking and fallback backend contracts.
fix(acp): derive fallback spellings when the model config-option push is rejected (#9281)

The claude adapter advertises model variants under spellings its 'model'
config option does not accept (prefixed provider ids with a [1m] window
marker), and the fold in resolve_wire_model_id only works against a warm
advertised-model cache. On a cold cache the raw id reached the wire, the
adapter rejected it, and the session reset onto the default with no
explanation.

Derive fallback candidates from the id itself at both config-option wire
sites and let the adapter judge each: verbatim, then prefix-stripped, then
window-stripped. An explicit switch (set_model) raises the typed
AcpModelUnavailable instead of a generic AcpError when every spelling is
refused; a startup application of an inherited value keeps the session on
the backend default, mirroring the withhold contract and the effort
push's value-rejection ladder.
fix(usage): surface refused-transcript count so UNC home stops reading zero (#9254)

On a Windows roaming-profile (UNC) home the usage page counted zero sessions
silently: every transcript is refused by validate_file_path and the count was
only logged server-side. Carry refused_transcripts in the /api/usage/kiro
payload and render a warning banner on the usage page so the zero is shown as
incomplete rather than as a fact. Does not admit the sessions dir to the UNC
gate (that trust decision is open issue #8079); the refusal itself is unchanged.

Closes #6733
fix(dashboard): mark inherited default agent on composer chips (#8770) (#9253)
fix(mcp): expand header value references in the remote probe (#9249)

* fix(mcp): expand header value references in the remote probe

The dashboard's remote MCP probe sent configured headers verbatim, so a
static auth header whose value carries a documented ${VAR}/${env:VAR}
runtime reference reached the server as literal text and was correctly
rejected. Because _needs_authorization treats any Authorization key as a
supplied credential, the 401 rendered the row Error / HTTP 401 with a
hint advising the user to delete a header that authenticates fine in
every session.

The probe now resolves header value references through the gateway
rewriter's existing declared-env expander (same regex, same
credential-filtered source view, unresolved stays literal for kiro-cli
parity), uses the expanded map for the request and for
_needs_authorization's sent-headers view, and threads it into both
redact_mcp_error call sites so an error echoing a resolved secret is
scrubbed by the exact-value layer. An Authorization value still carrying
an unresolved reference supplied nothing, so it no longer suppresses
needs_auth.

Fixes #9206

* fix(mcp): scrub individually resolved placeholder values in probe errors

A partially expanded header value (${TOKEN}${MISSING}) sends
'<resolved>${MISSING}', so neither the full sent value nor the
Authorization suffix in redact_mcp_error's scrub set matches a server
echoing only the resolved fragment. _expand_header_placeholders now also
returns each individually resolved placeholder value, and both redaction
call sites pass them as a new extra_values leg, folded in under the same
credential length regimes (below the minimum length a value is skipped,
since no boundary rule separates it from prose words).

Adopts the GPT 5.6 review lane's blocking finding on
mcp_discovery.py:680.

---------

Co-authored-by: dwu96 <dwu96@amazon.com>
perf(dev-fleet): skip npm ci and rebuild on a backend-only sync (#9227)

A non-edition Pull + Build appended npm ci and npm build + stage
unconditionally, so a sync that moves only Python still deleted and
reinstalled website/node_modules from an unchanged lockfile and re-ran a
full vite build reproducing a byte-identical bundle.

The skip decision is made post-fetch by the preflight step -- the only
window where the incoming ref is pinned and the worktree has not yet been
merged to it. The preflight signals the verdict by exiting a reserved code
(EXIT_FRONTEND_SKIP) that the runner trusts ONLY from the preflight step's
label; the runner then suppresses the npm ci and build+stage steps, holding
the verdict in its own state. A worktree-run step (a pip lifecycle script)
exiting the same code is demoted to a plain failure, so it cannot forge a
skip and ship stale assets. Skipping a step also skips its node_modules
transaction, which must not run for a no-op or it would delete the tree.
feat(chat): Formatted/Raw toggle on markdown content cards (#9224)

Adds a Formatted | Raw segmented toggle to markdown content cards in the chat transcript, matching the control tool detail cards carry. Formatted renders through the transcript's markdown pipeline; Raw is the verbatim source with the edit affordance. Formatted is the default, overridable via a new Chat setting. Closes #9196.
fix(dashboard): swipe navigation for multi-image viewer (#9190)

The image viewer opens with a SET -- dispatchLightbox() collects every
img[data-lightbox-image] in the nearest [data-image-scope] -- but the only way
through it was ArrowLeft/ArrowRight. On a phone there is no keyboard, so every
image after the first was unreachable and nothing on screen said the set existed.

A horizontal drag now pages through the set. The one-finger overlay gesture locks
an AXIS once it crosses the slop, then either pulls down to dismiss (unchanged) or
sideways to page, so a diagonal drag can no longer do both. Four product decisions,
each matching an existing decision in the same component rather than inventing one:

* Commit on DISTANCE only, like the dismiss path, and at a shorter threshold (64px
  vs 96px): paging is reversible, a dismiss destroys the viewing context, so paging
  can commit on less travel.
* Rubber-band at index 0 and at the last image, reusing the divisor the upward
  dismiss drag already used -- a silent no-op at the ends reads as a broken gesture.
* Show position in the set ("2 of 4") on an aria-live pill. Without an affordance
  the gesture is invisible, and this is also the first thing to announce the image
  change to a screen reader.
* Own the gesture only at fit zoom, exactly as dismiss does; above fit a horizontal
  drag is already pan, handled on the <img>.

Owning the horizontal axis here is safe because the app-wide nav drawer yields to
any element whose computed touch-action is none, which the overlay already set to
take page zoom. The keyboard path, the pinch, the double-tap and the desktop
click-to-close are untouched.

Closes #5799
fix(security): never waive exfil redaction for model-authored URLs (#7820) (#9189)

A GitHub issue-prefill link is redacted in chat as
`[REDACTED: suspicious URL to github.com]`, which #7820 reports as a false
positive. Two earlier rounds of this change waived the aggregate query-LENGTH
signal for that shape -- first on the validated shape alone, then additionally
pinned to this project's own tracker. Both are withdrawn. Neither was safe, and
the difference between them was only who reads the payload.

What reaches `redact_exfiltration_urls` is MODEL-AUTHORED text:

  injected content steers the model into emitting a prefill URL whose `body`
  carries percent-encoded private context; the waiver skips the length check;
  the link renders as the familiar "file an issue" affordance; the user submits
  it; and the issue is PUBLIC, so the attacker reads it.

Pinning the repository does not close that -- this project's tracker is
world-readable by design. A URL's shape says nothing about who authored it, and
a marker placed IN the text travels in the channel the injection controls. So no
validation performed on a model-emitted URL can establish provenance, and that
is a property of the class rather than of any one spelling of the check.

- Remove the frontend waiver: `isPrefilledIssueUrl` and the `EXFIL_ISSUE_*`
  constants in `website/src/utils/sanitize.ts` (they landed for #7824). The
  aggregate-length signal there is unconditional again. This is the production
  change in this commit.
- The BACKEND needed no deletion after rebasing onto #9183, which split
  `security.py` into a package: `security/exfil.py` was re-derived from a base
  that never carried the waiver, so its length gate is already unconditional.
  What lands there is the reason it must stay that way, recorded at the gate so
  the next person with a long legitimate URL narrows the heuristic for every
  host instead of carving out a shape.
- Deliver #7820's feature through the TRUSTED STRUCTURED CHANNEL the product
  already ships, rather than through the redactor. `diagnostics._issue_url`
  assembles the prefill query from structured fields (version, channel,
  what-happened, context, install) with `urlencode`; it travels as
  `BundleResult.github_issue_url` on a JSON response no redactor scans; and
  `ReportProblemModal` / `ReportProblemCard` render their own
  `<a href={result.github_issue_url}>`. Nothing on that path is text a model
  wrote, so nothing on it needs a waiver. `diagnostics.py` already documented
  this split, with `terminal_issue_url` as the bounded variant for paths that DO
  get relayed through prose.
- Repoint the parity guard from pinning a carve-out to pinning its ABSENCE on
  both halves, reading each enforcing source at run time. The backend sweep runs
  over the whole `security/` package rather than one module, because a waiver
  reintroduced in any of the nine modules or in the facade would be just as live
  -- the single-file path this replaces was left pointing at a deleted file by
  #9183, which is exactly the failure mode. The length comparison is asserted at
  its own site on each side, so a waiver spelled with fresh identifiers still
  fails, and the structured seam is asserted present because deleting the waiver
  is only free while that seam exists.

Red-first against the pre-fix head: a prefill link to this project's own tracker
with an encoded payload rendered as a live link.

The withdrawn allow-list held GitHub's classic prefill keys, while the trusted
builder uses issue-FORM keys, which that list never contained -- so the waiver
only ever served links the model typed, the exfiltration surface and nothing
else.

Refs, not Closes: #7820 asks for a narrower heuristic and also reports
`monitorportal.amazon.com`. Both are still redacted in chat, and a test pins
them as getting the same verdict. Narrowing aggregate query length is a per-host
security-ceiling decision on its own merits, and a per-shape escape hatch is not
a substitute for it.

Refs #7820
feat(connections): default-on launch with explicit card set (#9149)

The Connections gallery was merged on main but held behind an opt-in
`connections_ui: true`, so a shipped build reached it only after a
hand-edit of the instance's config.json. Flip that default: the gallery
is now on for every install that never touched the flag, while
`connections_ui: false` remains the escape hatch that empties the
Services panel and puts chat back as the only authorize prompt.

The key discovery is that holding GitHub back cost NO new mechanism.
A per-provider launch gate already exists on both sides of the seam --
`launch_gate_passed` in src/kiro_crew/connections/registry.json, filtered
by `get_visible_providers()` in registry.py and by `CONNECTION_PROVIDERS`
in website/src/pages/connections/registry.ts -- and GitHub is already
`launch_gate_passed: false` there because its OAuth-app registration
under the kirodotdev org is outstanding. So the launch set is the six
providers those filters already produce (Notion, Linear, Atlassian,
Stripe, Vercel, GitLab), and the flip adds zero production lines for
per-provider gating. `test_only_gated_launch_services_are_visible`
already pins GitHub's exclusion on the backend; this change adds the
matching assertion on the frontend's exported list.

The predicate keeps the old "never guess from a sloppy value" rule and
points it at the safe direction, which is now off. An absent key is ON,
an exact `true` is ON, and everything else present -- including a
hand-edited `"false"` -- is OFF, so an opt-out cannot silently fail to
take. A config that has not been read yet (undefined, and a failed
fetch) stays OFF: the opt-out lives in that config, so opening before
reading it would flash a gallery the user disabled and fire its status
queries on their behalf. That preserves today's loading behavior exactly
rather than introducing a new transient.

KNOWN DEPENDENCY, not fixed here: on a live gateway the flag never
reaches the browser at all, because GET /api/config/kirocrew strips
unknown top-level keys (`_masked_config_dict` pops `_extra_sections`).
The default-on half of this change works regardless -- it is the
absent-key path. The `connections_ui: false` escape hatch only becomes
functional once fix/connections-ui-flag-roundtrip makes the key
schema-known. Landing this before that fix therefore ships a gallery
with no working opt-out, which is why the flip is merge-gated on a human
re-test.

Prose that asserted the feature was unreleased is updated in the same
pass so the code no longer contradicts itself: the hook docstring,
CapabilitiesPage's flag docstring, ConnectionsPage's `servicesEnabled`
docstring and its empty-list comment, and McpTab's mint-engine comment.
ConnectionsPage's parameter default stays `false` so a caller that omits
the prop cannot open a gallery by omission.

Tests: ConnectionsUiGate.test.ts is rewritten for the new default
(absent key opens, explicit false closes, unread config closes, sloppy
values close) and gains a launch-set block asserting GitHub is absent
and every offered provider passed its gate. McpTab.test.tsx re-points
its baseline mock at the shipped default, converts the chat-prose
fallback case to an explicit `connections_ui: false`, and adds a case
proving the in-place sign-in reaches a managed row with no flag key at
all. No user-facing strings were added, so no i18n catalog changes.
test(issue-radar): pin auto-nudge crew turns resolve their own identity (#9071)

An Issue Radar crew driven by an auto-nudge cycle reaches its ledger
tools through the same _run_chat entry a human turn uses, which resolves
identity as effective_session_key(slot) and hands it to the one shared
publish_turn_identity writer. So a nudge turn and a direct turn on the
same slot resolve the SAME session identity, and the strict gate lets
the crew through -- the property #5905 assumed was broken.

This is the positive twin of the existing subagent refusal test: a
subagent resolves to its PARENT slot and is refused; an auto-nudge crew
is the same principal re-entered on a timer and is admitted. Nothing
pinned that the nudge fire path keeps routing through the shared writer,
so a future refactor of _fire_dashboard_nudge could silently reintroduce
the confusing refusal. These regression tests assert the property (same
identity, one shared writer), not the call ordering.

Also prunes the file from the black shrinking-baseline now that it is
black-clean.
fix(portability): keep the export archive inside the crew directory (#9070)

* fix(portability): keep the export archive inside the crew directory

`create_export_zip` walks `workspace`, `plan_memory` and `skills` with
`rglob("*")` and skips an entry that `is_symlink()`, so that an export never
carries bytes from outside the crew directory. That skip is blind to the escape
that costs the most: `rglob` DESCENDS a directory link, and the file on the far
side is an ordinary one — `is_symlink()` false — so it is written straight into
the archive. On Windows the link is typically a junction, which `is_symlink`
does not report at all, and a junction needs none of the privilege a directory
symlink needs there.

The two filters below the skip do not catch it either. `_is_excluded` and
`is_sensitive_path` both read the LEXICAL path, which runs through the link's
own name and therefore looks like ordinary crew content — so a sensitive file
behind a link passes the sensitivity check that exists to stop exactly this.

Measured on unpatched main with a real junction: `workspace/memory/linked/
not-ours.md` appeared in the export's namelist, sourced from outside the crew
directory. The consequence class is content the user then hands to someone else,
since an export archive is made to be moved off the host.

Fixed by requiring the RESOLVED path to stay under the resolved crew directory —
the repo's existing idiom (`apps/backend.py:651`). Resolving is what covers both
shapes at once: it follows every reparse point on the way down and answers where
the bytes actually live. `mc` is resolved once so a legitimately linked
`$KIROCREW_HOME` does not reject the whole export. The `is_symlink()` skip is
kept as-is; this adds a layer rather than replacing one.

The import side of this module is untouched.

`test_export_skips_symlinks` cannot cover this — it plants a link that IS the
entry, and it `pytest.skip`s where symlinks cannot be created, i.e. on the
platform where the junction spelling lives. The new tests use
`conftest.make_dir_link` and need no privilege.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(portability): archive the descriptor that was validated

`create_export_zip` walked `workspace/`, `plan_memory/` and `skills/` with
`rglob("*")`, which DESCENDS a directory link while the file on the far side
is an ordinary one, so the walk's own `is_symlink()` skip never fired for it.
Neither by-name filter below that skip is a containment test either:
`_is_excluded` is a rule about the archive name, and `is_sensitive_path` asks
whether a path is a PROTECTED location -- it does resolve links, so a linked
`~/.aws` was caught -- never whether it is inside the crew directory. An
ordinary file of the user's, reached through a link dropped in the workspace,
was sensitive to none of them and went into an archive the user hands on.

A resolve-and-compare would answer that for an instant only: `ZipFile.write`
takes a NAME and opens it again, so the file that was checked and the file
that is read are two separate lookups, and a running gateway gives agent
tools write access to that workspace while an export can be triggered.

`_open_verified` inverts the order -- open first, then ask the kernel where
the open thing is via `pinned_fs.fd_real_path` -- and `_add_from_fd` streams
the entry from that descriptor, so check and use address one object. A
hardlink alias, which no path-based guard can see, is refused on the
descriptor's link count; `force_zip64=True` keeps a source over `ZIP64_LIMIT`
archiving as `ZipFile.write` used to.

That settles what may be ARCHIVED. It does not settle what may be TOUCHED,
and on Windows those are different questions: resolving a path whose
component is a link to a UNC share IS an outbound SMB authentication, so a
refusal computed afterwards has already paid the cost it exists to prevent.
No pathname check fixes it -- every by-name check is a check-to-open window
and an adversary that can plant the link chooses when. The names have to be
held rather than inspected.

The enumeration was the last place that still inspected them. Pinning the
candidate's ancestors closed the swap race, but `rglob` had already descended
a PRE-PLANTED junction, and `is_file()` and `is_sensitive_path()` had already
resolved what it yielded, before any of it ran. Measured on this module,
exporting a workspace holding one planted junction: 14 resolving calls went
out through it -- `os.path.realpath` and `ntpath._getfinalpathname` -- while
the export correctly archived nothing from behind it. Nothing being archived
was never the question.

So the walk descends and verifies in one motion instead. `_walk_pinned` pins
a directory with `platform_compat.pin_directory` before listing it -- the
handle omits `FILE_SHARE_DELETE`, so a held directory can be neither renamed
nor deleted, nor can anything above it, and the open refuses to follow a
reparse point, so a junction at the name fails there instead of being
traversed -- then classifies each child from the listing Windows already
returned, where the attributes and reparse tag arrive inline and cost no
lookup THROUGH the child. A child directory is descended only by pinning it
in turn, so the path the kernel walks to reach any component runs entirely
through components already opened and verified, starting at the crew root
itself. This is the pattern `aws_control/backend/storage.py` already uses to
hold the path a sandboxed CLI writes through. The leaf goes through the new
`platform_compat.open_file_no_reparse`, which opens a reparse point AS ITSELF
rather than following it, so the refusal and the open are one operation;
POSIX keeps the `O_NOFOLLOW` open it already had, named.

`_pin_ancestors` and `_open_inside` are gone rather than kept alongside this:
the walk holds the same chain, for the whole subtree instead of re-walking it
per file, so keeping them would be two mechanisms doing one job.

The walk starts at the RESOLVED root, since `$KIROCREW_HOME` may itself be a
link and `pin_directory` refuses a reparse point at a name -- pinning the
configured spelling would return an empty export on such a host.

The exported set is unchanged: on a tree covering nesting, `EXCLUDE_DIRS`,
`EXPORT_EXCLUDE`, `.pid` and `skills/auto`, the archive is byte-identical to
the one the previous walk produced.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
feat(knowledge): scope local_knowledge_search to a namespace (#9032)

The knowledge store already models a namespace label on items (with an index), and the dashboard already lists, assigns and browse-filters by it. Search was the one verb the label never reached: HybridRetriever and local_knowledge_search scoped only by source_id.

Add an optional namespace filter to the search seed legs (keyword + vector), mirroring the existing source_id scoping. namespace is a plain items.namespace column match -- a relevance/organisation filter, not a security boundary -- and composes with source_id. The graph leg stays unfiltered, as it is for source_id.

Refs #8266

Co-authored-by: gh-autofix#2887 <chenmingwei23@users.noreply.github.com>
fix: persist the deferred-note hold with the slot so it survives a restart (#4093) (#8982)

POST /api/chat/slots/{slot}/note replies 200 with visibleDeferred: true for
a note held during a running turn, but both halves of the hold lived only
in _ChatSlot._deferred_notes — a gateway restart between the 200 and the
next turn silently voided the delivery promise.

The hold now persists through the slot's own metadata line under one
invariant: retirement is ROW-DERIVED. Every note carries an id; the flush
stamps each delivered inject row with it (meta.noteId) and records
rebind-dropped ids on the slot; the full save — reading the on-disk and
live holds UNDER the history lock — retires exactly the entries whose
rows are in the window it writes (or whose ids were dropped) and keeps
everything else. Row and retirement land in one atomic file replace; the
drop records are consumed only AFTER that write commits, since a dropped
note's row never exists and the record is its only retirement path.

- enqueue (durable-before-200): asyncio.to_thread + update_metadata_if,
  everything read inside the lock-time guard; the write MERGES by note id
  (union_deferred_notes), pins the posted note (ensure=) so a racing
  turn-end flush cannot yield a 200 with no durable copy, and pins the
  TARGET to the history key authorized at enqueue, re-verified under the
  store lock — a cron/workflow rebind in the persist window is refused
  (uniform not-found shape) instead of writing app content into a foreign
  transcript's metadata. The union never evicts: at the 2x ceiling the
  NEW note is refused (429). On EVERY failure branch, a rollback that
  finds the note already drained means a flush DELIVERED it — the 200
  stands, because any error would make the caller re-post a line the
  user already saw. Other failures roll back BY IDENTITY and answer a
  retryable 503 (including an UNREADABLE record)
- deferred notes are bounded at the ENQUEUE boundary (413 over 4000
  chars); the durable copy is persisted VERBATIM, never truncated
- both restore paths replay the hold up to the durable CEILING (2x the
  live cap — every durable entry is a 200-acknowledged note); restored
  notes are sanitized fail-closed (no session stamp -> dropped;
  over-bound content -> dropped; malformed context half dropped alone)
- the flush never writes metadata; a crash between flush and save
  re-delivers on restore (at-least-once)
- docs updated in the same commit (App Kit api-reference, session.md,
  endpoint docstring): do not re-post after a restart; 503 = retry,
  413/429 = boundary refusals, 404 = ownership/rebind refusal

_pending_context (the /context queue) stays memory-only: only the context
halves embedded in held notes ride the same metadata shape naturally.

Closes #4093

Co-authored-by: Nick Bowers <nrb@amazon.com>
feat: speak replies with the host's own engine, no install needed (#8957)

Text-to-speech needed an install before it could say anything: Piper wants a
binary and a voice model on disk, Polly wants AWS credentials, so turning on
auto-speak on a fresh machine produced silence and a settings panel with two
paths that both start with homework.

Add a third provider, `system`, and make it the default. It drives the speech
engine the operating system already ships -- `say` on macOS, System.Speech
through Windows PowerShell 5.1, `espeak-ng` on Linux when present -- so
auto-speak works with nothing downloaded and nothing configured. Linux is the
one platform where the engine can be absent; that is reported as unavailable
with the package to install rather than failing silently at synthesis time.

The engine is resolved through `trusted_system_bin`, not PATH, so a shim in an
agent-writable directory cannot be handed model output, and the spoken text
never reaches argv: `say` and `espeak-ng` read it on stdin, and the Windows path
writes it to a temp file that a constant base64 -EncodedCommand script reads,
so no quoting decision is ever made about model output.

This provider deliberately does NOT route through `wrap_argv`. Windows has no
sandbox backend, so a wrap fails closed on the one platform whose built-in
engine users depend on, and there is nothing to confine in an OS component
resolved from a directory the user cannot write. Piper keeps its wrap: it runs a
downloaded model through a third-party binary. A test pins the distinction.

Also fixes two things the new provider surfaced: `_resolve_piper_binary` looked
for `~/piper-venv/bin/piper` on every platform, so a correct Windows install was
never found (`Scripts\piper.exe`), and the module documented Piper as having no
Windows build, which the `piper-tts` wheel has published since 1.3.0.
fix(config): hold the sidecar advisory lock in KiroCrewConfig.save() and offload async callers (#4767) (#8906)

KiroCrewConfig.save() was an unlocked whole-document replace: its rename
could land inside an update_config_locked holder's read-modify-write (CLI
writer, boot refresh, second gateway), silently discarding the other
writer's change -- every field in the document exposed.

Two halves, landing together per the recorded failure modes of the first
attempt (#4371):

HALF 1 -- lock the writer. The sidecar acquire in update_config_locked is
extracted into _config_write_lock() and save() now writes under it: the
SAME <config>.lock sidecar, beside the resolved symlink target, so both
writer families contend on one lock and the lifecycle stays one shared
file (no new residue -- the Windows orphan concern from #4371). The write
itself stays atomic + mode-preserving via write_config_atomically, and
the overlay-subtraction content is untouched. save()'s docstring now
states the staleness contract plainly: it publishes an in-memory
snapshot, so it is ONLY for single-flow callers with no suspension
between load and save (CLI one-shots, the boot default-config write);
read-modify-write flows belong on update_config_locked.

HALF 2 -- dashboard writers become DELTA read-modify-writes, off-loop.
Every .save() call site was enumerated and classified. Coroutine callers
no longer call save() at all: each persists the keys it owns as a delta
mutate through update_config_locked -- read, re-check, and write inside
ONE flock hold -- dispatched off the loop via run_config_write (the
transaction shape its docstring prescribes) or, where the asyncio config
lock is already held, via the module's cancellation-draining
_drained_to_thread:

- dashboard/handlers/updates.py api_log_level: delta on
  agent.log_level
- dashboard/handlers/files.py workspace create/update/delete: delta on
  the one workspaces entry, with the state-dependent preconditions
  (name/dir collision, default-workspace and agent references) re-run
  against the document as read inside the lock and surfaced as 4xx
  conflicts. The copy_from tree is staged only after ALL path validation
  passes, installed inside the locked mutate (atomic os.replace, or a
  merge copy when the destination pre-exists), and every cleanup of a
  staged tree runs in a worker, never inline on the loop
- dashboard/handlers/agents.py agents-sync + agent-create: delta on the
  agents entries (adds re-checked, package/aim prunes re-derived, name
  conflicts re-checked against the in-lock document), via
  _drained_to_thread under the held asyncio lock
- dashboard/handlers/onboarding_import.py: both former manual-lock sites
  route through run_config_write; the state PUT is a delta on
  dashboard.import_onboarded; the unused local _get_config_lock wrapper
  removed
- cli_server.py gateway-boot default-config write: asyncio.to_thread
  (file absent, nothing to lose, no loop-side writers yet)
Sync CLI/wizard callers (cli_commands, cli_config, cli_cloud,
cloud/wizard) stay on save(): single-flow, no suspension between load
and save. crew_chat.py st.save()/self.save() are CrewStore, and mochi
stats_service self.save() is its own persistence -- not KiroCrewConfig.

Tests: red-before-green concurrency pair (save waits on a held sidecar;
a locked writer landing inside save's critical window survives), sidecar
lifecycle (only the one shared .lock beside config.json; symlinked
config locks beside the target), in-lock precondition re-check suite for
the workspace handlers (stale snapshot passes, fresh on-disk document
refuses, unrelated entries survive the delta), staging-lifecycle tests
(no destination mutation or staged residue on conflict or failed
validation), a runtime off-loop probe on the log-level handler, and a
self-tested AST ratchet forbidding any coroutine from calling
KiroCrewConfig.save() inline.

Closes #4767

Co-authored-by: Nick Bowers <nrb@amazon.com>
fix(members): dispatch server carries the gateway home override (#8611)

The crew member DM session's kirocrew-dashboard MCP entry carried only the
session key (and, since #8837, the bound port). The server resolves *which
gateway* to call from its data home, so on any install where KIROCREW_HOME is
set -- a pod, a second profile -- it presented the member's identity to the
default home's gateway, which has no such member slot and refused every verb
as caller_unidentified while tools/list looked healthy.

Carry the same home override every managed Crew server already carries
(_managed_mcp_env), through the same helper so the two cannot drift. On a
default install the helper returns {} and the emitted entry is unchanged.

The per-member conversation index (#8612) no longer rides in this PR; it
travels with its consumer, #8613, which is stacked on this branch.
feat(members): open the last member on arrival, mirror it in the URL (#8546)

The Crew Members page landed on an empty column every visit and forgot
which member was open when the user navigated away and back. Now:

- A visit that names no member opens the remembered one, else the first
  row in display order — never the empty column.
- The last member opened is remembered per browser (mc-members-last-member,
  via safeStorage), so leaving for Sessions/Settings and returning, or a
  reload, lands on the same conversation. A remembered member that was
  deleted or renamed falls back to the first row without an error.
- The open member rides the URL (?member=<name>): a reload keeps it and a
  link lands on one. Switching members REPLACES the entry — the page holds
  one history entry however many members are visited, so Back leaves it in
  one press, the Sessions sidebar's rule; only the below-md roster->thread
  step pushes. The value is the exact crew name, not the slug — the slug
  is lossy and would misroute Oncall to oncall. A link naming a member
  that is gone takes the same fallback and says so in a warn-toned status
  above the thread, leading with the swap ("Showing X — “Y” is no longer
  on the roster."; 13 catalogs + en-XA): the user asked for someone
  specific, and a silently mounted other thread is the misroute this page
  exists to prevent. The stand-in opened by that fallback is the page's
  choice, not the user's, so it does NOT become the memory — one dead
  link cannot overwrite the member the user had chosen.
- Below md the page stays a two-level list->detail navigation: no
  ?member= IS the roster, so no auto-open there (same rule as
  SidePanelLayout's remembered tab). A stale ?member= returns to the
  roster with the same notice above the list. The header back pops the
  entry the roster pushed (no duplicate roster entry in history) and
  drops the param in place for a deep link, which has no roster behind it.

Tests cover default, restore, stale fallback (memory: silent; URL: with
notice on both sides of md, retired on the next open, memory preserved),
URL-over-memory, click writes URL+memory, a driven-history walk over two
members that leaves the page in one Back, and the below-md back semantics
(the useNavigate mock records AND performs against the MemoryRouter).
fix(pod): scope pod kiro-cli oauth grants to the pod home (#8528)

A pod isolates KIROCREW_HOME and KIRO_HOME but deliberately keeps the real
HOME, and kiro-cli derives its MCP OAuth artifact directory from the spawned
process's own $HOME. So a pod REUSED the operator's machine-level grants (a
provider card read Connected from a grant minted on the real machine) and a
grant minted INSIDE a pod outlived pod down as a real, durable credential.
Both break test fidelity and the destroy-grants-after-each-smoke-test
requirement.

Two halves, one shared resolver:

- mcp_grant.kiro_oauth_cache_dir() -- the single default all four callers
  (mint, status, disconnect, mcp_discovery's remote probe) reach with no
  explicit cache_dir -- now resolves through the new
  config.paths.kiro_oauth_cache_home(), which honours KIROCREW_OS_HOME and
  rejects the same unsafe targets as kiro_home()'s KIRO_HOME. This moves the
  pod gateway's own grant reads onto the pod's tree.
- acp.client._apply_pod_home_remap(), applied identically at both spawn
  transports, remaps a pod-spawned kiro-cli child's HOME/USERPROFILE to that
  same directory. kiro-cli offers no env override for just its OAuth cache,
  so remapping the child's HOME is the only way to move its own WRITES.
  Gated on KIROCREW_POD=1 plus positive membership in
  ACP_BACKENDS_POD_HOME_REMAP -- its own set, not a reuse of the
  internal-sandbox one, because "carries its own OS sandbox" and "relocating
  HOME moves its credential store" are different questions (harness-parity H6).

Sign-in still works: pod.runtime._seed_pod_os_home create-only stages the
AGENT RUNTIME's own identity store -- the per-platform paths derived from
identity_stores.store_mappings(), which is where the harness actually resolves
its access token -- into the pod tree at boot. No host .aws/sso/cache contents
are copied: an earlier revision staged those and it was deleted, so a pod's
.aws/sso/cache starts EMPTY and holds only grants that pod itself mints. A pod
therefore cannot be pre-authorized to a provider nobody consented to inside
it, by construction rather than by a filename glob.

A boot viability probe (agent_sdk.pod_child_probe) is the last gate before
serving: it spawns the child through the same confinement production uses
(env scrub, sandbox wrap, cgroup scope, rlimit preexec) and routes an
unbootable child through _refuse, so a signed-out or dead child makes pod up
fail loudly with a terminal exit code instead of serving a broken pod.

AWS_CONFIG_FILE / AWS_SHARED_CREDENTIALS_FILE are deliberately NOT exported
into the pod child. An earlier revision pinned both at the real home so a pod
turn could still reach the operator's profiles; that made each name an alias
for a path the sensitive-path keystone fences, and three review rounds each
closed one spelling of the retrieval. The alias was deleted at its source
instead -- security.py records the full reasoning, including why a name-based
deny rule is defensible for the variables that hold a SECRET and not for the
ones that hold a PATH.

The real passwd home stays fenced: security.py's matchers run in the gateway
process against its own Path.home(), and the remap only ever mutates the dict
handed to the child spawn, never os.environ.

The os-home tree nests under the pod home, so cleanup_home's existing pod
down sweep reclaims a pod's grants with everything else.
feat(chat): add inline paste token composer (#8310)

Add a default-off Lexical composer path with atomic inline paste nodes, editor-neutral selection and focus controls, shared clipboard policy, lazy-load rollback, and focused regression coverage while preserving the textarea fallback.
fix(slack): report the real dashboard link-click window, not the constant (#7265)

`generate_token` mints `exp = now + min(LINK_WINDOW_SECS, session_ttl)` so a
link can never authenticate past the session it grants. Both Slack surfaces
that report that window still printed the unclamped constant, so
`/kirocrew dashboard 1m` promised "Click within 5m" about a link that dies in
one — a 5x overstatement of a window the user has to act inside.

Report the clamped value at both reporters: the DM built in
`allowlist.send_dashboard_link` and the ephemeral block built in
`events._handle_dashboard`. For a full-length caller both strings are
byte-identical to before, because the clamp only ever tightens.

Original change authored by Leon (@leonlaiyc).

Co-authored-by: Leon <276034861+leonlaiyc@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
feat(cron): allow assigning a Schedule-page folder when creating a cron (#7249)

cron_add/cron_update (MCP) accept a 'folder' argument (name or id; a
missing name is created through POST /api/cron-folders, the dashboard's
own endpoint, so the create shares the Schedule page's lock and
in-memory list). 'kirocrew cron add' gains --folder (existing folders
only). App manifests can set 'folder' on a cron entry (a NAME, resolved
at registration; unresolved degrades to ungrouped with a warning and is
re-applied on the next enable, so the assignment survives the
disable/enable delete-and-recreate cycle).

Shared read-only resolver in cron.py (load_cron_folders /
lookup_cron_folder_id): cron_folders.json stays dashboard-owned; no
non-dashboard surface writes it directly.

Co-authored-by: Aurélien Andrey <aurand@amazon.fr>
feat(session): recover warm-pool hits for effort-override sessions (#7096)

Apply reasoning effort overrides post-claim on warm-pool processes via provider.change_effort, keeping the warm-pool hit path active for slots carrying reasoning effort overrides.

Fixes #6248
feat(meetings): import a recording into a meeting (#5741)

POST …/{id}/import takes a host path to an audio file, transcribes it with
the gateway's own batch speech-to-text, and dispatches each line through the
same admission transaction live speech uses, so an imported recording is
persisted to the transcript and reaches the agents exactly as if spoken.

Every dispatched line requires the SESSION OBJECT admitted at import start —
a meeting id is a name, not an identity — so a meeting stopped, deleted, and
recreated under the same id mid-import gets a 410 (meeting_session_replaced)
instead of the old recording's lines.

A recording that would split into more than MAX_IMPORT_LINES lines is
refused whole with 413 (recording_too_long) rather than silently truncated:
a capped import that returns success while the recording's tail is missing
is data loss the user cannot see.

Original feature authored by Kai Mitsuzawa (kaizawa97). Rebase onto main,
locale conflict resolution, the session-identity fix, and the overflow
rejection by Kiro Crew.

Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
fix(issue-radar): open lock sidecars non-truncating before the acquire (#9275)

The 18 lock context managers in issue_radar's store.py and crew_store.py
opened the lock sidecar with open(lock_path, "w") and only then handed the
descriptor to platform_compat.file_lock(..., exclusive=True). "w" truncates
at open, before the lock is held. On Windows the acquire routes to
msvcrt.locking, and a truncating open of a lock file whose first byte another
holder already locked raises a sharing violation instead of waiting, so the
contending acquirer fails before it reaches the lock and the mutual exclusion
silently does not happen. POSIX flock tolerates it, which is why it is
invisible on Linux.

Each site now ensures the parent dir, lock_path.touch(exist_ok=True), then
open(lock_path, "r+") -- writable (msvcrt.locking needs it) but not
truncating -- acquiring on that handle exactly as before. Same shape and
rationale as work_ledger._open_lock (#9237) and session_pid.py (#9250).

Refs #9248
fix(apps): read the answer to the stop the Job SDK already performs (#9262)

A runner that submits to a pool and returns the unwaited
concurrent.futures.Future hands the work back, so the SDK holds the only
reference to it for one instant. _close_quietly already asked that
reference to cancel -- as hygiene -- and discarded the answer, while
_undriven_result had already worded the record as work that 'may still be
running ... and cannot stop'. So a run whose work provably never started
was recorded as work a retry could overlap.

_stop_returned_work now makes that stop deliberate, takes it before the
verdict is worded, and answers three ways: True only for a
concurrent.futures.Future whose cancel() returned True, which that class
documents as the call never running; False when the work is already
executing; None when no guarantee is available. An asyncio.Task can
answer cancel() with True and finish anyway, so a truthy cancel is never
read as a stop.

Refs #7814

Co-authored-by: Kiro Crew <noreply@kiro.dev>
fix(hooks): stop the hooks.json lock opens from truncating the lock file (#9279)

The two writers of hooks.json — webhooks.locked() and the register_hook
MCP tool (mcp_tools/control.py) — both opened their shared lock sidecar
with open(lock_path, "w") and only then acquired the lock. "w"
truncates AT OPEN, so the mutation happens before the lock that is
supposed to guard it is held.

On Windows the acquire routes to msvcrt.locking, and a truncating open
of a lock file whose first byte another holder already locked raises a
sharing violation instead of waiting — the contending acquirer fails
before it ever reaches the lock, and the mutual exclusion the lock
exists to provide silently does not happen. POSIX flock tolerates the
truncate, which is why the defect is invisible on Linux.

These two sites are ONE unit: both resolve to the SAME
<data-home>/hooks.json.lock from two different modules, which is exactly
the cross-process contention the defect needs — webhooks.locked() is
documented public precisely because register_hook must share its lock
discipline. Fixing one without the other would leave the pair
half-locked and the Windows failure fully live.

Both sites now touch(exist_ok=True) and open "r+" — writable, which
msvcrt.locking requires, but not truncating. Same shape as
work_ledger._open_lock (PR #9237), session_pid.py (PR #9250), and
dashboard/handlers/mcp.py's _McpFileLock, which was written this way
from the start.

Truncation is the direct, platform-independent observable, so the tests
seed the lock file, take and release the lock, and require the bytes to
have survived: they fail on every platform if a truncating open comes
back.

Part of the #9248 sweep (one subsystem per PR, per the issue); the
remaining subsystems get their own follow-up issues.

Co-authored-by: dwu96 <dwu96@amazon.com>
Co-authored-by: Kiro Crew <noreply@kiro.dev>
revert: restore windows startup by reverting #8117

This reverts commit 259db3970e91f4bf6842456b713ad031eed4902f.

Restore the Windows Kiro delegation contract: the macOS settings probe
must not prevent an explicitly classified official Kiro backend from
starting on a fresh Windows install. Kiro CLI remains a trusted runtime
dependency; its internal sandbox is outside this Crew-side validation.

Revert the whole PR for immediate recovery, including its UI-stream
deadline and debug-only precise-memory-info switch. Remove the obsolete
stalled-stream test together with its subsequent determinism changes.

Validation on this branch: 140 backend tests passed, 5 platform skips;
23 Electron native-logging tests passed. Changed Python files pass
isort and flake8; the staged diff passes the whitespace check.

revert: put the AI review lanes back on Opus 4.8 and Fable 5

This reverts commit ecf50cadd4336f40d2166c835bc780118372ec57 (#9158).

Fable 5.1 is listed ACTIVE on Bedrock in this account and its us.
inference profile exists, but it is not actually invokable from these
lanes: every first call is rejected at zero tokens. The three advisory
lanes hid that behind --fallback-model, so they reported success while
modelUsage named us.anthropic.claude-opus-4-8, and the GPT lanes'
adjudication pass carries no fallback, so it failed outright and turned
the required GPT 5.6 Review check red on four pull requests inside
sixteen minutes.

Listing a model as available was not evidence that the role may invoke
it. Re-landing the bump needs a real InvokeModel check first, and the
advisory lanes need it too: their green was the fallback, not Fable 5.1.

The two corrected labels for the Opus-4.8-running claude-review.yml lane
go back to saying Fable 5 with this revert. That is pre-existing wording,
wrong but harmless, and it returns with the retry rather than holding up
an urgent revert.

fix(instances): journal every warm-set write and the handshake drops behind a stuck pane (#9141)

A remote crew pane can sit on "loading pane" with nothing in
gateway-launch.log to explain it. The pane journal added in #8274/#8813
covers the viewport's own warm paths, but the one warm-writer it does not
own -- connectInstanceInto, shared by tab clicks and the auto-connect
fan-out -- was silent, and three state changes that put a pane into that
bucket left no line at all.

connectInstanceInto now journals `warm` / `warm-declined` / `warm-failed`
tagged `via=select|auto-connect`, in the same shape the viewport uses. A
connect that answers `connected` with no port or no token leaves the OLD
warm entry standing (a dead port), so the tab still renders an iframe and
the user sees only "loading"; that is now the one `warm-declined` line it
was missing.

InstancesViewport journals three more moments:
- `evict`: the K-cap LRU eviction, the only teardown the user never asked
  for. The next click re-warms the pane as a brand-new load, so an evicted
  pane that then fails reads, without this line, as a pane that was fine
  until it suddenly was not.
- `watchdog-armed`: the 15s load watchdog starting. A pane that spins
  forever WITHOUT ever producing `load-timeout` is a pane whose watchdog
  never armed, and only the absence of this line says so.
- `ready-unattributed`: an `mc-embedded-ready` from a loopback origin the
  parent cannot map to a warm pane -- the handshake dropped because the
  origin map has not caught up with a port change or an eviction. Journaled
  only for this message type and only for a loopback origin; the child
  sends it at most six times per load, so it cannot flood.

No token material reaches the log: `paneLog` redacts secret-named fields
and the new test pins that the token string never appears.

Co-authored-by: Joe Guo <zejiangg@amazon.com>
fix(slack): stop a refused progress card from splitting the reply (#9260)

A task card is progress decoration and the 30s elapsed-time refresh
re-sends it for as long as a tool runs, so on a several-minute tool phase
it is the only thing appending to the stream. Both Slack pipelines
rotated the stream when Slack refused that append: the message the reader
was watching was stopped mid-answer and the rest of the reply continued
in a new one, which reads as a reply that failed followed minutes later
by an unexplained second reply.

_append_task now skips the refused card and keeps the stream.
_append_stream still rotates when real text is refused, which is the
moment a rotation is worth its price, and that replacement stream now
opens with a continuation marker so the two messages read as one answer.
test(work-ledger): name the cause when the binding race test shortfalls (#9257)

test_two_conductors_binding_one_worker_at_once_yield_exactly_one_binding
fails on Backend Tests (Windows) (4) intermittently and reports only
"assert 2 == 3". Its bind helper caught only WorkLedgerError, so anything
else (a bare OSError from a Windows sharing violation, per #9250's own
docstring) killed the thread silently, appended nothing, and shortened the
count -- discarding the one fact that identifies the cause.

Record one outcome per thread keyed by conductor, catch BaseException and
keep the type + message, and flag a thread still alive after join(timeout).
Put the per-thread outcomes in both assertion messages so the next Windows
failure names its exception instead of a count. The == 1 and == 3
assertions are unchanged: this adds diagnosis, not tolerance.
fix(session-pid): stop the PID lock opens from truncating the lock file (#9250)

The three PID lock helpers opened their lock file with `open(path, "w")`
and only then acquired the lock. `"w"` truncates AT OPEN, so the
truncation happens before the lock is held.

On Windows the acquire routes to `msvcrt.locking`, and a truncating open
of a lock file whose first byte another holder already locked raises a
sharing violation instead of waiting -- so the contending acquirer
crashes with a bare OSError before it ever reaches `file_lock`, and the
serialisation the lock exists to provide never happens. POSIX `flock`
tolerates the truncate, which is why this was invisible on Linux and
reddened only the Windows shards.

Issue #9248, which named `session_pid.py` as the site most likely to bite
in practice: PID files are read by other processes precisely while they
contend. It named two sites and asked whoever picked it up to re-run the
grep rather than trust the list; doing so found a third,
`_periodic_pid_sweep`, which is the worst of them because it runs on a
timer while `_track_session_pid` contends for the same lock.

All three now `touch(exist_ok=True)` and open `"r+"` -- writable, which
`msvcrt.locking` requires, but not truncating. Same shape as
`dashboard/handlers/mcp.py`'s `_McpFileLock`, which was already written
this way, and as `work_ledger._open_lock`.

Truncation is the direct, platform-independent observable, so the tests
seed the lock file, take and release the lock, and require the bytes to
have survived: they fail on every platform if the truncating open comes
back, rather than only on Windows.

`webhooks.py` carries the same pattern and is deliberately left alone --
issue #9248 asks for one change per subsystem so each gets its own
review.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
fix(work-ledger): stop the lock-file open from truncating on Windows (#9237)

The store's _open_lock opened its lock file with open(path, "w"), which truncates on open. On Windows a truncating open of a lock file whose first byte another holder already locked under msvcrt.locking raises a sharing violation instead of waiting, so a second contending acquirer crashes with a bare OSError before it reaches file_lock -- the bind it was serialising is never mutually excluded. POSIX flock tolerates the truncate, so the defect was Windows-only. Fix mirrors dashboard/handlers/mcp.py: touch + open r+ (writable, no truncate).
fix(acp): give session/set_mode the session-start budget on Windows (#9225)

session/set_mode boots the switched-to agent's MCP servers, the same
(re-)initialization that gives session/new and session/load their 90s
budget, but both set_mode call sites used the generic 30s _REQUEST_TIMEOUT.
A switched-to server pending OAuth holds the response for its full 30s
wait, so the 30s budget races it exactly as it would session start. Pass
the already-resolved session-start budget to both set_mode calls.

Closes #9185
feat: add contributes.panelTabs app-manifest contribution (#7975)
test(acp): re-record frame-replay snapshots for the wire_title field (#9232)

The replay corpus recorded by #9161 predates the wire_title field #9073 added to every tool_call event 3 minutes later, so main's own corpus no longer matches main's own render. Regenerated with scripts/update_acp_frame_snapshots.py; the only delta is the new wire_title key.
refactor(electron): share typed preload bridge contracts (#9228)

Co-authored-by: DeryFerd <DeryFerd@users.noreply.github.com>
fix(messaging): keep prose that merely mentions [STEERING visible (#9209)

`_SteeringMarkerFilter` held any buffered tail that began `[STEERING` until it
found a `]`, and deleted it at flush if none arrived. That is a
locate-by-substring decision, not a grammar one: the filter already hands on a
CLOSED frame that fails `_STEER_MARKER_RE` as ordinary text, so the same
sentence survived when the writer happened to type a `]` later and vanished
when they did not.

Measured on main -- `"Use the [STEERING protocol to redirect"` reaches the
channel as `"Use the "`, and `"text [STEERING nonsense] tail"` arrives whole.
The filter runs in `TurnDriver` upstream of every renderer, so an agent
explaining the steering protocol loses the rest of its message on Discord,
Telegram and WhatsApp. It also negates
`test_unfinished_marker_prefix_grammar.py`'s
`test_prose_mentioning_steering_is_left_visible`, which pins that exact string
as visible one layer down.

The unterminated tail is now judged by the grammar the marker actually has: a
tail that can still extend into `[STEERING steer-<id>]` is held as before, and
one that has already diverged is prose and is handed on. The probe is compiled
from `constants._STEERING_TAIL_PREFIX_RE`'s pattern -- the same closure
`split_trailing_protocol_suffix` uses downstream -- so the grammar keeps one
source, with `IGNORECASE` added to match this module's own recognizer, since
here a tail judged prose is EMITTED and a probe stricter than the recognizer
beside it would leak part of a real frame.

Fail-closed behaviour is unchanged: a tail that was still a viable marker when
the stream ended is dropped, not emitted, and the 16 KiB ceiling is checked
before the grammar probe so an adversarial buffer cannot make it re-scan a
growing string.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
fix(command-bar): attribute contributed rows to the validated app name (#9226)

* fix(command-bar): attribute contributed rows to the validated app name

A contributed command's attribution came from `app.displayName`, which is
free text the app chooses, so it could not do the one job it has.

An app declaring `displayName: "Kiro Crew"` put that string where the row
states its owner, and the row then read as native while its prompt goes to
an agent with tools. In the other direction `||` is not the emptiness test
it looks like: the manifest validator refuses only a falsy `displayName`,
so `"   "` or a zero-width `\u200b` is "present", wins over the name, and
renders the empty label that `kindLabel` shows as a bare kind -- character
for character what a builtin row shows.

The label now comes from `name`, the install identity. `KEBAB_RE` limits it
to `[a-z0-9]` plus single hyphens, so it can neither be blank nor spell a
host word with a space or a capital, and it is unique per installed app.
The clip path already used `name`; the unclipped path now agrees with it.

* docs(command-bar): add before/after evidence for the attribution fix

Captured with the repo's own scripts/capture-command-bar-contributed.mjs harness,
with the external app's displayName set to "Kiro Crew" so the BEFORE frame shows
the impersonation the fix removes rather than merely a friendly name.
fix(autonudge): make an armed auto-nudge loop readable via monitor_inspect (#9221)
fix: treat a serve config naming only other ports as a free 443 (#7999)

A serve status document that keys mappings by port (TCP by bare number,
Web/AllowFunnel by host:port) and names no key for 443 is positive
evidence that 443 is vacant, not an unknown. Previously any unrelated
serve config -- another project on port 80 -- made the Phone access card
and `kirocrew tailnet up` refuse to publish with "could not identify what
is on port 443", on exactly the developer workstations most likely to run
other tailscale-serve projects.

serve_state() now sets a port_free reading via _has_port_shaped_keys(),
and publish() proceeds when the port is provably free; a shared _key_port()
parser keeps the port-evidence read and the 443 detector from ever
disagreeing (a leading-zero key must not read as evidence while hiding the
443 mapping it names). Documents with serve content but no port-shaped keys
keep refusing; a stranger's handler at 443/ keeps refusing and the Phone
access card derives `occupied` for it up front instead of offering a publish
that fails one click later. unpublish() leaves other ports' config untouched.

Co-authored-by: Antigravity AI <ai@gotad.net>
fix(connections): honest transport-error copy on the needs-attention card (#9148)

Gate the provider-verdict headline on auth-shaped evidence via errorIndicatesProviderRejection; transport failures (timeout, DNS, reset, unknown) now render connection_unreachable instead of claiming the provider invalidated the grant. Default is no-verdict. New connection_unreachable key in all 13 locale catalogs plus regenerated pseudolocale.
fix(protocol): tolerate a Markdown wrapper around the [OPTIONS:] marker (#9174)

A model sometimes wraps the whole trailing marker line in inline code or
emphasis -- `[OPTIONS: A | B]` in backticks, or **[OPTIONS: A | B]**. The
wrapper character lands after the closing bracket, which broke the
end-of-line anchor: the marker was neither parsed nor stripped, the turn
lost its follow-up pills, and the raw marker leaked to the user as
literal code-styled text. Every surface shares the grammar, so
dashboard, Slack, previews, and the Discord/Telegram trailer split all
lost their buttons on the same input.

The grammar already absorbs the same class of model tic (a stray
`](OPTIONS)` link close), so this widens it symmetrically and tightly:

- a LEADING wrapper run (` / * / _, at most 3) matches only at line
  start after optional indent, so emphasis belonging to preceding prose
  is never eaten;
- a TRAILING run only when it abuts the closer (or its `(...)` tic) AND
  the marker is line-anchored: a mid-line marker keeps the pre-widening
  grammar byte for byte, so an inline code span quoting a marker
  (`Use [OPTIONS: A | B]` in backticks) never loses its closing
  character. Python spells the condition as a `(?(lwrap)...)`
  conditional group; JS, which has no conditionals, as a two-branch
  alternation with (S, labels) group pairs (1,2)/(3,4);
- the Python `labels` group is named (the conditional group precedes
  it), and the group-reading consumers (slack, messaging renderer,
  dashboard) read `group("labels")` / branch pairs accordingly;
- frontend regex and both backend mirrors change in one commit so the
  grammars cannot drift;
- the partial-marker stripper and the backend trailer splitter pull a
  line-leading wrapper along with a still-streaming marker, so the
  wrapper is never stranded in the visible half;
- ReDoS linearity is preserved: the wrapper class shares no character
  with the indent or trailing whitespace classes, each alternation
  branch is the proven linear shape, and both wrapper positions are
  anchored by the required [OPTIONS: literal.

Tests in both languages cover backtick-wrapped, emphasis-wrapped,
leading-only, trailing-only, the negative rows that must stay negative
(trailing period, trailing prose, non-abutting wrapper, 4+ runs,
prose-owned emphasis, and the mid-line wrapped/quoted forms including
the inline-code corruption case), streaming-prefix behaviour, group
contracts in both languages, and adversarial wrapper runs against the
linearity guards.

Closes #9110

Co-authored-by: Joe Guo <zejiangg@amazon.com>
fix(directive): claim the out-of-band record by the call's input, not the result (#9073)

The out-of-band session-directive path parked the tool's validated payload on
the gateway and let the consumer claim it -- but the consumer learned WHICH
record to claim by reading the directive marker back out of the tool RESULT
text (`session_directive.peek`). That text is whatever the backend chooses to
put on the wire, and KAS reshaped it four ways in as many weeks: the envelope
re-serialised with every quote escaped (#8182), the result copied into both
`response` and `message` (#8841, kiro-agent bc5906adf), one field swapped for
an offload reference above a size threshold, and every string capped at 30k
chars with the tail-anchored marker falling off the end. Each shape was one
more repair branch in `acp/_dispatch.py`, which every backend shares, and the
next kiro-agent release could add another. Conductor frames were already at
22k against the 30k cliff.

The tool call's INPUT reaches both sides through no envelope at all. The MCP
server receives it as the `arguments` of `tools/call`; the consumer sees it as
the `rawInput` of the ACP `tool_call` frame, which kiro-agent emits uncapped.
So the record is now keyed by `session_directive.call_input_digest` of the tool NAME plus those
raw arguments (the name because every no-argument tool hashes `{}` alike; a
planted `reset_conversation({})` was otherwise claimable by any `{}` call):

* `mcp_core._call_tool` digests the raw args BEFORE validation (validation adds
  schema defaults the model never typed) into a ContextVar;
  `control._emit_directive` posts it beside the payload as `input_digest`.
* `api_session_directive` requires it (400 without -- a record nothing can
  claim is worse than an honest refusal) and `directive_queue.publish` stores
  it. `directive_queue.claim` matches on `(session_key, input_digest)` inside
  the claiming turn; the `(kind, args)` correlation is gone.
* `chat_runner` records the digest of `raw_tool_params` on every
  `EVENT_TOOL_CALL`, refreshes it from a `tool_call_update` carrying rawInput
  (claude-agent-acp streams an empty input first), and claims by it on the
  final result frame. The claim is attempted when the frame carries a marker
  OR a record is parked for the session and the call has a digest, so a
  result whose marker was capped off entirely still arms. `_meta` is dropped
  before hashing: kiro-agent strips it before `callTool`, so the server never
  sees the block the frame carries.

Same trust shape as the marker it replaces: model-controlled content, bound to
the session by arriving on its own event stream in the call the tool served. A
caller who can park a record for another session still needs THAT session's
model to make a call with identical arguments in the same turn. The applied
payload is always the record's; the digest only picks which record.

Deleted: `_repair_escaped_marker`, `_marker_bearing_text`, `_elide_marker_value`,
`_dumps_elided_siblings`, `ELIDED_MARKER_VALUE`, `session_directive.peek`,
`peek_failure_reason`, and the marker-envelope branches in both result
builders (`_dispatch` and the legacy `AcpClient`). The kiro-cli path
(`_meta.kiro` identity + `decode` from the marker) is unchanged; the messaging
TurnDriver never used the queue a…
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…irodotdev#9070)

* fix(portability): keep the export archive inside the crew directory

`create_export_zip` walks `workspace`, `plan_memory` and `skills` with
`rglob("*")` and skips an entry that `is_symlink()`, so that an export never
carries bytes from outside the crew directory. That skip is blind to the escape
that costs the most: `rglob` DESCENDS a directory link, and the file on the far
side is an ordinary one — `is_symlink()` false — so it is written straight into
the archive. On Windows the link is typically a junction, which `is_symlink`
does not report at all, and a junction needs none of the privilege a directory
symlink needs there.

The two filters below the skip do not catch it either. `_is_excluded` and
`is_sensitive_path` both read the LEXICAL path, which runs through the link's
own name and therefore looks like ordinary crew content — so a sensitive file
behind a link passes the sensitivity check that exists to stop exactly this.

Measured on unpatched main with a real junction: `workspace/memory/linked/
not-ours.md` appeared in the export's namelist, sourced from outside the crew
directory. The consequence class is content the user then hands to someone else,
since an export archive is made to be moved off the host.

Fixed by requiring the RESOLVED path to stay under the resolved crew directory —
the repo's existing idiom (`apps/backend.py:651`). Resolving is what covers both
shapes at once: it follows every reparse point on the way down and answers where
the bytes actually live. `mc` is resolved once so a legitimately linked
`$KIROCREW_HOME` does not reject the whole export. The `is_symlink()` skip is
kept as-is; this adds a layer rather than replacing one.

The import side of this module is untouched.

`test_export_skips_symlinks` cannot cover this — it plants a link that IS the
entry, and it `pytest.skip`s where symlinks cannot be created, i.e. on the
platform where the junction spelling lives. The new tests use
`conftest.make_dir_link` and need no privilege.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(portability): archive the descriptor that was validated

`create_export_zip` walked `workspace/`, `plan_memory/` and `skills/` with
`rglob("*")`, which DESCENDS a directory link while the file on the far side
is an ordinary one, so the walk's own `is_symlink()` skip never fired for it.
Neither by-name filter below that skip is a containment test either:
`_is_excluded` is a rule about the archive name, and `is_sensitive_path` asks
whether a path is a PROTECTED location -- it does resolve links, so a linked
`~/.aws` was caught -- never whether it is inside the crew directory. An
ordinary file of the user's, reached through a link dropped in the workspace,
was sensitive to none of them and went into an archive the user hands on.

A resolve-and-compare would answer that for an instant only: `ZipFile.write`
takes a NAME and opens it again, so the file that was checked and the file
that is read are two separate lookups, and a running gateway gives agent
tools write access to that workspace while an export can be triggered.

`_open_verified` inverts the order -- open first, then ask the kernel where
the open thing is via `pinned_fs.fd_real_path` -- and `_add_from_fd` streams
the entry from that descriptor, so check and use address one object. A
hardlink alias, which no path-based guard can see, is refused on the
descriptor's link count; `force_zip64=True` keeps a source over `ZIP64_LIMIT`
archiving as `ZipFile.write` used to.

That settles what may be ARCHIVED. It does not settle what may be TOUCHED,
and on Windows those are different questions: resolving a path whose
component is a link to a UNC share IS an outbound SMB authentication, so a
refusal computed afterwards has already paid the cost it exists to prevent.
No pathname check fixes it -- every by-name check is a check-to-open window
and an adversary that can plant the link chooses when. The names have to be
held rather than inspected.

The enumeration was the last place that still inspected them. Pinning the
candidate's ancestors closed the swap race, but `rglob` had already descended
a PRE-PLANTED junction, and `is_file()` and `is_sensitive_path()` had already
resolved what it yielded, before any of it ran. Measured on this module,
exporting a workspace holding one planted junction: 14 resolving calls went
out through it -- `os.path.realpath` and `ntpath._getfinalpathname` -- while
the export correctly archived nothing from behind it. Nothing being archived
was never the question.

So the walk descends and verifies in one motion instead. `_walk_pinned` pins
a directory with `platform_compat.pin_directory` before listing it -- the
handle omits `FILE_SHARE_DELETE`, so a held directory can be neither renamed
nor deleted, nor can anything above it, and the open refuses to follow a
reparse point, so a junction at the name fails there instead of being
traversed -- then classifies each child from the listing Windows already
returned, where the attributes and reparse tag arrive inline and cost no
lookup THROUGH the child. A child directory is descended only by pinning it
in turn, so the path the kernel walks to reach any component runs entirely
through components already opened and verified, starting at the crew root
itself. This is the pattern `aws_control/backend/storage.py` already uses to
hold the path a sandboxed CLI writes through. The leaf goes through the new
`platform_compat.open_file_no_reparse`, which opens a reparse point AS ITSELF
rather than following it, so the refusal and the open are one operation;
POSIX keeps the `O_NOFOLLOW` open it already had, named.

`_pin_ancestors` and `_open_inside` are gone rather than kept alongside this:
the walk holds the same chain, for the whole subtree instead of re-walking it
per file, so keeping them would be two mechanisms doing one job.

The walk starts at the RESOLVED root, since `$KIROCREW_HOME` may itself be a
link and `pin_directory` refuses a reparse point at a name -- pinning the
configured spelling would return an empty export on such a host.

The exported set is unchanged: on a tree covering nesting, `EXCLUDE_DIRS`,
`EXPORT_EXCLUDE`, `.pid` and `skills/auto`, the archive is byte-identical to
the one the previous walk produced.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants