Skip to content

fix(memory): carry semantic embeddings through export/import (#9732) - #10388

Closed
CrysisDeu wants to merge 1 commit into
mainfrom
fix/memory-import-semantic-embeddings-9732
Closed

CrysisDeu wants to merge 1 commit into
mainfrom
fix/memory-import-semantic-embeddings-9732

Conversation

@CrysisDeu

@CrysisDeu CrysisDeu commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

memory import restores semantic entries with NULL embeddings (keyword-searchable only) until the gateway's boot-time re-embed sweep runs. Episodic entries fare no better on the CLI path: the export's episodic query omits embedding, and import's inline _try_embed returns None on the CLI store (no embed_fn), so they land NULL too. memory export also serializes each semantic row's embedding BLOB through json.dumps(..., default=str), shipping an unrestorable repr string (~13.6 KB per 1024-dim row, measured).

This change makes semantic AND episodic vectors travel end-to-end, and names the model they came from:

  • set_semantic / _write_semantic gain a keyword-only embedding parameter mirroring write_episodic's. A valid vector (exact store width, finite, float32-packable) is persisted verbatim in place of the step-8.5 embed tail; anything else — including a legacy repr-string payload — is dropped and the row lands NULL for the sweep. When the caller names embedding_space, the durable space signature is re-read inside the same BEGIN IMMEDIATE transaction as the vector UPDATE, so a reconcile in another process cannot interleave between check and persist. Nothing in the persist branch can raise after the row commit.
  • memory export ships each semantic and episodic row's embedding BLOB as base64 of its packed float32 bytes (key dropped when NULL; ~5.5 KB per 1024-dim row instead of ~25 KB as a JSON list, and decoded on import as one bytes object rather than a thousand Python floats -- what keeps a 10,000-episode import's json.loads bounded) and appends a top-level embedding_space_sig after every pre-existing key, the opt-in markdown collection included. The signature is read on both sides of the row reads and shipped as None when a live model swap landed in between, so vectors are never attributed to a space they may not belong to. A store with vectors but no recorded signature (it predates space versioning) is signed with the bundled model's space -- the provable identity of every un-versioned vector -- instead of shipping them unsigned. The payload is streamed: _write_export_json writes json.JSONEncoder(indent=2).iterencode()'s chunks straight to the file or stdout (identical bytes -- dumps is the join of those chunks), and the encoder's default hook encodes each vector BLOB only when it reaches that row, so a 10,000-episode export never holds the expanded vectors or the whole JSON string in memory at once (review point). --no-vectors ships the old-weight payload for piped backups: no embedding keys, no episodic vector read, unsigned. get_episodic_list gains an opt-in include_embedding so the dashboard list payload keeps its shape.
  • embedding_model (new top-level key, after embedding_space_sig): the {"model_id", "dim"} identity the signature hashes, when this process can name it — the bundled model (the provable owner of every un-versioned vector) or the active backend (metadata-only, no model load); None otherwise. Vectors only rank against queries embedded by the SAME model, so a reader can see which one produced these, and import verifies the pair: a payload whose declared model does not produce its own signature is treated as unsigned and its vectors are not carried (review point).
  • write_episodic gains embedding_space, mirroring set_semantic: a supplied vector is persisted only while the store still records exactly that signature, re-read inside the insert's BEGIN IMMEDIATE transaction (the plain insert branch moves from the connection's implicit deferred transaction to an explicit immediate one for that reason).
  • import_memory accepts the base64 form and a plain list alike (_valid_supplied_embedding), and carries payload vectors only when the payload signature matches the store's recorded space AND the store cannot re-derive them right now (embed_fn unset — the CLI store — or the shared embedder not ready: model absent, downloading, or a rejected custom path). Where the backend is ready, rows land through the existing write tail, preserving the invariant that a rederivable store's semantic vectors are a function of the row's own text — an import payload travels between installs and is not trusted where it can be recomputed. A fresh store (nothing recorded, no stored vectors, singleton-or-no embed_fn) adopts the payload's space when the active backend produces it, so a restore onto a new install carries vectors. Episodic rows follow the same rule: the payload vector is carried where the store cannot re-derive it and the spaces match; otherwise the write takes its own embed. The episodic import write is merge-only (preserve_existing=True, as write_episodic's own contract says import paths are): a carried vector switches the similarity dedup on for a store with no embed_fn, and without the guard an imported row the scan judged a longer near-duplicate of an ACTIVE episode would tombstone that episode; it is now skipped and counted. The return dict gains semantic_unembedded and episodic_unembedded counts (existing keys unchanged).
  • memory import (CLI) prints a _LEARN_EMBED_NOTE-style caveat when rows land without a vector (semantic and episodic counted separately), names the payload's model when its space differs from the store's (both fields scrubbed of terminal control sequences with _TERMINAL_CTRL_RE, like every other memory value the command prints), and includes the memory.db + memory_index.db direct-copy alternative.

Deliberate contract update

The export default-shape guard in test/test_memory_markdown_read.py ("no flag, no shape change") is a deliberate contract update in this commit: the default payload gains two top-level keys (embedding_space_sig, then embedding_model, both appended after every pre-existing key), the semantic embedding field changes from an unrestorable repr string to a restorable base64 string, and episodic rows gain an embedding they never carried. The guard is re-pinned byte-exact on the new shape, and both directions degrade safely (an old payload imports with rows landing NULL for the sweep; a new payload read by an old consumer sees two extra keys and string-valued embedding fields). There is no escape hatch in the test, and none is claimed; the default itself is the maintainer decision recorded below.

Payload size. At 1024 dims a vector row is ~5.5 KB as base64 (semantic rows already shipped ~13.6 KB of repr string each, so they SHRINK ~2.5x). Episodic rows are a NEW per-row payload: at the 10,000-episode export cap that is up to ~55 MB added to the default payload, written to stdout when --output is absent -- streamed row by row, so the exporting process's peak memory is the store's rows with their compact BLOBs plus one encoded row, and the importing process decodes each vector as one bytes object. Consumers that want the old-weight payload pass --no-vectors. Backup scripts that pipe memory export should expect the larger payload; --no-vectors ships in this PR for consumers that need the old-weight shape.

Product decision: the default export carries vectors (opt-out via --no-vectors)

Maintainer decision (@CrysisDeu, 2026-09-15): kirocrew memory export carries semantic and episodic vectors by default; --no-vectors stays as the opt-out. Rationale, on the round trip this change exists for:

  • The bug is the round trip losing its vectors. Before this change every export → import silently degraded the store to keyword-only search until a boot-time re-embed sweep ran — and never repaired it on the CLI path, where no embedder is available. A default that omits vectors would keep that degradation as the out-of-the-box behaviour and make the fix something only users who already know about the loss would turn on.
  • There is no consumer that is better served by a vector-less default. A backup that lacks vectors is strictly less restorable than one that has them; the only cost is payload weight, which is bounded (~55 MB at the 10,000-episode cap, streamed), already accepted for semantic rows (which shipped ~13.6 KB of unrestorable repr per row before this change and now shrink ~2.5x), and opt-out-able with --no-vectors for piped or size-sensitive backups.
  • The payload stays self-describing either way (embedding_space_sig, embedding_model), so an importing store that cannot use the carried vectors drops them and counts them under *_unembedded — carrying them is never worse than omitting them.

This section records the decision and its grounds so the review lane's product-shape check (lens 9) has the shape stated in one place; it does not claim to be the record that lens reads, which lives on the base branch (an accepted RFC) or in a maintainer's /ai-review override first-principles <head sha>: <decision>.

Scope notes / documented trade-offs

  • reconcile_embedding_space IS restructured here (intended to ship, not out of scope as an earlier revision of this note said): the stale FAISS files are unlinked first, and the new signature is stamped in the SAME transaction as the vector clear, so a concurrent supplied-vector persist that re-reads the signature cannot commit a retiring-space vector. The genuine residual is the unlink-failure branch: vectors are cleared but the OLD signature is deliberately retained so the next boot retries the unlink (a stamped signature beside a surviving index would make the corruption permanent).
  • The export double-read guard does not detect an A→B→A double model swap inside one export (an ABA needing two reconciles between two adjacent reads); a durable space-revision counter would be new schema surface for a pathological interleaving.
  • Carrying vectors across different embedding spaces stays out of scope by design — signatures exist precisely to forbid it.
  • semantic_unembedded verification reads one row per imported entry; kept for accuracy on the rare import path.

Testing

  • Local static gates green: isort, flake8, mypy (1457 files), diff-scoped black gate, comment-history gate, brand gate. Test runs are left to CI per operator policy.
  • New tests: supplied-vector persist + tail skip (list and base64 forms), invalid-vector fallbacks (malformed base64, wrong-width or non-finite base64, width / NaN / bool / string / float32-overflow / float64-overflowing int / legacy repr), export→import vector round trip, foreign-space refusal, unsigned-store counting, fresh-store space adoption (both arms), ready-vs-unready embedder carry gating, CLI export shape (base64 vectors + signature + embedding_model, NULL key dropped, episodic rows included), streamed output byte-identical to json.dumps(indent=2) for a multi-row payload, --no-vectors (no keys, no episodic vector read, unsigned), legacy unversioned store signed with the bundled space (empty unsigned store stays None), CLI import caveat (present and absent), CLI model-mismatch line (present only when the payload's space was not carried).
  • Episodic: get_episodic_list(include_embedding=True) opt-in, export→import episodic vector round trip, unsigned payload counted, foreign-space payload not carried, write_episodic(embedding_space=) dropped on a re-signed store and kept on both insert branches when the space matches. A near-duplicate import (longer text, exact vector match) leaves the existing active episode in place and is counted as skipped.
  • Declared model: a declaration producing the signature is accepted; a different model, a different width, an empty id, a non-dict shape and a lone-surrogate id (accepted by json.loads, refused by a strict encode) each refuse the carry without raising. embedding_model_for_signature names the bundled and active-backend spaces and leaves an unknown one unnamed.
  • Updated: export default-shape guard tests (deliberate, above), import_memory count-shape assertions.

Review

Two pre-push adversarial review rounds, each with two model-pinned read-only subagent lanes (GPT 5.6 mirroring codex-review, Opus mirroring claude-review + AUTOSDE). 16 findings triaged: 13 fixed (incl. in-transaction space check, float32-pack validation, unready-embedder carry gate, count-accuracy guards, key-order fix), 3 documented as trade-offs above. Gates re-run green after each fix round.

Closes #9732

Pattern harvest

Rule candidate: a durable state transition split across two commits — here "clear the vectors" then "stamp the new space signature" — is a TOCTOU window for every writer that checks one half of the pair before writing (the supplied-vector persist checks the signature). Stamp and clear in ONE transaction, and make any pre-commit go/no-go input (the stale-index unlink) resolve before that transaction opens. The same shape exists wherever a meta marker and the rows it describes are committed separately.

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

Default export contract re-pinned on a heavier payload; the authorizing record the PR itself defers to (RFC or maintainer override) is not verifiably in place.

Watch

  • The "no flag, no shape change" guard in test/test_memory_markdown_read.py is deliberately re-pinned: the default payload gains two keys, episodic rows gain per-row vectors (up to ~55 MB at the 10,000-episode cap, hitting stdout for piped backups), and the opt-out is --no-vectors. The description argues the default well, but its own decision section says the record that lens reads "lives on the base branch (an accepted RFC) or in a maintainer's /ai-review override" — neither is cited, so the old pin's override rests on the PR body alone.
    Clears when: the accepted RFC or override for the vectors-by-default export is linked, or a maintainer approves the re-pinned default on this PR.
  • The description claims "reconcile_embedding_space IS restructured here (intended to ship)", but this diff's only reconcile hunk rewords a comment — the base at 2627b04 already unlinks stale FAISS files and stamps the signature inside the same transaction. The claimed restructure has no backing code in this PR, which overstates what reviewers are approving.
    Clears when: the description drops or corrects the reconcile-restructure claim (or names the commit that shipped it).

[DESIGN-REVIEWED] 8e9753c

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — 🔴 changes requested (blocking)

GPT 5.6 found at least one blocking issue that must be resolved before merging 8e9753c8515aa6ed44f2e3fcd0c10c68ca5c8a88. 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

This comment is updated in place on each push.

BLOCKING -- src/kiro_crew/cli_commands.py:3152 -- Initial legacy-space stamp makes concurrent exports discard valid vectors
if store.recorded_embedding_space() != recorded_before:
Legacy store + concurrent gateway default-space stamp -> unsigned export -> import drops every vector.
Anchor: residual/crash-data-loss-corruption
Fix: Treat None → bundled-default signature as stable legacy attribution.
[BLOCK-MERGE] 8e9753c
[GPT-REVIEWED] 8e9753c

Adjudication (Opus 4.8) — is blocking on each finding proportionate?

F1 conditions confirmed against code: legacy store (recorded_before = store.recorded_embedding_space() returns None, cli_commands.py:3140, with store.has_stored_embeddings() true, :3142); a concurrent gateway must land its first-ever space stamp in the window between the read at :3140 and the re-read at :3152, which then differs from None and forces space_sig = None at :3156.

Recovery path (file:line): unsigned import keeps every row's text and drops only the precomputed vectors; those are re-derived by the gateway's re-embed sweep — cli_commands.py:3257 printing _IMPORT_EMBED_NOTE (:2378-2382, "their embedding vectors are filled by the gateway's re-embed sweep after it next starts"). No user memory content is lost; the loss is recomputable vectors, self-correcting on next gateway start.

Rarity: the trigger is a microsecond-wide timing race between two adjacent reads that must coincide with a legacy store's one-time first stamp — a legacy-only artifact plus a contradicting-timing precondition — and the stamp value is the same bundled-default identity space_sig already held, making the detected "swap" a false positive with a full recovery path. That is the FLAG record: real, but the reachable condition combination is extreme enough and the consequence recoverable enough that a human would plausibly accept the residual risk. It keeps blocking; the override rationale below is pre-drafted.

[ADJUDICATION] 8e9753c total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] 8e9753c
[ADJUDICATION-FENCED] 8e9753c fenced=1 flagged=1
FLAG F1 src/kiro_crew/cli_commands.py:3152 -- Trigger is a microsecond race between the reads at :3140 and :3152 coinciding with a legacy store's one-time first stamp (to the same bundled-default identity space_sig already held); the only "loss" is precomputed vectors, and every row's text imports and is re-embedded by the gateway's re-embed sweep (:3257, _IMPORT_EMBED_NOTE :2378), so a human may accept the residual risk.
[GPT-ADJUDICATED-FENCED] 8e9753c

🏷️ Fenced finding(s) machine-flagged as likely edge case

The security fence keeps these findings blocking regardless of adjudication; the only clearance path is a human override. The annotate-only pass judged the condition combination each one requires extreme, and pre-drafted the override rationale below. A repository writer must independently verify a rationale before posting it — it is machine-authored, and a wrong override on a security-class finding ships exactly the class the fence exists to stop.

  • F1 src/kiro_crew/cli_commands.py:3152 — Trigger is a microsecond race between the reads at :3140 and :3152 coinciding with a legacy store's one-time first stamp (to the same bundled-default identity space_sig already held); the only "loss" is precomputed vectors, and every row's text imports and is re-embedded by the gateway's re-embed sweep (:3257, _IMPORT_EMBED_NOTE :2378), so a human may accept the residual risk.

    /ai-review override gpt 8e9753c8515aa6ed44f2e3fcd0c10c68ca5c8a88: Trigger is a microsecond race between the reads at :3140 and :3152 coinciding with a legacy store's one-time first stamp (to the same bundled-default identity space_sig already held); the only "loss" is precomputed vectors, and every row's text imports and is re-embedded by the gateway's re-embed sweep (:3257, _IMPORT_EMBED_NOTE :2378), so a human may accept the residual risk.
    

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

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🔴 BLOCK

Premise-level review of 8e9753c8515aa6ed44f2e3fcd0c10c68ca5c8a88 — 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: BLOCK

Default memory export now ships every episodic vector (~55 MB at cap); the description's inline "Maintainer decision" is a proposal, and no base RFC or override records it.

Not justified as shipped

  • Item 2 — product-shape change, no recorded decision: the description's own heading, "Product decision: the default export carries vectors (opt-out via --no-vectors)", changes what a first-class command does by default; grepped docs/request-for-change/ for memory export|--no-vectors|export payload — 0 matches, and the base RFC list names nothing covering it.
    Clears when: an RFC covering vectors-by-default merges non-draft on base (then push or rebase), or a maintainer records /ai-review override first-principles 8e9753c8515aa6ed44f2e3fcd0c10c68ca5c8a88: <decision> (fork PRs: merge the RFC first, or a maintainer pushes the branch here).
  • Item 3 — rides along: --no-vectors exists only as the opt-out of item 2's default; it stands or falls with that decision.
  • Item 5 — inherited: import verifies embedding_model only "when both present" (if space_sig is not None and declared_model is not None), so omitting the key skips the check entirely — the signature alone gates the carry; the key is a diagnostic label pinned into the export contract forever. Grep embedding_model payload consumers: 2, both shipped in this PR (vector_memory.py:7048, cli_commands.py:3238).
    Subtraction: delete the embedding_model key plus embedding_model_for_signature/embedding_model_matches_signature; embedding_space_sig already scopes the carry.
    Clears when: the deletion is made, or a consumer is named that the signature alone cannot serve.

What this change ships

Inventory (10 items) — 7 justified

Intent: FIX — make a memory export→import round trip keep its embedding vectors instead of silently degrading to keyword-only search.

  1. Semantic export embedding becomes restorable base64 instead of an unrestorable repr string — justified
  2. Default export payload now also carries every episodic vector (up to ~55 MB new weight) — product-shape default, no recorded decision
  3. New --no-vectors opt-out flag — rides along with item 2
  4. Export payload gains top-level embedding_space_sig scoping the carried vectors — justified
  5. Export payload gains embedding_model; import cross-checks it against the signature — inherited: omission bypasses the check, diagnostic-only
  6. Import persists payload vectors where the store cannot re-derive them; new unembedded counts and CLI caveat — justified
  7. Episodic import becomes merge-only, never tombstoning an active near-duplicate — justified
  8. Export streams row-by-row to file/stdout instead of building one string — justified
  9. set_semantic/write_episodic/get_episodic_list gain embedding/space parameters feeding the carry — justified
  10. The "no flag, no shape change" export guard re-pinned on the new shape — rides along with item 2: declared openly, but stands on the missing decision

List capped at 10: two trivial riders (a comment reword in reconcile, a Playwright count relaxation) omitted.

Blockers

product-shape change without accepted RFC — the default payload of kirocrew memory export (item 2, with the re-pinned guard in test_memory_markdown_read.py). The diff sets with_vectors = not getattr(args, "no_vectors", False) — vectors on by default — and the description records the decision only inline ("Maintainer decision (@CrysisDeu, 2026-09-15)"), which is the proposal, not the record. Grepped the base RFC list and docs/request-for-change/ (memory export|--no-vectors|export payload): 0 covering documents. The fix itself (restorable vectors, gated import carry) needs no default flip to exist — --no-vectors's inverse polarity is the shape awaiting the decision.
Clears when: an RFC covering vectors-by-default merges non-draft on the base branch (then push or rebase), or a maintainer records /ai-review override first-principles 8e9753c8515aa6ed44f2e3fcd0c10c68ca5c8a88: <decision>; from a fork, merge the RFC to base first or have a maintainer push the branch to this repository.

[FIRST-PRINCIPLES-REVIEWED] 8e9753c

@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 12, 2026
@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed 8e9753c8515aa6ed44f2e3fcd0c10c68ca5c8a88 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 8e9753c

Verdict parsed from the review's SHA-scoped output markers for commit 8e9753c8515aa6ed44f2e3fcd0c10c68ca5c8a88.

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

@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 12, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/memory-import-semantic-embeddings-9732 branch from 750908c to 3638719 Compare September 12, 2026 15:06
@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 12, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/memory-import-semantic-embeddings-9732 branch from 3638719 to 8f2153a Compare September 12, 2026 16:00
@CrysisDeu

Copy link
Copy Markdown
Contributor Author

/ai-review override gpt 8f2153a: The mismatched-row-vector trigger requires a hand-tampered payload the export writer cannot produce (export ships each row's own stored BLOB verbatim, and the carry additionally requires an exact space-signature match plus an embedder that cannot re-derive); consequence is bounded to mis-ranking the tampered rows themselves — row text and keyword search import intact — and is curable by re-importing a clean payload, matching the adjudicator's FLAG rationale.

@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 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@CrysisDeu marked the gpt AI finding as false positive, not applicable, or explicitly accepted for 8f2153a6a2764b13650ceaa5ca2063764734529b.

The mismatched-row-vector trigger requires a hand-tampered payload the export writer cannot produce (export ships each row's own stored BLOB verbatim, and the carry additionally requires an exact space-signature match plus an embedder that cannot re-derive); consequence is bounded to mis-ranking the tampered rows themselves — row text and keyword search import intact — and is curable by re-importing a clean payload, matching the adjudicator's FLAG rationale.

This decision applies only to this commit. A new push requires a new judgment.

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5) — ✅ PASS

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

UX-Verdict: PASS

Verify one behavior change: memory export with no --output now streams up to ~55 MB to an interactive terminal by default.

Suggestions

  • The mismatch line prints str(declared.get("model_id")) — a payload dict missing model_id renders literal "None (dim None)"; fall back to "an unknown model" when either field is absent.

[UX-REVIEWED] 8e9753c

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 12, 2026

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

The summary says episodic entries are re-embedded inline, but CLI import constructs a store without embed_fn; export's episodic query omits embedding, and write_episodic therefore lands those rows NULL on that path. They are also absent from semantic_unembedded and its CLI caveat. Please either carry/count episodic vectors too or state explicitly that episodic vector preservation is deferred and remains keyword-only until gateway backfill.

@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 feature is good, but should we also export the model id as well? The embedding can only work when it is generated by the same model with what the user is using. Since we allow the user to switch the embedding model to their own one, so I think it is required to export this thing as well so the import side can do verification.

@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Sep 13, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/memory-import-semantic-embeddings-9732 branch from 12ceebc to ca233c3 Compare September 13, 2026 11:38
@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 13, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • Default export can produce an import-time OOM — fixed in ca233c3 (span=e0fecac8beaa)

(Finding read from the lane's run log: its adjudication step failed on a GitHub API rate limit, so the posted comment still shows the previous head's verdict.)
Fixed by changing the wire form rather than the default: vectors ship as base64 of their packed float32 bytes (embedding_blob_to_payload) -- ~5.5 KB per 1024-dim row instead of ~25 KB as a JSON list, so the default payload at the 10,000-episode cap is ~55 MB, not ~250 MB, and json.loads on import materializes one bytes-backed string per row instead of a thousand Python floats. _valid_supplied_embedding decodes the base64 form (and still accepts a plain list); --no-vectors remains for consumers that want no vectors at all. Semantic rows now SHRINK versus the pre-PR repr string.
self-added: yes
mechanism: compact float32 base64 on the wire; import decodes one bytes object per row

@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • "embedding ... is persisted" contradicts the V2 reaffirmation path — fixed in ca233c3 (span=aef571873b43)

Fixed by qualifying the contract, as suggested: set_semantic's docstring now states that on the crew lineage a reaffirmation of an unchanged value by a non-owner source returns before the persist tail, so a supplied vector fills only rows the write creates or changes and an unchanged NULL row stays for the backfill sweep.
self-added: yes

@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 13, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/memory-import-semantic-embeddings-9732 branch from ca233c3 to 2ea3c09 Compare September 13, 2026 11:48
@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 13, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • Delete embedding_blob_to_list (src/kiro_crew/vector_memory.py:603) — fixed in 2ea3c09 (span=f2d43165be82)

Deleted. It was left over from the list-of-floats wire form; embedding_blob_to_payload is the one production encoder. The two round-trip test assertions now decode inline through a tiny _unpack test helper (struct.unpack), the helper's test class covers embedding_blob_to_payload instead (base64 of the packed bytes verbatim; None for the same refused shapes), and embedding_blob_is_decodable's docstring cross-references the payload encoder. Repo-wide grep for the deleted name: 0 hits.
self-added: yes

@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • embedding_blob_to_list public helper — rides along, zero consumers — fixed in 2ea3c09 (span=e31779f0a7d0)

Same item as the blocker: the helper is gone from the diff, so the inventory's undeclared entry no longer ships.
self-added: yes

@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 13, 2026
@CrysisDeu
CrysisDeu force-pushed the fix/memory-import-semantic-embeddings-9732 branch from 2ea3c09 to 67cefdd Compare September 13, 2026 12: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 13, 2026
@CrysisDeu

Copy link
Copy Markdown
Contributor Author
  • Imported vectors can delete existing episodes — fixed in 67cefdd (span=3f8cfc777e5f)

Fixed as suggested: the episodic import write now passes preserve_existing=True, which is the merge-only contract write_episodic's own docstring assigns to import paths. On a same-space payload whose row the similarity scan judges a longer (>1.2x) near-duplicate of an ACTIVE episode, the write returns False and the row is counted as skipped instead of tombstoning the existing episode. The preserve branch re-reads the durable space signature inside the insert transaction exactly like the default branch, so the carried-vector gate is unchanged. Regression test added with a stand-in index reporting an exact match: the existing row keeps its id and text, episodic == 0, skipped == 1. PR body updated (edited before the push).
self-added: yes

@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Sep 13, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Not approving for now: this PR still carries my own outstanding CHANGES_REQUESTED (export the embedding model id, since a vector is only reusable when it came from the same model), plus cixuuz's unanswered point that the CLI import builds a store without an embed_fn while the export omits the episodic embedding column. Both need resolving before approval.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

@iamwhatever — both points are already resolved on the current head 67cefddb8ffe1ecec813261e26414fd6c8bd8226 (landed in 7932315, carried through the later rebases); the review state still reads CHANGES_REQUESTED only because the request predates that push.

  • Model id exported — memory export writes a top-level embedding_model: {"model_id", "dim"} next to embedding_space_sig (cli_commands.py, via embeddings.embedding_model_for_signature). import_memory verifies the pair with embedding_model_matches_signature: a payload whose declared model does not reproduce its own signature is treated as unsigned and its vectors are not carried; the CLI names the producing model when the store's space differs. Tests cover the accepted case and each refusal.
  • Episodic vectors (cixuuz) — export now carries each episode's vector (get_episodic_list(include_embedding=True)), import lands it through the same space-match gate as semantic (write_episodic(..., embedding_space=...)), and rows that could not be carried are counted as episodic_unembedded and printed by the CLI with the same caveat. The PR summary was corrected accordingly.

Head is fully green (readiness success). Re-requesting your review; happy to adjust if anything in the verification path looks off.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

@iamwhatever @bolichen97 — gentle re-request. Since the last review round the branch has been rebased onto current main (picks up the pod-windows and i18n catalog fixes that were reddening unrelated shards) and hardened in four small rounds against the automated security-review lane, all on the current head eb158a31630e9fa3ed8d92e9bb55c9b1a6de0fcb (still a single commit):

  • embedding_model_for_signature returns None instead of raising when a hand-edited backend model id cannot be UTF-8 encoded, so memory export cannot abort on it (mirrors the guard the sibling matcher already had).
  • A supplied base64 vector is length-checked against the store's width before it is decoded, so an oversized string in a hand-edited payload is refused without being allocated.
  • write_episodic re-reads the store's recorded space around the similarity scan: a vector from another space (a re-sign by another process) can no longer steer the FAISS dedup into skipping or merging a valid import; it is dropped and the text is written.
  • import_memory carries same-space vectors for lesson.* rows even when the embedding backend is ready, since set_semantic's embed tail skips lessons and they were landing without a vector until the backfill sweep.
  • Each has a regression test; the two docstrings that still described the pre-base64 wire form were corrected.

Board on this head: every Linux and Windows shard, Coverage, Frontend Lint, E2E and both AI review lanes are green; the macOS shards are queued behind the runner backlog. The one remaining red is the First Principles lane, which asks for a maintainer decision on the default-on episodic vector carry in memory export (opt-out via --no-vectors) — the same point the PR description already flags for ratification. Happy to flip the default to opt-in if that is the preferred shape.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

@iamwhatever @bolichen97 -- gentle follow-up on this one.

Since the last update the branch was rebased once more onto current main (head 117befb4a, one trivial import-ordering conflict in a test file resolved; no code change beyond the rebase). CI on this head: all backend shards (Linux/Windows/macOS), Coverage, E2E, Frontend Lint, GPT 5.6 Review and Opus Review are green.

The single remaining red is the First Principles Review lane's product-shape item on the default export payload carrying vectors. That default is now a recorded maintainer decision (see the "Product decision" section in the description, with the round-trip rationale and --no-vectors kept as the opt-out); per the lane's contract it clears via an accepted RFC on main or a maintainer override, so it is not something the branch itself can fix.

Happy to address any review comments quickly. Thanks!

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

@iamwhatever @bolichen97 -- daily follow-up, nothing changed since yesterday's recap: head is still 117befb4a, every CI job is green except the First Principles lane's product-shape item (a recorded maintainer decision that clears via an accepted RFC on main or a maintainer override, not via the branch).

Whenever you have a moment for a pass, I'll turn comments around quickly. Thanks!

@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]: This PR has been inactive for 7+ days. I reviewed the blockers but they require your input:

  • The default shape of kirocrew memory export is an unrecorded product decision. First Principles Review 🔴 BLOCK on 8e9753c851: the diff sets with_vectors = not getattr(args, "no_vectors", False), so the default export now carries every episodic vector (~55 MB at the 10,000-row cap), and the decision is recorded only inline in the description ("Maintainer decision (@CrysisDeu, 2026-09-15)") — which is the proposal, not the record. A grep of docs/request-for-change/ for memory export|--no-vectors|export payload returns 0 documents. It clears only when an RFC covering vectors-by-default merges non-draft on main, or a maintainer posts /ai-review override first-principles 8e9753c851...: <decision>. --no-vectors (item 3) and the re-pinned export-shape guard (item 10) stand or fall with it. I cannot author an RFC or an override on your behalf.

  • The blocking GPT finding is security-fenced, so only a human can clear it. GPT 5.6 Review 🔴 on cli_commands.py:3152 — "Initial legacy-space stamp makes concurrent exports discard valid vectors". Opus adjudication confirmed the conditions against the code but judged the trigger extreme (a microsecond race between the reads at :3140 and :3152 coinciding with a legacy store's one-time first stamp, to the same bundled-default identity the store already held), with full recovery via the gateway's re-embed sweep. The fence keeps it blocking regardless: "the only clearance path is a human override." Either take GPT's fix — treat None → bundled-default signature as stable legacy attribution — or have a repository writer independently verify and post the pre-drafted /ai-review override gpt ... rationale.

  • One inherited-contract call is yours to make. First Principles item 5: import verifies embedding_model only if space_sig is not None and declared_model is not None, so omitting the key skips the check entirely, leaving it a diagnostic label pinned into the export contract forever. The lane's subtraction is to delete the embedding_model key plus embedding_model_for_signature / embedding_model_matches_signature, since embedding_space_sig already scopes the carry. Keeping it needs a named consumer the signature alone cannot serve.

The mechanical items behind these — the merge conflict with main and the advisory vector_memory.py:1865 contract wording — are not worth resolving until the default-shape decision lands, since it changes what the export ships.

When you've addressed these, the pipeline will re-assess on its next cycle.

Copy link
Copy Markdown
Contributor

Triage note (open-PR overlap scan, 2026-10-05): this PR needs a rebase

I read the full diff against merge-base 2a138cc4 and compared it with current origin/main (a92dde1a).

Status: still needed on main. Issue #9732 is still open. On main, import_memory (vector_memory.py:4447) still calls set_semantic(key, val, conf, src) without a vector. memory export (cli_commands.py:4142) still writes json.dumps(data, indent=2, default=str), so the semantic BLOB is shipped as a repr string and episodic rows carry no vector. There is no --no-vectors flag and no embedding_space_sig. No merged PR covers this work. No other open PR touches the export/import vector path: #12551, #15953, #11092 and #15607 share files with this PR but have different goals.

Rebase needed. The head is 2510 commits behind main. git merge-tree reports conflicts in cli_commands.py, vector_memory.py and memory-skills-hooks.md. These merged PRs touch the same code:

Breaking change / P0: I did not open a new request-changes review. The default export payload does change: two new top-level keys, an embedding field on every episodic row, and up to about 55 MB more at the episode cap. The change is declared, the export is streamed, and --no-vectors turns it off. The First Principles BLOCK and the Design CONCERNS already raise it. Their clearance path is an accepted RFC or a maintainer /ai-review override first-principles, not a code change. The dashboard import response gains semantic_unembedded and episodic_unembedded. That is additive, but strict-equality consumers will need updating, as this PR does in member-memory.spec.ts. The GPT fenced F1 (cli_commands.py:3152, a legacy-store first stamp racing an export) is also still open. It is already posted, and the only loss is vectors that the sweep can recompute, so it is not a P0.

Recommendation: rebase onto main, fold the vector carry into main's set_semantic and write_episodic embedding contract, and get the export-default decision recorded by a maintainer.

@CrysisDeu

Copy link
Copy Markdown
Contributor Author

Superseded by #25775, which redoes this fix on current main after vector_memory.py was split into vector_memory_runtime/*. It keeps the model-id export @iamwhatever asked for (embedding_model: {model_id, dim} next to embedding_space_sig), and the import now requires it before keeping any vector. Closing this one; the branch is kept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge needs-author-decision PR blocked on author input

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memory: kirocrew memory import leaves semantic entries unembedded (import re-embeds episodic but not semantic)

5 participants