Skip to content

fix(sandbox): keep the scope probe refresh off PATH, decode bus paths - #15636

Merged
bolichen97 merged 2 commits into
mainfrom
fix/scope-probe-no-path-walk
Oct 1, 2026
Merged

bolichen97 merged 2 commits into
mainfrom
fix/scope-probe-no-path-walk

Conversation

@bolichen97

@bolichen97 bolichen97 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The cgroup-scope probe added in #15622 never stalls the gateway's event loop on a hung PATH entry, and never drops the cgroup ceiling because a D-Bus bus address was percent-escaped.

#15622 merged with two blocking findings from its GPT 5.6 review still open, both in code that PR added:

  1. The probe now refreshes on a 60s TTL and on session changes, and each refresh ran shutil.which("systemd-run") on the event loop. That is a walk of every PATH entry, and one entry on a stalled network mount freezes the loop and the liveness heartbeat.
  2. _user_bus_socket_paths dialed DBUS_SESSION_BUS_ADDRESS unix:path= values literally. The D-Bus spec lets any byte be %XX-escaped, so an escaped address that names a bus outside XDG_RUNTIME_DIR probed as unreachable, and spawns ran without the fork-bomb/memory ceiling.

Why it matters

(1) is a gateway-wide freeze that ends in a watchdog kill and a crash loop on hosts with automounted or network PATH entries. (2) silently drops a security ceiling on hosts whose bus address is escaped.

Not a goal

What changed (motivation → approach → change)

  • _compute_cgroup_scope_probe resolves systemd-run through the new platform_compat.trusted_system_bin_quiet, a handful of stats over fixed system directories. This is the lookup cgroup_scope_argv already uses to pin the wrapper it prepends, without its miss diagnostic, which itself walks PATH with shutil.which; the review's second round found that walk. trusted_system_bin now delegates to it and keeps the diagnostic, so its behaviour is unchanged. The probe's answer also matches what the wrapper can actually use. Before, a systemd-run found only on PATH made the probe answer "available", and the wrapper then refused it.
  • _user_bus_socket_paths percent-decodes each unix:path= value (urllib.parse.unquote_to_bytes → os.fsdecode) before it is stat'ed and dialed. A value that decodes to an empty path or contains a NUL cannot name a socket and would make os.stat raise ValueError on the spawn path, so it is skipped.

Backwards compatibility

Compatible: on a host whose systemd-run is in a trusted directory and whose bus address is unescaped, the probe's answer is unchanged. A host with systemd-run only on PATH already got no ceiling from the wrapper. It now also gets a probe answer that says so, which also stops the bus locators from being forwarded to a spawn that is not wrapped.

Tests

test/test_cgroup_scope_probe_liveness.py:

  • test_a_percent_escaped_bus_address_is_decoded: the only live bus is reachable through an escaped unix:path=. Red without the decode.
  • test_a_probe_refresh_never_walks_path: shutil.which raises if called, and a TTL refresh must still answer (True, "ok"). Red with shutil.which restored.
  • test_a_probe_miss_never_walks_path: no trusted systemd-run and platform_compat.shutil.which raises; the probe must answer unavailable without walking PATH. Red with the diagnosing trusted_system_bin.
  • test_a_bus_address_naming_no_socket_never_breaks_a_spawn (%00, an embedded %00, and an empty path=): the probe and wrapper still work off the XDG_RUNTIME_DIR bus. Red without the NUL filter.

All 17 tests in the file pass. test_sandbox_argv, test_per_runtime_process_resources, test_sandbox_agent_slice_identity and test_session_scope_reap pass (327). test_platform_compat and every test that references trusted_system_bin pass (6296). The one failure, TestPeakRssIsThisProcesss, fails identically on unmodified main on this host. flake8, isort, mypy (src/kiro_crew, 0 issues), black, docs-lint and the comment-history gate are clean. docs/system-specs/common/platform-compat.md gains a row for the quiet lookup.

Manual verification

N/A — unit coverage sufficient: both changes are pure functions of the environment and the fixed system directories, and both tests exercise them through the real probe against a real listening socket.

Related Issues

Follow-up to #15622 (its GPT 5.6 review findings F1 and F2). Refs #11473. Internal report: https://t.corp.amazon.com/187b5c6e-b5cb-4d1b-9c36-ccf8c598e4f4

Pattern harvest

Rule candidate: review-prompt
Pattern: a once-per-process lookup that becomes periodic (TTL or fingerprint refresh) inherits the event-loop budget of every call, so PATH walks and other unbounded filesystem lookups inside it must be swapped for fixed-directory resolution.

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

Two defects the post-logout probe fix (#15622) introduced, from its
review:

- The probe now refreshes on a TTL, and every refresh resolved
  systemd-run with shutil.which on the event loop. A PATH entry on a
  stalled mount would hang the gateway's loop. The probe now uses
  platform_compat.trusted_system_bin, the same fixed-directory lookup
  cgroup_scope_argv already pins its wrapper with.
- DBUS_SESSION_BUS_ADDRESS unix:path= values may percent-escape any
  byte. Probing the escaped spelling literally misses a live bus that
  lives outside XDG_RUNTIME_DIR and drops the cgroup ceiling. The value
  is now decoded before it is dialed.
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] 5843231

Description read

[DESCRIPTION-READ] 4d764448cf0d1ba8ec2bfa4f11fa0fab658188ef0b00f11b3233d4348c2d6e2b

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

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 58432310adf122afb64478e13312fdf9ef061569 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Verify on one real NixOS/Homebrew-style host (systemd-run on PATH only) that the probe's new "unavailable" answer gates nothing beyond the wrapper that already refused.

What this change ships

Inventory (7 items) — 7 justified

Intent: FIX — stop the TTL-refreshed cgroup-scope probe from freezing the event loop on a stalled-mount PATH walk, and stop a percent-escaped D-Bus address from silently dropping the spawn ceiling (both tests red on base).

  1. A probe refresh resolves systemd-run by a few stats of fixed system dirs, never PATH — justified
  2. Hosts with systemd-run only on PATH now get probe answer "unavailable" (ceiling was already refused by the wrapper) — justified
  3. Probe miss reason now names the trusted-directory requirement — justified
  4. New platform_compat.trusted_system_bin_quiet helper + spec row; 2 counted consumers (sandbox.py:15551, delegation at platform_compat.py:3125) — justified
  5. Escaped unix:path= bus addresses are decoded, so an escaped address keeps the ceiling — justified
  6. Decoded empty/NUL paths are skipped instead of raising ValueError at spawn — justified
  7. Four tests pinning the no-PATH-walk and decode behaviours — justified

[FIRST-PRINCIPLES-REVIEWED] 5843231

Description read

[DESCRIPTION-READ] 984cf95cb7d7ffd37c33cba0e80564b8d408e5b7f66d2520c800a2f16679e286

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

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 58432310adf122afb64478e13312fdf9ef061569 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 5843231

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

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed 58432310adf122afb64478e13312fdf9ef061569 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 5843231

Verdict parsed from the review's SHA-scoped output markers for commit 58432310adf122afb64478e13312fdf9ef061569.

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

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 1, 2026
Second-round review of this PR: trusted_system_bin's miss diagnostic
still calls shutil.which, so a host with no trusted systemd-run walked
PATH on the event loop at the first probe refresh. The probe now uses
platform_compat.trusted_system_bin_quiet, the same fixed-directory
lookup without the diagnostic, and reports the miss in its reason.

A D-Bus unix:path= value that decodes to an empty path or one holding
a NUL cannot name a socket and made os.stat raise ValueError on the
spawn path; such values are now skipped.
@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 Oct 1, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

The Backend Tests (Windows) (2) failure is test_native_skill_projection.py alias-lock sweeping, which is red on main (#15651, fix in #15633). This change is Linux-only: on Windows the probe returns "not Linux" before any code it touches. Every other check on 5843231 is green, GPT 5.6 Review included.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 1, 2026
@bolichen97
bolichen97 merged commit 865732f into main Oct 1, 2026
142 of 151 checks passed
@bolichen97
bolichen97 deleted the fix/scope-probe-no-path-walk branch October 1, 2026 02:56
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 1, 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.

1 participant