Skip to content

fix: backfill a 0.7.0.5 member session's execution_context on read - #13672

Merged
bolichen97 merged 1 commit into
mainfrom
fix/legacy-member-session-execution-context-13398
Sep 25, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/legacy-member-session-execution-context-13398

Conversation

@bolichen97

@bolichen97 bolichen97 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

After the automatic upgrade from 0.7.0.5 to 0.7.0.8, every chat bound to a Crew Member's private memory stops working. Sending a message shows the error card Execution memory is unavailable: session has no canonical member identity; Global was not used, and asking the agent in such a chat to spawn sub-agents fails with The execution identity is unavailable; Global memory was not used. The transcript is intact; only the chat's member binding cannot be read.

Why it matters

Every internal 0.7.0.x install that created a Crew Member and chatted with it loses all of those chats on upgrade, with no repair path other than hand-editing metadata files. It is the second breaking metadata change in the 0.7 line and was reported independently by two users on the same day (#13398).

What changed (motivation → approach → change)

Symptom A 0.7.0.5 member chat is refused by read_session_execution on 0.7.0.6+
Root cause #11780 made execution_context the canonical member carrier; #12103 backfilled the config and the V2 store at process start, but nothing ever backfilled the session record, so read_session_execution (src/kiro_crew/execution_context.py) raised MissingExecutionIdentity for the {agent, memory_store} shape and the repair branch below it in chat_runner was unreachable
Change read_session_execution derives the carrier from the store's declared owner_member_id and persists it once, only when the attribution is unambiguous

A 0.7.0.5 member chat carries agent and a memory_store naming the member's V2 store, and no execution_context. The start-of-process store migration already attributed that store to exactly one member (owner_member_id). The read now uses that same fact: when the owner id names exactly one configured member, that member resolves to this store, and the record's own agent names that member (by alias or id), the read builds the member's execution context with resolve_member_execution, carrying the record's own app attribution so an app-owned chat keeps its per-app governance profile, and writes it into the record with a compare-and-set against the exact legacy shape it read. Every later read decodes the field like any other session.

No member is ever guessed. A record with no agent, an agent naming anyone else, an explicit template pick, a store the migration could not attribute (two bound members), a member_id marker, a restricted memory mode, or a non-string app is left byte-for-byte unchanged and still refused, and the refusal now names the remedy that works for that store: open a new chat with the same member (its memory is intact) or archive this one when the store has an attributed owner, or the legacy store repair kirocrew doctor names when the start-of-process migration could not attribute it (a new chat with that member would fail the same way). A successful backfill logs one INFO line naming the session, so an operator can see which chats were migrated. The derived identity is never vouched, because the store came from the session's own record; the migrated session stands exactly where a member session stands after a gateway restart and re-establishes own-store authority the same way. The write is a direct compare-and-set rather than bind_session_execution, which re-enters this read. A lost race re-reads and returns what the other reader committed.

Docs: docs/system-specs/modules/session.md (agent selection provenance) and docs/system-specs/modules/memory-skills-hooks.md (the store migration's session-record half) describe the backfill and its bounds.

Existing-user visible behaviour: unchanged for every session that already carries execution_context, every Global session, every V1 named-store session, and every ambiguous legacy record (still refused, same exception type, same canonical member identity phrase). Changed only for (1) an unambiguous 0.7.0.5 member record, which previously raised and now loads, and (2) the text of the refusal for ambiguous records, which gains a remedy sentence; and (3) one new INFO log line per backfilled session.

Backwards compatibility

Compatible: nothing main accepts is rejected, renamed or removed. A record main refused now loads when its attribution is unambiguous; every other input keeps the same outcome and exception type. The one text change is additive (canonical member identity is retained, the remedy sentence is appended). required=True reads are unchanged.

Tests

test/test_legacy_member_session_backfill.py (new): the unambiguous record derives the owner and persists the carrier, capture_session_execution and a required=True read agree with it, the backfill never vouches, the member id is accepted as agent, an app-owned record keeps its app in the carrier and a record without one derives an empty app, a lost compare-and-set returns the winner's record; every ambiguous shape (other agent, unknown agent, no agent, template pick, unattributed store, member_id marker, restricted mode, non-string app) stays refused with an unchanged record, the unattributed store naming the store repair and every other shape naming a new chat; a record with a carrier, a Global session, a V1 named-store session, an undeclared store and a malformed carrier behave exactly as before.

test/test_legacy_session_history_save.py (updated): the unambiguous record now derives on save/close; two new cases keep the original coverage that a record with no owning agent is still refused and still saves and closes its transcript.

Manual verification

N/A — unit coverage sufficient: the tests run the real upgrade sequence (_write_legacy_home → repair_legacy_member_stores → a 0.7.0.5-shaped record) against the same functions the chat, spawn and workflow paths call.

Related Issues

Fixes #13398

Pattern harvest

Rule candidate: agents-md
Pattern: a refactor that adds a required identity field to a persisted record must ship the one-shot backfill for records written before the field existed -- the same rule #12103 harvested, applied to the session record it missed

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

@bolichen97
bolichen97 requested review from a team and hoang-phan98 September 25, 2026 04:12
@bolichen97

Copy link
Copy Markdown
Contributor Author

Intent: Make a member chat written on 0.7.0.5 ({agent, memory_store}, no execution_context) loadable again on 0.7.0.6+ by deriving and persisting its carrier at first read, only when the store's declared owner is unique and the record's own agent names it.
Not a goal: Guessing a member for any ambiguous record (those stay refused, with a remedy in the text); vouching the derived identity; changing how records that already carry execution_context, Global sessions or V1 named-store sessions are read; a startup sweep over every session file; splitting the shared 409 text in _shared.py; a versioned session-metadata migration framework.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Confirm against a real upgraded 0.7.0.5 home from #13398 that the first read backfills — tests replay the sequence, no manual run did.

[DESIGN-REVIEWED] 92db533

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 92db5335e4376126b5239db7e17bffd39d9b2f7e — 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 one counted sibling: read_run_execution (src/kiro_crew/subagent_persistence.py:463) still refuses a pre-carrier V2 run record — confirm no 0.7.0.5 subagent run survives upgrade to hit it.

That sibling carries its own pin ("V2 never infers identity") and run records are short-lived, so it reads as deliberately out of scope, not a point patch — but the description's "the session record it missed" implies completeness, and only the author can confirm no upgraded run record is ever re-read. Everything else is grounded: the defect has a linked issue (#13398) and tests that fail on base; all 33 read_session_execution call sites (grepped) funnel through the one changed choke point, so the fix sits at the cause; the rewritten "refused, and stays refused" pin in test_legacy_session_history_save.py is reversed with evidence and declared; the write reuses the existing update_metadata_if mechanism rather than adding one; no new public surface, config key, or flag ships.

What this change ships

Inventory (6 items) — 6 justified

Intent: make member chats written on 0.7.0.5 readable again after the upgrade that added execution_context — a FIX.

  1. A pre-0.7.0.6 member chat whose store has one declared owner matching its agent loads again — justified
  2. Still-ambiguous legacy chats stay refused, but the error now names the remedy (new chat, or the kirocrew doctor store repair) — justified
  3. Refusal text gains a "predates 0.7.0.6" explanation alongside the retained phrase — justified
  4. One INFO log line per backfilled session — justified
  5. The backfilled record is rewritten once (carrier persisted, store/mode normalized) via compare-and-set — justified
  6. session.md and memory-skills-hooks.md updated in the same commit — justified

[FIRST-PRINCIPLES-REVIEWED] 92db533

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 92db5335e4376126b5239db7e17bffd39d9b2f7e and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 92db533

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

@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 Sep 25, 2026
@bolichen97
bolichen97 force-pushed the fix/legacy-member-session-execution-context-13398 branch from ebda1cc to cc270db Compare September 25, 2026 04:32
@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 Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 92db533

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

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

A member chat written on 0.7.0.5 carries {agent, memory_store} and no
execution_context. #11780 made that field the canonical carrier and
#12103 backfilled the config and the V2 store at process start, but no
path ever backfilled the session record, so read_session_execution
raised MissingExecutionIdentity for every such chat after the upgrade:
the chat could not run, could not spawn, and every private-memory
request answered member_identity_unavailable. The repair branch nine
lines below the raise in chat_runner was unreachable.

read_session_execution now derives the carrier from the store's
declared owner_member_id and persists it once, with a compare-and-set
against the exact legacy shape it read, only when the attribution is
unambiguous: the owner id names exactly one configured member, that
member resolves to the same store, and the record's own agent names
that member. No member is ever guessed. Every other shape (no agent,
another agent, a template pick, an unattributed store, a member_id
marker, a restricted mode) is left untouched and still refused, and
the refusal now names the remedy. The derived identity is never
vouched, so the migrated session stands where any member session
stands after a restart.

Records that already carry execution_context, Global sessions and V1
named-store sessions are not touched.

Fixes #13398
@bolichen97
bolichen97 force-pushed the fix/legacy-member-session-execution-context-13398 branch from cc270db to 92db533 Compare September 25, 2026 05:09
@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 Sep 25, 2026
@bolichen97

bolichen97 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Preserve app ownership during backfill (span=6b5c9235d385) — fixed in 92db533

The backfill now reads the record's own app, refuses a non-string value, threads it into resolve_member_execution, and keeps it in the compare-and-set predicate, so an app-owned legacy chat's carrier carries the same app identity a fresh selection would and /api/spawn runs the per-app profile half of governance.
Pinned by test_an_app_owned_record_keeps_its_app_attribution, test_a_record_without_an_app_derives_an_empty_app and test_a_malformed_app_attribution_is_not_backfilled.

@bolichen97

bolichen97 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Refusal names a remedy that fails for an unattributed store (span=daf128424dc3) — fixed in 92db533

The refusal now branches on the store: a store with an owner_member_id keeps "open a new chat with the same member"; a store the start-of-process migration could not attribute names LEGACY_MEMBER_STORE_REMEDY (the same text the boot log and kirocrew doctor use) and says to restart and reopen this chat, which the backfill then admits.
Pinned by test_a_store_the_migration_could_not_attribute, which asserts the store-repair remedy is present and the new-chat remedy absent.

@bolichen97

bolichen97 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Item 3 — remedy sentence rides along (span=09269c9bdf2d) — rebutted

The remedy text is the other half of the same fix, not a rider: the backfill admits only the unambiguous record, and every record it cannot admit still fails at exactly the site this PR touches, so the refusal that site raises must tell the user the step that works. The intent comment names it ("those stay refused, with a remedy in the text") and the description's behaviour section declares it as a visible change.

@bolichen97

bolichen97 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Item 4 — INFO log line undeclared (span=942c36958589) — fixed (description) in 92db533

The description now declares the one INFO line a successful backfill logs, and the session spec names it; no code change was needed.

@bolichen97

bolichen97 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Item 3 — remedy sentence rides along (span=09269c9bdf2d) — rebutted

The remedy text is the other half of the same fix, not a rider: the backfill admits only the unambiguous record, and every record it cannot admit still fails at exactly the site this PR touches, so the refusal that site raises must tell the user the step that works. The intent comment names it ("those stay refused, with a remedy in the text") and the description's behaviour section declares it as a visible change.

@bolichen97

bolichen97 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Item 4 — INFO log line undeclared (span=942c36958589) — fixed (description) in 92db533

The description now declares the one INFO line a successful backfill logs, and the session spec names it; no code change was needed.

@bolichen97
bolichen97 enabled auto-merge (squash) September 25, 2026 05:12
@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 Sep 25, 2026
@bolichen97
bolichen97 merged commit 6404696 into main Sep 25, 2026
94 checks passed
@bolichen97
bolichen97 deleted the fix/legacy-member-session-execution-context-13398 branch September 25, 2026 05:34
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 25, 2026
wknight1 pushed a commit to wknight1/KiroCrew that referenced this pull request Oct 5, 2026
…irodotdev#13672)

A member chat written on 0.7.0.5 carries {agent, memory_store} and no
execution_context. kirodotdev#11780 made that field the canonical carrier and
kirodotdev#12103 backfilled the config and the V2 store at process start, but no
path ever backfilled the session record, so read_session_execution
raised MissingExecutionIdentity for every such chat after the upgrade:
the chat could not run, could not spawn, and every private-memory
request answered member_identity_unavailable. The repair branch nine
lines below the raise in chat_runner was unreachable.

read_session_execution now derives the carrier from the store's
declared owner_member_id and persists it once, with a compare-and-set
against the exact legacy shape it read, only when the attribution is
unambiguous: the owner id names exactly one configured member, that
member resolves to the same store, and the record's own agent names
that member. No member is ever guessed. Every other shape (no agent,
another agent, a template pick, an unattributed store, a member_id
marker, a restricted mode) is left untouched and still refused, and
the refusal now names the remedy. The derived identity is never
vouched, so the migrated session stands where any member session
stands after a restart.

Records that already carry execution_context, Global sessions and V1
named-store sessions are not touched.

Fixes kirodotdev#13398

Co-authored-by: w <w@k.local>
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.

Crew-member sessions created before execution_context cannot run or spawn after upgrade (session metadata never migrated)

2 participants