Skip to content

fix(sandbox): stop wrapping spawns in systemd-run after logout - #15622

Merged
bolichen97 merged 1 commit into
mainfrom
fix/scope-probe-bus-loss
Oct 1, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/scope-probe-bus-loss

Conversation

@bolichen97

@bolichen97 bolichen97 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A gateway that was started inside an SSH session keeps spawning agents, cron scripts and app backends after the user's last session logs out, instead of failing every spawn with "Failed to connect to bus" until it is restarted.

On a Linux host without lingering, logind stops the per-user systemd manager and removes /run/user/<uid> (and user-<uid>.slice) when the last login session ends. XDG_RUNTIME_DIR stays set in the gateway's environment. _probe_cgroup_scope() decided "a user session exists" from the presence of that variable and cached the answer for the life of the process, so a gateway that probed while the user was logged in kept prepending systemd-run --user --scope to every spawn. systemd-run can no longer reach any bus and exits 1 with Failed to connect to bus: No such file or directory before it execs the command it wraps. Every agent respawn, script cron and app backend then fails, with no self-heal, until someone restarts the gateway; auto-paused crons also stay paused after that restart. A gateway restarted after the logout probes correctly and degrades, so two gateways disagreed about the same host.

Reported on a Cloud Desktop (internal ticket: https://t.corp.amazon.com/187b5c6e-b5cb-4d1b-9c36-ccf8c598e4f4), where the only workaround, loginctl enable-linger, needs sudo.

Why it matters

Every Linux user who starts or auto-updates the gateway over SSH on a host without lingering loses all sandboxed spawns at logout. The gateway looks healthy while every spawn fails, and the error only shows up as a per-cron last_error or as agents that cannot respawn.

Not a goal

What changed (motivation → approach → change)

Symptom → root cause: the probe's session half (user manager, bus, delegated slice) belongs to the user's login, but it was cached as if it were process-stable, and it trusted an environment variable instead of the bus.

Approach: make the cached answer follow the session, cheaply enough to check at every spawn on the event loop, and use the fallback the sandbox already has.

src/kiro_crew/sandbox.py:

  • _compute_cgroup_scope_probe now requires a reachable bus (_user_bus_reachable). It tries a non-blocking AF_UNIX connect() on the sockets systemd-run --user dials: the unix:path= entries of DBUS_SESSION_BUS_ADDRESS, then $XDG_RUNTIME_DIR/systemd/private and $XDG_RUNTIME_DIR/bus. A missing socket, a stale socket file with no listener, or a seccomp/LSM EPERM (cgroup scope probe reports available when D-Bus socket is unreachable #11473) all count as unavailable. EAGAIN from a full backlog counts as reachable, so the connect can never stall the loop or drop the ceiling under load. The "unavailable" reason names the remedy (loginctl enable-linger $USER).
  • _probe_cgroup_scope keys its cache on _cgroup_scope_session_fingerprint(): stat-only (st_dev, st_ino) of the runtime dir, each bus socket and the user slice's cgroup.controllers, plus the locator values. It recomputes when the fingerprint changes, and in any case every _CGROUP_SCOPE_PROBE_TTL_SECONDS (60s). The TTL catches a manager that died and left its socket behind. A recompute runs under a lock and also drops the _cpu_controller_delegated cache, which was cached for life too.
  • An availability flip is logged by _log_cgroup_scope_transition. A loss is a SECURITY warning stating that new spawns run without the fork-bomb/memory ceilings and naming the reason and remedy, and it is emitted even if the one-time startup warning already fired. A restore is logged at info. The ceiling therefore never drops silently, and it comes back on its own when the user logs in again.

Guarantees that stay the same:

  • When the manager is present, the argv is byte-identical (same systemd-run scope, properties and slice).
  • Without a manager, spawns take the existing cgroup_scope_argv passthrough, the same path a gateway started without a manager takes.
  • cgroup_scope_bus_env reads the same gate, so no bus locator is forwarded to a spawn that is not wrapped. If the two calls in sandboxed_spawn_argv straddle a flip, the env -u shim stays inside the wrapped argv, so the child still never sees the locators.
  • The post-exec rlimit delivery (create_subprocess_limited / run_limited / popen_limited via the spawn shim) is untouched, so RLIMIT_NOFILE and the other rlimits still apply after exec on the fallback path.

Docs: docs/architecture/resource-protection.md §Availability and fallback and docs/system-specs/modules/security.md describe the session-following gate.

Backwards compatibility

Compatible: when a user manager is reachable the probe returns the same (True, "ok") and the argv is unchanged. Hosts without one already degraded. The only behaviour change is on hosts where the old probe said "available" but systemd-run could not run, where every spawn previously failed.

Tests

test/test_cgroup_scope_probe_liveness.py (new, Linux-only) stands up a fake user manager: a real listening AF_UNIX socket in a runtime dir under tmp_path plus a fake cgroup.controllers. The host's real user manager is never contacted, because the conftest session floor already strips the real locators.

  • test_logout_after_probe_stops_wrapping_spawns_in_systemd_run is the reported sequence: probe while live, then remove the runtime dir with the variables still set. The spawn must be unwrapped, no locators are forwarded, and a SECURITY warning names enable-linger. Red on main: argv was still /usr/bin/systemd-run ….
  • test_ceiling_returns_when_the_manager_comes_back: re-login bounds spawns again without a restart.
  • test_transition_warns_once_not_per_spawn, test_a_second_outage_is_reported_too: one warning per flip, including a later outage after the startup warning.
  • test_bus_gone_but_slice_still_delegated_is_unavailable, test_stale_bus_socket_with_no_listener_is_unavailable, test_bus_connect_refused_by_policy_is_unavailable (cgroup scope probe reports available when D-Bus socket is unreachable #11473): the bus gate on its own.
  • test_a_listener_with_a_full_backlog_is_reachable_and_never_blocks: EAGAIN counts as reachable.
  • test_unchanged_session_reuses_the_cached_probe, test_cached_probe_is_rechecked_after_its_ttl: one compute per session state, plus the TTL.
  • test_cpu_delegation_is_reread_with_the_session.

All 9 of the original tests failed on main; all 11 pass. Each invariant line was mutation-checked and reds at least one test: fingerprint comparison removed, bus connect removed, cpu-cache reset removed, transition log removed, EAGAIN treated as unreachable, TTL removed, remedy dropped from the reason. Existing suites that use the probe (test_sandbox_argv, test_per_runtime_process_resources, test_sandbox_agent_slice_identity, test_session_scope_reap and every other test referencing cgroup_scope) pass. flake8, mypy (src/kiro_crew, 0 issues), black, isort and docs-lint are clean.

Manual verification

On a Linux host with systemd 252 (the real user manager was left running and never stopped):

  • env XDG_RUNTIME_DIR=/tmp/<gone> DBUS_SESSION_BUS_ADDRESS=unix:path=/tmp/<gone>/bus systemd-run --user --scope -q -- true printed Failed to connect to bus: No such file or directory and exited 1. This is the reported symptom, with the env a logged-out gateway carries.
  • In one process with the fixed code: the probe was (True, 'ok') with the live session. Pointing the locators at the removed dir made cgroup_scope_argv return the unwrapped argv, which ran and printed its output, and logged the SECURITY transition warning naming loginctl enable-linger. Restoring the locators wrapped the next spawn in /usr/bin/systemd-run again and logged "available again".

Related Issues

Fixes #11473

Internal report: https://t.corp.amazon.com/187b5c6e-b5cb-4d1b-9c36-ccf8c598e4f4. Related but not duplicated: #7363 and #14955 (pod-side handling of hosts with no per-user manager), #11352.

Pattern harvest

Rule candidate: review-prompt
Pattern: a process-lifetime cache of host state that belongs to a login session or other external lifecycle (the user manager, /run/user/<uid>, a bus) must be keyed on a cheap fingerprint of that state or a TTL; "the environment is process-stable" does not hold for the systemd user session.

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

@bolichen97
bolichen97 requested a review from a team as a code owner October 1, 2026 00:25
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Oct 1, 2026
The cgroup-scope probe was computed once per process from the presence
of XDG_RUNTIME_DIR and cached for life. On a host without lingering,
logind stops the per-user manager and removes /run/user/<uid> at the
last logout while the variable stays set, so a gateway started inside
an SSH session kept prepending `systemd-run --user --scope` and every
agent respawn, cron script and app backend died with "Failed to
connect to bus" until the gateway was restarted.

The probe now requires a bus socket that accepts a non-blocking
connect() (which also covers a stale socket file and a seccomp policy
refusing the connect, #11473), and its cache is keyed on a stat-only
fingerprint of the runtime dir, bus sockets and user slice, re-checked
per spawn, with a 60s TTL behind it. When the manager is gone, spawns
take the existing no-scope path a gateway started after logout takes,
with a SECURITY warning naming `loginctl enable-linger`; the ceiling
comes back on its own when the manager returns. The cpu-delegation
cache is refreshed with it.

Refs: #11473
@bolichen97
bolichen97 force-pushed the fix/scope-probe-bus-loss branch from 02837e8 to ec4d5e3 Compare October 1, 2026 00:34
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — 🔴 changes requested (blocking)

GPT 5.6 found at least one blocking issue that must be resolved before merging ec4d5e30d08b1223371fe7e9aae859b25c3fb2e0. 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

This comment is updated in place on each push.

BLOCKING -- src/kiro_crew/sandbox.py:15500 -- Re-login leaves aggregate cgroup state stale
_CPU_DELEGATED = None
logout/re-login → runtime slice properties vanish → only CPU cache resets → concurrent scopes run without aggregate limits and trigger OOM failures
Anchor: residual/crash-data-loss-corruption
Fix: invalidate and asynchronously reapply the aggregate slice-limit caches when the user manager returns.
[BLOCK-MERGE] ec4d5e3
[GPT-REVIEWED] ec4d5e3

Adjudication (Opus 5) — is blocking on each finding proportionate?

Harm rung: MEDIUM-to-HIGH residual, but the condition combination is the PR's own motivating scenario, not an extreme one.
Conditions confirmed: aggregate caches are set once and never invalidated by the new session-aware recompute (_SLICE_MEMHIGH_APPLIED set only at src/kiro_crew/sandbox.py:15754, short-circuited at :15721; recompute resets only _CPU_DELEGATED at :15500), while both aggregate properties are --runtime and die with the login session (:15709-15711, :16179-16181); the hard ceiling does self-heal (:16408-16414, memory.max == "max" → re-apply), so the surviving gap is the soft MemoryHigh throttle layer (:15663), after which breaches reach the hard slice ceiling and OOM-kill a scope — visible and attributed at :16379-16431.
Real fix cost: one reset of the existing _SLICE_MEMHIGH_APPLIED/_SLICE_LIMITS_APPLIED flags inside the recompute block that already resets _CPU_DELEGATED, reusing the existing per-spawn reconcile worker (:15838-15860) — small, no new mechanism, so no rarity argument can carry a FLAG on a condition (logout then re-login of an SSH-hosted gateway) this PR exists to handle.

[ADJUDICATION] ec4d5e3 total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] ec4d5e3

[ADJUDICATION-FENCED] ec4d5e3 fenced=1 flagged=0
UPHOLD-FENCED F1 src/kiro_crew/sandbox.py:15500 -- Logout-then-re-login is precisely the transition this PR teaches the probe to follow, and the soft aggregate MemoryHigh cache has no reset or self-heal anywhere (unlike _SLICE_LIMITS_APPLIED at :16408), so the condition combination is ordinary operation rather than an extreme one a human could dismiss.
[GPT-ADJUDICATED-FENCED] ec4d5e3

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

@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
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Confirm the deliberate fail-open: a same-uid process killing the user manager now yields unbounded-but-logged spawns where it previously yielded failed spawns.

[DESIGN-REVIEWED] ec4d5e3

Description read

[DESCRIPTION-READ] 854f7c8ea900177e979650a281a5eb40b3c1070acd521d293583ca2ae8e47872

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 ec4d5e30d08b1223371fe7e9aae859b25c3fb2e0 — 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 the one unverified residual: a live session dbus with a dead user manager still probes "reachable" — spawns there fail exactly as on base, no worse.

What this change ships

Inventory (7 items) — 7 justified

Intent: FIX — a gateway started over SSH keeps wrapping spawns in systemd-run --user after logout, failing every spawn until restart (internal ticket + test red on main).

  1. Spawns stop being wrapped once the user manager is gone, taking the existing no-scope path — justified
  2. The ceiling returns on its own at re-login, without a gateway restart — justified
  3. Cached probe is also re-checked on a 60s TTL (dead manager, stale socket) — justified
  4. A mid-run availability flip is now logged; loss is a SECURITY warning, even after the startup warning — justified
  5. The unavailable reason now names the remedy (loginctl enable-linger $USER) — justified
  6. CPU-delegation answer follows the session instead of being cached for life (same root cause, in-scope sibling; pod siblings fix(pod): stop offering enable-linger on hosts with no per-user manager #7363/fix(pod): pod status refuses on a host that cannot run pods #14955/pod: Dev Fleet pods cannot start on a Cloud Dev Desktop (no systemd --user bus; enable-linger unavailable) #11352 declared deferred) — justified
  7. Docs updated in the same commit (resource-protection.md, security.md) — justified

[FIRST-PRINCIPLES-REVIEWED] ec4d5e3

Description read

[DESCRIPTION-READ] edff69bf0d9643e5743fcc9e7ce2a0c91c74990a4d345dcc53d1bd4e30738f75

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.

@bolichen97
bolichen97 merged commit 321fd99 into main Oct 1, 2026
92 of 96 checks passed
@bolichen97
bolichen97 deleted the fix/scope-probe-bus-loss branch October 1, 2026 00:56
@bolichen97

Copy link
Copy Markdown
Contributor Author

This merged at ec4d5e3 while the GPT 5.6 review's two blocking findings were still open: F1, the TTL refresh resolving systemd-run through shutil.which on the event loop, and F2, percent-escaped unix:path= values in the D-Bus address not being decoded. Both are real and both are in code this PR added. They are fixed, with tests, in #15636. The Backend Tests (Windows) (2) failure here is test_native_skill_projection.py lock-file sweeping, which fails the same way on other open PRs (for example #15626), so it is unrelated to this change.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Opus 5 Review — 🔴 changes requested (blocking)

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

BLOCKING — the new fail-open bus probe lets the sandboxed agent delete its own fork-bomb / memory ceiling.

BLOCKING — src/kiro_crew/sandbox.py:15543

    bus_ok, bus_reason = _user_bus_reachable()
    if not bus_ok:
        return (False, bus_reason)

/run/user/$UID is a same-uid tmpfs the launcher itself writes into (sandbox.py:9060, 9281) and nothing masks, ro-binds or seccomp-filters it for an agent child, so one bash tool call doing rm -f /run/user/$UID/bus /run/user/$UID/systemd/private → next spawn's fingerprint changes → _user_bus_reachable() returns False → cgroup_scope_argv returns argv unwrapped → every later agent/cron/app spawn runs with no TasksMax/MemoryMax/MemorySwapMax=0 (RLIMIT_NPROC and RLIMIT_AS are opt-in and default 0, security/helpers.py:76,96), where before the change the same deletion made systemd-run fail closed.
Fix: in _compute_cgroup_scope_probe, accept unreachability as "no session" only on evidence the agent cannot forge — require _stat_identity(os.environ["XDG_RUNTIME_DIR"]) is None (logind removed the runtime dir) before degrading, and keep wrapping when the runtime dir is still present but a socket vanished.

FINDING — src/kiro_crew/sandbox.py:15500 — the recompute block resets only _CPU_DELEGATED, so when the manager returns the recovered gateway restores the per-scope ceiling but never the aggregate one: ensure_agents_slice_limits is called once at boot (slack/gateway.py:16045) and returned False with _SLICE_LIMITS_APPLIED still False, which is also the gate on the only self-heal (if _SLICE_LIMITS_APPLIED: at 16408), while _SLICE_MEMHIGH_APPLIED still equals desired so _ensure_agent_slice_memory_high no-ops on a --runtime property that died with the old manager → kirocrew-agents.slice carries no MemoryMax/TasksMax/MemoryHigh for the rest of the process, so N concurrent agent trees can collectively exceed host RAM → Fix: clear _SLICE_LIMITS_APPLIED/_SLICE_MEMHIGH_APPLIED/_SLICE_MEMHIGH_DISABLED beside _CPU_DELEGATED and have _log_cgroup_scope_transition's available arm re-run ensure_agents_slice_limits() off-thread.

[BLOCK-MERGE] ec4d5e3
[OPUS-REVIEWED] ec4d5e3

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

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

@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Oct 1, 2026
bolichen97 added a commit that referenced this pull request Oct 1, 2026
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.

(cherry picked from commit e5a68df)
(cherry picked from commit 623f2b4)
bolichen97 added a commit that referenced this pull request Oct 1, 2026
…#15636)

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

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.

* fix(sandbox): resolve the probe's systemd-run without any PATH walk

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.
bolichen97 added a commit that referenced this pull request Oct 1, 2026
…ease/0.8.0 (#15638)

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

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.

(cherry picked from commit e5a68df)
(cherry picked from commit 623f2b4)

* fix(sandbox): resolve the probe's systemd-run without any PATH walk

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.

(cherry picked from commit 5843231)
bolichen97 added a commit that referenced this pull request Oct 1, 2026
… release/0.8.0 (#15619)

* fix(windows): backport the directory-junction hardening to release/0.8.0 (#15666)

Backport of #14327, #14962, #15310 to release/0.8.0, cherry-picked in main's merge order.

* fix(windows): anchor six directory-link fences to pinned descriptors (#14327)
  (cherry picked from commit 6b0a6d5)
* fix(config): refuse a link or junction at the workspace dir name (#14962)
  (cherry picked from commit 4bb50ef)
* fix(windows): make four is_symlink guards see a junction (#12379, #10492) (#15310)
  (cherry picked from commit 6d54165)

* style(test): black-format the failed-start reap test and drop its history wording on release/0.8.0 (#15665)

test/test_acp_runtime_failed_start_reap.py arrived with #15625 not
black-formatted (fails scripts/check_black_formatting.py on the release
tip), and the _gone docstring said "no longer runs", which
scripts/check_comment_history.py flags as history narration. Black 26.3.1
(--target-version py310) reflow, and the docstring now reads "has stopped
running", the wording the #15664 forward-port uses. Test file only.

* fix(adaptive): keep a same-window gate step from eating idle recovery (#15595)

Idle recovery (#15541) took its exec step only when nothing else had
changed on the sample. A spawn-gate increase earned on the same sample
set that shared flag, so the idle exec step due on it was skipped, and
the gate step also restarted the one-increase-per-window clock: the
exec cap then waited a further window for a step it had already been
due.

Judge the idle step on the exec track alone. Both tracks keep sharing
one increase-per-window clock across samples, as the earn rules do.

An increase's reason now names each track it moved: the exec note only
when the exec cap moved, and every gate step as "spawn gate target
X -> Y" (the policy's target; the daemon confirms or clamps it). A
gate-only step used to read "clean window earned +1", and a gate step
beside an exec step was not mentioned at all.

(cherry picked from commit f23a39f)

* fix(acp): treat only JSON whitespace as an empty mcp.json (#15673)

#15627 read an empty or whitespace-only MCP settings file as absent, using
bytes.strip() with no argument. That also strips \x0b and \x0c, which JSON
does not allow, so a file holding only those bytes read as "no restrictions"
instead of failing closed like any other malformed document. The emptiness
check now strips only space, tab, CR and LF (RFC 8259); anything else goes
to the parser and fails closed as before #15627.

Refs #15616

(cherry picked from commit 157fd51)

* fix(sandbox): backport the scope probe PATH and bus-path fixes to release/0.8.0 (#15638)

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

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.

(cherry picked from commit e5a68df)
(cherry picked from commit 623f2b4)

* fix(sandbox): resolve the probe's systemd-run without any PATH walk

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.

(cherry picked from commit 5843231)

* fix(chat): restore the interrupted turn when Resume lands on a natively loaded session (#15643) (#15644)

* fix(chat): restore the interrupted turn when Resume lands on a natively loaded session (#15643)

kiro-cli appends a prompt to <sid>.jsonl only once the model has answered
it. When the process serving a turn dies mid-answer (a gateway restart, a
crash, a recycled runtime) that request is never written, so session/load
brings the conversation back without it. A natively resumed session gets
no Kiro Crew replay, so the Resume press on that turn sent a bare "finish
the user's most recent request" with the request missing: the model
answered the turn before it, or said there was nothing to continue.

Reproduced against kiro-cli 2.26.1: after a completed turn and a second
turn killed mid-stream, session/load restores only the first. The path is
any native resume: a dashboard chat with agent.tool_search off, a
dashboard chat linked to a channel, and the automatic connection-lost
recovery on a respawned runtime.

When the Resume message or the connection-lost recovery runs on a session
that this turn natively resumed, _run_chat now prepends the interrupted
turn from the slot's own transcript (the opener the turn-in-flight marker
restores, plus the partial answer), bracketed [INTERRUPTED TURN] so the
context scanner attributes it. A cold start that replays already carries
the turn and is unchanged. A session whose only turn was interrupted was
already covered: SessionMap.get prunes a sid whose log holds no turn.

Backport of #15643 to release/0.8.0. Conflict: context.py still carries
compress_thread_history here (removed on main by #14952); the new helper
is placed after it.

* fix(chat): open the interrupted-turn restore at the right row, and mint it after the scrub (#15643)

A cron, app or synthesis delivery opens its turn as an inject row. The
interrupted-turn walk only stopped at user, nudge and sub-agent rows, so
for such a turn it reached the already-answered request before it and
restored that as the user's most recent request. Openers now include the
inject kinds dashboard.state.TURN_OPENING_INJECT_KINDS names (the
dispatching kinds minus recovery and user_replay, which continue a turn).

The session-busy recovery (_BUSY_RECOVER_MSG) also resets the session and
session/loads the same native conversation, so it gets the restore too.

The frame tells the model the request inside it is the one to carry on
with, so its markers join _STRUCTURAL_MARKER_RES and the runner prepends
it after the egress scrub, like the task checklist; the builder scrubs
the restored payload itself.

The turn-in-flight marker now copies a sub-agent completion opener too
(_LOCAL_TURN_OPENER_ROLES / _LOCAL_TURN_PROMPT_ROLES): without it a crash
before the flush loses that row, and the restore would walk past it to
the previous, already-answered request.

* fix(mcp): repair Windows command casing at every resolver, not only the rewriter

On Windows `shutil.which` spells the extension it appends exactly as
PATHEXT spells it, so a bare `demo-mcp` resolves to `demo-mcp.EXE` while
the file on disk is `demo-mcp.exe`. A launcher that dispatches on its own
argv[0] basename case-sensitively (a tool manager's multiplexer shim)
refuses to run under that spelling and the MCP server never starts.

The rewriter already restored the on-disk basename, but the agent-config
resolver (`agent._resolve_command`) and the dashboard probe
(`mcp_discovery`) consumed raw `which` output, and the resolver's result is
PERSISTED as the spec's absolute `command`. An absolute command is accepted
verbatim on every later pass, so the uppercase spelling written once looked
operator-authored to the rewriter from then on and its repair never ran.

Move the helper to `kiro_crew.env.resolved_command_casing`, beside the
`mcp_search_path` the three resolvers already share, and apply it on both
return paths of `_resolve_command` and in the probe. Repairing at the
resolver also keeps the provenance record's `emitted` value repaired, so
`command_is_ours` still recognises the entry and re-derivation stays on.

Fixes #11627

(cherry picked from commit aa7c0bd, #15071;
 applied as its pre-#14919 revision 457210d plus the round-2 test
 and docstring delta, since release/0.8.0 predates the agent.py split)
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.

cgroup scope probe reports available when D-Bus socket is unreachable

1 participant