Skip to content

fix(dashboard): save and close sessions written before execution_context - #12116

Merged
bolichen97 merged 1 commit into
mainfrom
fix/legacy-v2-session-history-save
Sep 20, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/legacy-v2-session-history-save

Conversation

@iamwhatever

Copy link
Copy Markdown
Contributor

Problem / Motivation

Closing a chat that was created before the one-SQLite-store member memory landed (#11780) does not work: the tab disappears and comes straight back. The gateway log shows the same error on every attempt and on every periodic flush of that chat:

UnknownMemoryStore: Execution memory is unavailable: session has no canonical member identity; Global was not used

The chat's record names a member's V2 store in memory_store but has no execution_context, because that field did not exist when the record was written.

Why it matters

Anyone who had a crew-member chat open across the upgrade cannot close it. Its transcript is also never flushed again, so new rows in that chat are lost on restart.

What changed (motivation → approach → change)

Symptom close fails with history_save_failed, slot is restored to the list
Root cause _save_slot_to_history asks read_session_execution for the retention mode; a record with a private store and no execution_context is refused as identity, and the save propagated that refusal
Change that one refusal gets its own type, MissingExecutionIdentity; the save catches exactly it and uses the slot's own memory_mode

src/kiro_crew/execution_context.py raises MissingExecutionIdentity (declared in src/kiro_crew/memory_stores.py, a subclass of UnknownMemoryStore) at the two places a readable record marks a member or a V2 store but carries no execution_context. src/kiro_crew/dashboard/chat_persistence.py catches only that type in retention_allows_write and falls back to the slot's memory_mode, which that function already requires to be persistent.

The transcript write is not private-memory access: the carrier only decides retention there, and a record with no carrier has no stricter retention than the slot's own. Reading such a record for private memory stays refused. An unreadable record, a present-but-malformed execution_context, and an undeclared store stay plain UnknownMemoryStore and still fail the save.

Backwards compatibility

Compatible: MissingExecutionIdentity subclasses UnknownMemoryStore with the same message, so every existing except UnknownMemoryStore / except ValueError and every pytest.raises(UnknownMemoryStore) still matches. No accepted input is rejected.

Tests

test/test_legacy_session_history_save.py:

  • a pre-identity record saves its transcript, and reading it for identity is still refused
  • _close_slot on such a record archives it and does not restore the slot (fails on main with SlotCloseError: failed to save history)
  • the same record in a temporary slot still writes nothing
  • a present-but-malformed execution_context still fails the save
  • an undeclared memory_store still fails the save
  • both absent-carrier sites raise MissingExecutionIdentity

Manual verification

Reproduced on a host upgraded to bc0d2b0cf: a kirocrew-conductor chat from the previous build could not be closed, with the traceback above at chat_persistence.py retention_allows_write. Not yet re-verified on the host with this patch; the close test drives the same _close_slot path.

Related Issues

no linked issue: found on a live host, no issue was filed.

Pattern harvest

Rule candidate: review-prompt
Pattern: a guard that resolves identity/authorization is called from a persistence path that only needs a retention mode, so an identity refusal fails the write

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|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

A chat record written before the one-SQLite-store member memory landed
names a member's V2 store in ``memory_store`` but carries no canonical
``execution_context``. ``read_session_execution`` refuses such a record as
identity, and ``_save_slot_to_history`` called it unguarded, so every
periodic flush and every close of that session raised
``UnknownMemoryStore: session has no canonical member identity``. The close
handler then restored the slot, and the tab could never be dismissed.

The transcript write is not private-memory access: the carrier only decides
retention there. That one refusal now has its own type,
``MissingExecutionIdentity``, raised only at the two absent-carrier sites;
the save catches exactly it and falls back to the slot's own ``memory_mode``
(already required to be ``persistent``). An unreadable record, a
present-but-malformed carrier and an undeclared store stay plain
``UnknownMemoryStore`` and still fail the save. Authorizing private memory
from a store name stays refused where it is read for that purpose.
@iamwhatever
iamwhatever requested review from a team and krishdhasmana September 19, 2026 23:21
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Intent: A chat whose record was written before execution_context existed (names a member V2 store, has no carrier) can be flushed and closed again. Only that one identity refusal is tolerated by the transcript save; it is tolerated only for deciding retention, and the slot's own memory_mode decides.
Not a goal: Repairing the record (adding an execution_context to old sessions), granting private-memory access from a store name, or tolerating any other UnknownMemoryStore (unreadable record, malformed carrier, undeclared store) on the save path.

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

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 70099ccda4527316c59da79c0d09880502ce8a4a and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 70099cc

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

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

The legacy-record fix covers one consumer; history consolidation asks the same retention-only question and still fails on the same records.

Watch

The fix catches MissingExecutionIdentity only in _save_slot_to_history, but history_consolidation.py:823 makes the identical retention-only read (execution.memory_mode != "persistent") on the same session keys — a legacy record raises there too, so memory extraction for those chats keeps failing every pass even after this PR ships, the same "fails on every attempt" class the description diagnoses.
Clears when: the author shows consolidation is unreachable for legacy records, or extends the same typed-exception fallback (with a test) there — here or in a named follow-up.

The description concedes "Not yet re-verified on the host with this patch." The new close test drives _close_slot end-to-end, so this is thin rather than absent, but the live host is the only place the original traceback was observed.
Clears when: the author confirms the upgraded host can close the previously stuck chat, or states the test environment is equivalent.

Suggestions

Legacy records are never healed, so every save of every legacy chat takes the raise-and-catch path forever; writing a retention-only carrier back on first successful save would retire MissingExecutionIdentity instead of making it a permanent runtime state — worth weighing as a follow-up, not here.

[DESIGN-REVIEWED] 70099cc

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 70099ccda4527316c59da79c0d09880502ce8a4a — 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

Description admits "Not yet re-verified on the host" that reproduced the bug — confirm a real pre-#11780 record actually closes before merge.

Not justified as shipped

  • Item 4 — undeclared: a new logger.debug line fires on the fallback; harm-free rider, inventory only.
  • Item 5 — undeclared: the reorder makes a non-persistent slot skip the record read entirely, so an unreadable record no longer fails a temporary slot's save; harm-free (nothing would be written either way), inventory only.

What this change ships

Inventory (5 items) — 3 justified

Intent: let a crew-member chat created before execution_context existed be closed and its transcript flushed again — a FIX, with a reproduction and traceback in the description and a test the PR adds that fails on base.

  1. Closing a pre-upgrade crew-member chat archives instead of bouncing back — justified
  2. Periodic flush of such a chat writes its transcript again, so rows survive restart — justified
  3. New exception type MissingExecutionIdentity distinguishing the absent-carrier refusal (grep: 2 raise sites, exactly 1 catch consumer at chat_persistence.py:3321 — the singular form, not generalized) — justified
  4. A debug log line when the fallback fires — undeclared, harm-free rider
  5. Temporary-mode slots skip the record read, so an unreadable record no longer fails their save — undeclared, harm-free rider

The identity refusal itself respects the pinned decision at execution_context.py:124 ("never infer membership from a name"), which rules out the backfill-migration cause-level alternative; typing the refusal so the one retention-only caller can interpret it is the mechanism-level fix, and the description states what stays refused. Grep of read_session_execution (40+ call sites): the other callers resolve identity for member-memory access, where refusal on these records has a named cause.

[FIRST-PRINCIPLES-REVIEWED] 70099cc

@github-actions

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed 70099ccda4527316c59da79c0d09880502ce8a4a — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 70099cc

Verdict parsed from the review's SHA-scoped output markers for commit 70099ccda4527316c59da79c0d09880502ce8a4a.

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

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

iamwhatever commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Consolidation makes the same retention read — rebutted (span=11ae52404904)

Consolidation is not the same class: after the retention read at history_consolidation.py:823 it calls _resolve_memory_identity -> store_of_session -> read_session_execution again, then WRITES extracted facts into the resolved store. For a legacy record that store is a member's V2 database. That is private-memory access, which this PR's intent explicitly keeps refused; the transcript save tolerates the refusal only because it writes no memory.
Extending the fallback there would authorize V2 memory writes from a store name, which execution_context.py forbids ("never infer membership from a name") and which the reviewed refusal tests pin.
Reachability on legacy records: the raise happens before the snapshot and before billing (attempted.total == 0, billed = False), so no attempt is charged and no marker is written; the outer except Exception logs and re-raises. Nothing is extracted into any store, which is the correct outcome for a record with no canonical identity. The retry cadence of a refused identity is pre-existing behaviour of every refusal on that path, not introduced here.

@iamwhatever

iamwhatever commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Not re-verified on the live host — rebutted (test environment is equivalent) (span=5fa30dc25214)

The host record that could not be closed was read directly: metadata with agent set, memory_store naming a declared V2 member store, and no execution_context key. test_legacy_v2_record_close_archives_and_does_not_restore builds a record of exactly that shape through the real ConversationLog, rehydrates the same slot fields, and drives the real _close_slot -> save_slot_off_loop -> _save_slot_to_history -> retention_allows_write -> read_session_execution chain.
On main that test fails with SlotCloseError: failed to save history (code history_save_failed), the same exception and code the host log recorded at chat_handlers.py _close_slot. With the patch it archives the record and the slot is not restored.
Re-verifying on the host means restarting the live gateway with an unmerged patch; that is deferred to the normal update after merge.

@iamwhatever

iamwhatever commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Heal legacy records on first save — rebutted (span=aa9b9edda3ed)

Writing a carrier back from the store name is inferring membership from a name, which execution_context.py forbids and the intent lists under "Not a goal". On the host where this was found the member itself has no member_id and the store no owner_member_id, so no valid carrier could be written at all; #12103 repairs the member first. A session repair can only follow that and belongs with it, not in a persistence path.
The runtime cost of the fallback is one refused read per save of a legacy chat, the same read that path already made.

@iamwhatever

iamwhatever commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Undeclared: new logger.debug on the fallback — rebutted (justified) (span=cb7599b1e912)

It is the only observable trace that a save took the fallback. Debug level because retention_allows_write runs up to three times per save and on every periodic flush; a warning there would repeat for the life of every legacy chat.

@iamwhatever

iamwhatever commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor Author
  • Undeclared: non-persistent slot skips the record read — rebutted (justified) (span=1f94c64e0c5c)

A temporary/incognito slot writes nothing whatever the record says, so reading the record can only add a failure to a save that has nothing to save. Skipping it keeps a restricted slot closable even when its record is unreadable. test_legacy_v2_record_in_a_restricted_slot_still_writes_nothing pins that the restricted slot still writes nothing.

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

Approved: fix-class, readiness:passed, no conflict.

@bolichen97
bolichen97 merged commit c0be415 into main Sep 20, 2026
90 checks passed
@bolichen97
bolichen97 deleted the fix/legacy-v2-session-history-save branch September 20, 2026 01:43
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 20, 2026
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…ext (kirodotdev#12116)

A chat record written before the one-SQLite-store member memory landed
names a member's V2 store in ``memory_store`` but carries no canonical
``execution_context``. ``read_session_execution`` refuses such a record as
identity, and ``_save_slot_to_history`` called it unguarded, so every
periodic flush and every close of that session raised
``UnknownMemoryStore: session has no canonical member identity``. The close
handler then restored the slot, and the tab could never be dismissed.

The transcript write is not private-memory access: the carrier only decides
retention there. That one refusal now has its own type,
``MissingExecutionIdentity``, raised only at the two absent-carrier sites;
the save catches exactly it and falls back to the slot's own ``memory_mode``
(already required to be ``persistent``). An unreadable record, a
present-but-malformed carrier and an undeclared store stay plain
``UnknownMemoryStore`` and still fail the save. Authorizing private memory
from a store name stays refused where it is read for that purpose.

Co-authored-by: EC2 Default User <ec2-user@ip-172-31-10-71.ec2.internal>
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.

2 participants