Skip to content

fix: keep agent temp dirs short so mcp server sockets fit - #33378

Merged
bolichen97 merged 1 commit into
mainfrom
fix/30271-short-scratch-label
Nov 10, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/30271-short-scratch-label

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An MCP server that binds a Unix socket under its temp directory starts in a chat on a default Linux or Windows data home, in a dedicated session as well as in the shared runtime.

In a chat the agent starts its MCP servers itself, and they inherit the agent's temp directory, <data home>/scratch/<label>-<token8>. The MATLAB MCP server creates its socket up to 54 bytes below that directory and refuses a socket path over 105 bytes, so it fails with socket path is too long: in every dedicated session (the label is the session key, up to 40 characters), and in the shared runtime on Windows for any username longer than 6 characters.

Why it matters

Anyone who adds a socket-binding MCP server (MATLAB is the reported one) cannot use it in chats: Connect works through the gateway, then the same server fails in the chat. The only workaround is a Windows-only environment override or a per-server temp directory, and neither fits a shared server definition.

Not a goal

  • A writable temp root outside the data home, the only remedy for a long data home. It widens what the sandbox lets an agent write, so it is the operator's call.
  • The gateway's own managed MCP temp directory (shortened in fix(mcp): shorten managed tmp root so a Unix socket fits sun_path #30443).
  • A warning when a temp directory leaves too little room for a socket.

What changed (motivation → approach → change)

MCP servers that bind a Unix socket under their temp directory, such as MATLAB's, now start in chats on a default Linux or Windows data home, in dedicated sessions too. Those servers inherit the agent's scratch directory as their temp directory, and its name carried a label (the session key, up to 40 characters, or runtime) that pushed the socket path past MATLAB's 105-byte limit.

Each scratch directory is now named by its random token alone, <data home>/scratch/<token8>, and the label goes to one debug log line at allocation. The token already made each name unique and each sweep single-owner, and the sweep reads owner markers and idle time, never names, so reclaiming is unchanged.

Room left for a 54-byte socket name under MATLAB's 105-byte limit, by username length u:

Default data home Before: shared runtime Before: dedicated session After (both)
Linux /home/<u>/.kiro/crew u ≤ 9 never u ≤ 17
Windows C:\Users\<u>\.kiro\crew u ≤ 6 never u ≤ 14

The scratch troubleshooting doc now tells the shared runtime's tree apart by age, size and a live .owner instead of a runtime-* name, the specs and comments that spelled the old layout (agent_scratch, sandbox_leaves.py, context management, cron temp dirs, the private-state allocation) name <token8>, and the fixture host-data check still catches a recorded scratch path in the new shape.

Backwards compatibility

Compatible: directories made before the change keep their names and are swept exactly as before, and nothing reads a label back out of a name.

The name no longer carries the label. Its readers:

Reader: src/kiro_crew/agent_scratch.py:sweep_dead_scratch -- chat -- reads owner pids and idle time, never the name; TestLivenessSweep in test_agent_scratch.py
Reader: src/kiro_crew/diagnostics.py:_scratch_log_dir_name -- release -- bundle members become kiro-chat/<token8>.log; the log text still shows which process wrote it; test_diagnostics_kiro_log_layout.py
Reader: src/kiro_crew/docs/troubleshooting.md:scratch -- release -- finds the shared runtime's tree by age, size and a live .owner (updated here)
Reader: src/kiro_crew/cron_script_child_env.py:_allocate_cron_scratch -- cron -- still a fresh per-run dir under the scratch root; test_cron_run_scratch.py
Reader: src/kiro_crew/acp/harness/deepseek.py:resolve_spawn -- chat -- the probe window is found by the path its wrap received; test_a_successful_read_back_removes_its_own_probe_window
Reader: scripts/check_acp_frame_host_data.py:PATTERNS -- release -- its scratch run id pattern also matches scratch/<token8>; test_a_scratch_dir_named_by_its_token_alone_is_caught

A person browsing ~/.kiro/crew/scratch or .quarantine can no longer tell from the name which session made a directory. At the default WARNING log level the label is recorded nowhere; the .owner pids and the files inside are what remain.

Tests

  • test_name_leaves_room_for_a_unix_socket (shared runtime label, 40-character session key): the allocated directory plus the MATLAB socket name fits 105 bytes on a default Linux and Windows home. Red before: 106 bytes on Windows for runtime, 136 on Linux for a session key.
  • test_a_scratch_dir_named_by_its_token_alone_is_caught: the fixture host-data check flags a recorded scratch/<token8> path.
  • The cron, DeepSeek probe and sweep-order tests stop reading the label from the name and keep what they prove.

Proof: PROVEN test/test_acp_frame_host_data.py::test_a_scratch_dir_named_by_its_token_alone_is_caught, test/test_agent_scratch.py::TestAllocate::test_name_leaves_room_for_a_unix_socket[runtime], test/test_agent_scratch.py::TestAllocate::test_name_leaves_room_for_a_unix_socket[agent:main:dashboard:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx] (head 9115913)

Determinism: the 10 added or changed test ids ran 20 times at -n0 and 10 times at -n 4 --dist loadgroup beside test_overload_home_fence.py and test_diagnostics_kiro_log_layout.py, all green, plus one shuffled order (seed 17459), green.

Manual verification

N/A — the change is a path name, and the test measures the path the allocator really creates; no socket-binding MCP server runs in CI.

Related Issues

Part of #30271
Builds on #30443.

Sibling sweep

Swept: git grep -nE ""TMPDIR"" -- src/
Sibling: src/kiro_crew/mcp_gateway/backend_tmp.py:158 -- tracked in #30271
Sibling: src/kiro_crew/dashboard/handlers/office_slides.py:673 -- not affected -- a document converter's work dir, it starts no MCP server
Sibling: src/kiro_crew/dashboard_verify.py:933 -- not affected -- a browser profile dir for the verifier, it starts no MCP server

Pattern harvest

Not generalizable: the only budget at stake is what a third-party server appends below a temp dir we hand it, and the two places that hand an MCP server one (agent scratch, the gateway's managed temp) are both covered by a length test.

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

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 8, 2026 19:53
@bolichen97
bolichen97 requested a review from Zedmor November 8, 2026 19:53
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/sandbox_leaves.py

  • @bolichen97 posted a complete reasoning template for 9115913.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 911591337b7125a257e5306b83a2d1e3a71d2519 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 8, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 911591337b7125a257e5306b83a2d1e3a71d2519 — 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: every item is the fix or the docs and tests that have to follow it. The label still reaches one debug log line, so nothing is lost.

Notes

  • Item 2 — undeclared: the label parameter is now passed only to a logger.debug call. All 3 callers still build a label (grepped allocate_scratch\(). The description mentions this, so it is inventory only. Subtraction: none needed now. The parameter could be removed later if the debug line is never used.

What this change ships

Inventory (5 items) — 4 justified

Intent: let a socket-binding MCP server (MATLAB) start inside chats on a default data home. This is a FIX.

  1. Scratch dirs are named <token8> instead of <label>-<token8>, so socket paths fit — justified
  2. The session label leaves the directory name and goes only to a debug log line — undeclared (the description does mention the log line)
  3. The host-data fixture check also flags scratch/<token8> paths — justified
  4. The troubleshooting doc finds the shared runtime tree by age, size and a live .owner instead of a runtime-* name — justified
  5. Specs and comments now spell the new directory layout — justified

[FIRST-PRINCIPLES-REVIEWED] 9115913

Description read

[DESCRIPTION-READ] e83df097a48836dcc12fa8caf6c67d28b1b2f8da9db0ead1b310789c88389294

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

No design-level concerns. Naming each scratch directory by its random token alone fixes the socket-length overflow at its cause. The sweep and diagnostics readers don't parse the name, so they keep working.

Notes

  • The session label is now logged only at debug level, so at the default log level nothing ties a scratch or .quarantine tree to its session. If operators need that link, an owner-marker field would keep it without making the path longer.

[DESIGN-REVIEWED] 9115913

Description read

[DESCRIPTION-READ] 2d7f2d0534bcfc02aeabb9559e040db11fc5db36d61426c2088551f52b8ae9dd

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 911591337b7125a257e5306b83a2d1e3a71d2519 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 9115913

Verdict parsed from the review's SHA-scoped output markers for commit 911591337b7125a257e5306b83a2d1e3a71d2519.

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

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 911591337b7125a257e5306b83a2d1e3a71d2519 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 9115913

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

@bolichen97
bolichen97 enabled auto-merge (squash) November 8, 2026 20:14
@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 8, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Author's reasoning for the sensitive path this head touches.

Sensitive change review

  • Head commit: cddf741
  • What rule changed: no rule changed; the only edit to src/kiro_crew/sandbox_leaves.py is one comment, which now spells the scratch layout <home>/scratch/<rand> instead of <home>/scratch/<label>-<rand>.
  • Before -> after (what was allowed/blocked, now): unchanged; the scratch root is masked as a whole for every sandboxed process before and after, and each spawn still gets only its own directory back as a private window. Only the directory's name loses the label.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): nothing from this file, since no code line in it changed. For the rename itself, a name collision fails that allocation's mkdir and the spawn falls back to the inherited temp dir, the same path any allocation failure takes today.
  • Evidence checked (which sandbox result proves it): the diff of sandbox_leaves.py is that one comment line; test_overload_home_fence.py and test_subagent_shared_scratch.py, which pin the mask and the per-spawn window, passed on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): the related backend set, 3816 tests across 59 files including the scratch, cron, DeepSeek probe and sandbox mask tests, passed locally on this head.
    • Backward compatible (old config / old data / old callers still work, how checked): directories made before the change keep their names and are swept as before, because the sweep reads owner markers and idle time, never names (TestLivenessSweep).
    • Existing tests (which suites passed on this head): every backend gate in the local gate list passed on this head; the one red CI test (test_dashboard_server_composition_contract.py) is red on main too and is fixed in test: count the 140 lazy imports the server owners now hold #33383.
  • How to undo: revert the single commit; no data, config or marker format changes, so nothing needs migrating back.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] The red Backend Tests (3.12, 6) and Backend Tests (Windows) (6) shards fail on test/test_dashboard_server_composition_contract.py::test_the_lazy_imports_stay_inside_the_functions_that_need_them (assert 140 == 139), which fails the same way on main's own CI run for 012380a; this PR touches nothing it counts. #33383 updates that count; this PR waits for it, and Coverage Gate follows the shard.

@bolichen97
bolichen97 force-pushed the fix/30271-short-scratch-label branch from cddf741 to 217d781 Compare November 9, 2026 05:06
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/architecture/context-management.md, docs/system-specs/modules/acp-client.md, docs/system-specs/modules/learn-cron-dashboard.md, src/kiro_crew/docs/troubleshooting.md, src/kiro_crew/sandbox_leaves.py since this head went green (2caa69b -> d2c6817); CI re-running.

The new base carries #33383, which fixes the main red (test_dashboard_server_composition_contract.py::test_the_lazy_imports_stay_inside_the_functions_that_need_them) that failed Backend Tests (3.12, 6), Backend Tests (Windows) (6) and Coverage Gate on cddf741. The patch is unchanged.

[operator: bolichen97]

@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 Nov 9, 2026
@bolichen97

bolichen97 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Author's reasoning for the sensitive path this head touches.

Sensitive change review

  • Head commit: 217d781
  • What rule changed: no rule changed; the only edit to src/kiro_crew/sandbox_leaves.py is one comment, which now spells the scratch layout <home>/scratch/<rand> instead of <home>/scratch/<label>-<rand>.
  • Before -> after (what was allowed/blocked, now): unchanged; the scratch root is masked as a whole for every sandboxed process before and after, and each spawn still gets only its own directory back as a private window. Only the directory's name loses the label.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): nothing from this file, since no code line in it changed. For the rename itself, a name collision fails that allocation's mkdir and the spawn falls back to the inherited temp dir, the same path any allocation failure takes today.
  • Evidence checked (which sandbox result proves it): the diff of sandbox_leaves.py is that one comment line; test_overload_home_fence.py and test_subagent_shared_scratch.py, which pin the mask and the per-spawn window, passed on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): the related backend set, 3826 tests across 59 files including the scratch, cron, DeepSeek probe and sandbox mask tests, passed locally on this head.
    • Backward compatible (old config / old data / old callers still work, how checked): directories made before the change keep their names and are swept as before, because the sweep reads owner markers and idle time, never names (TestLivenessSweep).
    • Existing tests (which suites passed on this head): every backend gate in the local gate list passed on this head (isort, flake8, mypy, black, the script checks, the flake-pattern ratchet). This head is rebased onto main with test: count the 140 lazy imports the server owners now hold #33383, the fix for the shard-6 red the previous head showed.
  • How to undo: revert the single commit; no data, config or marker format changes, so nothing needs migrating back.

@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 9, 2026

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving. Scratch dirs are named <token8> instead of <label>-<token8>, so MCP servers that bind a Unix socket under TMPDIR (MATLAB) fit the 105-byte limit (agent_scratch.py:544, test/test_agent_scratch.py:70-79, scripts/check_acp_frame_host_data.py:52). No code reads the label back from a name, and a mutation turns the guarding test red. Static Ratchet and macOS tests are main drift.

In a chat the agent starts its MCP servers itself and they inherit
the agent's scratch directory as their temp dir. That directory was
named <label>-<token8>, and the label (the session key, up to 40
characters, or "runtime") pushed a server's socket path past the
105-byte limit the MATLAB MCP server enforces: always in a dedicated
session, and on Windows for any username over 6 characters.

Name each scratch directory by its random token alone and write the
label to a debug log line instead. The token already made each name
unique and each sweep single-owner, and the sweep reads owner markers,
not names, so reclaiming is unchanged. The troubleshooting doc, the
specs that spelled the layout and the fixture host-data check follow
the new name.

Part of #30271
@bolichen97
bolichen97 force-pushed the fix/30271-short-scratch-label branch from 217d781 to 9115913 Compare November 10, 2026 00:48
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/architecture/context-management.md, docs/system-specs/modules/acp-client.md, docs/system-specs/modules/learn-cron-dashboard.md, src/kiro_crew/agent_scratch.py, src/kiro_crew/docs/troubleshooting.md, src/kiro_crew/sandbox_leaves.py since this head went green (d2c6817 -> fd5d9ef); CI re-running.

The new base carries #33695, which fixes the main red (test/test_pid_reader_ratchet.py::test_owner_marked_sites_match_the_recorded_count, 9 owner-marked pid reader(s) in src, recorded 8) that failed Static Ratchet Gate and macOS Tests / Backend Tests (macOS) (4) on 217d781; Await Fast Gate and Coverage Gate followed from it, and Inclusive Language and Build Desktop (ubuntu-22.04-arm) failed on an upstream 504. A re-run would have tested the same old merge commit, so this push is the only way to a fresh run. The patch is unchanged.

[operator: bolichen97]

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Author's reasoning for the sensitive path this head touches.

Sensitive change review

  • Head commit: 9115913
  • What rule changed: no rule changed; the only edit to src/kiro_crew/sandbox_leaves.py is one comment, which now spells the scratch layout <home>/scratch/<rand> instead of <home>/scratch/<label>-<rand>.
  • Before -> after (what was allowed/blocked, now): unchanged; the scratch root is masked as a whole for every sandboxed process before and after, and each spawn still gets only its own directory back as a private window. Only the directory's name loses the label.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): nothing from this file, since no code line in it changed. For the rename itself, a name collision fails that allocation's mkdir and the spawn falls back to the inherited temp dir, the same path any allocation failure takes today.
  • Evidence checked (which sandbox result proves it): the diff of sandbox_leaves.py is that one comment line; test_overload_home_fence.py and test_subagent_shared_scratch.py, which pin the mask and the per-spawn window, passed on this head.
  • No regression:
    • Tools still work (which tools/commands were run, result): the related backend set ran locally on this head, 3876 passed and 8 skipped; the one other test, test_browser_harness_install.py::test_the_installers_pip_reads_no_index_from_the_owners_pip_config, timed out on a 60-second pip config list under host load and passed when re-run alone.
    • Backward compatible (old config / old data / old callers still work, how checked): directories made before the change keep their names and are swept as before, because the sweep reads owner markers and idle time, never names (TestLivenessSweep).
    • Existing tests (which suites passed on this head): every backend gate in the local gate list passed on this head (isort, flake8, mypy, black, the script checks, docs lint, the flake-pattern ratchet, semgrep on the diff). This head is rebased onto main with test: count the ninth owner-marked pid reader in src #33695, the fix for the pid-reader ratchet red the previous head showed; the patch is unchanged.
  • How to undo: revert the single commit; no data, config or marker format changes, so nothing needs migrating back.

@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 readiness: checking Automated validation is still running labels Nov 10, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 10, 2026
@bolichen97
bolichen97 merged commit dd69815 into main Nov 10, 2026
99 of 101 checks passed
@bolichen97
bolichen97 deleted the fix/30271-short-scratch-label branch November 10, 2026 13:32
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants