Skip to content

fix(chat): a fork of a legacy chat keeps the agent its parent ran as - #19973

Merged
dodgeblaster merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:fix/fork-legacy-exec-context
Oct 20, 2026
Merged

dodgeblaster merged 1 commit into
kirodotdev:mainfrom
Pearcekieser:fix/fork-legacy-exec-context

Conversation

@Pearcekieser

@Pearcekieser Pearcekieser commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A fork of a chat that predates execution identities starts on the agent the parent chat used.

Forking a chat that has no execution_context in its transcript header writes template_id as the parent's agent alias. For a chat on the default agent the child records {"selection_kind": "template", "template_id": "default"}. default is a config.agents row that binds the kirocrew template, and no kiro-cli agent named default exists. The child's first turn asks the backend for agent default and fails with "Agent default is not available".

Why it matters

Every pinned or long-lived chat created before execution identities existed is a legacy parent. Forking one, or forking a fork of one, is the normal way to branch an old conversation, and the child cannot answer a single message. The user has to open a new chat and loses the copied transcript.

Not a goal

  • Repairing children already written with a wrong template_id. They need the agent picked again or a new chat.
  • Changing how a parent that already has an execution_context is forked. That carrier is copied as is.
  • The separate "Crew Member 'default' is unavailable" failure on a member-kind carrier for a template-only alias.
  • The same alias-as-template carrier in dashboard/messaging_api/spawn.py:326, which builds ExecutionContext(None, ..., "template", agent or "kirocrew") when no crew is given. It is deferred to a follow-up PR so this one stays on the fork path.

What changed (motivation → approach → change)

A forked legacy chat failed on its first turn because the fork wrote the agent alias where the carrier expects a kiro-cli template name. resolve_session_agent_bindings launches execution.template_id verbatim, so an alias there is a missing agent.

_fork_execution_context in dashboard/chat_fork.py now records the identity the parent's own turns resolve to with no carrier. For a config.agents alias on a slot whose agent_kind is not template, that is the crewmate, so the child gets the member-kind record resolve_member_execution builds, the same one an owner's create writes. That record carries the crewmate's template, model pin and store. default launches kirocrew, and a crewmate such as builder keeps its amzn-builder template and its model pin instead of dropping to a plain template session. A template-stamped slot, or a name that is not an alias (possibly a template only the parent's project declares), stays a template carrier under the name as written, as before. The fork asks resolve_agent_identity for that alias-or-template call, the same _resolve_agent_selection rule the parent's own turns use, so the two cannot drift apart. Before that call the fork maps a stored skill-view name back to the agent it was built from with _source_of_view, as resolve_session_agent_bindings does first, so a view built from a crewmate alias forks as that crewmate. The slot's agent_kind joins the frozen fork identity tuple, so a parent whose stamp changes mid-fork is refused like any other identity drift. The store check and memory mode are unchanged. The V2 refusal now also checks the crewmate's resolved store: a carrier-less parent with no recorded store used to pass that check on the default store, and would have bound the child to the crewmate's private V2 memory.

Backwards compatibility

Compatible: only the legacy-parent branch changes. For an alias parent it replaces a template carrier that could not launch with the member-kind carrier the parent's own turns resolved to. Template-stamped and non-alias parents get the same carrier as before.

Removes nothing. A crewmate parent whose store differs from the slot's recorded store is refused by the existing recorded-store check, where before it got a carrier that could not launch. That parent still runs; only the fork is refused, with the same store_unavailable 503 as any other identity drift. A carrier-less parent of a V2 crewmate is refused the same way.

Tests

test_legacy_fork_keeps_the_identity_the_parent_ran_as in test/test_chat_fork_member_memory.py forks five carrier-less parents. For default and for a builder crewmate pinned to sonnet, on blank and member stamps, it asserts a member-kind carrier, then resolves the child through resolve_session_agent_bindings and checks the template, alias and model pin match the parent's. A template-stamped builder and a plain template name stay template carriers under the name as written. On main the default child records template_id == "default". test_legacy_fork_of_a_v2_crewmate_alias_is_refused forks a carrier-less parent of a V2 crewmate with an empty and a default recorded store and asserts a 503 with no child; the empty case fails on the previous head. test_legacy_fork_of_a_skill_view_name_resolves_its_source_agent forks a parent whose stored agent is a skill-view name built from builder and asserts the builder member carrier; it fails on the previous head with a template carrier under the view name. test/test_session_control_fork.py now expects the seven-field identity tuple. The related backend set from scripts/run_scoped_tests.py passes (1916 tests after the rebase on main), and test_session_control_fork.py with the fork tests passes (61). After the skill-view change, 229 fork and retired-agent-name tests pass.

Manual verification

The failing session on a live install had header "agent": "default" and "execution_context": {"selection_kind": "template", "template_id": "default", ...}, forked from a parent with no execution_context. The new test reproduces that header shape.

Related Issues

Fixes #19972

Pattern harvest

Rule candidate: review-prompt
Pattern: an agent alias from config.agents stored or passed where a kiro-cli template name is expected, without going through resolve_agent_identity or resolve_agent_bindings.

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

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): this fixes a bug (issue #19972), and the fork account cannot add labels. Could a maintainer add the bug label to the PR and the issue?

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Oct 13, 2026
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

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

Revision c3a213f828610749f7089be8c1b42ac0de3d3322 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 13, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of c3a213f828610749f7089be8c1b42ac0de3d3322 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: PASS

One unfixed sibling of the same alias-as-template cause is still open: dashboard/messaging_api/spawn.py:330. The PR declares it deferred, so confirm the follow-up gets filed.

What this change ships

Inventory (6 items) — 6 justified

Intent: a fork of a chat from before execution identities existed can answer its first message on the agent the parent used. This is a FIX (#19972).

  1. Forking an old chat on an alias like default or builder now starts on that crewmate, with its template, model pin and store, instead of failing with "Agent default is not available". — justified
  2. An old chat stored under a skill-view name now forks as the agent the view was built from. — justified
  3. Forking an old chat whose crewmate has private V2 memory is now refused with a 503 store_unavailable and no child is created. — justified
  4. Forking a crewmate chat whose crewmate store differs from the slot's recorded store is now refused, where before the child was created but could not launch. — justified
  5. A parent whose agent_kind stamp changes during the fork now makes the fork refuse. — justified
  6. The session-control spec gains a paragraph on how a parent with no recorded identity is forked. — justified

[FIRST-PRINCIPLES-REVIEWED] c3a213f

Description read

[DESCRIPTION-READ] 79f238a1f5db188f12b5cf2ff9cadcab1b9543f4c86e6e21e0d49f4d63b4e36b

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of c3a213f828610749f7089be8c1b42ac0de3d3322 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

Nothing to check.

[DESIGN-REVIEWED] c3a213f

Description read

[DESCRIPTION-READ] 5b22e50a9efb10daa9c924c367696e8732af5c629b435fae1dae3128f6c66239

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] c3a213f

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

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

Review details

FINDING -- src/kiro_crew/dashboard/chat_fork.py:113 -- Function-local _source_of_view and resolve_member_execution imports hide dependencies and violate top-level-imports; both modules already load through chat_persistence -> Fix: move these two new imports to module scope.
[GPT-REVIEWED] c3a213f

@Pearcekieser Pearcekieser changed the title fix(chat): a fork of a legacy chat launches its agent's template fix(chat): a fork of a legacy chat keeps the agent its parent ran as Oct 13, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/fork-legacy-exec-context branch from ab166a9 to ce6d29a Compare October 14, 2026 00:01
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

issue (non-blocking): A forked crewmate-alias chat lost the crewmate's workspace and model pin.

Upheld and fixed in ce6d29a. For a carrier-less parent whose agent is a config.agents alias and whose slot agent_kind is not template, _fork_execution_context now builds the carrier with resolve_member_execution. That is the member-kind record an owner's create writes, with the crewmate's template, model pin and store. A template-stamped slot and a name that is not an alias keep a template carrier under the name as written. The slot's agent_kind is now the seventh field of the frozen fork identity, so a stamp that changes mid-fork is refused as identity drift.

test_legacy_fork_keeps_the_identity_the_parent_ran_as covers the "Clears when" condition. For default and for a builder crewmate pinned to sonnet, on blank and member stamps, it resolves the forked child through resolve_session_agent_bindings and asserts the parent's template, alias and model pin. Two more cases cover a template-stamped builder and a plain template name, which stay template carriers.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision labels Oct 14, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/fork-legacy-exec-context branch from ce6d29a to 6955f1e Compare October 14, 2026 05:02
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): rebased on main as 6955f1e.

green_age.py reported the green run on ce6d29a as stale. Main had moved 82 commits, and some of them touch chat_fork.py. The rebase applied with no conflicts.

question (non-blocking): design review, a legacy alias parent whose recorded store differs from the crewmate's current store.

That fork is refused on purpose. The existing recorded-store check already refuses a fork when the parent's stored memory store does not match the resolved one, and this PR keeps that check. The parent chat keeps running; only the fork is refused.

issue (blocking): first-principles review, a legacy parent with no recorded store whose crewmate uses V2 memory.

Upheld. Before this commit, an empty recorded store skipped the V2 refusal, so the fork was attached to the crewmate's private V2 store. The fork now checks the store returned by resolve_member_execution and refuses it when memory_version == 2. test_legacy_fork_of_a_v2_crewmate_alias_is_refused covers a parent with an empty store and one with default; the empty-store case fails on ce6d29a and passes on 6955f1e. The 1916 scoped backend tests pass, and flake8, isort and mypy are clean.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 14, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/fork-legacy-exec-context branch from 6955f1e to 482170d Compare October 14, 2026 05:32
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=9703a2c0dd8b

issue (non-blocking): fixed in 482170d.

The inline agent in cfg.agents and agent_kind != "template" predicate is gone. The fork now calls resolve_agent_identity(cfg, agent, selection_kind=agent_kind) and takes the member branch when the returned alias is non-empty, so _resolve_agent_selection is the only spelling of the rule. The 88 fork tests pass unchanged.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=17e6d76947a7

suggestion (non-blocking): fixed in 482170d.

agent_kind is now a required parameter of _fork_execution_context. Its only caller passes it through the identity tuple, so no call site changed.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

span=83b55fcac10a

note (non-blocking): fixed in 482170d, by the same change as the duplicate-predicate item.

The crewmate-alias branch now comes from resolve_agent_identity, which wraps the alias_hit rule at config/loader.py:7643, instead of a second copy of it.

@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Oct 15, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/fork-legacy-exec-context branch from e107901 to 6b4d944 Compare October 15, 2026 09:16
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): rebased on main, no behaviour change. The failures on e107901 in test_workflow_matrix_max_parallel (codeql.yml) and test_app_mcp_tool_policy_scope came from main and were fixed there by #20702. The rebase to 6b4d944 had no conflicts, and the chat fork tests, the max-parallel test and flake8 pass on the new base. This push also re-runs shard (3.12, 8), whose test_agent_scratch failure passes locally.

@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 readiness: checking Automated validation is still running labels Oct 15, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/fork-legacy-exec-context branch from 6b4d944 to 64438fb Compare October 15, 2026 17:46
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): rebased on main, no behaviour change. The Windows (7) failure on 6b4d944 was test_app_mcp_tool_policy_scope.py from main, which #20802 fixed. A correction to my 09:16 comment: #20702 fixed only the codeql max-parallel and AI-review workflow tests, not this Windows failure. The rebase to 64438fb had no conflicts, and the 94 chat fork and policy-scope tests pass on the new base.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

question (non-blocking): could a maintainer re-run the Automated Rule Check job in run 38780200744 on 64438fb? The fork account cannot re-run jobs. The job hit its 10-minute timeout-minutes while still in actions/checkout and was cancelled, so no rule ran. The other jobs in that Code Review run (Semgrep, PR Hygiene, Inclusive Language) passed, and both AI reviews report no findings on this head.

@Pearcekieser
Pearcekieser force-pushed the fix/fork-legacy-exec-context branch from 64438fb to 33b8465 Compare October 15, 2026 20:17
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): rebased on main, no behaviour change. This push re-runs Automated Rule Check, which was cancelled on 64438fb after its 10-minute limit while still in actions/checkout; every other check on that commit passed. The rebase to 33b8465 had no conflicts, and the 89 chat fork tests and flake8 pass on the new base.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 15, 2026
@Pearcekieser
Pearcekieser force-pushed the fix/fork-legacy-exec-context branch from 33b8465 to 2797328 Compare October 15, 2026 21:15
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): rebased on main, no behaviour change. Backend Tests (Windows) (6) on 33b8465 failed test_the_lazy_imports_stay_inside_the_functions_that_need_them with assert 84 == 83. That count was red on main at my base and #20930 fixed it by pinning 84. The rebase to 2797328 had no conflicts, and the composition contract test, the chat fork tests and flake8 pass on the new base, 202 tests in all.

@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 15, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at 2797328.

The fix looks sound. A carrier-less parent now resolves the same way its own turns do: skill-view names map back to their source agent, and a config.agents alias gets the member carrier. A carrier-less fork of a crewmate with private V2 memory is refused (chat_fork.py L112-L127). The new tests re-resolve the child, so they would catch the old template_id == "default" bug. CI is green on this head, and GPT and Opus have no findings.

Two things keep it on hold:

  1. Human review required. This changes which identity and memory store a forked chat is bound to, including the private V2 memory refusal. That is a memory-isolation boundary between crew members, so a maintainer needs to review it whatever the AI lanes say.
  2. Untracked follow-up. ## Not a goal defers the same alias-as-template carrier in spawn.py L329 to "a follow-up PR". Design Review and First Principles both ask that it be tracked, and no issue exists. Please open one issue for it and link it in the PR description.

To clear: link the spawn.py follow-up issue, and a maintainer reviews the fork identity change.

— crew-pr-reviewer (r106)

@mbriones98 mbriones98 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.

Checks green and readiness passed at 2797328; no behavior change.

A parent chat with no execution record forked to a template carrier whose
template_id was the slot alias, so a fork of a `default` chat asked the
backend for an agent called default. The fork now records what the
parent resolved to: a config.agents alias on a slot not stamped template
becomes that crewmate's member-kind record (template, model pin, store);
any other name stays a template under the name as written.
@Pearcekieser
Pearcekieser force-pushed the fix/fork-legacy-exec-context branch from 2797328 to c3a213f Compare October 19, 2026 20:30
@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): rebased on main, no behaviour change. Main had gained 631 commits since 2797328, including 5 that touch chat_fork.py and 10 that touch session-control.md, so the freshness check called the old green stale. The rebase to c3a213f had no conflicts, and the 93 chat fork and session-control fork tests and flake8 pass on the new base. The diff is the same as the approved head, so this needs a re-approval only because the push dismisses the earlier one.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

question (non-blocking): could a maintainer approve the workflow runs on c3a213f? CI, Build, Fast Gate, Design Review and the other fork workflows have sat at "action required" since the 20:30Z push, so no test has run on this head yet. The commit is a no-conflict rebase of the approved 2797328 onto main.

@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at c3a213f.

The fix looks sound. A carrier-less parent now resolves the way its own turns do: a skill-view name maps back to its source agent, a config.agents alias gets the member carrier, and a V2 crewmate is refused (chat_fork.py L113-L129). The new tests re-resolve the child, and CI is green on this head.

What keeps it on hold:

  1. Human review. The change decides which identity and memory store a forked chat binds to, including the private V2 memory refusal. A maintainer needs to sign off on that boundary. mbriones98 approved this head with the note "no behavior change", which reads as a rebase check rather than a review of the boundary.
  2. Untracked follow-up. ## Not a goal still defers the same alias-as-template carrier in spawn.py L329 to "a follow-up PR", and no issue exists. Please open one and link it in the description.
  3. Unanswered GPT finding on this head: the function-local imports at chat_fork.py L113 (advisory top-level-imports). Move them to module scope or post a target=gpt disposition explaining why they stay local.

— crew-pr-reviewer (r113)

@Pearcekieser

Copy link
Copy Markdown
Contributor Author
issue (non-blocking): upheld and fixed in 6cad824. The `_source_of_view` import now sits at module scope in `chat_fork.py`. `session_agent_selection` imports nothing from `kiro_crew.dashboard`, so moving it adds no import cycle. `resolve_member_execution` was already a function-local import in this function before this PR, which only added `_source_of_view`, so I left it where it was. The same commit is rebased on main, which had gained 66 commits including #22150 in `chat_fork.py`, with no conflicts. On the new base, 363 chat fork, session-control fork and dashboard composition-contract tests pass, and flake8 and isort are clean.

@Pearcekieser

Copy link
Copy Markdown
Contributor Author

note (non-blocking): correction to my 03:16 comment. This PR merged at 03:15:06Z with head c3a213f, before my push of 6cad824 landed, so the _source_of_view import move did not ship and chat_fork.py on main still imports it inside the function. I'll carry that move in the follow-up PR for the spawn.py:329 alias-as-template carrier.

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.

Fork of a legacy chat fails with Agent default is not available

4 participants