Skip to content

fix: name the lessons a write superseded instead of a bare insert - #8585

Merged
bolichen97 merged 1 commit into
mainfrom
fix/lesson-containment-supersede-7206
Sep 6, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/lesson-containment-supersede-7206

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

What is the problem?

write_lesson dedupes on substring containment. In the direction where the SUBMITTED
rule contains a STORED one, the stored row is tombstoned:

if existing_lower in rule_lower:
    self.delete_semantic(existing["key"], source)
    continue

Reproduced on a throwaway store at origin/main:

1) write "never force push to a shared branch"                    -> INSERTED, 1 live row
2) write "when a release is in progress, never force push to a
   shared branch, and tell the release manager first"             -> INSERTED, reason=None, truthy
3) live rows: 1   (only the second rule)
4) is the general rule still stored? False   (is_deleted=1)
5) log records emitted by the deleting write: NONE

Both halves of the report hold, and the second is worse than reported. The write is
silent at every level:

  • LessonWriteResult has outcome / reason / stored / wrote -- every field
    describes the SUBMITTED lesson. Nothing can carry a deleted row.
  • This branch was the only one of the four in the dedup scan that deleted without
    logging. Its three siblings each log (Lesson dedup:, Lesson conflict:,
    Lesson semantic dedup:).
  • The delete is a tombstone, so the row is gone from get_lessons, learn_list and the
    injected lessons block.

The deletion itself is deliberate, and this PR does not change it. Three independent
records establish intent: the docstring (longer wins, newer replaces older), the spec
dedup table, and -- decisively -- onboarding_import.py:4269-4274, which routes to
set_semantic_if_absent precisely because

write_lesson ... deletes an existing lesson on exact-substring OR >50% topic overlap
... which for an import means a foreign directive can delete a correction the USER
taught the agent.

A contract described that exactly is not an accident, and the remedy chosen there was to
avoid the function rather than change it.

Why this issue matters to the user

The lesson store is the surface where a user teaches the agent. Attaching a condition to
a rule makes the text longer and the guidance narrower, so "longer wins" retires the
rule that applies in more cases and keeps the one that applies in fewer. The user never
retracted the general rule, was told the save succeeded, and cannot find the loss: the
tombstone is filtered by every read path. On the reporter's own store 291 rows carry
is_deleted = 1, and there is currently no way to attribute any of them.

How our fix solves it

Symptom -> cause -> fix:

  • Symptom: learn_add says "Saved lesson" for a call that destroyed a lesson.
  • Cause: not the deletion (deliberate) but that no channel could report it. The
    result type had no field for it, and this one branch did not even log.
  • Fix: LessonWriteResult gains superseded: tuple[str, ...] = (), populated at
    all three delete sites (substring, topic-overlap, semantic). One result object
    cannot report some of its deletions and stay trustworthy -- a field that is truthful
    for one branch and silently empty for another is worse than no field. Defaulted, so
    the ~60 existing construction sites are unchanged.
  • Carried on every return path after the scan, including REFUSED -- that is the path
    where it matters most, since rows were deleted and nothing was stored in their place.
    ENRICHED is decided in pass 1 and skips the scan, so it always reports none.
  • The substring branch gets the log line its three siblings already have.
  • Rendered by /api/lessons (a JSON array, always present), the learn add CLI, and the
    learn_add tool -- in full, not counted and not truncated, because that text is the
    last readable copy of a tombstoned row.

Why not loosen the containment test. It would have been wrong twice. It does not
work: verbatim containment at word boundaries makes the stored rule's keyword set a
SUBSET of the submitted rule's, so topic-overlap scores 100% and deletes the same row
three lines below. Measured by excising the branch from source -- the general rule is
still gone, with Lesson conflict: ... (100% overlap). And it would cost the check its
ability to say no, accumulating a near-identical row for every re-phrasing. Nothing
here is loosened. The same rows are deleted as before.

Two of the reporter's three questions are untouched by design -- whether text length may
stand in for scope, and whether the delete direction should exist at all. Both are
behaviour changes to stores users already have, and #6175 extends the same supersede
policy to the semantic branch, so they belong together and with the maintainers. Only
the reporting question is answered here. Refs #7206.

The report names the whole stored lesson, clause included. Dedup compares rules
through _lesson_embed_text, which returns a mapping row's rule field alone so the
comparison basis matches the embedding space. Reporting on that same rendering dropped
the stored NOT-clause, which is the sharpest half of the guidance -- so the clause became
unrecoverable at the exact moment the row was tombstoned, inside the mechanism that
exists to stop that. The three report sites now use _lesson_display_text, the
recomposition the injected prompt and learn list already use, so a restored rule reads
exactly as it was stored. Every COMPARISON stays on the embed rendering, so no dedup
decision moves: existing_lower, the keyword set, the len() tiebreak and both log
lines are untouched.

Sanitizing the reported text. Reporting a superseded rule prints stored USER text on
a path that never printed it before, so both output surfaces are routed through the
treatment each already applies to stored text -- neither is a new mechanism:

  • The CLI strips terminal control sequences with _TERMINAL_CTRL_RE, THEN redacts
    credentials and exfiltration URLs. The order is the whole correctness of this, and the
    intuitive order is the unsafe one. An earlier revision redacted first, on the stated
    reasoning that an escape inside a credential would break the regex if the controls went
    first -- that was exactly backwards. Measured: with AKIA<CSI>IOSFODNN7EXAMPLE stored,
    redact-then-strip prints AKIAIOSFODNN7EXAMPLE verbatim, because the escape stops the
    credential regex matching and the control-strip then REASSEMBLES the token;
    strip-then-redact masks it. Stripping can only ever JOIN characters, never split a
    token, so running it first can only help the regex. A test plants the pre-split
    credential so a future reordering reddens -- the two single-treatment tests each show
    one treatment happens and neither shows they compose in the safe order.

    An earlier revision of this change was control-stripping only, on the grounds that
    learn list prints every stored lesson to the same terminal with the same treatment.
    That was the wrong comparison and is reversed here: learn list is an EXPLICIT request
    to see the store, while this block surfaces a lesson the user did not ask for and is
    about to lose. The right comparison is the route, which delivers the SAME field and does
    redact -- so controls-only made one feature's two delivery paths disagree about whether
    a superseded rule may carry a secret. A lesson written by history consolidation also
    carries model output the user never typed, so "their own store" is not "their own
    knowledge".

The recovery it advises is one the policy actually permits. Earlier wording said only
"re-add it with wording that does not overlap this one", which is incomplete in a way that
sends the user into a refusal: a VERBATIM re-add of the superseded rule is declined by the
substring branch, since the narrower rule now contains it. Measured, all three cases:
verbatim re-add -> deduped/substring_covered, nothing restored; wording sharing few
significant words -> inserted, both rules coexist, nothing superseded (so it does NOT
ping-pong); removing the narrower rule first -> the general rule inserts and is restored
verbatim. The text now names the two that work and says plainly that a verbatim re-add is
declined, and both are pinned by tests.

  • POST /api/lessons sends the array through _redact_memory_field, the shared chain
    this handler already applies to the lesson's own rule and category. Redacting at the
    route covers both readers, since the dashboard and the learn_add tool each see only
    what the route sends. This path is worse than a read: the row is being deleted, so this
    response is the only place that text is echoed at all.

  • Every log line in this dedup scan now carries IDENTITIES, never lesson content.
    A lesson holds whatever the user once told the agent -- credentials, paths, names -- so
    a log line reproducing its text converts a silent-deletion bug into a disclosure bug,
    on a sink that persists to disk and may reach a notification channel. All three lines
    log the store's own row ids (lesson.<digest>), the category, and a count or the
    overlap ratio: enough for an operator to see THAT a general rule was replaced and
    WHICH one, joined to the tombstoned row, the delete_semantic audit record, and the
    matching superseded entry. The text lives only in the result -- the read path the
    lessons themselves use -- where every surface redacts it.

    The id is logged rather than a freshly computed digest deliberately: a new hash would
    correlate with nothing. Nothing here hashes anything, so no weak-hashing exposure is
    added -- _lesson_key already derived these ids, and CodeQL flags that derivation at
    its own site (vector_memory.py:445 on main, alert feat(issue-radar): open same-repo references in an in-app sheet #643), not at a line that logs the
    result.

    Two of the three lines are main's, and they are touched for one reason: they are the
    two alerts CodeQL attributes to this PR. git blame on the merge commit CI analysed
    puts both on 64e47961a (the fork import), and the MD5 alert on d1aa30999 -- this
    PR's commit appears in none of them; they are reported because the surrounding hunks
    changed. An earlier revision instead wrapped them in redact_and_truncate, which was
    worse twice over: it tripped
    test_security_posture.py::TestGateSideLogRedactorSpelling (a gate-side log line must
    read redact_log_via_context, not the companion-blind baseline pass) AND added CodeQL
    alerts, because wrapping a tainted value in a call CodeQL does not model as a sanitizer
    makes the flow visible where a bare slice was not tracked. Removing the text answers
    both gates without arguing with either, and the census stays at 0 found / 0 expected.

  • The CLI strips terminal control sequences with _TERMINAL_CTRL_RE, THEN redacts
    credentials and exfiltration URLs. The order is the whole correctness of this, and the
    intuitive order is the unsafe one. An earlier revision redacted first, on the stated
    reasoning that an escape inside a credential would break the regex if the controls went
    first -- that was exactly backwards. Measured: with AKIA<CSI>IOSFODNN7EXAMPLE stored,
    redact-then-strip prints AKIAIOSFODNN7EXAMPLE verbatim, because the escape stops the
    credential regex matching and the control-strip then REASSEMBLES the token;
    strip-then-redact masks it. Stripping can only ever JOIN characters, never split a
    token, so running it first can only help the regex. A test plants the pre-split
    credential so a future reordering reddens -- the two single-treatment tests each show
    one treatment happens and neither shows they compose in the safe order.

    An earlier revision of this change was control-stripping only, on the grounds that
    learn list prints every stored lesson to the same terminal with the same treatment.
    That was the wrong comparison and is reversed here: learn list is an EXPLICIT request
    to see the store, while this block surfaces a lesson the user did not ask for and is
    about to lose. The right comparison is the route, which delivers the SAME field and does
    redact -- so controls-only made one feature's two delivery paths disagree about whether
    a superseded rule may carry a secret. A lesson written by history consolidation also
    carries model output the user never typed, so "their own store" is not "their own
    knowledge".

The recovery it advises is one the policy actually permits. Earlier wording said only
"re-add it with wording that does not overlap this one", which is incomplete in a way that
sends the user into a refusal: a VERBATIM re-add of the superseded rule is declined by the
substring branch, since the narrower rule now contains it. Measured, all three cases:
verbatim re-add -> deduped/substring_covered, nothing restored; wording sharing few
significant words -> inserted, both rules coexist, nothing superseded (so it does NOT
ping-pong); removing the narrower rule first -> the general rule inserts and is restored
verbatim. The text now names the two that work and says plainly that a verbatim re-add is
declined, and both are pinned by tests.

  • POST /api/lessons sends the array through _redact_memory_field, the shared chain
    this handler already applies to the lesson's own rule and category. Redacting at the
    route covers both readers, since the dashboard and the learn_add tool each see only
    what the route sends. This path is worse than a read: the row is being deleted, so this
    response is the only place that text is echoed at all.

  • The log line this change adds identifies both rows by their md5 KEY, never by text.
    A log is a persistent sink, so a credential in a lesson would sit in gateway.log
    indefinitely; filtering it on the way out only narrows that, while logging keys removes
    it. An operator can still tie the line to the superseded entry in the result and to
    the delete_semantic audit row, and the RESULT is the recovery channel -- it carries
    the full text, redacted at each surface.

    An earlier revision instead wrapped three log sites in redact_and_truncate, including
    the two pre-existing sibling lines. That is withdrawn and those two are byte-identical
    to main again. It failed two gates at once, and both were right: this repo's own
    ratchet (test_security_posture.py::TestGateSideLogRedactorSpelling) requires a
    gate-side log line to read redact_log_via_context rather than the companion-blind
    baseline pass, and CodeQL raised three new py/clear-text-logging alerts because
    wrapping a tainted value in a call it does not model as a sanitizer made the flow
    visible where a bare slice was not tracked. Removing the text answers both without
    arguing with either, and it leaves the pre-existing lines' behaviour untouched -- they
    still log rule[:60] raw, as on main, which the test asserts explicitly rather than
    leaving implicit.

  • The CLI redacts credentials and exfiltration URLs, then strips terminal control
    sequences with _TERMINAL_CTRL_RE. Both, in that order: an escape sequence embedded
    inside a credential would break the credential regex if the controls went first, so the
    secret would escape redaction. Same two redactors, same order, this file already applies
    to a verdict reason at cli_commands.py:1893.

    An earlier revision of this change was control-stripping only, on the grounds that
    learn list prints every stored lesson to the same terminal with the same treatment.
    That was the wrong comparison and is reversed here: learn list is an EXPLICIT request
    to see the store, while this block surfaces a lesson the user did not ask for and is
    about to lose. The right comparison is the route, which delivers the SAME field and does
    redact -- so controls-only made one feature's two delivery paths disagree about whether
    a superseded rule may carry a secret. A lesson written by history consolidation also
    carries model output the user never typed, so "their own store" is not "their own
    knowledge".

  • POST /api/lessons sends the array through _redact_memory_field, the shared chain
    this handler already applies to the lesson's own rule and category. Redacting at the
    route covers both readers, since the dashboard and the learn_add tool each see only
    what the route sends. This path is worse than a read: the row is being deleted, so this
    response is the only place that text is echoed at all.

  • Every lesson text this scan logs goes through redact_and_truncate (already imported
    and used in this file), which redacts BEFORE slicing so a credential straddling 60
    chars cannot leak as an unredacted fragment. A log is a persistent sink, so a raw
    [:60] would keep a credential-bearing lesson in gateway.log indefinitely.

    Applied to all three lesson-text log sites in the scan, not only the one this change
    added, and that widening is deliberate: the supersede path runs through the substring
    AND topic-overlap branches, so a guarantee holding on one and not the other is worth
    nothing. It is the same argument as populating superseded at every delete site. The
    two pre-existing sites logged raw text on main; the helper is an existing one, so no
    mechanism is introduced.

Every path that carries a superseded rule now redacts credentials: the CLI, the route,
the learn_add tool (via the route), and all three log lines. The audit is closed on the
text this change introduces.

The one thing deliberately left as it is on main is the Saved: line's echo of the rule
the user just typed. It is their own input in the same breath -- masking a string they
literally just put on their own command line would tell them nothing and hide their own
command from them -- where a STORED rule may have been written by consolidation, an
import, or a subagent, and is printed when they are not looking at it.

Base. Rebased onto origin/main at 6b7847856f6c2cb7926a768c3039ae1d6827a3ac, stated here so a red never costs an
argument about whose it is. Only a push moves the base -- a re-run recomputes against the
base recorded in the original event -- so any inherited red older than this sha is not
this PR's. main's own push-event CI was green on c791f0f1d (12:27:52Z), which this base
contains; the tip's own push CI had not reported when the rebase was taken.

The one CodeQL red is not this PR's, and here is why without re-deriving it.

What tests we did

test/test_lesson_write_outcome.py, 10 new tests in two classes.

Positive control. Run against pristine origin/main with only the test file copied
in: 6 failed, 4 passed. Four fail with
AttributeError: 'LessonWriteResult' object has no attribute 'superseded', one with
assert 'REMOVED 1 stored lesson' in 'Saved lesson: a rule' -- main's own words for a
write that removed a lesson -- and one on the route omitting the key. The 4 that pass are
deliberate characterization pins that must hold both ways:

  • test_the_general_rule_is_still_deleted -- asserts the supersede still happens, so a
    later "fix" cannot loosen containment while the reporting tests stay green.
  • test_the_refuse_direction_is_unchanged_and_deletes_nothing -- the other direction of
    the same test keeps declining and mutating nothing.
  • test_removing_only_the_substring_branch_would_not_have_saved_the_lesson -- computes
    the overlap ratio from the store's own _lesson_keywords so it cannot drift from the
    arithmetic the branch performs.
  • test_the_tool_ignores_a_superseded_field_that_is_not_a_list_of_text -- the field
    crosses HTTP; a malformed value must read as "none reported".

Security fixes carry their own positive control. Stashing only the two src changes
and re-running the same tests: AssertionError: raw credential returned in a response and
AssertionError: the OSC payload itself must not survive. Both fail without their fix.

Suites run (only files touching this path; never the full suite):
test_lesson_write_outcome test_lesson_contradiction test_lesson_project_scope
test_api_input_validation test_json_object_body_guard (244 passed) *
test_vector_memory test_vector_memory_coverage test_onboarding_import
test_lesson_ranking test_memory_smoke test_embedding_model_apply (762 passed,
11 skipped) * test_cli_commands_coverage -k "learn or lesson" (11 passed) *
test_ephemeral_sessions test_mcp_core_more_coverage
test_instance_credential_pairing test_history test_history_coverage (799 passed).
1816 passed, 0 failed.

Gates: black gate (diff-scoped) * flake8 * isort * mypy (4 files) * docs-lint.sh
(261 files) -- all green.

Two pre-existing exact-body assertions on POST /api/lessons were updated for the added
key; they are the only deletions in the test diff.

Any other suggestions on the work

  • The dashboard Memory tab is a deliberate follow-up, not an oversight. First
    Principles is right that MemoryTab.tsx receives superseded and renders none of it,
    so the reported silence survives on that surface. It is deferred on two measured
    grounds. First, the string is user-facing, and this repo translates through a formal
    pipeline (website/src/i18n/TRANSLATION-PROMPT.md: "the prompt is the pipeline", with
    per-locale style guides, a glossary, and CI-validated shards across 14 catalogs) --
    hand-writing nine translations would bypass a documented process. Second, website/
    has no installed node_modules on this machine, so tsc, vitest and the three i18n
    gates cannot run here, and OverviewMemoryTabCov80.test.tsx mocks createLesson and
    would need updating. Shipping a frontend change I cannot verify into an otherwise
    verified PR is the wrong trade. The route already sends the field, so the follow-up is
    a self-contained UI change: response type, render, test.
  • Attribution is still missing. delete_semantic records no reason, so a tombstone
    from this branch is indistinguishable from a learn_remove. That is why the
    reporter's 291-tombstone figure cannot be attributed, and it stays true after this PR
    -- the report reaches the caller in the moment, not the historical record. A reason at
    tombstone time is worth having whichever way the policy questions are decided.
  • The two stores disagree, and only one is documented. LessonStore._insert_or_enrich
    matches on exact rule text plus scope and has no rule that supersedes, so the JSONL
    store keeps both the general rule and the narrower one. The same two learn_add calls
    leave 2 lessons in JSONL and 1 in the vector store. Noted in the spec here; whether
    they should agree is a policy question.
  • fix(memory): let a newer lesson supersede its near-duplicate #6175 does not conflict. It edits the semantic-similarity region below the
    substring branch. But it aligns that branch with the policy under question, so if the
    delete direction is ever withdrawn, both need deciding together.
  • Recovery is SQL-only. A learn list --deleted or an undo would turn this warning into
    something the user can act on directly.

Pattern harvest

Rule candidate: when a report says an operation is "silent", check every level
independently -- result value, log, and store -- and check whether the sibling branches in
the same loop announce themselves. Here three of four dedup branches logged and one did
not, and that asymmetry inside a single function separated the deliberate policy
(deleting) from the accident (not saying so), which decided what the fix had to be.

Rule candidate: before loosening a check to save data it destroys, excise the check and
measure. The collapse here was over-determined -- the next rule down deleted the same row
at 100% overlap -- so the tempting fix would have changed nothing a user could see while
costing the check its ability to say no.

Refs #7206

@chenmingwei23
chenmingwei23 requested review from a team and iamwhatever September 4, 2026 22:57
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 4, 2026
@github-actions

github-actions Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

Sound additive reporting fix, but the report is ephemeral and interactive-only, so the stated harm survives on unattended and dashboard paths.

Watch

  • history_consolidation.py:1240 calls write_lesson and reads only the boolean; a consolidation-driven supersede still tombstones with no user-visible or durable trace ("the result is the only place that can carry this"), and since delete_semantic records no reason, the loss remains unattributable after the reply scrolls away. The tombstone-reason follow-up the description names is the real closure for "the user cannot find the loss" — worth tracking as a committed follow-up, not a suggestion.
  • The dashboard Memory tab receives superseded and renders none of it, so the primary interactive surface keeps the exact silence this PR exists to fix; the i18n-pipeline deferral is reasonable only if that follow-up actually lands.

Suggestions

  • A supersede reason written at delete_semantic time would make both Watch items solvable with one mechanism and enable the proposed learn list --deleted.

[DESIGN-REVIEWED] d4f81c4

@github-actions

github-actions Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] d4f81c4

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

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

@github-actions

github-actions Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of d4f81c42b1a272808fd81f62366549baf2af8c3d — 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.

I have everything I need. The reuse claims check out (_redact_memory_field at _shared.py:47, _TERMINAL_CTRL_RE and the redactors already imported in cli_commands.py, _lesson_display_text at vector_memory.py:553), and the one gap I found is that the dashboard client (website/src/api/client.ts:2642) types the create-lesson response as ok/outcome/reason only — nothing in website/ reads the new field.

First-Principles-Verdict: CONCERNS

The fix is real and minimal, but the dashboard — one of the three human surfaces with this exact silence — still says nothing.

What this change ships

Intent: tell the user which stored lessons a lesson-save silently deleted. This is a FIX.

  1. A deleting write now names the rules it tombstoned in its result — justified
  2. learn add CLI prints a REMOVED block with each rule and working recovery advice — justified
  3. learn_add tool answer warns and quotes the removed rules — justified
  4. /api/lessons response always carries a superseded array — justified, but zero renderers in website/
  5. Reported text keeps the stored NOT-clause via the existing display rendering — justified
  6. Reported text is sanitized through each surface's existing treatment — justified, reuses _redact_memory_field / _TERMINAL_CTRL_RE
  7. The one silent delete branch now logs like its three siblings — justified
  8. Existing Lesson dedup / Lesson conflict log lines drop rule text for row ids — rides along, undeclared
  9. Spec section rewritten for the asymmetric dedup and the new field — mandated same-commit

Watch

  • The description's named harm — the user "was told the save succeeded, and cannot find the loss" — survives verbatim on the dashboard Memory tab. Grepped superseded under website/src: zero consumers of the response field (client.ts:2642 types the response as ok/outcome/reason only), so the field reaches the browser and dies there. One unfixed sibling surface of the exact silence this FIX targets; if deferring it is deliberate, nothing records that.
  • Item 8 rewrites two pre-existing sibling log lines (text → row ids) inside a FIX, unmentioned in the description's "its three siblings each log" framing. The disclosure rationale is a named boundary so it stands, but it silently breaks any operator grep keyed on rule text.

[FIRST-PRINCIPLES-REVIEWED] d4f81c4

@github-actions

github-actions Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] d4f81c4

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

@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 4, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/lesson-containment-supersede-7206 branch from 0cc86fb to d03ce0d Compare September 4, 2026 23:24
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 4, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/lesson-containment-supersede-7206 branch from d03ce0d to 2eca019 Compare September 4, 2026 23:36
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 4, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/lesson-containment-supersede-7206 branch from 2eca019 to 5c3c0d7 Compare September 5, 2026 00:23
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 5, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/lesson-containment-supersede-7206 branch from 5c3c0d7 to bf2c1a1 Compare September 5, 2026 00:36
@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 5, 2026
Comment thread src/kiro_crew/vector_memory.py Fixed
Comment thread src/kiro_crew/vector_memory.py Fixed
Comment thread src/kiro_crew/vector_memory.py Fixed
@chenmingwei23
chenmingwei23 force-pushed the fix/lesson-containment-supersede-7206 branch from bf2c1a1 to e0e1aeb Compare September 5, 2026 01:08
@github-actions github-actions Bot removed the readiness: checking Automated validation is still running label Sep 5, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

GPT's cron.py control-split finding is FILED, not fixed here: #8750.

Zero-delta against base (the same route already sends the lesson's own rule and
category through _redact_memory_field, so unmodified origin/main passes a
control-split credential today), and the fix has no clean home yet -- the only
control-strip regex is private to cli_commands.py, so closing it means either promoting
it into security.py or changing _redact_memory_field for every caller. Neither belongs
in a PR about lesson reporting. The issue states the mechanism, the measurement, and both
candidate homes with the tradeoff, and it is explicit that the leak is demonstrated at the
redactor and NOT at the model.

GPT 5.6 now reports no blocking findings on af2ebddef9b72aba6cee43ba2e2012aa93dd51d4.

CodeQL on this head is down to ONE alert, py/weak-sensitive-data-hashing at
src/kiro_crew/vector_memory.py:462. That is main's own open alert #643 at line 445,
shifted by this PR's line delta: on the merge commit CI analysed, git blame puts the line
on d1aa30999, and this PR's commit appears nowhere in it. The two py/clear-text-logging
alerts that were live on the previous head are gone -- the dedup scan's log lines now carry
row ids, the category and a count instead of lesson text.

…insert

write_lesson deduplicates on substring containment, and the direction where the
SUBMITTED rule contains a STORED one tombstones the stored row. Teaching "when a
release is in progress, never force push to a shared branch" therefore retired a
stored "never force push to a shared branch", and the call returned
LessonWriteOutcome.INSERTED with reason=None -- so the caller was told its lesson
was saved and the store no longer held any rule against force pushing outside a
release. The row is a tombstone, so it is also gone from get_lessons, learn_list
and the injected lessons block.

The deletion is deliberate and stays. Three separate records establish it: the
docstring's "longer wins" and "newer replaces older", the spec's dedup table, and
onboarding_import, which routes to set_semantic_if_absent precisely BECAUSE
"it deletes an existing lesson on exact-substring OR >50% topic overlap" -- a
contract described that exactly is not an accident, and the remedy chosen there
was to avoid the function rather than change it.

The silence was not deliberate, and it was total. This branch was the only one of
the four in the dedup scan that deleted a row without logging; its three siblings
each log. Nothing in LessonWriteResult could carry a deleted row either, so the
event left no trace at any level.

So: every rule the scan deletes is now recorded in LessonWriteResult.superseded
and named -- in full, not counted -- by /api/lessons, the learn add CLI and the
learn_add tool. Collected at all three delete sites, not just the substring one:
one result object cannot report some of its deletions and stay trustworthy.

Loosening the containment test would have been the wrong fix twice over. It would
not work -- verbatim containment at word boundaries makes the stored rule's
keyword set a SUBSET of the submitted rule's, so topic overlap scores 100% and
deletes the same row three lines below, measured -- and it would cost the check
its ability to say no, accumulating a near-identical row per re-phrasing. Nothing
here is loosened; the same rows are deleted as before.

Refs #7206
@chenmingwei23
chenmingwei23 force-pushed the fix/lesson-containment-supersede-7206 branch from af2ebdd to d4f81c4 Compare September 5, 2026 13:18
@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: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Sep 5, 2026

@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 after strict tech-lead review.

Data integrity — the core question. superseded is populated at ALL THREE delete sites (substring existing_lower in rule_lower, topic-overlap ratio >= 0.5, semantic longer-wins) and carried on EVERY return path after the dedup scan: DEDUPED/substring_covered, DEDUPED/semantic_similarity, REFUSED, and INSERTED/ENRICHED. That completeness is what makes the field trustworthy — a result that reported some of its deletions and not others would be worse than none. The REFUSED path is the one that matters most and it is covered: rows were tombstoned and nothing was stored in their place.

No deletion behaviour moves. Every comparison stays on the embed rendering (existing_text, existing_lower, the keyword set, the len() tiebreak); only the REPORT uses _lesson_display_text, with a fallback to the comparison text so the report can never be emptier than the row it names. Keeping the stored NOT-clause in the report is right — that is the sharpest half of the guidance and the row is a tombstone, so there is no second place to read it from. Two characterization tests pin the supersede so a later "fix" cannot loosen containment while the reporting tests stay green.

Result type. Frozen dataclass, tuple default (), appended last — the ~60 existing two-arg construction sites are untouched and truthiness is unchanged.

Security. CLI order is correct and non-obvious: strip terminal controls FIRST, then redact. Stripping can only JOIN characters, never split a token, so it can only help the credential regex; the reverse order leaks AKIA<CSI>IOSFODNN7EXAMPLE verbatim by reassembling it after the regex has already failed to match. Route redacts through _redact_memory_field, which I verified recurses into lists (_shared.py). All three dedup log lines now carry row ids + category + count instead of lesson text, which removed CodeQL #811/#812/#813 (no longer open) rather than papering over them. The residual control-split bypass in _redact_memory_field is zero-delta against main — the same route already sends the lesson's own rule and category through the same helper — and is correctly filed as #8750 instead of being fixed in a lesson-reporting PR.

The one CodeQL red is not this PR's. Verified independently: code-scanning/alerts?ref=refs/pull/8585/merge returns ZERO alerts, and the only open alert on this file is #643 (py/weak-sensitive-data-hashing, open since 2026-08-20 at line 445). This PR adds +17 lines above 445 (the docstring and field hunks at 165/191), which is exactly the shift to 462, and the diff adds no hashing call. CodeQL is not a required context — the commit status is success on PR Readiness.

Signals. All five AI lanes green on this head: GPT 5.6 and Opus 4.8 no findings; Design and First Principles CONCERNS (advisory, not BLOCK) and both name the SAME deferred item — the dashboard Memory tab renderer plus a reason at delete_semantic time. The route already sends the field, so that follow-up is self-contained UI work, and deferring an unverifiable website/ change (no node_modules, nine i18n locales through a formal pipeline) out of an otherwise fully verified backend PR is the right trade. The six cancelled check-runs are superseded duplicate runs; each has a success on this head.

Scope and module rules. Backend + spec + tests only, no website/ files, so the ux-review-required ruleset does not apply. docs/system-specs/modules/memory-skills-hooks.md documents the asymmetric substring rule, the superseded field, and the conflict-resolution table row — the module's spec-with-code requirement is met. 1 commit, Pattern harvest present.

The honest scoping is the strongest thing here: the deletion policy and the length-as-scope question are left to maintainers with #6175, and only the reporting gap is closed.

@bolichen97
bolichen97 merged commit 0341f11 into main Sep 6, 2026
74 of 81 checks passed
@bolichen97
bolichen97 deleted the fix/lesson-containment-supersede-7206 branch September 6, 2026 01:56
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 6, 2026
NicholasRBowers pushed a commit to isotope14/KiroCrew that referenced this pull request Sep 6, 2026
Semantic lesson dedup tie-broke on `len(rule) > len(existing_text)` and
DROPPED the submission when it lost, so character count decided which of
two near-identical rules was current.

Corrections land on the losing side of that comparison as a rule: a
retraction collapses a detailed stale claim ("tool X is available, 48
verbs, attaches on port 9224") into a short accurate one ("tool X is not
installed"). The shorter text lost, and the stale lesson stayed in
effect -- the one outcome that actively misleads the agent rather than
merely losing detail. Observed live: a measured correction was refused
while the claim it disproved kept applying, and the only recovery was a
blind learn_remove on a guessed substring.

The substring and topic-overlap branches directly above already
supersede the stored row unconditionally, so newest-wins makes the three
dedup paths agree instead of one of them arbitrating on length.

The learn_add reply had a matching problem: it printed the SUBMITTED rule
straight after "an existing stored lesson already covers it", which reads
as a quote of the stored lesson. A caller believed it had been shown the
winner, could not tell a correct dedup from a dropped correction, and was
never told the replace path. It now labels the text as what was DROPPED
and names the learn_list/learn_remove sequence.

Substring dedup still refuses -- a rule literally contained in a stored
one is genuinely covered.

Drive-to-green additions on top of isotope14's original change (rebase
onto current main plus review fixes):

- Guard the supersede by stored authority: a stored row that outranks the
  write -- `user_explicit` over a lower-authority source, or strictly
  higher stored confidence (the onboarding import writes user lessons at
  confidence 1.0 under source "import") -- is never displaced by it. That
  write returns the old deduped outcome instead, so newest-wins cannot
  invert the authority order `_write_semantic` already enforces for
  same-key writes. Regression tests cover both directions plus the
  import-sourced row, and were proven red without the guard.
- Rebase composition: keep main's `superseded` reporting (kirodotdev#8585) on the
  supersede path, and log row ids rather than rule text, matching the
  identities-not-content logging doctrine in this scan.
- The learn_add deduped reply is tailored by reason code: the
  `semantic_similarity` case is now only reachable when a lower-authority
  write hit a user_explicit lesson, so that reply must not coach the
  learn_remove-and-re-add path around the guard.
- Spec sync: the dedup table row in
  docs/system-specs/modules/memory-skills-hooks.md drops "longer text
  wins" for "newer replaces older" and notes the user_explicit
  protection.

Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
NicholasRBowers pushed a commit to isotope14/KiroCrew that referenced this pull request Sep 7, 2026
Semantic lesson dedup tie-broke on `len(rule) > len(existing_text)` and
DROPPED the submission when it lost, so character count decided which of
two near-identical rules was current.

Corrections land on the losing side of that comparison as a rule: a
retraction collapses a detailed stale claim ("tool X is available, 48
verbs, attaches on port 9224") into a short accurate one ("tool X is not
installed"). The shorter text lost, and the stale lesson stayed in
effect -- the one outcome that actively misleads the agent rather than
merely losing detail. Observed live: a measured correction was refused
while the claim it disproved kept applying, and the only recovery was a
blind learn_remove on a guessed substring.

The substring and topic-overlap branches directly above already
supersede the stored row unconditionally, so newest-wins makes the three
dedup paths agree instead of one of them arbitrating on length.

The learn_add reply had a matching problem: it printed the SUBMITTED rule
straight after "an existing stored lesson already covers it", which reads
as a quote of the stored lesson. A caller believed it had been shown the
winner, could not tell a correct dedup from a dropped correction, and was
never told the replace path. It now labels the text as what was DROPPED
and names the learn_list/learn_remove sequence.

Substring dedup still refuses -- a rule literally contained in a stored
one is genuinely covered.

Drive-to-green additions on top of isotope14's original change (rebase
onto current main plus review fixes):

- Guard the supersede by stored authority: a stored row that outranks the
  write -- `user_explicit` over a lower-authority source, or strictly
  higher stored confidence (the onboarding import writes user lessons at
  confidence 1.0 under source "import") -- is never displaced by it. That
  write returns the old deduped outcome instead, so newest-wins cannot
  invert the authority order `_write_semantic` already enforces for
  same-key writes. Regression tests cover both directions plus the
  import-sourced row, and were proven red without the guard.
- Rebase composition: keep main's `superseded` reporting (kirodotdev#8585) on the
  supersede path, and log row ids rather than rule text, matching the
  identities-not-content logging doctrine in this scan.
- The learn_add deduped reply is tailored by reason code: the
  `semantic_similarity` case is now only reachable when a lower-authority
  write hit a user_explicit lesson, so that reply must not coach the
  learn_remove-and-re-add path around the guard.
- Spec sync: the dedup table row in
  docs/system-specs/modules/memory-skills-hooks.md drops "longer text
  wins" for "newer replaces older" and notes the user_explicit
  protection.

Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
NicholasRBowers pushed a commit to isotope14/KiroCrew that referenced this pull request Sep 7, 2026
Semantic lesson dedup tie-broke on `len(rule) > len(existing_text)` and
DROPPED the submission when it lost, so character count decided which of
two near-identical rules was current.

Corrections land on the losing side of that comparison as a rule: a
retraction collapses a detailed stale claim ("tool X is available, 48
verbs, attaches on port 9224") into a short accurate one ("tool X is not
installed"). The shorter text lost, and the stale lesson stayed in
effect -- the one outcome that actively misleads the agent rather than
merely losing detail. Observed live: a measured correction was refused
while the claim it disproved kept applying, and the only recovery was a
blind learn_remove on a guessed substring.

The substring and topic-overlap branches directly above already
supersede the stored row unconditionally, so newest-wins makes the three
dedup paths agree instead of one of them arbitrating on length.

The learn_add reply had a matching problem: it printed the SUBMITTED rule
straight after "an existing stored lesson already covers it", which reads
as a quote of the stored lesson. A caller believed it had been shown the
winner, could not tell a correct dedup from a dropped correction, and was
never told the replace path. It now labels the text as what was DROPPED
and names the learn_list/learn_remove sequence.

Substring dedup still refuses -- a rule literally contained in a stored
one is genuinely covered.

Drive-to-green additions on top of isotope14's original change (rebase
onto current main plus review fixes):

- Guard the supersede by stored authority: a stored row that outranks the
  write -- `user_explicit` over a lower-authority source, or strictly
  higher stored confidence (the onboarding import writes user lessons at
  confidence 1.0 under source "import") -- is never displaced by it. That
  write returns the old deduped outcome instead, so newest-wins cannot
  invert the authority order `_write_semantic` already enforces for
  same-key writes. Regression tests cover both directions plus the
  import-sourced row, and were proven red without the guard.
- Semantic supersedes are deferred until the scan settles the write: rows
  are scanned newest-first, not authority-first, so deleting mid-scan let
  a lower-authority near-duplicate be destroyed just before a
  higher-authority match declined the write -- losing a stored lesson
  while storing nothing. Deletions now run only on the path where the
  submission is stored; a declined write deletes nothing from this
  branch. Proven red-before-green with a two-row scan-order test.
- Rebase composition: keep main's `superseded` reporting (kirodotdev#8585) on the
  supersede path, and log row ids rather than rule text, matching the
  identities-not-content logging doctrine in this scan.
- The learn_add deduped reply is tailored by reason code: the
  `semantic_similarity` case is now only reachable when a lower-authority
  write hit a user_explicit lesson, so that reply must not coach the
  learn_remove-and-re-add path around the guard.
- Spec sync: the dedup table row in
  docs/system-specs/modules/memory-skills-hooks.md drops "longer text
  wins" for "newer replaces older" and notes the user_explicit
  protection.

Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
NicholasRBowers pushed a commit to isotope14/KiroCrew that referenced this pull request Sep 7, 2026
Semantic lesson dedup tie-broke on `len(rule) > len(existing_text)` and
DROPPED the submission when it lost, so character count decided which of
two near-identical rules was current.

Corrections land on the losing side of that comparison as a rule: a
retraction collapses a detailed stale claim ("tool X is available, 48
verbs, attaches on port 9224") into a short accurate one ("tool X is not
installed"). The shorter text lost, and the stale lesson stayed in
effect -- the one outcome that actively misleads the agent rather than
merely losing detail. Observed live: a measured correction was refused
while the claim it disproved kept applying, and the only recovery was a
blind learn_remove on a guessed substring.

The substring and topic-overlap branches directly above already
supersede the stored row unconditionally, so newest-wins makes the three
dedup paths agree instead of one of them arbitrating on length.

The learn_add reply had a matching problem: it printed the SUBMITTED rule
straight after "an existing stored lesson already covers it", which reads
as a quote of the stored lesson. A caller believed it had been shown the
winner, could not tell a correct dedup from a dropped correction, and was
never told the replace path. It now labels the text as what was DROPPED
and names the learn_list/learn_remove sequence.

Substring dedup still refuses -- a rule literally contained in a stored
one is genuinely covered.

Drive-to-green additions on top of isotope14's original change (rebase
onto current main plus review fixes):

- Authority pre-pass (settled after a review retrospective across three
  rounds on this span): every refusal this change introduces is decided
  BEFORE the scan takes its first deletion. A non-mutating pre-pass over
  the same rows the semantic branch sees (shared lazy-backfill budget,
  blobs memoized onto the row dicts) returns the old deduped outcome when
  a stored near-duplicate outranks the write -- `user_explicit` over a
  lower-authority source, or strictly higher stored confidence (the
  onboarding import stores user lessons at confidence 1.0 under source
  "import"). A write declined on authority therefore deletes nothing and
  reports an empty `superseded`; the mutating scan keeps main's
  delete-as-you-go shape for the write-proceeds path. Regression tests
  cover both guard directions, the import-sourced row, and the
  declined-write-deletes-nothing sequence, each proven red without the
  protection.
- Rebase composition: keep main's `superseded` reporting (kirodotdev#8585) on the
  supersede path, and log row ids rather than rule text, matching the
  identities-not-content logging doctrine in this scan.
- The learn_add deduped reply is tailored by reason code: the
  `semantic_similarity` case is now only reachable when a lower-authority
  write hit a user_explicit lesson, so that reply must not coach the
  learn_remove-and-re-add path around the guard.
- Spec sync: the dedup table row in
  docs/system-specs/modules/memory-skills-hooks.md drops "longer text
  wins" for "newer replaces older" and notes the user_explicit
  protection.

Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
NicholasRBowers pushed a commit to isotope14/KiroCrew that referenced this pull request Sep 7, 2026
Semantic lesson dedup tie-broke on `len(rule) > len(existing_text)` and
DROPPED the submission when it lost, so character count decided which of
two near-identical rules was current.

Corrections land on the losing side of that comparison as a rule: a
retraction collapses a detailed stale claim ("tool X is available, 48
verbs, attaches on port 9224") into a short accurate one ("tool X is not
installed"). The shorter text lost, and the stale lesson stayed in
effect -- the one outcome that actively misleads the agent rather than
merely losing detail. Observed live: a measured correction was refused
while the claim it disproved kept applying, and the only recovery was a
blind learn_remove on a guessed substring.

The substring and topic-overlap branches directly above already
supersede the stored row unconditionally, so newest-wins makes the three
dedup paths agree instead of one of them arbitrating on length.

The learn_add reply had a matching problem: it printed the SUBMITTED rule
straight after "an existing stored lesson already covers it", which reads
as a quote of the stored lesson. A caller believed it had been shown the
winner, could not tell a correct dedup from a dropped correction, and was
never told the replace path. It now labels the text as what was DROPPED
and names the learn_list/learn_remove sequence.

Substring dedup still refuses -- a rule literally contained in a stored
one is genuinely covered.

Drive-to-green additions on top of isotope14's original change (rebase
onto current main plus review fixes):

- Authority pre-pass (settled after a review retrospective across three
  rounds on this span): every refusal this change introduces is decided
  BEFORE the scan takes its first deletion. A non-mutating pre-pass over
  the same rows the semantic branch sees (shared lazy-backfill budget,
  blobs memoized onto the row dicts) returns the old deduped outcome when
  a stored near-duplicate outranks the write -- `user_explicit` over a
  lower-authority source, or strictly higher stored confidence (the
  onboarding import stores user lessons at confidence 1.0 under source
  "import"). The pre-pass covers PURE semantic matches only: a row the
  scan's substring or topic-overlap branch would claim first keeps main's
  lexical outcome (those branches are source-blind by main's design). A
  write declined on authority therefore deletes nothing and reports an
  empty `superseded`; the mutating scan keeps main's
  delete-as-you-go shape for the write-proceeds path. Regression tests
  cover both guard directions, the import-sourced row, and the
  declined-write-deletes-nothing sequence, each proven red without the
  protection.
- Rebase composition: keep main's `superseded` reporting (kirodotdev#8585) on the
  supersede path, and log row ids rather than rule text, matching the
  identities-not-content logging doctrine in this scan.
- The learn_add deduped reply is tailored by reason code: the
  `semantic_similarity` case is now only reachable when a lower-authority
  write hit a user_explicit lesson, so that reply must not coach the
  learn_remove-and-re-add path around the guard.
- Spec sync: the dedup table row in
  docs/system-specs/modules/memory-skills-hooks.md drops "longer text
  wins" for "newer replaces older" and notes the user_explicit
  protection.

Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
NicholasRBowers pushed a commit to isotope14/KiroCrew that referenced this pull request Sep 7, 2026
Semantic lesson dedup tie-broke on `len(rule) > len(existing_text)` and
DROPPED the submission when it lost, so character count decided which of
two near-identical rules was current.

Corrections land on the losing side of that comparison as a rule: a
retraction collapses a detailed stale claim ("tool X is available, 48
verbs, attaches on port 9224") into a short accurate one ("tool X is not
installed"). The shorter text lost, and the stale lesson stayed in
effect -- the one outcome that actively misleads the agent rather than
merely losing detail. Observed live: a measured correction was refused
while the claim it disproved kept applying, and the only recovery was a
blind learn_remove on a guessed substring.

The substring and topic-overlap branches directly above already
supersede the stored row unconditionally, so newest-wins makes the three
dedup paths agree instead of one of them arbitrating on length.

The learn_add reply had a matching problem: it printed the SUBMITTED rule
straight after "an existing stored lesson already covers it", which reads
as a quote of the stored lesson. A caller believed it had been shown the
winner, could not tell a correct dedup from a dropped correction, and was
never told the replace path. It now labels the text as what was DROPPED
and names the learn_list/learn_remove sequence.

Substring dedup still refuses -- a rule literally contained in a stored
one is genuinely covered.

Drive-to-green additions on top of isotope14's original change (rebase
onto current main plus review fixes):

- Authority pre-pass (settled after a review retrospective across three
  rounds on this span): every refusal this change introduces is decided
  BEFORE the scan takes its first deletion. A non-mutating pre-pass over
  the same rows the semantic branch sees (shared lazy-backfill budget,
  blobs memoized onto the row dicts) returns the old deduped outcome when
  a stored near-duplicate outranks the write -- `user_explicit` over a
  lower-authority source, or strictly higher stored confidence (the
  onboarding import stores user lessons at confidence 1.0 under source
  "import"). The pre-pass covers PURE semantic matches only: a row the
  scan's substring or topic-overlap branch would claim first keeps main's
  lexical outcome (those branches are source-blind by main's design).
  The mutating semantic branch's own supersedes are DEFERRED and execute
  only when the write proceeds, so a later `substring_covered` refusal
  cannot strand a deletion newest-wins took where the old tie-break would
  have refused. A write declined for any reason therefore deletes nothing
  via the semantic branch and reports it honestly in `superseded`.
- The learn_add deduped reply labels the quoted text as the DROPPED
  submission and names the learn_list -> learn_remove -> re-add recovery.
  (An earlier draft carried a second, authority-flavored reply variant;
  it was unreachable on a current build and is removed.)
- Rebase composition: keep main's `superseded` reporting (kirodotdev#8585) on the
  supersede path, and log row ids rather than rule text, matching the
  identities-not-content logging doctrine in this scan.
- Spec sync: the dedup table row in
  docs/system-specs/modules/memory-skills-hooks.md drops "longer text
  wins" for "newer replaces older" and notes the user_explicit
  protection.

Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
NicholasRBowers pushed a commit to isotope14/KiroCrew that referenced this pull request Sep 7, 2026
Semantic lesson dedup tie-broke on `len(rule) > len(existing_text)` and
DROPPED the submission when it lost, so character count decided which of
two near-identical rules was current.

Corrections land on the losing side of that comparison as a rule: a
retraction collapses a detailed stale claim ("tool X is available, 48
verbs, attaches on port 9224") into a short accurate one ("tool X is not
installed"). The shorter text lost, and the stale lesson stayed in
effect -- the one outcome that actively misleads the agent rather than
merely losing detail. Observed live: a measured correction was refused
while the claim it disproved kept applying, and the only recovery was a
blind learn_remove on a guessed substring.

The substring and topic-overlap branches directly above already
supersede the stored row unconditionally, so newest-wins makes the three
dedup paths agree instead of one of them arbitrating on length.

The learn_add reply had a matching problem: it printed the SUBMITTED rule
straight after "an existing stored lesson already covers it", which reads
as a quote of the stored lesson. A caller believed it had been shown the
winner, could not tell a correct dedup from a dropped correction, and was
never told the replace path. It now labels the text as what was DROPPED
and names the learn_list/learn_remove sequence.

Substring dedup still refuses -- a rule literally contained in a stored
one is genuinely covered.

Drive-to-green additions on top of isotope14's original change (rebase
onto current main plus review fixes):

- Authority pre-pass (settled after a review retrospective across three
  rounds on this span): every refusal this change introduces is decided
  BEFORE the scan takes its first deletion. A non-mutating pre-pass over
  the same rows the semantic branch sees (shared lazy-backfill budget,
  blobs memoized onto the row dicts) returns the old deduped outcome when
  a stored near-duplicate outranks the write -- `user_explicit` over a
  lower-authority source, or strictly higher stored confidence (the
  onboarding import stores user lessons at confidence 1.0 under source
  "import"). The pre-pass covers PURE semantic matches only: a row the
  scan's substring or topic-overlap branch would claim first keeps main's
  lexical outcome (those branches are source-blind by main's design).
  The mutating semantic branch's own supersedes are DEFERRED and execute
  only when the write proceeds, so a later `substring_covered` refusal
  cannot strand a deletion newest-wins took where the old tie-break would
  have refused. A write declined for any reason therefore deletes nothing
  via the semantic branch and reports it honestly in `superseded`.
- The learn_add deduped reply labels the quoted text as the DROPPED
  submission and names the learn_list -> learn_remove -> re-add recovery.
  The `semantic_similarity` reason -- only reachable when the stored row
  outranks the write -- deliberately withholds that coaching: following
  it would delete the row the store just protected. A test locks the
  reply to never name learn_remove.
- Rebase composition: keep main's `superseded` reporting (kirodotdev#8585) on the
  supersede path, and log row ids rather than rule text, matching the
  identities-not-content logging doctrine in this scan.
- Spec sync: the dedup table row in
  docs/system-specs/modules/memory-skills-hooks.md drops "longer text
  wins" for "newer replaces older" and notes the user_explicit
  protection.

Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
NicholasRBowers pushed a commit to isotope14/KiroCrew that referenced this pull request Sep 9, 2026
Semantic lesson dedup tie-broke on `len(rule) > len(existing_text)` and
DROPPED the submission when it lost, so character count decided which of
two near-identical rules was current.

Corrections land on the losing side of that comparison as a rule: a
retraction collapses a detailed stale claim ("tool X is available, 48
verbs, attaches on port 9224") into a short accurate one ("tool X is not
installed"). The shorter text lost, and the stale lesson stayed in
effect -- the one outcome that actively misleads the agent rather than
merely losing detail. Observed live: a measured correction was refused
while the claim it disproved kept applying, and the only recovery was a
blind learn_remove on a guessed substring.

The substring and topic-overlap branches directly above already
supersede the stored row unconditionally, so newest-wins makes the three
dedup paths agree instead of one of them arbitrating on length.

The learn_add reply had a matching problem: it printed the SUBMITTED rule
straight after "an existing stored lesson already covers it", which reads
as a quote of the stored lesson. A caller believed it had been shown the
winner, could not tell a correct dedup from a dropped correction, and was
never told the replace path. It now labels the text as what was DROPPED
and names the learn_list/learn_remove sequence.

Substring dedup still refuses -- a rule literally contained in a stored
one is genuinely covered.

Drive-to-green additions on top of isotope14's original change (rebase
onto current main plus review fixes):

- Authority pre-pass (settled after a review retrospective across three
  rounds on this span): every refusal this change introduces is decided
  BEFORE the scan takes its first deletion. A non-mutating pre-pass over
  the same rows the semantic branch sees (shared lazy-backfill budget,
  blobs memoized onto the row dicts) returns the old deduped outcome when
  a stored near-duplicate outranks the write -- `user_explicit` over a
  lower-authority source, or strictly higher stored confidence (the
  onboarding import stores user lessons at confidence 1.0 under source
  "import"). The pre-pass covers PURE semantic matches only: a row the
  scan's substring or topic-overlap branch would claim first keeps main's
  lexical outcome (those branches are source-blind by main's design).
  The mutating semantic branch's own supersedes are DEFERRED and execute
  only when the write proceeds, so a later `substring_covered` refusal
  cannot strand a deletion newest-wins took where the old tie-break would
  have refused. A write declined for any reason therefore deletes nothing
  via the semantic branch and reports it honestly in `superseded`.
- The learn_add deduped reply labels the quoted text as the DROPPED
  submission and names the learn_list -> learn_remove -> re-add recovery.
  The `semantic_similarity` reason -- only reachable when the stored row
  outranks the write -- deliberately withholds that coaching: following
  it would delete the row the store just protected. A test locks the
  reply to never name learn_remove.
- Rebase composition: keep main's `superseded` reporting (kirodotdev#8585) on the
  supersede path, and log row ids rather than rule text, matching the
  identities-not-content logging doctrine in this scan.
- Spec sync: the dedup table row in
  docs/system-specs/modules/memory-skills-hooks.md drops "longer text
  wins" for "newer replaces older" and notes the user_explicit
  protection.

Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
NicholasRBowers pushed a commit to isotope14/KiroCrew that referenced this pull request Sep 9, 2026
Semantic lesson dedup tie-broke on `len(rule) > len(existing_text)` and
DROPPED the submission when it lost, so character count decided which of
two near-identical rules was current.

Corrections land on the losing side of that comparison as a rule: a
retraction collapses a detailed stale claim ("tool X is available, 48
verbs, attaches on port 9224") into a short accurate one ("tool X is not
installed"). The shorter text lost, and the stale lesson stayed in
effect -- the one outcome that actively misleads the agent rather than
merely losing detail. Observed live: a measured correction was refused
while the claim it disproved kept applying, and the only recovery was a
blind learn_remove on a guessed substring.

The substring and topic-overlap branches directly above already
supersede the stored row unconditionally, so newest-wins makes the three
dedup paths agree instead of one of them arbitrating on length.

The learn_add reply had a matching problem: it printed the SUBMITTED rule
straight after "an existing stored lesson already covers it", which reads
as a quote of the stored lesson. A caller believed it had been shown the
winner, could not tell a correct dedup from a dropped correction, and was
never told the replace path. It now labels the text as what was DROPPED
and names the learn_list/learn_remove sequence.

Substring dedup still refuses -- a rule literally contained in a stored
one is genuinely covered.

Drive-to-green additions on top of isotope14's original change (rebase
onto current main plus review fixes):

- Authority pre-pass (settled after a review retrospective across three
  rounds on this span): every refusal this change introduces is decided
  BEFORE the scan takes its first deletion. A non-mutating pre-pass over
  the same rows the semantic branch sees (shared lazy-backfill budget,
  blobs memoized onto the row dicts) returns the old deduped outcome when
  a stored near-duplicate outranks the write -- `user_explicit` over a
  lower-authority source, or strictly higher stored confidence (the
  onboarding import stores user lessons at confidence 1.0 under source
  "import"). The pre-pass covers PURE semantic matches only: a row the
  scan's substring or topic-overlap branch would claim first keeps main's
  lexical outcome (those branches are source-blind by main's design).
  The mutating semantic branch's own supersedes are DEFERRED and execute
  only when the write proceeds, so a later `substring_covered` refusal
  cannot strand a deletion newest-wins took where the old tie-break would
  have refused. A write declined for any reason therefore deletes nothing
  via the semantic branch and reports it honestly in `superseded`.
- The learn_add deduped reply labels the quoted text as the DROPPED
  submission and names the learn_list -> learn_remove -> re-add recovery.
  The `semantic_similarity` reason -- only reachable when the stored row
  outranks the write -- deliberately withholds that coaching: following
  it would delete the row the store just protected. A test locks the
  reply to never name learn_remove.
- Rebase composition: keep main's `superseded` reporting (kirodotdev#8585) on the
  supersede path, and log row ids rather than rule text, matching the
  identities-not-content logging doctrine in this scan.
- Spec sync: the dedup table row in
  docs/system-specs/modules/memory-skills-hooks.md drops "longer text
  wins" for "newer replaces older" and notes the user_explicit
  protection.

Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
bolichen97 pushed a commit that referenced this pull request Sep 10, 2026
Semantic lesson dedup tie-broke on `len(rule) > len(existing_text)` and
DROPPED the submission when it lost, so character count decided which of
two near-identical rules was current.

Corrections land on the losing side of that comparison as a rule: a
retraction collapses a detailed stale claim ("tool X is available, 48
verbs, attaches on port 9224") into a short accurate one ("tool X is not
installed"). The shorter text lost, and the stale lesson stayed in
effect -- the one outcome that actively misleads the agent rather than
merely losing detail. Observed live: a measured correction was refused
while the claim it disproved kept applying, and the only recovery was a
blind learn_remove on a guessed substring.

The substring and topic-overlap branches directly above already
supersede the stored row unconditionally, so newest-wins makes the three
dedup paths agree instead of one of them arbitrating on length.

The learn_add reply had a matching problem: it printed the SUBMITTED rule
straight after "an existing stored lesson already covers it", which reads
as a quote of the stored lesson. A caller believed it had been shown the
winner, could not tell a correct dedup from a dropped correction, and was
never told the replace path. It now labels the text as what was DROPPED
and names the learn_list/learn_remove sequence.

Substring dedup still refuses -- a rule literally contained in a stored
one is genuinely covered.

Drive-to-green additions on top of isotope14's original change (rebase
onto current main plus review fixes):

- Authority pre-pass (settled after a review retrospective across three
  rounds on this span): every refusal this change introduces is decided
  BEFORE the scan takes its first deletion. A non-mutating pre-pass over
  the same rows the semantic branch sees (shared lazy-backfill budget,
  blobs memoized onto the row dicts) returns the old deduped outcome when
  a stored near-duplicate outranks the write -- `user_explicit` over a
  lower-authority source, or strictly higher stored confidence (the
  onboarding import stores user lessons at confidence 1.0 under source
  "import"). The pre-pass covers PURE semantic matches only: a row the
  scan's substring or topic-overlap branch would claim first keeps main's
  lexical outcome (those branches are source-blind by main's design).
  The mutating semantic branch's own supersedes are DEFERRED and execute
  only when the write proceeds, so a later `substring_covered` refusal
  cannot strand a deletion newest-wins took where the old tie-break would
  have refused. A write declined for any reason therefore deletes nothing
  via the semantic branch and reports it honestly in `superseded`.
- The learn_add deduped reply labels the quoted text as the DROPPED
  submission and names the learn_list -> learn_remove -> re-add recovery.
  The `semantic_similarity` reason -- only reachable when the stored row
  outranks the write -- deliberately withholds that coaching: following
  it would delete the row the store just protected. A test locks the
  reply to never name learn_remove.
- Rebase composition: keep main's `superseded` reporting (#8585) on the
  supersede path, and log row ids rather than rule text, matching the
  identities-not-content logging doctrine in this scan.
- Spec sync: the dedup table row in
  docs/system-specs/modules/memory-skills-hooks.md drops "longer text
  wins" for "newer replaces older" and notes the user_explicit
  protection.

Co-authored-by: isotope14 <266124104+isotope14@users.noreply.github.com>
Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…dev#6175)

Semantic lesson dedup tie-broke on `len(rule) > len(existing_text)` and
DROPPED the submission when it lost, so character count decided which of
two near-identical rules was current.

Corrections land on the losing side of that comparison as a rule: a
retraction collapses a detailed stale claim ("tool X is available, 48
verbs, attaches on port 9224") into a short accurate one ("tool X is not
installed"). The shorter text lost, and the stale lesson stayed in
effect -- the one outcome that actively misleads the agent rather than
merely losing detail. Observed live: a measured correction was refused
while the claim it disproved kept applying, and the only recovery was a
blind learn_remove on a guessed substring.

The substring and topic-overlap branches directly above already
supersede the stored row unconditionally, so newest-wins makes the three
dedup paths agree instead of one of them arbitrating on length.

The learn_add reply had a matching problem: it printed the SUBMITTED rule
straight after "an existing stored lesson already covers it", which reads
as a quote of the stored lesson. A caller believed it had been shown the
winner, could not tell a correct dedup from a dropped correction, and was
never told the replace path. It now labels the text as what was DROPPED
and names the learn_list/learn_remove sequence.

Substring dedup still refuses -- a rule literally contained in a stored
one is genuinely covered.

Drive-to-green additions on top of isotope14's original change (rebase
onto current main plus review fixes):

- Authority pre-pass (settled after a review retrospective across three
  rounds on this span): every refusal this change introduces is decided
  BEFORE the scan takes its first deletion. A non-mutating pre-pass over
  the same rows the semantic branch sees (shared lazy-backfill budget,
  blobs memoized onto the row dicts) returns the old deduped outcome when
  a stored near-duplicate outranks the write -- `user_explicit` over a
  lower-authority source, or strictly higher stored confidence (the
  onboarding import stores user lessons at confidence 1.0 under source
  "import"). The pre-pass covers PURE semantic matches only: a row the
  scan's substring or topic-overlap branch would claim first keeps main's
  lexical outcome (those branches are source-blind by main's design).
  The mutating semantic branch's own supersedes are DEFERRED and execute
  only when the write proceeds, so a later `substring_covered` refusal
  cannot strand a deletion newest-wins took where the old tie-break would
  have refused. A write declined for any reason therefore deletes nothing
  via the semantic branch and reports it honestly in `superseded`.
- The learn_add deduped reply labels the quoted text as the DROPPED
  submission and names the learn_list -> learn_remove -> re-add recovery.
  The `semantic_similarity` reason -- only reachable when the stored row
  outranks the write -- deliberately withholds that coaching: following
  it would delete the row the store just protected. A test locks the
  reply to never name learn_remove.
- Rebase composition: keep main's `superseded` reporting (kirodotdev#8585) on the
  supersede path, and log row ids rather than rule text, matching the
  identities-not-content logging doctrine in this scan.
- Spec sync: the dedup table row in
  docs/system-specs/modules/memory-skills-hooks.md drops "longer text
  wins" for "newer replaces older" and notes the user_explicit
  protection.

Co-authored-by: isotope14 <266124104+isotope14@users.noreply.github.com>
Co-authored-by: Kiro Crew <noreply@kirodotdev.github.io>
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.

3 participants