Repository navigation
feat(memory): tag consolidation writes by kind, opt-in shadow routing - #24511
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the setting is opt-in and defaults to Notes
[DESIGN-REVIEWED] 3c6d233 Description read[DESCRIPTION-READ] 195f1bc9304a72bfc593a51521a18e892a5708cb98e4cba30cf42a0500852a9f 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 blocks: the setting defaults to Notes
What this change shipsInventory (7 items) — 4 justifiedIntent: an operator measures how the model would sort consolidation's
[FIRST-PRINCIPLES-REVIEWED] 3c6d233 Description read[DESCRIPTION-READ] 5c6b3d679dd96c7c103da876b8ba8b2ab626fb84a119174d9a18d1bcc9c89103 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: |
a404954 to
155625d
Compare
155625d to
a4096ec
Compare
|
Goal line edited at the user's explicit request: the default is now |
a4096ec to
d020946
Compare
d020946 to
58f80c8
Compare
58f80c8 to
d761d05
Compare
d761d05 to
2b6868a
Compare
memory.kind_routing (default off) lets consolidation ask the model to tag each semantic item fact, event or state, and route project.* writes by it on both write paths, right after the unseen-delete fence. Under off the prompt and writes are unchanged. shadow (opt-in) writes exactly as before and keeps a bounded log in memory_meta: one counter row a day, and at most 50 samples a day, 2,000 in all and 1 MB, for the first 7 days. enforce (opt-in) saves an event as a dated episode and refuses a state item under the audited work_state code. No stored row changes.
2b6868a to
3c6d233
Compare
CrysisDeu
left a comment
There was a problem hiding this comment.
Review at 3c6d233b: isolation holds; ship shadow only
Checked the hard rule first: both write paths (history_consolidation_memory.py:987, vector_memory_member.py:~687) log into the session's already-resolved store, no shared/global fallback, and nothing in the store or model output can change the mode — the flag lives only in config.json, which agent tools cannot write. Default-off is pinned; routing scope is code-bounded (project.* creates/updates only, first 20; pref.*/user.*/lesson.*/deletes/user_explicit excluded). Format compat is fine. Good.
Maintainer decision: land shadow only in this PR; remove enforce, MODE_ENFORCE, WORK_STATE, _audit_refusals and the enforce-only key-naming line outright (not stubbed or flagged off). Two reasons: the PR's own motivation says shadow comes "before any write is refused", and the mechanism change (model classification replacing the RFC's key+value regex, open question #1 settled as "refuse") is an RFC amendment made inside the implementation PR — that needs to land on the base first (rfc-memory-hygiene.md), then enforce comes back in its own PR once shadow samples have been read.
Also before merge:
- MINOR —
memory_kind_routing.py:281-285,365: shadow samples keep up to 200 chars of raw model value, including values the writer then rejects (routing runs beforevalidate_semantic), with no redaction and no age pruning (rows outlive the 7-day window forever once caps stop pushing). Pass values throughredact_and_truncate(..., 200)and drop sample rows when the window closes. - MINOR — mode read twice per pass (
history_consolidation_pass.py:679andmemory_kind_routing.py:205); resolve once in_consolidateand pass it down. - MINOR — commit body says enforce "saves an event as a dated episode"; code/body/spec say fact. Reword before squash.
- NIT — RFC front matter
implementation-prs: [](:9) and the Rollout line (:250, "on by default") contradict this PR. - Optional — a two-member test (consolidate into alice, assert bob's
memory_meta/memory_eventsuntouched) would pin the isolation claim directly.
Posted by code-reviewer (Kiro Crew member) on behalf of @CrysisDeu. Full report on file.
Problem / Motivation
Goal: An opt-in setting lets consolidation tag every
project.*fact it writes as afact,eventorstate, and log, inside hard size caps, what routing by that tag would do, so work state can later be kept out of semantic memory without guessing.Step 0 of the memory-hygiene plan measured one developer host (issue #16354, RFC #23049):
project.*rows are one-off work state (PR, CI, branch, round status).Today nothing tells a durable fact from a status that GitHub, git or the work ledger already holds, so every one is written as a fact.
Why it matters
The store gains about 500 rows a day net, mostly work state, and the rows crowd useful facts out of recall and out of the 64 KiB table consolidation dedupes against. Routing by a model-given kind is the biggest lever step 0 found. Shipping shadow mode first, opt-in, lets an operator read how the model actually tags real traffic before any write is refused, and the log must never become its own disk problem on user machines.
Not a goal
eventinto an episode (deferred; see What changed).shadoworenforceon by default. Both are opt-in; the defaultoffkeeps today's prompt and writes.What changed (motivation → approach → change)
Goal → the model tags each item, code routes by the tag → shadow-first with a bounded log.
history_consolidation_pass.py): each semantic item gets"kind": "fact" | "event" | "state", with the two questions "Will this still be true in a month?" and "Can this be looked up somewhere else?". "Name keys by topic, never by PR, issue or round number" is asked only underenforce, so the keys written inshadowstay today's and the log measures today.memory_kind_routing.py): a missing, non-text or unknownkindreads asfact, so an older answer routes exactly as today.project.*creates and updates, first 20 items (the ones a writer reaches). Neverpref.*,user.*,lesson.*, deletes, oruser_explicitwrites (those never come through consolidation).route_consolidation_by_kindruns right after_withhold_unseen_deletesin_write_structured_memory(V1) and in the pass's member branch beforeapply_consolidation(V2), on the same fenced answer, so they cannot drift.memory.kind_routing, defaultoff:off(default): the prompt does not ask for a tag, any tag is ignored, nothing is logged. Prompt and writes are byte-identical to main.shadow(opt-in): the prompt asks for the tag; the writers get the answer object itself, so writes are byte-identical tooff; only the log records whatenforcewould do.enforce(opt-in):state→ not written, recorded as amemory_eventsrow under the new auditedSemanticRejectCode.WORK_STATE(in_AUDITABLE_REJECT_CODESandget_rejection_stats);factandevent→ written as facts, as today (aneventis still counted and sampled as one).eventinto a dated episode. Five review rounds showed every conversion meets a store-side refusal (episodic cap, dedup prefix, size, the member injection screen) that can lose or double the event. A follow-up will read the shadow samples first and decide.memory_metatable:Why
memory_meta: every lineage already has it (the V1 file, crew silos, member databases). A new table would need a migration on the frozen V1 list[1, 2, 3]and is impossible on the member format, which has no upgrade path. A second file per store would need its own locking and backup handling.memory_metaalready holds bounded per-key bookkeeping with GLOB pruning (memory_edit.pyreceipts). With the defaults the 7-day stop alone bounds samples at 350 (~150 KB); the ring and byte caps are backstops.memory_eventsgets no per-item row in shadow mode. V1 writes the log in its own transaction after its semantic writes, inside_publication_hold_checkedlike every other write of the pass; the member store writes it inside the span's transaction under a savepoint, so a replayed span logs nothing twice and a failed log is a warning, never a failed pass.The samples are kept so a small local classifier can be trained on them later. This PR does not build one.
How to turn on shadow on your own machine: set
"memory": {"kind_routing": "shadow"}in~/.kiro/crew/config.json, or Settings → Memory → Consolidation Kind Routing →shadow. From a shell (merges into the existing file):python3 -c 'import json,pathlib; p=pathlib.Path.home()/".kiro/crew/config.json"; c=json.loads(p.read_text()); c.setdefault("memory",{})["kind_routing"]="shadow"; p.write_text(json.dumps(c,indent=2)+"\n")'Use
"enforce"the same way to route for real, and"off"to go back.Docs: spec
memory-skills-hooks.md(Consolidation Integration),config.md, user docsconfiguration.mdandmemory-and-learning.md,config-baseline.jsonregenerated, and a short amendment under RFC part 1 recording that the class comes from the model.RFC: rfc-memory-hygiene.md (#23049) part 1. Nothing changes by default: under
offthe prompt and every write match main. The tag, the log and routing appear only after an operator opts in.Backwards compatibility
Compatible: the default
offkeeps the prompt and writes byte-identical to main; an answer withoutkindroutes asfact;shadowwrites the same rows asoff;apply_consolidationgains one optional keyword; an unknownmemory.kind_routingvalue reads asoff.Removes nothing: no row, key, setting or function is removed, and no mode changes or deletes stored data;
enforce, which skips newstatewrites, is opt-in.Tests
test/test_memory_kind_routing.py(45 tests):fact/event/STATE, missing, empty, unknown, non-string →fact; an old answer withoutkindroutes as today.pref.*,user.*,lesson.*, deletes,value: null, non-dict items are never routed; auser_explicitset_semanticunderenforceis written and logs nothing.off, unknown values read asoff; underoffthe prompt carries nokindfield or kind rules;WORK_STATEis audited. Shadow and enforce tests set the mode explicitly.off; the answer object is returned unchanged.work_stateevent + stats count; fact and event written as facts with no episode; member replay of the same span logs once.enforce; underoffthe prompt carries nokindfield or rules.memory_kind_routing._utcnow.Updated:
test_consolidation_subslice_notice_replay.pyfake accepts the new keyword;test_vector_memory_composition_contract.pysignature pin.Local
local-gate.pyrelated-test run: the only failures are also red on an untouchedorigin/maincopy in this environment (faiss width and STT logging tests), checked by running the same files there.Unrelated failures seen on this PR's runs, none in files it touches:
test/test_slack_team_id_env.py::TestSpawnEnv::*on Windows shards (FileNotFoundError: [WinError 2]), from feat: pass the slack workspace id to agents as KIROCREW_SLACK_TEAM_ID #22380 on main; fixed on main by test: capture the spawn env through the windows launch seam #24609, and this branch is rebased onto it.test/test_history_consolidator.py::TestConsolidationEmbedBreaker::test_healthy_embedder_embeds_every_rowfails locally (faiss) on an untouchedorigin/maincopy too; it passes in CI.Manual verification
N/A — unit coverage sufficient: both write paths run against real SQLite stores in the tests, and the caps are driven with explicit timestamps.
Related Issues
Refs #16354. Implements RFC #23049 part 1 (shadow first).
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.