Skip to content

fix(session): don't resume in an earlier process's hidden scratch dir - #30129

Merged
buluoray merged 1 commit into
mainfrom
crew/slack/fix-kas-uv-cwd-eperm
Nov 5, 2026
Merged

buluoray merged 1 commit into
mainfrom
crew/slack/fix-kas-uv-cwd-eperm

Conversation

@buluoray

@buluoray buluoray commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An older chat whose recorded working directory was an earlier process's scratch tree resumes and answers, instead of dying at start-up with process exited (rc=None).

On macOS some older chat sessions fail every turn with process exited (rc=None) while new sessions work. The kiro-cli start-up log shows EPERM: operation not permitted, uv_cwd: the child cannot read its own working directory.

Why it matters

The chat is unusable and the card gives no hint why. Agents are told to put clones and worktrees in $KIROCREW_SCRATCH, and set_project into such a worktree is common, so any conversation that did this breaks once its process ends (gateway restart, idle reap, crash).

Not a goal

What changed (motivation → approach → change)

  • Symptom: a resumed session's kiro-cli exits at start-up with EPERM ... uv_cwd; the card says process exited (rc=None).
  • Root cause: on a resume with no explicit cwd, get_or_create uses the cwd the session map recorded if it is still a directory (src/kiro_crew/session_allocation_parts/get_or_create.py, the stored_cwd block). The check runs in the gateway, which can see every scratch tree. The new process gets a fresh scratch tree, and the sandbox masks the scratch root except that tree (sandbox_leaves.py scratch leaf; Seatbelt deny file-read* over the mask with only the private window, sandbox_seatbelt.py). The child is still created in the old tree (acp/launch.py process_directory → host._spawn_work_dir), so its getcwd() is denied.
  • Change: _stored_cwd_is_hidden_scratch skips a stored cwd that resolves inside agent_scratch.scratch_root() unless it lies in the shared_scratch tree this spawn is handed (that one is re-exposed). The session then starts in its default directory, and a warning names the skipped directory. A stored cwd outside the scratch root is kept exactly as before.
  • Alternative considered: re-expose the old tree to the new process. That is fix(scratch): resume a conversation into the scratch tree it had #30062's design for trees it records from now on; it cannot help sessions recorded before it, and a tree from another process must stay hidden.
  • Interaction with fix(scratch): resume a conversation into the scratch tree it had #30062: it sets shared_scratch from recorded_tree after this check runs. Once both land, that lookup should move before this check (or this check should read the recorded tree) so a resumed cwd inside the recorded tree is kept.

Backwards compatibility

Compatible: only a stored cwd under the scratch root, outside the spawn's shared tree, is skipped, and such a cwd already failed to start under the sandbox.

Removes nothing: the stored cwd stays in the session map; only this spawn does not start in it.

Tests

  • test/test_session_get_or_create.py::TestGetOrCreatePoolClaim::test_resume_skips_a_stored_cwd_in_an_earlier_process_scratch: a resume whose stored cwd is in an old scratch tree starts with no cwd; a stored cwd outside the scratch root is still used; a stored cwd inside the shared_scratch tree is still used.

Proof: PROVEN test/test_session_get_or_create.py::TestGetOrCreatePoolClaim::test_resume_skips_a_stored_cwd_in_an_earlier_process_scratch (head 81ceb6d)

Ran: test/test_session_get_or_create.py, test/test_session_map_cwd.py, test/test_subagent_shared_scratch.py (124 passed, single process).

Manual verification

N/A — not reproduced on a macOS host; the unit test covers the cwd choice, and the sandbox mask that denies the old tree is existing behaviour.

Related Issues

Related: #26229, #28595 (EPERM from a masked path at MCP start-up), #30062 (resume keeps its scratch tree).

Sibling sweep

Swept: git grep -n "get_cwd(" -- src/
Sibling: src/kiro_crew/teams/renderer.py:140 -- not affected -- reads the cwd to render a path, spawns nothing

Pattern harvest

Not generalizable: the only resume path that starts a sandboxed child in a recorded directory is this one.

Checklist

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

Contributions are accepted under the project's Apache-2.0 license.

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners November 5, 2026 02:30
@buluoray
buluoray requested a review from mbriones98 November 5, 2026 02:30
@buluoray
buluoray enabled auto-merge (squash) November 5, 2026 02:30
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 81ceb6d2b4562503f027a248278e9d1349595f49 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 81ceb6d2b4562503f027a248278e9d1349595f49 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: skipping a stored cwd the new process cannot read fixes the start-up crash, and a revert undoes it cleanly.

Notes

  • The "is it hidden?" check is a gateway-side guess at what the sandbox masks, using the "off" mode as a stand-in. On a host where the mode is not "off" but no OS backend masks anything (Windows, or a host with no sandbox backend), a readable worktree cwd gets skipped for no reason. Asking the sandbox layer whether it masks the path (the scratch leaf disposition) would give one source of truth.
  • The skip shows up only in the gateway log. The resumed agent's history still names the old worktree, but it now starts in the default directory, so its relative paths silently point somewhere else. A one-line note in the resumed turn's context would stop it working against the wrong tree.
  • The ordering with fix(scratch): resume a conversation into the scratch tree it had #30062 that the description flags (shared_scratch is set from recorded_tree after this check runs) needs to be resolved in whichever PR merges second. Otherwise a cwd inside the recorded tree is dropped.

[DESIGN-REVIEWED] 81ceb6d

Description read

[DESCRIPTION-READ] 286e9587bdc12d1ca269be43d76b2a850792cc62b088ff2d4e2a5f30daa45882

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 81ceb6d2b4562503f027a248278e9d1349595f49 — 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 does not.

First-Principles-Verdict: PASS

Nothing blocks. The resume-cwd skip fixes the mechanism at the only resume path that starts a sandboxed child in a recorded directory. If its premise is wrong, the session starts in its default directory and still runs.

What this change ships

Inventory (5 items) — 3 justified

Intent: let an older chat that last worked in an earlier process's scratch tree resume and answer, instead of failing at start-up with process exited (rc=None). FIX.

  1. A resumed chat whose recorded working directory is in an earlier process's scratch tree now starts in its default directory. — justified
  2. A warning log line names the directory that was skipped. — justified
  3. With the sandbox off, a recorded scratch-tree directory is still used. — undeclared (in the spec, not the description)
  4. If the sandbox floor cannot be read, the directory counts as hidden and is skipped. — undeclared fallback branch
  5. The session spec now says when a resumed cwd is kept. — justified

[FIRST-PRINCIPLES-REVIEWED] 81ceb6d

Description read

[DESCRIPTION-READ] 98d801c9a156f1a392b051f12e4d997024a7ad62053f497de2d4d565f5b4f416

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 81ceb6d2b4562503f027a248278e9d1349595f49 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 81ceb6d

Verdict parsed from the review's SHA-scoped output markers for commit 81ceb6d2b4562503f027a248278e9d1349595f49.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 81ceb6d2b4562503f027a248278e9d1349595f49 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ human override accepted

Human judgment by @buluoray overrides the GPT 6.1 finding for 81ceb6d2b4562503f027a248278e9d1349595f49; the recorded reason is authoritative for this commit.

[GPT-OVERRIDE] 81ceb6d

This comment is updated in place on each push.

The model was not re-run because an authorized human decision supersedes it.

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 81ceb6d2b4562503f027a248278e9d1349595f49 false-positive: <reason, 20 to 500 characters>

@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 Nov 5, 2026
@buluoray
buluoray force-pushed the crew/slack/fix-kas-uv-cwd-eperm branch from 35d414c to dc0e0d3 Compare November 5, 2026 04:06
@buluoray

buluoray commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Disposition for head dc0e0d366de157fbaeb68adaa2f7c5a12eeb8466

Opus 5.5 / GPT 6.1 F1 (get_or_create.py:713, keep the scratch cwd when the launch masks nothing): fixed.
_stored_cwd_is_hidden_scratch now returns False when agent.sandbox, clamped up to the governance floor (sandbox_tiers._clamp_sandbox_mode(configured_sandbox_mode()), the same clamp wrap_argv applies), is off. An unreadable floor still counts as masked, so the session starts in its default directory, which it can always read. New test test_resume_keeps_a_stored_scratch_cwd_when_the_sandbox_is_off; it fails with the off branch removed.

Backend Tests (3.12, 7) / (Windows) (7): the three test/test_slack_code_channels_events.py failures were on main's merge base at the time, not this diff (#30062 failed the same three). main fixed them in 03dc8a1 (#30127). This head is rebased onto f3c97e5 and the three tests pass locally.

A conversation that worked in its $KIROCREW_SCRATCH records that tree as
its cwd. Its next process gets a fresh scratch tree and the sandbox hides
the old one, but the gateway still starts the child there, so kiro-cli
cannot read its own working directory and exits at start-up (EPERM,
uv_cwd on macOS), shown as process exited (rc=None). Skip a stored cwd
inside the scratch root unless it lies in the tree the spawn shares, and
log the skipped directory.
@buluoray
buluoray force-pushed the crew/slack/fix-kas-uv-cwd-eperm branch from dc0e0d3 to 81ceb6d Compare November 5, 2026 05:11
@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 Nov 5, 2026
@buluoray

buluoray commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Disposition for head 81ceb6d2b4562503f027a248278e9d1349595f49

Opus 5.5: no blocking findings.

GPT 6.1 F1 (get_or_create.py:105, keep the cwd when the Kiro spawn's sandbox is delegated): rebutted, kept as is.

  • The trigger is real. When the spawn is delegated to Kiro's own sandbox (sandbox_wrap.py:876-878: Windows Kiro spawns, and macOS when Kiro's internal sandbox is on), Crew's scratch mask is not applied.
  • The window is small. A dead process's scratch tree is swept an hour after its process group dies (agent_scratch.py, _UNOWNED_GRACE_SECONDS = 3600). After that the recorded cwd fails is_dir and is dropped on main too. So the finding needs a resume inside that hour, of a chat whose recorded cwd is another process's scratch tree, on a delegated spawn.
  • The result fails safe. The session starts in its default directory, which it can always read, and a warning names the skipped directory. Nothing is exposed and no data is lost, and the user can give a cwd again.
  • Predicting delegation here would mean copying wrap_argv's decision (platform, Kiro internal-sandbox setting, extra hides, caller classification) into session allocation. That is a second copy of a security decision that can drift. The cost does not fit this edge case.

An override for this lane needs a maintainer decision.

@buluoray

buluoray commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Owner decision on GPT 6.1 F1 (get_or_create.py:105, delegated sandbox): accepted as is. A resume on a delegated spawn (Windows Kiro, or macOS with the Kiro internal sandbox on) whose recorded cwd is another process scratch tree starts in the default directory with a warning. This only happens within the hour before the sweep removes that tree, and it fails safe. Copying the wrap_argv delegation decision into session allocation is not worth it. Rebuttal: #30129 (comment)

@buluoray

buluoray commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

/ai-review override gpt 81ceb6d owner-decision: Delegated-sandbox resume of another process scratch cwd only falls back to the default dir with a warning, inside the hour before the sweep removes that tree; fails safe, no data or privilege impact. Decision: #30129 (comment)

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Human judgment recorded

@buluoray recorded a owner-decision release (class owner-decision) for the gpt AI finding on 81ceb6d2b4562503f027a248278e9d1349595f49.

Delegated-sandbox resume of another process scratch cwd only falls back to the default dir with a warning, inside the hour before the sweep removes that tree; fails safe, no data or privilege impact. Decision: #30129 (comment)

This decision applies only to this commit. A new push requires a new judgment.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 5, 2026
@buluoray
buluoray merged commit 599e33e into main Nov 5, 2026
105 of 109 checks passed
@buluoray
buluoray deleted the crew/slack/fix-kas-uv-cwd-eperm branch November 5, 2026 06:50
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 5, 2026
buluoray added a commit that referenced this pull request Nov 5, 2026
Cherry-picked with -x from main onto release/0.12.0 for 0.12.1, in
main merge order. Every pick applied clean.

- #29990 fix(approvals): resolve an approval by id only in the session it was shown in
  (cherry picked from commit 4d2b8a5)
- #30129 fix(session): don't resume in an earlier process's hidden scratch dir
  (cherry picked from commit 599e33e)
- #30205 fix(acp): let Crew's MCP servers defer on the KAS engine bundle
  (cherry picked from commit 3d4e4a6)
- #30279 fix: keep one more credential value out of log output
  (cherry picked from commit 9fcf80f)
- #30195 fix(acp): answer KAS user-input questions instead of letting Deny read as yes
  (cherry picked from commit bbf4e6d)
- #30199 fix: redact four log lines and tighten two small checks
  (cherry picked from commit 16ff876)

Co-authored-by: Bolin Chen <17506219+bolichen97@users.noreply.github.com>
Co-authored-by: Joe Guo <12429733+iamwhatever@users.noreply.github.com>
buluoray added a commit that referenced this pull request Nov 6, 2026
Cherry-picked with -x from main onto release/0.12.0 for 0.12.1, in
main merge order. Every pick applied clean.

- #29990 fix(approvals): resolve an approval by id only in the session it was shown in
  (cherry picked from commit 4d2b8a5)
- #30129 fix(session): don't resume in an earlier process's hidden scratch dir
  (cherry picked from commit 599e33e)
- #30205 fix(acp): let Crew's MCP servers defer on the KAS engine bundle
  (cherry picked from commit 3d4e4a6)
- #30279 fix: keep one more credential value out of log output
  (cherry picked from commit 9fcf80f)
- #30195 fix(acp): answer KAS user-input questions instead of letting Deny read as yes
  (cherry picked from commit bbf4e6d)
- #30199 fix: redact four log lines and tighten two small checks
  (cherry picked from commit 16ff876)

Co-authored-by: Bolin Chen <17506219+bolichen97@users.noreply.github.com>
Co-authored-by: Joe Guo <12429733+iamwhatever@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants