Skip to content

fix(adaptive): restore a cut concurrency cap once the host sits idle - #15541

Merged
bolichen97 merged 1 commit into
mainfrom
fix/adaptive-idle-recovery
Sep 30, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/adaptive-idle-recovery

Conversation

@bolichen97

@bolichen97 bolichen97 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A concurrency cap the adaptive controller cut under pressure climbs back once the gateway sits idle and clear, and the status report says why the cap is low.

A user ran overlapping long workflows that hit timeouts, provider-process failures and CPU/memory pressure. The controller cut the execution cap to 1 of 9 slots. After every workflow finished and the pressure cleared, the cap stayed low ("idle time does not restore capacity"). It later reached only 2/9, so ctx.parallel() work ran mostly one call at a time.

Root cause (src/kiro_crew/adaptive/policy.py on main @ c1a02ce):

  • The only growth path is _maybe_increase. It needs demand at the cap (sample.demand >= self._exec_cap) and completions since the last change (or a progress probe, which needs queued > 0 and running >= cap). The module doc says so: "An idle track never drifts up." An idle process has neither.
  • demand, completions and progressing all come from SubagentManager (controller.py build_sample / _ingest_manager_runs). Workflow ctx.agent() calls and TaskRunner steps run on the runner lane (taskq/adapters/runner.py RunnerLane). That lane is bounded by the same effective cap, and its session/new starts feed record_start (acp/runtime_start.py), so it can cut the cap. It can never earn it back, because its occupancy and completions are not the manager's.
  • A pause resumes only when sample.completions advances past the probe base (_while_paused). A probe slot taken by workflow work never reports, so the cap sat at 1 in probing indefinitely. One sub-agent completion resumes it at floor + 1 = 2, which matches the "only 2/9" the user saw.

Reproduced against unchanged main with the pure policy: severe memory for two samples, then an hour of clear idle samples, left the cap at 1 ("probe in flight"). A loop-lag cut 4 -> 2 -> 1 followed by an hour of clear idle samples also stayed at 1 ("clear; increase not yet earned or no demand").

Why it matters

Anyone whose workflows or sub-agents once met pressure keeps a crippled cap until they restart the gateway, even on an idle, healthy host. Workflow fan-out (ctx.parallel) is hit hardest because its own work can never earn the cap back. The report gives no hint why the cap is 1 of 9. RFC overload-resilience (status partial) sets the goal "recover from transient failures without a human restarting the Gateway", and its §5 "recovery up-scaling" row expects "pressure removed -> +1 per window".

Not a goal

What changed (motivation → approach → change)

Symptom: the cap stays cut on an idle, clear host. Cause: every growth path needs exec-track evidence that an idle track, or runner-lane load, never produces. Change:

  • Idle recovery (AdaptivePolicy): once the exec track has had no demand (running + queued == 0) and the host no signal of any kind for DEFAULT_IDLE_RECOVERY_SECS (60 s, two congestion-avoidance windows), a cap below the fresh-start value min(user_max, adaptive_initial) climbs +1 per clean window back to it. While paused and probing, a probe that never reported resumes at floor + 1, clamped to the fresh-start value (so adaptive_floor >= adaptive_initial cannot resume above it); the spawn gate stays at its floor, since idle is no backend-init evidence. Demand or any signal restarts the idle clock.
  • Bound = fresh-start value, not the user ceiling. A drained process never holds more untested concurrency than a restart would give it, and every step above that is still earned under the existing rules. The next corroborated pressure cuts exactly as before. Alternatives considered: restoring to the ceiling (this would admit a full untested burst on the next fan-out), and restoring to the pre-cut cap (the cap the pressure fired under).
  • Why the cap is low (telemetry):
    • The policy snapshot gains last_cut: the decision that last lowered the exec cap (action, reason, signals, sample time). An increase never clears it.
    • AdaptiveController.state() adds last_cut.age_secs.
    • resource_status prints Last pressure cut: decrease 42s ago (corroborated pressure: ...) while the cap is below the ceiling. It is labelled as the last cut rather than as the cause, because a cap that has recovered to its fresh-start value is still below the ceiling.
    • A clear hold names what the next step waits for: the ceiling, the idle clock (idle; restoring toward 4 in 25s), demand at the cap, or the completions still owed. Before, the reason was always the generic "increase not yet earned or no demand".
  • Spec docs/system-specs/modules/adaptive-concurrency.md is updated in the same commit: the decision-rule row, a new "Idle recovery" section, Visibility, Fixed tuning and Tests.

Backwards compatibility

Compatible: no config key, schema, API field or action enum is removed or renamed. The new snapshot/state keys are additive, PolicyParams.idle_recovery_secs has a default, and ADAPTIVE_DECISIONS still uses the existing increase / resume actions. Only hold reason strings changed text; no code or test on main matches them.

Tests

  • test_adaptive_policy.py::TestIdleRecovery:
    • A cut cap climbs back one step per 30 s window, only after 60 s idle and clear, to the fresh-start value (4) and not to the ceiling (9).
    • An unreported probe resumes once idle and clear, and the gate stays at its floor.
    • Demand, or a lone uncorroborated signal, restarts the idle clock.
    • Work below the cap is not idle, and its hold says "no demand at the cap".
    • A gate step in the same window does not spend the idle exec step.
    • A cap already at the fresh-start value never drifts.
    • last_cut names the cut (decrease, then pause) and survives an increase.
    • An idle resume never passes the fresh-start cap, even with floor == initial.
    • idle_recovery_secs <= 0 is refused.
  • test_adaptive_controller.py::test_an_idle_controller_restores_the_cap_and_names_the_cut: end to end through tick() on a virtual clock. A lag cut to 1, then an idle gateway, returns the manager's effective cap to 4. resource_status prints Last pressure cut: decrease 10s ago (corroborated pressure: loop_lag) while the cap is below the ceiling and drops the line at the ceiling.
  • Mutation: reverting src/ to main while keeping the new tests fails 7 of them (the no-drift guard passes both ways by design). Dropping only the idle-resume clamp fails test_an_idle_resume_never_passes_the_fresh_start_cap.

Manual verification

N/A. The controller is a pure state machine driven by samples. The e2e test drives the real AdaptiveController.tick() and the real resource_status renderer on a virtual clock, which is exactly the path a live gateway takes every 5 s.

Local gates on the head:

  • black --target-version py310 / isort / flake8 are clean on the touched files.
  • mypy src/kiro_crew: "Success: no issues found in 1997 source files".
  • scripts/docs-lint.sh passed.
  • Every test file that references adaptive or resource_status (60 files): 5066 passed. The 1 failure, test_security_path_resolve_bounded.py::test_the_resolver_pool_knob_reaches_the_pool_in_a_fresh_interpreter, is a host artifact: its fresh interpreter imports a stale editable install, and the test passes with PYTHONPATH=<worktree>/src.

Related Issues

Follow-up for the deferred runner-lane earn evidence: #15556. Related: #14013 (the learned-cost ceiling issue, a separate mechanism), #12710 (an earlier loop-lag source that pinned the cap at 1).

Pattern harvest

Rule candidate: review-prompt
Pattern: "a controller whose decrease reads a signal source (runner-lane session starts) that its increase cannot observe" — every AIMD input that can cut must either be able to earn, or be covered by a time-based retirement of the cut.

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 September 30, 2026 18:57
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 30, 2026
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Verify the deferred runner-lane-evidence follow-up is filed: pure workflow fan-out still tops out at the fresh-start cap (4 of 9) by design.

Suggestions

  • The old pin "an idle track never drifts up" survives in weakened wording plus test_a_cap_at_the_fresh_start_value_does_not_drift_when_idle; consider a superseding note in the RFC's §5 row (status partial) so the next reader sees which half of recovery up-scaling this shipped and which half (runner-lane earning above fresh-start) remains.

[DESIGN-REVIEWED] 9a56254

Description read

[DESCRIPTION-READ] c1d6ed3e2f29184832a5c490d8ec9b6ef5f04e5895af48ce996fedaf6bbe2f00

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 Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 9a56254f8f7dcebe87708e3f938ebda6d118e198 — 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 fresh-start bound is the agreed recovery target: idle resume relaxes the RFC-recorded "probe must complete" and "demand at the limit" rules.

The defect has checkable provenance (a reproduction against main in the description, and 7 new tests the stated mutation run fails with src/ reverted). The rewritten pin "An idle track never drifts up" is quoted by the description itself and shown wrong against RFC overload-resilience's own goal (partial on base; its §11 row expects "pressure removed → +1 per window", and neither its status prose nor the README index names recovery up-scaling as a deliberate divergence). The runner-lane evidence gap — the nameable deeper cause — is explicitly declared out of scope with the fix's level stated. last_cut has one counted consumer (resource_status.py:565, grep last_cut in src/: 3 files, all this path); idle_recovery_secs follows the spec-documented PolicyParams tuning-constant convention.

What this change ships

Inventory (8 items) — 8 justified

Intent: a concurrency cap the controller cut under pressure climbs back once the gateway sits idle, and the status report says why the cap is low — a FIX.

  1. A cut cap climbs +1 per clean window back to the fresh-start value after 60 s idle and clear — justified
  2. A paused controller whose probe never reported resumes once idle and clear; the spawn gate stays at its floor — justified
  3. The resource report prints "Last pressure cut: …" while the cap is below the ceiling — justified
  4. Hold reasons now name what the next increase waits for, replacing one generic string — justified
  5. New snapshot/state keys last_cut and age_secs readable by tooling — justified
  6. New tuning constant DEFAULT_IDLE_RECOVERY_SECS / PolicyParams.idle_recovery_secs with validation — justified
  7. Module-doc pin rewritten: "An idle track never drifts up" → "…never drifts up PAST the fresh-start cap" — justified
  8. adaptive-concurrency.md spec updated in the same commit — justified

[FIRST-PRINCIPLES-REVIEWED] 9a56254

Description read

[DESCRIPTION-READ] 527a47f6c1c241c44b2abc724e56d336c9995c87c9dce238b1c38a7535c478b0

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 Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 9a56254f8f7dcebe87708e3f938ebda6d118e198 and found no blocking issues.

This comment is updated in place on each push.

Review details

FINDING -- src/kiro_crew/acp/runtime.py:662 -- "falls back to the authored agent" contradicts retry exhaustion, which raises -> Fix: state that the session fails after retries.
FINDING -- src/kiro_crew/acp/runtime.py:5497 -- function-local import announce_alias violates top-level-imports -> Fix: move the import to module scope.
[GPT-REVIEWED] 9a56254

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

@bolichen97

Copy link
Copy Markdown
Contributor Author

Addressed the round-1 review on d03eb532f6 in 907c31b631 (amended, still one commit):

  • GPT 5.6: idle resume above the fresh-start cap when adaptive_floor >= adaptive_initial. Valid, fixed. The idle resume target is now min(floor + 1, exec_start), clamped to [floor, ceiling]. A clean probe completion keeps its existing floor + 1. New test TestIdleRecovery::test_an_idle_resume_never_passes_the_fresh_start_cap uses floor=4, initial=4, ceiling=9 and asserts a resume at 4 that stays at 4. Dropping only the clamp fails it.
  • GPT 5.6: "Lowered by" misattributes a recovered fresh-start cap to a historical cut. Valid, fixed as suggested. The line now reads Last pressure cut: ..., and the spec and tests are updated. It still shows only while the cap is below the ceiling.
  • First Principles: exec_start / idle_recovery_secs snapshot keys and the DEFAULT_IDLE_RECOVERY_SECS export have no consumer. Agreed, removed. The hold reason (idle; restoring toward 4 in 25s) already carries both values. last_cut stays, since controller.state() and resource_status read it.
  • Design: file the deferred runner-lane earn-evidence change. Filed as adaptive: runner-lane (workflow / TaskRunner) load can cut the exec cap but never earn it back above the fresh-start value #15556 and linked from Related Issues. The Goal and Not-a-goal sections are unchanged.

Local re-run on 907c31b631:

  • test_adaptive_policy.py, test_adaptive_controller.py, test_resource_status.py, test_mcp_core_more_coverage.py: 377 passed.
  • mypy src/kiro_crew: no issues in 1997 files.
  • flake8, black and isort are clean on the touched files, and docs-lint passed.

After overlapping long workflows met timeouts and memory pressure, the
adaptive controller cut the execution cap to 1 (or paused and probed at
1) and it stayed there for the life of the gateway: workflow
ctx.parallel() calls ran one at a time on a clear, idle host.

Every increase rule is earned on the exec track's own evidence --
demand at the cap and completions diffed from the sub-agent manager.
An idle process produces neither, and neither does load on the runner
lane (workflow ctx.agent() calls, TaskRunner steps): the lane is
bounded by the effective cap and its session starts feed the timeout
signal, so it can cut the cap, but its occupancy and completions are
not the manager's. A pause probe taken by such work never reports, so
the cap sat at 1; one sub-agent completion resumed it at floor + 1.

Add idle recovery: after 60 s with no exec demand and no pressure
signal of any kind, a cap below the fresh-start value
min(user_max, adaptive_initial) climbs +1 per clean window back to it,
and an unreported probe resumes at floor + 1 (never above the
fresh-start value; the spawn gate stays at its floor and earns on
inits). The bound means a drained
process never holds more untested concurrency than a restart would;
growth past it is still earned, and the next corroborated pressure
cuts as before.

Say why a cap is low: the policy snapshot keeps last_cut (the decision
that last lowered the exec cap, with its signals, and its age in
controller.state()), resource_status prints it as "Last pressure cut: ..."
while the cap is below the ceiling, and a clear hold names what the
next step waits for (the idle clock, demand at the cap, or the
completions still owed).
@bolichen97
bolichen97 force-pushed the fix/adaptive-idle-recovery branch from 907c31b to 9a56254 Compare September 30, 2026 20:58
@bolichen97

Copy link
Copy Markdown
Contributor Author

Round 2 on 907c31b631: all three lanes PASS. Advisory items handled in 9a56254f8f (amended, still one commit):

  • GPT 5.6: an idle resume raised the spawn gate without backend-init evidence. Valid; the gate track is out of this PR's goal. Fixed: on an idle resume only the exec cap moves, and the gate stays at its floor and earns on inits as before. A probe that actually completed still resumes both tracks at floor + 1. test_an_unreported_probe_resumes_when_idle_and_clear now asserts spawn_gate_capacity == 1. Forcing the gate raise back fails that test.
  • First Principles: do RFC §5's recorded increase rules all require demand at the cap? Yes. The §5.2 row reads "+1 after >= 20 successful inits AND >= 30s without pressure AND demand at the limit", so idle recovery is not one of those rules, and this PR does not relax them. It retires a cut under a bound the RFC already treats as safe with zero evidence: the fresh-start cap min(user_max, 4), which every new process gets before any sample. The goal it serves is RFC §1's "recover from transient failures without a human restarting the Gateway". Today a restart is the only way back to that value.
  • Design: runner-lane load reads as idle; does it oscillate mid-run? It cannot oscillate faster than the idle window. Any signal of any kind, including the session/new start latency and timeouts that runner-lane load produces, restarts the 60 s clock (test_demand_or_any_signal_restarts_the_idle_clock). A climb is then at most +1 per 30 s window, and only up to the fresh-start value. If that load re-creates corroborated pressure, the existing decrease halves the cap, and the next climb waits another full idle window. That gives a bounded AIMD sawtooth, with a period of at least 60 s, between the floor and the fresh-start value. Getting runner-lane load real earn evidence, so that it stops reading as idle, is adaptive: runner-lane (workflow / TaskRunner) load can cut the exec cap but never earn it back above the fresh-start value #15556.

Local re-run on 9a56254f8f:

  • test_adaptive_policy.py, test_adaptive_controller.py, test_resource_status.py, test_overload_acceptance.py, test_adaptive_startup_memory.py: 274 passed.
  • flake8 and black are clean, mypy on adaptive/ is clean, and docs-lint passed.

@bolichen97
bolichen97 merged commit d9d4d1a into main Sep 30, 2026
90 of 96 checks passed
@bolichen97
bolichen97 deleted the fix/adaptive-idle-recovery branch September 30, 2026 21:07
@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Sep 30, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

The round-3 GPT 5.6 finding on 9a56254f8f (a gate-only increase in the same window skipped the due idle exec step and reset its window) arrived after this PR merged. It is fixed in follow-up #15594, with a test that fails on main, and backported in #15595.

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

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

Review details

Idle recovery climbs at half the documented rate on a process that has never seen pressure or demand.

FINDING — src/kiro_crew/adaptive/policy.py:446 — the idle clock's only anchor in that state is since = self._last_increase_at, which _maybe_increase restamps on every idle step (self._last_increase_at = now), so a cap left below exec_start by a lowered-then-raised max_subagents on a gateway that never spawned a subagent and never met a signal earns +1 per 60 s instead of the +1 per 30 s clean window the post-pressure branch (anchored on the never-moving _last_pressure_at) gets and the spec's "recovers the same way" claims → Fix: stamp self._last_busy_at = now in the existing first-sample if self._last_increase_at == _NEVER block in observe and drop the _NEVER fallback in _idle_for, so the idle clock is never advanced by the increase it gates.

[OPUS-REVIEWED] 9a56254

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

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

bolichen97 added a commit that referenced this pull request Sep 30, 2026
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.
bolichen97 added a commit that referenced this pull request Sep 30, 2026
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.

(cherry picked from commit 34d32fb)
bolichen97 added a commit that referenced this pull request Sep 30, 2026
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.

When a gate step and an idle exec step land on one decision, its reason
now names both, so the history does not file the gate's earned step
under the exec track's note.
bolichen97 added a commit that referenced this pull request Sep 30, 2026
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.

When a gate step and an idle exec step land on one decision, its reason
now names both, so the history does not file the gate's earned step
under the exec track's note.

(cherry picked from commit 0838dc5)
bolichen97 added a commit that referenced this pull request Oct 1, 2026
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.

When a gate step and an idle exec step land on one decision, its reason
now names both, with the gate's actual move (slow start doubles it), so
the history does not file the gate's earned step under the exec
track's note.
bolichen97 added a commit that referenced this pull request Oct 1, 2026
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.

When a gate step and an idle exec step land on one decision, its reason
now names both, with the gate's actual move (slow start doubles it), so
the history does not file the gate's earned step under the exec
track's note.

(cherry picked from commit 56a8635)
bolichen97 added a commit that referenced this pull request Oct 1, 2026
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.
bolichen97 added a commit that referenced this pull request Oct 1, 2026
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 a13f272)
bolichen97 added a commit that referenced this pull request Oct 1, 2026
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.
bolichen97 added a commit that referenced this pull request Oct 1, 2026
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)
bolichen97 added a commit that referenced this pull request Oct 1, 2026
…#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)
bolichen97 added a commit that referenced this pull request Oct 1, 2026
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.

The idle note reports the idle clock read before the step moves the
increase clock, so a process that never saw pressure or demand does not
log "idle and clear for 0s".
bolichen97 added a commit that referenced this pull request Oct 1, 2026
…#15594)

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.

The idle note reports the idle clock read before the step moves the
increase clock, so a process that never saw pressure or demand does not
log "idle and clear for 0s".
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.

1 participant