Skip to content

fix: keep the run's model and effort on a continuation - #19006

Merged
javenciu merged 1 commit into
kirodotdev:mainfrom
javenciu:fix/continuation-keeps-run-model
Oct 13, 2026
Merged

javenciu merged 1 commit into
kirodotdev:mainfrom
javenciu:fix/continuation-keeps-run-model

Conversation

@javenciu

@javenciu javenciu commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A continuation of a sub-agent run uses the model and reasoning effort the run was spawned with, unless the caller names others.

A continuation of a sub-agent run requests no model and no reasoning effort, so it runs on the role default (agent.role_models['subagent'] / agent.role_efforts['subagent']) or the provider's default instead of the model and effort the run was spawned with. Every continuation path does this:

  • spawn_continue without a model: _continue_prelude_impl hands spawn the caller's model (None) and no reasoning_effort.
  • A spawn_steer follow-up (mode='follow_up'): the watcher calls continue_conversation_async with no model, and that call has no effort parameter.
  • A continuation after a gateway restart: the run's state.json records requested_model at spawn, but the continuation does not read it, and the effort is not recorded at all.

Why it matters

A caller that pins a run to model-a at high effort gets its follow-up turns from another model at another effort, and nothing in the reply says so. The continuation's own record shows requested_model="auto". Because "auto" means unpinned, the downgrade warning ("Requested X, served Y") cannot fire for it.

Not a goal

Two behaviors reviewers should know, both deliberate:

  • The effort carries over even when spawn_continue names another model. spawn_continue has no effort parameter, and adding one is not part of this change. So spawn_continue(model="model-b") on a run spawned at high runs model-b at high.
  • An in-memory run keeps what the caller pinned at spawn (SubagentInfo.model), not the stored requested_model. A run whose model came from the role default re-resolves the role default on a continuation, as before. After a gateway restart only state.json is left, so the continuation uses the stored requested_model, which is the effective pin and includes a role pin, and skips "auto" (an unpinned run).

Also not a goal: carrying the run's backend into a continuation (#18150 does that), or the other per-spawn options the continuation does not carry (allowed_tools, bare).

What changed (motivation → approach → change)

  • Motivation: a continuation is another turn of the same run. _continue_prelude_impl already inherits the context groups, the delegation and the memory store for that reason, but not the model or the effort.
  • Approach: resolve the run's own model and effort in the prelude, which every continuation path goes through: from the run in memory or, after a restart, from state.json.
  • Change:
    • src/kiro_crew/subagent_manager/continuation.py: the prelude keeps the model the caller pinned at spawn unless the caller names one, and passes the run's reasoning effort only while it keeps that model. A caller that names a model gets that model's own effort resolution (role pin, else default), because effort follows the model (docs/request-for-change/rfc-worker-model-inheritance.md, rule 4). After a restart the pin comes from pinned_model, not from requested_model: that is the effective pin and also holds agent.role_models['subagent'] and a model.route tier, so carrying it would freeze whatever the run happened to resolve, which a run still in memory does not do. On the async paths (spawn_continue over HTTP, the follow-up watcher) the state comes from the snapshot the caller already read off the event loop.
    • src/kiro_crew/subagent_manager/run.py: the crash-safe spawn write that records requested_model / resolved_model before the subagent_spawn event also records the caller's own pin as pinned_model (SubagentInfo.model) and reasoning_effort.
    • docs/system-specs/modules/subagent.md: the reasoning_effort entry said a continuation "resolves effort fresh (role pin, else default), the same parity as model". That sentence came with the per-call effort parameter in feat: add per-call reasoning_effort parameter to spawn_run (#4725) #4732, whose description names extending spawn_continue as "follow-up work, not part of this minimal-surface change". It describes the inherited behavior instead, including that a named model carries no effort. No record in docs/decisions/ covers continuation model or effort.
    • The two Not a goal bullets above describe the head this one replaces: the effort no longer carries over a model the caller names, and a restart reads the caller's pin, as the in-memory path does.

Backwards compatibility

  • An explicit model on spawn_continue still wins, and the effort then resolves for that model, as before this change.
  • A run spawned without a pin continues as before (role default, else provider default), whether or not the gateway restarted.
  • A run spawned before this change has neither pinned_model nor reasoning_effort in its state.json. After a restart its continuation requests no model and no effort, as before this change.
  • The behavior change: a continuation of a pinned run that names no model asks for that run's model and effort.

Tests

  • test/test_subagent_continuable.py:
    • a continuation without a model keeps model-a / high;
    • after a restart (run not in memory, read_state patched) it keeps the recorded pinned_model (model-a) and high; a record whose caller pinned nothing requests no model even though its requested_model names one, and so does a record without the field;
    • the role pin: a run whose caller pinned no model follows a later change of agent.role_models['subagent'], in memory and after a restart;
    • a follow_up_run follow-up, dispatched by the watcher, keeps model-a / high;
    • an explicit model="model-b" is requested and carries no effort, in memory and after a restart.
  • test/test_subagent_provenance_write.py: the spawn's provenance write records the run's effort (high, and "" for a run spawned without one) and the caller's own pin as pinned_model (the caller's model, "" when the model came from the role pin).
  • In short: red on origin/main 315affc (the two test files copied into a clean checkout, -n 0, 3 of 3 serial runs): 8 failed, 232 passed each, the same eight every run: the three continuation tests, the two effort cases and the three pinned_model cases of the write. The tests that pin what a continuation must not carry (a role pin after a restart, a named model's effort, a record with no caller pin) pass on main, which carries nothing. They fail on the previous head of this PR, which read requested_model after a restart and carried the effort over a named model: with the two files copied onto that head, 8 failed, 232 passed in 3 of 3 runs (the five guards and the three pinned_model cases).
  • Green on this branch (on origin/main 365d87c): the two files, 240 passed in 3 of 3 serial runs. The wait-discipline and flake-pattern ratchets: 92 passed in 3 of 3 runs on this head. The neighbours, 240 test files that import kiro_crew.subagent or subagent_manager, or name continue_conversation, spawn_continue, follow_up_run or pinned_model (minus test/test_service.py and test/test_codex_session_mcp.py, which act on the real user home), run together with -n 8: 21526 passed, 14 skipped, 5 xfailed, 2 failed. The two failures, test/test_home_pin_survives_monkeypatch_undo.py::test_the_guard_accepts_a_scratch_home (that run's pytest temp root sat under the data home, which the guard refuses) and test/test_open_slots_persistence.py::test_cancelled_restore_keeps_the_keys_it_never_read (a restore-timing premise under load), pass when their two files run alone: 144 passed in 3 of 3 runs.
E         {'model': None} != {'model': 'model-a'}
E         {'reasoning_effort_override': None} != {'reasoning_effort_override': 'high'}
FAILED test/test_subagent_continuable.py::test_continuation_without_a_model_keeps_the_runs_model_and_effort
FAILED test/test_subagent_continuable.py::test_continuation_after_a_restart_keeps_the_recorded_model_and_effort[caller-pinned]
FAILED test/test_subagent_continuable.py::test_a_follow_up_keeps_the_runs_model_and_effort
FAILED test/test_subagent_provenance_write.py::test_provenance_write_records_the_runs_reasoning_effort[high]
FAILED test/test_subagent_provenance_write.py::test_provenance_write_records_the_runs_reasoning_effort[]
FAILED test/test_subagent_provenance_write.py::test_provenance_write_records_the_callers_own_model_pin[caller-pin]
FAILED test/test_subagent_provenance_write.py::test_provenance_write_records_the_callers_own_model_pin[role-pin]
FAILED test/test_subagent_provenance_write.py::test_provenance_write_records_the_callers_own_model_pin[caller-pin-over-role-pin]

The spawn write records {'requested_model': 'model-req', 'resolved_model': 'model-served'} with no effort and no pin (assert None == 'high', assert None == 'model-req').

Manual verification

Not run against a live gateway. The tests drive the real SubagentManager continuation and run code with the mock session manager the continuation tests already use, and read what each continuation asks the provider for from get_or_create.

Screenshots / video

None; no UI change.

Related Issues

No issue found.

Pattern harvest

Rule candidate: review-prompt
Pattern: a per-spawn option that the continuation prelude (_continue_prelude_impl) does not carry into the resumed run, so a continuation runs on the default instead of what the run was spawned with.

A per-spawn option that the continuation prelude does not carry is one defect class: the backend (#18150), and here the model and the effort. The prelude does not carry allowed_tools or bare either (no match for either in _continue_prelude_impl); they are not examined here.

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

@javenciu
javenciu requested review from a team and KiroCrewCaptain as code owners October 11, 2026 01:44
@javenciu
javenciu requested a review from dodgeblaster October 11, 2026 01:44
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Oct 11, 2026
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision d5f1d1f0645d0e72b206252567995465c4341e9d touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of d5f1d1f0645d0e72b206252567995465c4341e9d via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Before merge, check that reviewers read the description's "What changed" note: the two frozen "Not a goal" bullets describe the previous head and contradict this code.

[DESIGN-REVIEWED] d5f1d1f

Description read

[DESCRIPTION-READ] 666c7496c71516c1ddf41955c5593f298f24d6839d5a780d947ac4dcef7fd510

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 11, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — 🟡 CONCERNS

Premise-level review of d5f1d1f0645d0e72b206252567995465c4341e9d via the fork AI-review pipeline — 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: CONCERNS

Continuations now inherit the spawn's model and effort, which reverses the spec's "NOT inherited by spawn_continue" for a first-class command. The cited RFC covers session_create, not continuations.

Not justified as shipped

  • Item 1 — inherited: the base spec says a continuation "resolves effort fresh (role pin, else default), the same parity as model". The diff makes both carry over. The only prior decision cited, rfc-worker-model-inheritance (accepted), covers crewmate session_create workers and never mentions continuations. feat: add per-call reasoning_effort parameter to spawn_run (#4725) #4732 deferring the work shows the old line was not a deliberate opposite, but it does not record a decision for this shape either. Whether this counts as a product-shape default is arguable, which is why it's CONCERNS and not BLOCK.
    Clears when: an RFC covering continuation model/effort inheritance is merged non-draft on the base (then push or rebase), or a maintainer posts /ai-review override first-principles d5f1d1f0645d0e72b206252567995465c4341e9d: <decision>.

What this change ships

Inventory (5 items) — 4 justified

Intent: a follow-up turn on a pinned sub-agent run stays on that run's model and effort. FIX.

  1. spawn_continue with no model now runs the caller's spawn-time model and effort — inherited (reverses the spec's continuation behavior)
  2. A spawn_steer follow-up keeps the run's model and effort — justified
  3. After a restart, a continuation reads the new pinned_model/reasoning_effort fields from state.json (one consumer each) — justified
  4. The spawn's provenance write now records pinned_model and reasoning_effort in state.json — justified
  5. The spec's reasoning_effort entry is rewritten to describe the inheritance — justified

[FIRST-PRINCIPLES-REVIEWED] d5f1d1f

Description read

[DESCRIPTION-READ] 9bb26288caafff0f5131e3bdec0519abae50ad9d970d2b38cb16985898ebcfdf

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

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed d5f1d1f0645d0e72b206252567995465c4341e9d via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] d5f1d1f

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed d5f1d1f0645d0e72b206252567995465c4341e9d via the fork AI-review pipeline; updated in place on each push.

Review details

Advisory finding only: a follow-up to a continuation that named a different model goes back to the first run's model.

FINDING — src/kiro_crew/subagent_manager/continuation.py:681 — original is always the conversation's first run (R), because a follow-up dispatches by the root id (subagent_id_from_conversation_key(info.conversation_key)). Suppose spawn_continue(R, model="model-b") starts run C1, and then a spawn_steer follow-up of C1 or a bare spawn_continue(R) arrives. That turn gets run_model, run_effort = original.model … = model-a/high and moves the session back off model-b. The pinned_model/reasoning_effort that C1 recorded are never read. → Fix: take the inherited model and effort from the conversation's most recent run (the latest _agents entry on conv_key). The after-restart path would also need the latest run record on that key, or the root's record updated whenever a continuation names a model.

[OPUS-REVIEWED] d5f1d1f

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 11, 2026
@javenciu
javenciu force-pushed the fix/continuation-keeps-run-model branch from 22fec18 to 610bc26 Compare October 11, 2026 07:14
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Oct 11, 2026
@javenciu
javenciu force-pushed the fix/continuation-keeps-run-model branch from 610bc26 to 3208427 Compare October 12, 2026 13:21
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 12, 2026
@javenciu
javenciu force-pushed the fix/continuation-keeps-run-model branch from 3208427 to ac69ef8 Compare October 12, 2026 20:24
@javenciu

Copy link
Copy Markdown
Contributor Author

Rebased onto main (65df088). The one conflict was the reasoning_effort bullet in docs/system-specs/modules/subagent.md: I kept main's text and re-applied this PR's sentence about a continuation inheriting the run's model and effort.

The four new tests in test/test_subagent_continuable.py now wait with await_until / async_wait_until, as the rest of that file has since #19334, instead of asyncio.wait_for(..., timeout=10) and a 0.05 s poll loop, so test/test_wait_discipline_ratchet.py passes.

@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 12, 2026
@javenciu
javenciu enabled auto-merge (squash) October 12, 2026 23:19

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes spawn_continue, spawn_steer follow-ups and post-restart continuations reuse the run's model and reasoning effort. The root cause, _continue_prelude_impl carrying neither, is real, and the in-memory path is right. The restart path reads a different source, though. In memory, the continuation keeps original.model, which is only the caller's pin. After a restart, continuation.py (the new recorded.get("requested_model") branch) reads requested_model, which run.py:2245 writes as eff_model or "auto". That value already includes the agent.role_models['subagent'] pin and any model.route derived tier, and the continuation passes it on as an explicit per-call model. Risk: after one restart, a run spawned under a role pin or a routed tier freezes that model as a caller pin, so a later change to the role pin never reaches that run again, while the same run without a restart follows the new pin. This is the Design CONCERNS on ac69ef8, and it has no reply. Fix: record the caller's own pin (info.model) in the provenance write in run.py:2600 next to reasoning_effort, and read that field after a restart instead of requested_model. Second, the effort is still carried when the caller names a different model, and the First Principles CONCERNS on that is also unanswered. The accepted rfc-worker-model-inheritance rule 4 says effort follows the model, and your own Goal line says "unless the caller names others". Pass reasoning_effort=run_effort only when model came from the run, and "" otherwise. Please update the matching spec sentence in subagent.md and add one test for each case. — crew-pr-reviewer (deep re-check)

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 13, 2026
A continuation (spawn_continue without a model, a spawn_steer
follow-up, a resume after a gateway restart) requested no model and
no reasoning effort, so it ran on the role or provider default instead
of the model and effort the run was spawned with.

The continuation prelude keeps the model the caller pinned at spawn
unless the caller names one, and keeps the run's reasoning effort only
with it: effort follows the model, so a caller that names a model gets
that model's own effort resolution. A run still in memory supplies its
per-spawn model and effort; after a restart they come from state.json,
where the crash-safe spawn write records the caller's own pin as
pinned_model beside the per-spawn effort. A restart reads pinned_model
rather than requested_model, the effective pin, which also holds the
sub-agent role pin and a routed tier: those resolve again for the
continuation, as they do for a run still in memory.

The spec sentence that said a continuation resolves effort fresh
(role pin, else default) describes the inherited behavior instead.
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 13, 2026
@javenciu
javenciu force-pushed the fix/continuation-keeps-run-model branch from ac69ef8 to d5f1d1f Compare October 13, 2026 01:28
@javenciu

Copy link
Copy Markdown
Contributor Author

Both points are fixed in the amended commit, rebased onto main (365d87c).

Restart reads a different model source (Design CONCERNS). The spawn's provenance write now also records the caller's own pin, pinned_model from info.model, next to reasoning_effort (subagent_manager/run.py:2623). After a restart the continuation prelude reads pinned_model (subagent_manager/continuation.py:693) instead of requested_model, so a model the run took from agent.role_models['subagent'] or a model.route tier is no longer carried as a pin. It resolves again, as it does for a run still in memory, and the "auto" special case goes with it. A record written before this change has no pinned_model, so its continuation requests no model, as before this PR. Tests: test_a_continuation_follows_a_later_change_of_the_role_pin (in memory and after a restart; the restart case fails on the previous head with 'role-model-x' == 'role-model-y'), the caller-pinned-nothing and record-without-the-field cases of test_continuation_after_a_restart_keeps_the_recorded_model_and_effort, and test_provenance_write_records_the_callers_own_model_pin for the write.

Effort carried over a named model (First Principles CONCERNS). The prelude now passes reasoning_effort=run_effort only when the caller named no model, and "" otherwise (subagent_manager/continuation.py:698 and :739). A caller that names a model gets that model's own effort resolution (role pin, else default), as rule 4 of rfc-worker-model-inheritance says. A caller that names the run's own model also counts as naming one, which avoids comparing model spellings. The reasoning_effort bullet in docs/system-specs/modules/subagent.md:3270 says so. Test: test_a_continuation_naming_another_model_carries_no_effort (in memory and after a restart; both fail on the previous head with the effort still high).

The two Not a goal bullets in the description describe the previous head, and this change reverses both. The Change section and the spec sentence carry the new behavior; the Tests section has the red and green counts.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Oct 13, 2026
@javenciu
javenciu requested a review from iamwhatever October 13, 2026 04:19

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes spawn_continue, spawn_steer follow-ups and post-restart continuations reuse the run's model and effort by resolving them in _continue_prelude_impl, the one prelude every continuation path goes through, so the root cause is fixed there. Both points from our CHANGES_REQUESTED on ac69ef8 are handled on d5f1d1f. run.py now records the caller's own pin as pinned_model (from info.model), and after a restart the prelude reads that field, not requested_model, so a role pin or a model.route tier is no longer frozen into a pin. I checked that _route_unpinned_start only reads info.model and never writes it, and that info.reasoning_effort is the per-call value (the role effort is applied separately at run.py:4160), so the effort side cannot freeze a role pin either. The effort is now passed only when the caller names no model, which follows rfc-worker-model-inheritance rule 4, and the subagent.md sentence was rewritten to match. Records written before this change have neither field and request neither, as before. The Opus advisory is real but not a defect: original is always the root run, so a bare continuation after one that named model-b goes back to the spawn pin, and the rewritten spec says exactly that ("keeps the model the caller pinned at spawn"), the same way delegation and backend are inherited. Base is main, checks are green, and the new tests cover each case and are shown red on main and on the previous head. — crew-pr-reviewer (deep re-check)

@javenciu
javenciu merged commit f8c3ecc into kirodotdev:main Oct 13, 2026
105 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants