Skip to content

feat(memory): let a setting steer what consolidation keeps and never stores - #37166

Merged
javenciu merged 1 commit into
mainfrom
feat/memory-extraction-instructions
Nov 14, 2026
Merged

javenciu merged 1 commit into
mainfrom
feat/memory-extraction-instructions

Conversation

@javenciu

@javenciu javenciu commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation (Goal)

Goal: a person can say, in their own words, what history consolidation should keep and what it must never store, for example "never store customer names" or "keep build commands".

Today every control on automatic memory is a switch: memory.persistence_enabled, memory.writes_enabled, memory.lesson_extraction_enabled, memory.kind_routing and the lesson tier and origin policies. They decide whether a kind of write happens. None of them lets the owner shape what the extraction step looks for. The extraction prompt is fixed in src/kiro_crew/history_consolidation_pass.py, so the only way to keep a topic out of memory is to turn a whole stage off, and the only way to keep a kind of fact in is to say "remember" every time.

This adds one string setting, memory.extraction_instructions. Empty (the default) changes nothing. Text is added to the consolidation prompt as one fenced block.

Why it matters

  • Privacy: "what will it remember about me" gets an answer the owner writes, not one chosen by the prompt's author.
  • Fit: a team that wants build commands and conventions kept, or customer data left out, no longer has to choose between all of consolidation and none of it.

Not a goal

  • A filter. The text steers the model; it does not post-process what the model returns, and it is not a guarantee that a topic never reaches memory. The docs say so.
  • Changing stored memory, learn_add, dashboard edits, or what the owner saves explicitly.
  • A dedicated Memory page control. The setting is a config key in the settings schema (config-baseline.json); a page field can follow.
  • Per-store or per-agent instructions.

What changed (motivation → approach → change)

Symptom → cause: the extraction prompt has no place for owner text, so nothing the owner writes can reach it.

  • src/kiro_crew/config/memory_sections.py: new field memory.extraction_instructions (default "") and extraction_instructions_from, which reads anything that is not text as empty, drops control characters other than newline and tab, trims, and cuts to 2,000 characters.
  • src/kiro_crew/config/section_builders.py: the loader passes the value through that reader.
  • src/kiro_crew/memory_extraction_guidance.py (new, 45 lines): builds the prompt block. The block names the text as the owner's, says it cannot change the JSON shape, key rules, limits or any rule above, and fences it. A run of three or more < or > inside the text is shortened so it cannot close the fence.
  • src/kiro_crew/history_consolidation_pass.py: appends the block after the memory sections and before ## Conversation to Process, on both the history pass and the preferences-only pass. An empty setting appends an empty string.
  • config-baseline.json (regenerated with scripts/generate_config_baseline.py), docs/system-specs/modules/config.md, src/kiro_crew/docs/configuration.md and src/kiro_crew/docs/memory-and-learning.md list the key.

Backwards compatibility

With the setting empty or absent, the prompt is byte for byte what it was; a test pins that for unset, "", whitespace and a wrong-typed value, on both passes, and it passes on main too. No stored data changes, and there is no new failure path: a value that is not text, or too long, is read as empty or cut, never refused. The key is new and optional, so older config files load as before.

Tests

  • Before: on main 858863b5b0, where this branch was built (it is now rebased onto 6a61c8465f, which still has no such setting), the new test file cannot import extraction_instructions_from. With that one import stubbed, 15 of the 17 cases fail (the setting and its reader do not exist, and a configured text does not reach the prompt) and the 2 cases that pin the empty-setting prompt pass.
  • After: all 17 pass.
  • Every test file that touches the config sections, the consolidation modules, the config baseline or these docs (90 files): 4432 passed, 6 skipped.
  • flake8, isort and mypy pass on the changed files; the repo's black gate, comment-history gate, flake and wait ratchets, sync-io gate and the lane CI checks pass.
  • Reproduce: python -m pytest test/test_memory_extraction_instructions.py -n0
  • Proof: PROVEN test/test_memory_extraction_instructions.py::test_text_adds_one_fenced_block_before_the_conversation[history], test/test_memory_extraction_instructions.py::test_an_empty_setting_leaves_the_prompt_byte_identical[history] (head c4629a9)

Manual verification

Run through _prompt_for (the consolidation pass with a stubbed model call): with {"memory": {"extraction_instructions": "never store customer names; keep build commands"}} the prompt ends with the guidance block, then ## Conversation to Process; removing exactly that block gives the prompt produced with no setting.

Sibling sweep

Sibling: src/kiro_crew/history_consolidation_pass.py skill-detection pass -- not affected -- it runs as its own pass over a wider window and states its own rules
Sibling: src/kiro_crew/memory_kind_routing.py -- not affected -- it adds text only under enforce; the guidance block is independent and sits after it
Sibling: src/kiro_crew/taskrunner.py lesson extraction -- not affected -- it does not use the consolidation prompt

Pattern harvest

Rule candidate: review-prompt
Pattern: a new owner-supplied string that reaches a model prompt is normalized at load (type, control characters, length), fenced, and placed after the fixed rules; an empty value must append nothing.

Related Issues

None filed; the gap is the one in the Problem section, found by reading the memory switches and the extraction prompt.

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

Contribution License Agreement

@javenciu
javenciu requested review from a team and KiroCrewCaptain as code owners November 14, 2026 09:16
@javenciu
javenciu requested a review from CrysisDeu November 14, 2026 09:17
@javenciu
javenciu enabled auto-merge (squash) November 14, 2026 09:17
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 14, 2026
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision c4629a98cf98189b8cd4a79e3685045a351c862b touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of c4629a98cf98189b8cd4a79e3685045a351c862b — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the new key is optional and defaults to empty, so the prompt stays byte for byte the same, and one revert removes it.

Notes

  • The config.md row says the block comes from history_consolidation_span._extraction_guidance_block, but the code is memory_extraction_guidance.configured_guidance_block. Point the spec at the real owner so the next reader finds it.

[DESIGN-REVIEWED] c4629a9

Description read

[DESCRIPTION-READ] e640f8434ec8a51ba6103a1fe1007e90206ffd0d36915f64614bceb174637f46

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of c4629a98cf98189b8cd4a79e3685045a351c862b — 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 does not.

First-Principles-Verdict: PASS

Nothing blocks: the new setting is off by default, nothing else in the repo steers consolidation, and the prompt has a single place where the block is added.

Notes

  • Item 1 — oversized: configured_guidance_block runs extraction_instructions_from(getattr(memory, "extraction_instructions", "")) on a value the loader already ran through extraction_instructions_from (section_builders.py). That makes 2 calls to one normalizer, and the getattr fallback covers a field that always exists. Subtraction: drop the second extraction_instructions_from call and the getattr default, and pass memory.extraction_instructions straight to guidance_block.

What this change ships

Inventory (5 items) — 4 justified

Intent: let the owner say in their own words what memory consolidation keeps and never stores. ADDITION.

  1. New optional config key memory.extraction_instructions (empty by default), cleaned on load (type, control characters, 2,000-character cap) — oversized (normalizes the same value twice)
  2. When the setting has text, the history consolidation prompt carries a fenced owner-guidance block just before the conversation — justified
  3. The same block on the preferences-only consolidation pass — justified
  4. Marker runs (<<<, >>>) in the owner text are shortened so the text cannot close the fence — justified
  5. The settings schema baseline and three docs list the key — justified

[FIRST-PRINCIPLES-REVIEWED] c4629a9

Description read

[DESCRIPTION-READ] 98af2825d56b9c8a23650196f91ee1b4efd4fcab24866480d38e0340ab15ab11

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of c4629a98cf98189b8cd4a79e3685045a351c862b and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] c4629a9

False positive or not applicable? A repository writer can comment:
/ai-review override gpt c4629a98cf98189b8cd4a79e3685045a351c862b false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

Notes:

  • docs/system-specs/modules/config.md:3612 points to history_consolidation_span._extraction_guidance_block, and no symbol by that name exists. The block is built by memory_extraction_guidance.guidance_block.
  • extraction_instructions_from keeps only characters where str.isprintable() is true. That drops non-ASCII spaces such as U+00A0 and U+3000, and U+200D (the zero-width joiner), which are not control characters. A no-break space in pasted text is removed, not turned into a space, so the words on each side join up.

[OPUS-REVIEWED] c4629a9

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable c4629a98cf98189b8cd4a79e3685045a351c862b false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Nov 14, 2026
…stores

Add memory.extraction_instructions, free text the history consolidation prompt carries as one fenced block after the fixed rules. Empty (the default) leaves the prompt byte for byte as it was.
@javenciu
javenciu force-pushed the feat/memory-extraction-instructions branch from 97b798b to c4629a9 Compare November 14, 2026 12:16
@javenciu

Copy link
Copy Markdown
Contributor Author

Rebased: onto main 6a61c8465f, which has #37171. The two Backend Tests shard-2 failures on 97b798b097 were test/tracing/test_tracing_otlp.py expecting four spans after #37005 added kirocrew.step; main's own run failed the same two tests until #37171 (issue #37169). This PR's diff is unchanged, and its 465 related tests pass on the new head c4629a98cf98.

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

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. On this head the review read the full diff and the single prompt assembly site in _consolidate. It found that an unset, empty, blank or wrong-typed setting leaves the prompt byte-identical on both the history and preferences-only passes. The new test file passed (17 tests). Mutation probes that drop or move the append, swap the while fence escape for an if, or skip load-time normalization each turn a test red. No open PR duplicates this work.
Done well: test_text_cannot_close_the_fence_early uses a hostile fake end marker plus a pasted ## Conversation to Process heading, so owner text provably stays inside its fence.
Optional:

  • docs/system-specs/modules/config.md:3612 names history_consolidation_span._extraction_guidance_block, which does not exist. The real owner is memory_extraction_guidance.configured_guidance_block.
  • memory_sections.py:656: isprintable() also deletes U+00A0, U+3000 and ZWJ/ZWNJ, so pasted text like "never store" becomes "neverstore". Mapping c.isspace() to a space first would keep the word breaks, and a test case could pin it.
  • memory_extraction_guidance.py:44 normalizes a value the loader already normalized, behind a getattr default for a field that always exists. guidance_block(KiroCrewConfig.load().memory.extraction_instructions) is enough.

@javenciu
javenciu merged commit e953941 into main Nov 14, 2026
97 of 98 checks passed
@javenciu
javenciu deleted the feat/memory-extraction-instructions branch November 14, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants