Skip to content

fix(adaptive): backport same-window idle recovery fix to release/0.8.0 - #15595

Merged
bolichen97 merged 1 commit into
release/0.8.0from
backport/0.8.0-adaptive-idle-gate-window
Oct 1, 2026
Merged

bolichen97 merged 1 commit into
release/0.8.0from
backport/0.8.0-adaptive-idle-gate-window

Conversation

@bolichen97

@bolichen97 bolichen97 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Backport of #15594 to release/0.8.0. Do NOT merge before #15594 merges on main. If #15594 changes before it lands, this branch is re-cut from its final commit. One commit, git cherry-pick -x 0c28df26bc, applied cleanly on release/0.8.0 @ 2f7b7c0 (which carries #15544, the backport of #15541).

Goal: On the 0.8.0 release line, an idle-recovery step on the execution cap is not delayed when the spawn gate earns its own increase in the same window.

Follow-up to #15541, closing the GPT 5.6 finding on its final head 9a56254f8f (the PR merged before the fix could be pushed). In AdaptivePolicy._maybe_increase, the idle exec step was guarded by if not changed. changed is shared with the gate track, so a gate-only increase in the same window made the due idle exec step skip. It also moved _last_increase_at, so the exec cap then waited one more 30 s window for a step it had already earned.

Why it matters

While the exec track is idle, MCP backend inits can keep the spawn gate earning. Every gate step would then push the exec recovery back a window, which stretches the "cap returns to the fresh-start value" time #15541 promises, and on a host with steady backend churn it could delay it repeatedly.

Not a goal

What changed (motivation → approach → change)

Symptom: a gate step in the idle window delays the exec idle step. Cause: the idle step read the shared changed flag rather than the exec track's own. Change: record exec_changed after the exec earn rules and guard the idle step on it, so a gate step on the same sample no longer suppresses the idle exec step due on it. Both tracks still share one increase-per-window clock across samples, as the earn rules always have. Every increase's reason now names each track it moved. The exec note appears only when the exec cap moved, and every gate step reads spawn gate target X -> Y on backend inits, the policy's target, since the daemon confirms or clamps it on apply. Before, a gate-only step read clean window earned +1, and a gate step beside an exec step was not named at all. One spec line (Tests) is updated.

Backwards compatibility

Compatible: no API, config or state key changes; only the timing of an idle exec step that was already due.

Tests

test_adaptive_policy.py::TestIdleRecovery::test_a_gate_step_does_not_spend_the_idle_exec_step: exec track cut to 1 and idle, gate busy and earning. On the sample where idle recovery is due, both the gate (+1) and the exec cap (1 -> 2) step. The decision's reason names both moves. TestSlowStart::test_an_idle_step_beside_a_doubled_gate_step_reports_both_moves pins the slow-start case (gate 4 -> 8, and the idle figure is the clock the rule judged, 60s), and test_every_gate_step_names_itself_and_only_itself pins a gate-only step and an earned exec step combined with a gate step. The first test fails on main (effective_exec_cap == 1, and the gate step is reported as clean window earned +1) and passes with the fix.

Manual verification

N/A. This is a pure policy state-machine change, and the unit test drives the exact sample sequence.

Local: test_adaptive_policy.py, test_adaptive_controller.py, test_resource_status.py, test_overload_acceptance.py, test_adaptive_startup_memory.py, test_mcp_core_more_coverage.py give 443 passed. flake8, black, mypy (adaptive/) and docs-lint are clean.

Related Issues

Backport of #15594. Follow-up to #15541 (GPT 5.6 finding on 9a56254f8f).

Pattern harvest

Not generalizable: a single shared "changed" flag across two independently-earning tracks. The file already documents per-track independence in _reset_bases, and this was the one place that read the combined flag.

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 21:48
@bolichen97
bolichen97 requested review from cruisercohen and removed request for a team September 30, 2026 21:48
@bolichen97

Copy link
Copy Markdown
Contributor Author

Local test evidence (head d4368b38de = release/0.8.0 @ e1a248b + cherry-pick -x 770f3085cd, CPython 3.12.13, Linux):

58 test files referencing adaptive / resource_status: 4742 passed, 141 warnings in 79.14s
mutation (adaptive/policy.py reverted to release/0.8.0, new test kept):
  test_a_gate_step_does_not_spend_the_idle_exec_step -> 1 failed
flake8 (touched files): clean
mypy src/kiro_crew: Success: no issues found in 1860 source files

Do not merge before #15594.

@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 6c4357ef9e5b6c939faccba1c9a38c60bd9e60c5 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify #15594 landed on main unchanged before merging; the description says this branch must be re-cut if it did not.

[DESIGN-REVIEWED] 6c4357e

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 6c4357ef9e5b6c939faccba1c9a38c60bd9e60c5 — 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 description's own precondition: #15594 merged on main unchanged — this branch must be re-cut from its final commit if it differed.

What this change ships

Inventory (5 items) — 4 justified

Intent: FIX — on the 0.8.0 line, a due idle-recovery step on the exec cap is no longer delayed by a same-window spawn-gate increase.

  1. A gate step in the same window no longer skips the due idle exec step — justified
  2. A decision moving both tracks now names each move in its reason — justified
  3. A gate-only increase is relabeled from clean window earned +1 to spawn gate target X -> Y — rides along, declared; the old string misfiled a gate move under an exec reason, and zero non-test consumers parse these strings (grepped clean window earned: policy.py and tests only)
  4. The adaptive-concurrency spec's Tests line now pins the new behavior — justified
  5. Three new tests pin the combined-step, slow-start and gate-only reasons — justified

[FIRST-PRINCIPLES-REVIEWED] 6c4357e

@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 6c4357ef9e5b6c939faccba1c9a38c60bd9e60c5 and found no blocking issues.

This comment is updated in place on each push.

Review details

FINDING -- src/kiro_crew/platform_compat.py:7291 -- "class PinnedDirectory" and associated changes exceed the adaptive-only backport scope -> Fix: rebase so the diff contains only the adaptive change.
[GPT-REVIEWED] 6c4357e

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

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

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

Review details

The spec paragraph this PR rewrote still claims every TestIdleRecovery case runs with slow start OFF, which the PR's own new case in that class turns ON.

FINDING — docs/system-specs/modules/adaptive-concurrency.md:380 — the unchanged qualifier Those cases construct their params with slow start OFF, because each one pins a congestion-avoidance rule; TestSlowStart owns the other regime now contradicts test_a_combined_step_reports_the_gate_move_it_made, added to TestIdleRecovery at test/test_adaptive_policy.py:779 with _params(exec_ceiling=9, exec_initial=4, slow_start=True, increase_successes=1) — the only slow-start-ON case outside TestSlowStart/TestSlowRecovery — so the spec's stated regime boundary is false for the class it names and misdirects whoever places the next slow-start case → Fix: amend the lines 380–382 qualifier to except the one combined-step case that pins the doubled gate note, or move that test into TestSlowStart.

[OPUS-REVIEWED] 6c4357e

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

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

@bolichen97
bolichen97 force-pushed the backport/0.8.0-adaptive-idle-gate-window branch from d4368b3 to 619a513 Compare September 30, 2026 22:47
@bolichen97

Copy link
Copy Markdown
Contributor Author

Re-cut from #15594's amended commit 34d32fbb26. That commit only narrows the comment and spec wording; the code is unchanged. The head is now 619a513b58 = release/0.8.0 @ e1a248b + a clean cherry-pick -x 34d32fbb26. The 58 test files referencing adaptive / resource_status give 4742 passed. Do not merge before #15594.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Opus 5 finding on 619a513b58 (a combined gate + idle-exec decision recorded only the exec note): valid. It is fixed at the source in #15594 (0838dc5cdb) and re-cut here. Head 54f77081dc = release/0.8.0 @ e1a248b + a clean cherry-pick -x 0838dc5cdb. The 58 adaptive / resource_status test files give 4742 passed. With policy.py reverted to release/0.8.0, test_a_gate_step_does_not_spend_the_idle_exec_step fails (1 failed). flake8 is clean, and mypy src/kiro_crew reports no issues in 1860 files. Do not merge before #15594.

@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 Oct 1, 2026
@bolichen97
bolichen97 force-pushed the backport/0.8.0-adaptive-idle-gate-window branch from 54f7708 to b0588c0 Compare October 1, 2026 00:22
@bolichen97

Copy link
Copy Markdown
Contributor Author

GPT 5.6 and Opus 5 on 54f77081dc both flagged spawn gate +1 misreporting a slow-start doubling. Fixed at the source in #15594 (56a8635a1f), which now reports spawn gate {before} -> {after}, and re-cut here. Head b0588c01a3 = release/0.8.0 @ 19c35d0 + a clean cherry-pick -x 56a8635a1f. The 58 adaptive / resource_status test files give 4743 passed. With policy.py reverted to release/0.8.0, both new tests fail (2 failed). flake8 is clean, and mypy src/kiro_crew reports no issues in 1860 files. Do not merge before #15594.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Oct 1, 2026
@bolichen97
bolichen97 force-pushed the backport/0.8.0-adaptive-idle-gate-window branch from b0588c0 to c42ddc9 Compare October 1, 2026 01:15
@bolichen97

Copy link
Copy Markdown
Contributor Author

GPT 5.6 on b0588c01a3 said the gate figure is a requested target. Fixed at the source in #15594 (a13f272e40), which now reads spawn gate target X -> Y and names each track it moved, and re-cut here. Head c42ddc9a1a = release/0.8.0 @ e683fb3 + a clean cherry-pick -x a13f272e40. The 58 adaptive / resource_status test files give 4753 passed. With policy.py reverted to release/0.8.0, the 3 new tests fail. flake8 is clean, and mypy src/kiro_crew reports no issues in 1861 files. Do not merge before #15594.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels 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
bolichen97 force-pushed the backport/0.8.0-adaptive-idle-gate-window branch from c42ddc9 to 6c4357e Compare October 1, 2026 01:28
@bolichen97

Copy link
Copy Markdown
Contributor Author

Re-cut onto #15594 f23a39f20c, which changes only a test comment to satisfy the Comment History Gate. Head 6c4357ef9e = release/0.8.0 @ a2cf0d9 + a clean cherry-pick -x f23a39f20c. The 58 adaptive / resource_status test files: 4753 passed, 141 warnings in 80.24s (0:01:20). The comment-history gate against release/0.8.0 passes. Do not merge before #15594.

@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 Oct 1, 2026
@bolichen97
bolichen97 merged commit 2f7b7c0 into release/0.8.0 Oct 1, 2026
25 of 31 checks passed
@bolichen97
bolichen97 deleted the backport/0.8.0-adaptive-idle-gate-window branch October 1, 2026 02:03
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 1, 2026
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