Repository navigation
refactor(vector_memory_runtime): reuse store helpers, drop a dead guard - #23744
Conversation
Three behaviour-preserving simplifications in the vector-memory owners, plus one false comment: - faiss_index.save_faiss_index stamps memory_meta through the store's own _write_meta_in_transaction instead of a hand-written copy of the same upsert. The same upsert, clock and open transaction; the helper re-takes the store's RLock, which the caller already holds. - write_lesson embeds its rule through embed_lesson, the method callers use to embed a rule ahead of the call, instead of restating its body. - store_bookkeeping._ineligible_ids drops an `if not chunk: continue` that cannot fire: every start the range yields is below len(unique), so every slice holds at least one id. - The comment on write_lesson's contains branch said the branch logs "like the siblings do". It logs nothing and neither do the topic or semantic branches: each at most queues a supersede, and the drain after set_semantic logs each queued row it retires or skips. The comment now says that, and its rationale for logging keys rather than row text moves to the drain, where the log lines are, restated for what holds there.
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns. Both new calls go to helpers whose bodies match the code they replace, and the removed guard can never run. [DESIGN-REVIEWED] 798f437 Description read[DESCRIPTION-READ] 4ba815e4d1a8867c21556555692564e1a9a26b5f83323955728398e75bdf48e5 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing to check. What this change shipsInventory (4 items) — 4 justifiedIntent: make the vector-memory code reuse the store's own helpers and correct a false comment, with no change in behaviour. This is a FIX (a cleanup refactor).
[FIRST-PRINCIPLES-REVIEWED] 798f437 Description read[DESCRIPTION-READ] 0215f6d5f99e0cc7e882b3c8af83e4d9c06bff0222c8fe465ba48a0464cf03e2 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: refactor (3 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: code-move only in vector_memory_runtime; the inline memory_meta upsert is replaced by the existing _write_meta_in_transaction helper with the same SQL, the inline embed is replaced by embed_lesson with the same expression, and the removed empty-chunk guard is unreachable because the range step never yields an empty slice; the rest is comment text.
Problem / Motivation
Goal: Make three spots in
src/kiro_crew/vector_memory_runtime/read as what they are, reusing the store's own helpers and dropping a guard that never fires, and correct one false comment, with no change in what the memory store stores, returns or logs.Three spots in the vector-memory owners say more than the code needs to:
faiss_index.save_faiss_indexhand-writes thememory_metaupsert that the store's_write_meta_in_transactionalready owns.write_lessonrestatesembed_lesson's one-line body.store_bookkeeping._ineligible_idsguards against an empty chunk that its own loop can never produce.The comment on
write_lesson's contains branch also says the branch logs "like the siblings do". In fact it logs nothing, and neither do the two branches beside it.Why it matters
Nothing is broken today. A hand-written copy of a helper is a second place to update when the upsert changes. An inline embed that restates
embed_lessonlets a pre-embedded rule (callers pass one in) and the onewrite_lessoncomputes itself drift apart. A comment that names a log call the code does not have sends the next reader looking for one. Each of these is a small cost every time someone reads this lesson-writing and FAISS-stamping code.Not a goal
embedding.py,embedding_repair.py,semantic.py,lessons.py,episodic_write.py, and the four-level nest inwrite_lesson's pre-pass. The last one sits next to hunks that open PR feat(overview): add search and inline editing to lessons table (#17982) #18831 inserts.VectorMemoryStore._cosine_sim: no source code calls it, but tests and the composition contract pin it.lesson_write.py's other comment that the lexical branches "supersede the stored row unconditionally", which reads oddly next tomay_retire_existing.What changed (motivation → approach → change)
The memory store behaves as before. Each spot now reuses the code that already owns the job, or loses a line that cannot run:
faiss_index.save_faiss_indexINSERT ... ON CONFLICTintomemory_metastore._write_meta_in_transaction("faiss_content_signature", stamp): the same upsert, clock (vector_memory._now_iso, read at call time) and openBEGIN IMMEDIATEtransaction. The helper re-takes_db_lock, athreading.RLockthe caller already holds, and does not commitwrite_lessonself._try_embed(rule) if self.embed_fn else Noneself.embed_lesson(rule), whose body is exactly that expressionstore_bookkeeping._ineligible_idsif not chunk: continuerange(0, len(unique), _MAX_SQL_PARAMS)yields is belowlen(unique), so every slice holds at least one idThe contains-branch comment now says what all three queueing branches do: each deletes nothing, at most queues a supersede, and the drain after
set_semanticlogs each queued row it retires or skips. The old comment's rationale for logging keys rather than row text moves to the drain, where the log lines are, restated for what holds there.Only a patch tells the old and new forms apart. A class- or instance-level patch of
_write_meta_in_transactionorembed_lessonnow reaches these two call sites. No test intest/patches either in a way whose outcome changes.Backwards compatibility
Compatible: no signature, return value, SQL effect, log line or import changes; the AST differs from
origin/mainonly at the three code sites above.Removes nothing: the deleted guard could never fire, the deleted upsert and embed expressions are the bodies of the helpers now called, and the comment edits change no code.
Tests
test_vector_memory_composition_contract.py::TestFaissAccelerator::test_save_then_load_round_trips_the_stamped_index.Noneredstest_vector_memory.py::TestValueSizeLimit::test_non_ascii_lesson_embedding_is_persistedandtest_vector_memory_embedding_lifecycle.py::TestSemanticWriteTimeEmbedding::test_lesson_write_keeps_raw_rule_vector.test_vector_memory*,test_lesson*andtest_embedding*file: 5602 passed, 0 failed. This run adds amarkdown-it-pyoverlay, which the host venv lacks. Without the overlay, 18 files fail identically onorigin/mainand the branch. A serial coverage run executes all three changed code lines.scripts/docs_lint.py --test,scripts/docs-lint.sh), the per-file coverage self-test, the--testself-tests, the flake-pattern ratchet and the vendor manifest.kirocrew learn listprints lesson text unredacted, so that sentence is gone. One reviewer's request to restore "redacted at every surface" and "may reach a notification channel" was dropped, as neither holds.scripts/scrub-lint.shis absent from the checkout (CI'sinternal-content-scancovers it). semgrep is not installed on this host (CI's SAST job runssemgrep/). The frontend did not run, as nothing underwebsite/,.github/orscripts/changed.Manual verification
N/A: the related tests execute every changed code line, and the mutation run shows they fail when those lines change. A head-vs-base probe compared the
memory_metarow, the statement order, lesson outcomes and_ineligible_idsresults over chunk sizes 1-500 and found them identical apart from SQL whitespace.Screenshots / video
Why no screenshot: backend-only refactor; no page, card or string changes.
Related Issues
Part of #16523
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.