Skip to content

fix(mcp): refuse sealed temp declarations at runtime - #10012

Merged
iamwhatever merged 1 commit into
mainfrom
fix/sealed-temp-runtime-wiring
Sep 11, 2026
Merged

iamwhatever merged 1 commit into
mainfrom
fix/sealed-temp-runtime-wiring

Conversation

@pepmach

@pepmach pepmach commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

A green MCP probe can disagree with the running server. The probe replaces a temp path under the sealed runtime directory, but runtime spawn can pass that unwritable path to the child.

Why it matters

The server can pass discovery and fail on its first temp write. The operator then debugs a server that the probe said was healthy.

What changed (motivation → approach → change)

Probe and runtime use one declared-temp rule. classify_declared_temp_env canonicalizes TMPDIR/TMP/TEMP, refuses the whole declaration when one key is sealed or unclassifiable, and fails closed under check-failed when classification raises.

gatewayd checks literal declarations before forwarding them. spawn_backend checks the final child environment before launch and selects the managed temp for every refusal. A gateway refusal removes both declared and inherited canonical temp keys, so a failed managed allocation falls to the platform default instead of the refused value. A relative declaration is unclassifiable because the daemon cwd and the child's work_dir differ. A secret:// temp skips the raw path check, resolves in memory, and reaches the final check with its secret identity attached.

Warning fields use one formatter. It hides resolved secrets, redacts ordinary paths and classifier errors, and repr-escapes control characters into one log line. The security-posture census counts both runtime warning sites. The three legacy Black-baselined files contain only functional hunks, and their baseline entries remain.

flowchart LR
  S[spec temp]:::ctx --> P[shared declared-temp rule]:::added
  R[secret:// temp]:::ctx --> V[resolve in memory]:::changed --> P
  P -->|cleared| D[declared temp]:::ctx
  P -->|refused or check-failed| M[managed temp]:::added
  D --> C[probe or runtime child]:::ctx
  M --> C
  classDef added fill:#DCFCE7,stroke:#16A34A,color:#14532D,stroke-width:2px
  classDef changed fill:#FEF3C7,stroke:#D97706,color:#78350F,stroke-width:2px
  classDef removed fill:#FEE2E2,stroke:#DC2626,color:#7F1D1D,stroke-dasharray:4 3
  classDef ctx fill:#E0F2FE,stroke:#0284C7,color:#0C4A6E
  linkStyle 0,3,5 stroke:#16A34A,stroke-width:2px
Loading

🟩 added · 🟨 changed · 🟥 removed · 🟦 unchanged

The probe and running backend make the same temp decision before the child starts.

Tests

  • TestDeclaredTempClassification locks canonical acceptance, whole-declaration refusal, redacted failure text, and fail-closed check errors.
  • test_relative_declaration_is_unclassifiable locks the daemon-cwd versus child-work_dir decision.
  • test_real_classifier_refuses_a_sealed_declaration drives a real <home>/run/... path through spawn_backend.
  • test_sealed_declaration_uses_managed_temp_and_warns, test_check_failure_uses_managed_temp_and_warns, and test_refusal_allocation_failure_uses_the_platform_default lock managed fallback and its diagnostics.
  • test_refusal_warning_escapes_newlines_in_the_declared_path and test_sealed_declared_temp_is_removed_before_spawn lock one-line warning fields at the probe and gateway boundaries.
  • test_secret_backed_refusal_never_logs_the_resolved_path and test_secret_temp_skips_raw_precheck_and_reaches_spawn_backend lock both secret-resolution boundaries.
  • TestGateSideLogRedactorSpelling locks callback-style baseline-redactor detection and both runtime census entries.

Manual verification

  • Requested serial regression and security gate: 2,256 passed, 8 skipped.
  • Mypy: no issues in 1,412 source files.
  • Black ratchet, isort, flake8, subprocess encoding, sync-I/O, comment history, and docs lint passed.

Screenshots / video

Not applicable: backend-only change with no UI surface.

Related Issues

Fixes #9843
Refs #9108

Pattern harvest

Rule candidate: review-prompt
Pattern: when a probe rewrites a declared resource before reporting health, every runtime spawn boundary must consume the same decision rule.

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

@pepmach
pepmach requested review from a team and krishdhasmana and removed request for a team September 11, 2026 00:10
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 11, 2026
@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 31eb9c09ffee5a8201baa9c9bee6705dc321a1ad and found no blocking issues.

This comment is updated in place on each push.

Review details

FINDING -- src/kiro_crew/mcp_discovery.py:2041 -- classify_declared_temp_env treats raw secret:// temp values as relative, so probes use managed temp while runtime may honor the resolved path and fail -> Fix: resolve secret-backed temp values before classification, matching gatewayd.
[GPT-REVIEWED] 31eb9c0

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

@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

One shared classification rule owned by sandbox.py, consumed at every spawn boundary, fail-closed, with the secret-resolution check correctly deferred — sound shape for #9843.

Suggestions

  • A spec with a deliberately work-dir-relative temp now silently degrades to the managed temp; if this bites real specs, resolving against work_dir at the final spawn_backend check (which already has it) is the escape hatch — as a follow-up, not here.

[DESIGN-REVIEWED] 31eb9c0

@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 31eb9c09ffee5a8201baa9c9bee6705dc321a1ad — 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.

All verification done. The key facts: spawn_backend( has exactly one call site (gatewayd:3510), so the new gateway-side literal pre-check and the new spawn-side final-env check guard the same single path — and the secret:// route already relies on the spawn-side check alone, with identical child-env outcomes on every branch I traced (refusal→strip→managed, allocation failure→platform default). The _path_identity docstring rewrite silently deletes a recorded security rationale. Everything else is derived from #9843 (a gap the base spec itself documented), the posture gate, or the same-commit doc rule.

First-Principles-Verdict: CONCERNS

The gatewayd literal pre-check re-decides what spawn_backend's final-env check already decides on the same single spawn path — including its secret:// carve-out, which exists only to dodge the pre-check.

Not justified as shipped

  • Item 2 — duplicate of spawn_backend's final-env check: spawn_backend( has exactly 1 caller (gatewayd.py:3510), so both checks guard one path; an accepted literal is classified twice per cold spawn, and the secret:// path already trusts the spawn-side check alone.
  • Item 9 — undeclared: the _path_identity docstring rewrite (sandbox.py) deletes the recorded security reason for lstat ("a planted symlink could point at a remote or stalling target... off-host I/O") and substitutes a redundancy argument, with no evidence the old reason was wrong; behavior is unchanged, so the rewrite ships nothing.

What this change ships

Inventory (10 items) — 8 justified

Intent: make the running MCP backend obey the same sealed-temp refusal the probe already applies, so a green probe stops certifying a server that dies on its first temp write — a FIX (#9843, gap documented in the base spec).

  1. A backend with a sealed declared temp now spawns on the managed temp instead of failing at first write — justified
  2. The gateway separately pre-checks literal declarations before forwarding — duplicate of spawn_backend's final-env check (1 caller, gatewayd.py:3510)
  3. Relative TMPDIR/TMP/TEMP declarations are now refused at every boundary, probe included — justified
  4. Refusal warnings redact paths/errors and repr-escape control characters into one log line — justified (rides along; log forging via untrusted spec text is a named boundary)
  5. secret:// temps skip the raw pre-check, are classified after resolution, and never log the resolved value — justified
  6. After a refusal, failed managed allocation falls to the platform default, and the warning says which fallback applied — justified
  7. The probe's private temp helpers became shared sandbox helpers — justified (3 consumers counted: probe, gatewayd, backend)
  8. Posture census counts both new warning sites and recognizes redactor= callbacks — justified (gate)
  9. _path_identity's security rationale for lstat replaced with a redundancy rationale — undeclared
  10. Spec "Probe temp" section rewritten as "MCP temp" in the same commit — justified

Watch

  • The gateway pre-check (gatewayd.py:3429–3488) is a second spelling of the spawn-side rule: on every branch (refusal, check-failed, allocation failure, lowercase re-emission) spawn_backend alone produces the identical child env — test_refusal_allocation_failure_uses_the_platform_default proves it without gateway help, and the secret:// route already runs on it exclusively.
    Clears when: the pre-check block is deleted with declared_temp_keys reverted to the raw one-line key filter, or the author names one child-env outcome that differs without it.
  • The _path_identity rewrite recasts a security pin as mere redundancy with no cited evidence; the old text already contained the redundancy argument alongside the security one, so the delta is purely the deleted security rationale.
    Clears when: the docstring hunk is reverted, or history/issue evidence shows the off-host-I/O rationale was wrong.

Subtractions

  • Delete the gatewayd classification block (gatewayd.py:3429–3488) and its census entry ("mcp_gateway/gatewayd.py": 1); pass declared_temp_keys=tuple(key for key in declared if key.upper() in CANONICAL_TEMP_KEYS) and keep secret_env_keys — the secret partitioning (secret_temp_keys/checkable_declared) deletes with it.
  • Revert the _path_identity docstring hunk in sandbox.py; the change under review never touches that function's behavior.

[FIRST-PRINCIPLES-REVIEWED] 31eb9c0

@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed 31eb9c09ffee5a8201baa9c9bee6705dc321a1ad — this comment is updated in place on each push.

Review details

No findings.

The sole candidate (case-duplicate temp keys colliding in spawn_backend's declared_values fold) does not survive falsification. Both the classification (classify_declared_temp_env → declared_values = {key.upper(): value …}) and the emission (spawn_backend else-branch, same {key.upper(): value …} fold over the same spawn_env in the same insertion order) collapse duplicate spellings identically, so the value that is classified is exactly the value that is emitted — a sealed path cannot be classified-safe-but-honored, and vice versa. In the only production caller (gatewayd._acquire_backend) the declared temp is re-emitted under its canonical uppercase key and spawn_env.update(declared) runs last, so the declaration always wins any collision with an ambient key. The premise input — a lowercase ambient tmpdir/tmp in the daemon environment — is unconfirmed and, being lowercase, is never consulted by tempfile anyway. (a) has no concrete input and (c) has no observable wrong outcome.

[OPUS-REVIEWED] 31eb9c0

Verdict parsed from the review's SHA-scoped output markers for commit 31eb9c09ffee5a8201baa9c9bee6705dc321a1ad.

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

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Sep 11, 2026

@chenmingwei23 chenmingwei23 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.

[code-review-sage] LGTM - no blocking findings. The change fixes a real probe/runtime divergence and does it at the right layer.

Assessment. A green MCP probe could disagree with the running server: the probe classified a spec-declared TMPDIR/TMP/TEMP against the sandbox seal, but the runtime spawn paths honoured a declared temp with no such check, so a server could pass discovery and then fail its first write into a sealed-parent temp (#9843). This PR consolidates one rule, sandbox.classify_declared_temp_env, and runs it off the event loop at all three spawn boundaries (probe_server, gatewayd._spawn, spawn_backend). Root-cause fix, not a symptom patch.

What I verified

  • Trust boundary / secret temp. A secret:// temp is NOT classified as a raw path in gatewayd._spawn (would misread URI text as a local path and echo a hostile secret name into the log). It stays provisionally declared, gets resolved in memory by resolve_secret_uris, and spawn_backend re-runs classify_declared_temp_env on the resolved value with declared_temp_keys=accepted_temp_keys. A sealed resolved path is refused at the final boundary and masked as <resolved secret> via format_declared_temp_refusals(hidden_keys=secret_env_keys). test_secret_temp_skips_raw_precheck_and_reaches_spawn_backend and test_secret_backed_refusal_never_logs_the_resolved_path lock both halves; the resolved path never reaches the warning.
  • Whole-declaration refusal. One refused key drops the entire temp declaration (refused gives accepted_temp_keys = ()), and all canonical temp keys are stripped from the spawn env. Correct: tempfile consults TMPDIR before TMP, so keeping a surviving sibling would make writability depend on spelling order. Verified for the mixed secret+checkable case too: a refused checkable key drops the secret key with it.
  • Fail-closed. A classifier exception refuses every declared key under check-failed and names the exception in the warning (test_check_failure_uses_managed_temp_and_warns). If managed-temp allocation then fails, no refused temp value survives in the env; the child falls to its platform default rather than the refused path.
  • Log-forging. Refused paths are repr-escaped after the caller's redactor runs, so an embedded newline cannot forge a second log record. test_sealed_declared_temp_is_removed_before_spawn asserts the forged-newline text does not appear in the emitted warning.
  • Windows. classify_declared_temp_path returns None on win32 without resolving (no native sandbox backend seals run/, and realpath/stat would open untrusted config text). Behaviour unchanged there.
  • No dangling refs / imports. The removed mcp_discovery privates (_CANONICAL_TEMP_KEYS, _refused_declared_temp_keys, _declared_temp_refusal_reasons) have no remaining callers. SECRET_URI_PREFIX, CANONICAL_TEMP_KEYS, redact, and the three sandbox helpers are all imported where used. SECRET_URI_PREFIX is exported with a backward-compat alias for existing call sites.
  • PoolKey. The PoolKey still hashes the caller's original effective env, so a refusal can conservatively split two equivalent managed-temp backends but can never collapse two distinct declarations into one pool: the safe direction.

Design notes (non-blocking)

  • The bulk of backend.py's diff (295 del / 361 add) is Black reformatting from removing it from .github/black-baseline.txt, plus the same for the two test files. The description accounts for this ("touched legacy Python surfaces are Black-clean, so three formatter-baseline entries are removed"). Description-to-diff fidelity holds in both directions.
  • security_posture.py adds a whole-file sandbox.py entry to the redaction-sink allowlist. Consistent with the existing entries (a pure scrubber with no output of its own; the probe/gateway loggers are the sinks), though a file-level match is broad.

Tests cover the classification matrix, canonical-key acceptance, whole-declaration refusal, fail-closed, managed fallback, off-loop execution, and both secret boundaries: not tautological. CI is green on the head SHA (d4513b6), including the GPT / Opus / Design / First-Principles / UX review lanes.

The human owns the merge verdict.

@bolichen97 bolichen97 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.

Maintainer review (agent-assisted, on behalf of @bolichen97), head d4513b6ad. The code is correct and is the complementary second half of #9108, not a duplicate: classify_declared_temp_env (sandbox.py:2080-2135, fail-closed check-failed, one refused key drops the whole declaration) applied at gatewayd _spawn (gatewayd.py:3418-3452, secret:// temps deferred) and at the spawn_backend chokepoint on the final resolved env. Not approvable on this base:

  • Blocking (process) — base is fix/pod-repro-8747, so no CI ran on this code. ci.yml, fast-gate.yml and build.yml trigger only on pull_request: branches: [main]; of the 13 workflow runs on d4513b6a none is the test suite, Black/isort/flake8/mypy or the build, and pr-readiness.yml:530-540 marks them "Not eligible" on a stacked base yet still published readiness: passed. The body's "2,138 passed / 65 passed / gates passed" is therefore unverified by CI. Two ways out, as said on #9108: fold this into #9108 (merge this branch into fix/pod-repro-8747 and let #9108's CI run on the combined diff, reviewed as one PR), or wait for #9108 to land and retarget this PR to main. Either way this code merges nowhere until a main-targeted run is green on it.
  • gatewayd.py:3436-3443, backend.py:4111-4120 — the log-site census ratchet was bypassed. Two new gate-side WARNING lines read the baseline redact through redactor=redact inside format_declared_temp_refusals (sandbox.py:2171); test_security_posture.py::_wraps_baseline_call counts only direct redact(...) calls, so _BASELINE_LOG_SITE_CENSUS stays mcp_gateway/backend.py: 2 with no gatewayd.py entry and the ratchet never fired. Add the entries (or route the two sites through a direct call) so the census reflects the code.
  • sandbox.py:2080 (inherited from #9108's classify_declared_temp_path) — a relative declared temp (TMPDIR=run/x) is classified against the daemon's cwd, but the child resolves it against cwd=work_dir (backend.py:4149), so a relative spelling can pass the check and still land in the seal, or be refused spuriously. Refuse non-absolute declarations as unclassifiable, or join with work_dir before classifying. Fix it once in #9108's helper.
  • sandbox.py:2127,2138-2149 — the check-failed failure text (f"{type(exc).__name__}: {exc}") is appended unredacted and not repr-escaped, unlike the path fields; a classifier exception that echoes the declared value can carry control characters or a credential into the log line.
  • Tests: every runtime refusal test stubs classify_declared_temp_path; no test drives a real <home>/run/... path through spawn_backend. Add one with the real classifier.
  • Scope: roughly 1,600 of the 4,300 changed lines are a Black reformat of backend.py and two test files; it triples the review surface of a security fix — ship it separately. Nit: after a refusal has stripped every temp key, backend.py:4132-4135 still logs "spawning with inherited temp" though the child gets the platform default.

Auto-Merge was never armed here and stays off.

Base automatically changed from fix/pod-repro-8747 to main September 11, 2026 06:59
@github-actions github-actions Bot added readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: passed Eligible automated validation passed for the current revision labels Sep 11, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

Update (maintainer, agent-assisted): #9108 was approved and merged by another maintainer at 06:59Z (93eb68e77), so GitHub retargeted this PR's base to main. That resolves the process blocker above by itself — ci.yml, fast-gate.yml and build.yml now run on this head, so please make sure the next push is rebased onto current main and let the suite go green. Two adjustments to the list above: (1) the relative-declared-temp finding (TMPDIR=run/x classified against the daemon's cwd, child resolves against work_dir) landed in #9108's classify_declared_temp_path unfixed, so it is now this PR's to fix — refuse non-absolute declarations as unclassifiable or join with work_dir before classifying; (2) the log-site census entries, the repr/redact of the check-failed text, the one unstubbed spawn_backend test and splitting the Black reformat out still stand. Ping when the head is up and it gets re-reviewed the same day.

@pepmach
pepmach force-pushed the fix/sealed-temp-runtime-wiring branch from d4513b6 to a5c18b3 Compare September 11, 2026 07:55
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 11, 2026
@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

self-added: no

  • rebutted: strict realpath already owns symlink resolution — span=51b023054779

classify_declared_temp_path resolves the original spelling with realpath(strict=True) before _path_identity runs. The identity helper therefore cannot prevent that resolution from reaching a remote target; its lstat only keeps the later alias walk on the component being compared.
Restoring the deleted sentence would document a security boundary this helper does not provide. The replacement at src/kiro_crew/sandbox.py:2015 states its actual role.

@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

self-added: no

  • rebutted: the probe cannot honor an unresolved secret URI as a temp path — span=fdacadfd36d3

The probe has no secret:// resolver. Mirroring gatewayd's skip would pass the literal URI to the probed child and report that declaration as honored; gatewayd's carve-out is safe only because it resolves the value before spawn_backend performs the final classification.
The probe instead fails closed onto its managed temp. Its warning formatter redacts and repr-escapes the reference, so neither the URI text nor control characters can forge a log line. Findings that require the probe to treat an unresolved secret reference as a usable filesystem path are covered by this ruling.

@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

self-added: no

  • rebutted: the two checks bind two different environment stages — span=9231682f6bc1

The gateway check judges the literal declared overlay before it enters spawn_env; the backend check judges the final child environment after secret:// resolution. The first strips refused declared and inherited canonical keys, while the second catches a resolved secret path and any final transformation.
The owning MCP temp contract deliberately binds both boundaries. One process does not make the two representations identical, so the later backstop does not make the earlier admission check redundant.

@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

self-added: no

  • rebutted: the removed lstat sentence described a boundary it cannot enforce — span=5c5eab4bec24

Strict realpath runs before _path_identity, so an absolute symlink target has already been followed before the helper calls lstat. The old off-host-I/O sentence was therefore false for this control flow.
The current docstring records the remaining invariant: lstat keeps the identity alias walk on the named component and avoids a second resolution. Keeping a false security rationale is not justified by this PR's scope.

@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

self-added: no

  • rebutted: classifier injection is the probe's bounded test seam — span=fc75e575c8f0

The probe imports its classifier binding and dispatches the shared env helper through asyncio.to_thread. Passing that binding explicitly lets probe tests replace only the probe seam while the runtime callers continue to use the shared default.
Deleting the keyword changes no product outcome and moves those tests onto the process-global sandbox classifier. The one keyword-only seam is smaller and more isolated than that wider patch scope, so it stays.

@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

self-added: no

  • rebutted: literal admission and final child-env validation are separate boundaries — span=d334bb26cb79

Gatewayd classifies the literal sidecar declaration before merging it into spawn_env; spawn_backend classifies the post-resolution child value. A plain refusal is removed at the first boundary, and a secret:// value is masked and judged only after resolution at the second.
The red-first inherited-temp regression proves the early boundary has its own state obligation. The two checks are intentionally stage-specific, not duplicate calls over one value.

@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

self-added: no

  • rebutted: keep the gateway admission check and final backend check — span=cb57e3c5138d

Removing the gateway block would let a literal declaration known to be refused enter spawn_env and secret resolution, leaving only the final launch check to recover. The current shape removes that value before the transition and still validates the final resolved child environment.
This is the owner-approved shared-rule contract recorded in the MCP temp spec. The fix keeps both boundaries and adds a regression that the first strips inherited canonical keys as well as the overlay.

@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

self-added: no

  • rebutted: keep the probe-local classifier injection seam — span=fcce43186eaa

mcp_discovery owns a caller-local classifier binding that its fail-closed and warning tests replace while the helper runs off-loop. The runtime callers deliberately take the default classifier.
Removing the keyword saves one parameter but forces probe tests to mutate the shared sandbox module instead. That widens test state for no runtime reduction, so the bounded caller seam stays.

@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 11, 2026
Share declared temp classification across probe and runtime spawn paths. Replace refused or unclassifiable declarations with the managed temp so probe and runtime cannot disagree.
@pepmach
pepmach force-pushed the fix/sealed-temp-runtime-wiring branch from a5c18b3 to 31eb9c0 Compare September 11, 2026 09:03
@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 11, 2026
@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

self-added: no

  • rebutted: relative temp declarations fail closed by design — span=beca4a494c8c

A relative temp has no single meaning across the probe daemon cwd and each backend work_dir. Refusing it at the shared classifier is what lets every caller make the same decision; resolving only at spawn_backend would restore probe/runtime disagreement.
No real spec requiring work-dir-relative temp is in evidence. Adding caller-specific resolution before such a case exists would widen the contract beyond this sealed-parent fix, so no follow-up is created.

@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

self-added: no

  • rebutted: literal admission and final child-env validation bind different stages — span=4264e2be13bf

Gatewayd judges the literal sidecar overlay before it enters spawn_env; spawn_backend judges the final child value after secret resolution. The first strips refused declared and inherited canonical keys, while the second catches a resolved secret path and final transformations.
The owning MCP temp contract deliberately binds both boundaries. One cold-spawn call path does not make its pre-resolution and post-resolution values identical.

@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

self-added: no

  • rebutted: the deleted lstat sentence described a boundary it cannot enforce — span=23af8560f963

realpath(strict=True) runs before _path_identity, so an absolute symlink target has already been followed before the helper calls lstat. The old off-host-I/O sentence was false for this execution order.
The current docstring records the actual invariant: lstat keeps the identity alias walk on the named component and avoids a second resolution. Restoring a false security rationale would make the comment less safe, not more.

@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

self-added: no

  • rebutted: the two checks enforce separate environment transitions — span=9fb8209cf270

The gateway check removes a refused literal declaration before the overlay-to-spawn_env transition. The backend check validates the post-resolution child environment and masks resolved secret values.
The inherited-temp regression demonstrates a distinct obligation at the early boundary: both the overlay and an ambient canonical twin must be removed there. The checks share a rule, not one input value.

@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

self-added: no

  • rebutted: do not restore a false remote-resolution rationale — span=d14dbde2c091

_path_identity runs after strict canonical resolution, so its lstat cannot prevent that earlier resolution from following an absolute symlink. The prior sentence attributed a protection to the wrong operation.
The replacement is grounded in the call order visible in classify_declared_temp_path: canonicalize first, then run the identity alias walk. That code evidence is why the comment changed.

@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

self-added: no

  • rebutted: keep the gateway admission check and final backend check — span=a3a66f121812

Removing the gateway block would let a literal declaration known to be refused enter spawn_env and the resolution stage, leaving only the final launch check to recover. The current shape rejects it before that transition and still validates the resolved child value.
This is the owner-approved shared-rule contract in the MCP temp spec. The census entry remains because the gateway warning is a real gate-side log site, not formatting noise.

@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

self-added: no

  • rebutted: keep the truthful post-realpath identity-walk comment — span=7550b59b3a84

Reverting the hunk would again claim that _path_identity prevents remote resolution even though realpath(strict=True) already ran. The helper cannot enforce that claim.
The present comment states only what the code does: compare the named component without performing another resolution. The behavior is unchanged; the documentation is more accurate.

@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

self-added: no

  • rebutted: unresolved probe secrets are outside the sealed-parent guarantee — span=643e0402b13c

The probe has no secret-resolution authority. Treating a literal secret:// reference as an honored temp would pass that URI to the child, while resolving it during a health check would widen credential access and lifecycle beyond this change.
The probe fails closed to managed temp; runtime resolves the secret and applies the same sealed-parent rule at the final child boundary. For an arbitrary unsealed path, the owning spec explicitly does not certify existence or writability. Findings requiring probe/runtime parity for every arbitrary temp path are covered by that narrow guarantee.

@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 11, 2026
@pepmach

pepmach commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

@bolichen97 I kept this PR as the runtime half after #9108 merged. The helper notes that missed that merge are carried here with the runtime fixes, so the final one-commit diff is based directly on main.

On relative declarations: classify_declared_temp_path now refuses a non-absolute value as unclassifiable before platform-specific resolution (src/kiro_crew/sandbox.py:2150-2151). The reason text names the daemon/child working-directory mismatch, and test_relative_declaration_is_unclassifiable pins TMPDIR=run/x (test/test_sandbox_argv.py:1108). The owning MCP temp spec states the same rule (docs/system-specs/modules/memory-skills-hooks.md:3570).

On probe log forging: the probe routes refused key/path fields through format_declared_temp_refusals and routes classifier failures through the same redaction and repr escaping (src/kiro_crew/mcp_discovery.py:2051-2061). test_refusal_warning_escapes_newlines_in_the_declared_path proves a newline stays inside one log field (test/test_mcp_discovery.py:2802).

On the stale cause list: TestSealedRuntimeParentPredicate names only sealed and unclassifiable; the deleted remote-or-device cause is gone from the class contract (test/test_sandbox_argv.py:1072-1083).

On _path_identity: its comment now describes why the identity walk uses lstat after the canonical spelling has already passed through strict realpath; it no longer claims that no-follow prevents the initial remote-resolution hazard (src/kiro_crew/sandbox.py:2015).

On the log-site census: the scanner recognizes a baseline redactor passed as a redactor= callback, not only a direct redact(...) call. The pooled-backend warning sites are recorded in _BASELINE_LOG_SITE_CENSUS (test/test_security_posture.py:255-276), with the daemon-process reason beside them.

On check-failed text: declared_temp_refusal_reasons redacts and repr-escapes the exception field before appending it (src/kiro_crew/sandbox.py:2258), using the same field helper as format_declared_temp_refusals (:2275). test_failure_reason_is_redacted_and_single_line covers both redaction and newline containment (test/test_backend_tmp.py:137).

On the real classifier path: test_real_classifier_refuses_a_sealed_declaration drives an actual <home>/run/... declaration through spawn_backend without stubbing classify_declared_temp_path (test/test_mcp_gateway_backend_coverage.py:4615).

On the fallback message and the remaining-value bug: a gateway refusal strips canonical temp keys from both the declared overlay and spawn_env before calling spawn_backend (src/kiro_crew/mcp_gateway/gatewayd.py:3454-3476). spawn_backend chooses "inherited temp" versus "platform default" from the canonical keys that remain in the real child environment (src/kiro_crew/mcp_gateway/backend.py:4102-4107). The gateway regression is at test/test_mcp_gatewayd_coverage.py:1128; the allocation-failure wording is pinned at test/test_mcp_gateway_backend_coverage.py:4714.

The whole-file Black reformats are pulled out. backend.py is Black-clean on current main, so the shrink-only gate requires its stale baseline row to be pruned; the two legacy coverage-test files keep their baseline entries. No whole-file reformat remains in this PR, and formatting-only work can ship separately.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Sep 11, 2026
@pepmach
pepmach dismissed bolichen97’s stale review September 11, 2026 10:58

Addressed at 31eb9c0: rebuilt as one commit on main with real CI, whole-file reformats removed, relative temp declarations refused, check-failed text redacted, census counts redactor callbacks, real-classifier test, gatewayd strips canonical keys from spawn_env too. See the reply comment.

@pepmach
pepmach requested a review from bolichen97 September 11, 2026 10:58

@cixuuz cixuuz 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.

Reviewed at 31eb9c0. The runtime now applies the shared declared-temp decision at literal and final resolved boundaries, refuses relative declarations, strips the full canonical declaration on refusal, fails closed on classifier errors, masks secret-backed values, keeps warning fields redacted and single-line, records the new log sites, and exercises the real sealed classifier path. The earlier relative-path, census, exception-text, test, and formatter-scope concerns are resolved; required checks are green.

@iamwhatever
iamwhatever merged commit 6977c3a into main Sep 11, 2026
92 of 94 checks passed
@iamwhatever
iamwhatever deleted the fix/sealed-temp-runtime-wiring branch September 11, 2026 19:17
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 11, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
Share declared temp classification across probe and runtime spawn paths. Replace refused or unclassifiable declarations with the managed temp so probe and runtime cannot disagree.
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.

Wire classify_declared_temp_path into spawn_backend and gatewayd so runtime refuses the same sealed temp the probe refuses

5 participants