Skip to content

feat: search and edit lessons in the memory tab - #31438

Merged
bolichen97 merged 1 commit into
mainfrom
fix/17982-lessons-search-edit
Nov 10, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/17982-lessons-search-edit

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A user can find a lesson in the Memory tab's Lessons table by its text, and correct a rule's wording there without deleting it and adding it again.

The Lessons card under Overview > Memory lists, sorts and deletes lessons, but it has no search and no way to fix a rule. Correcting one typo means deleting the row and re-adding it from the Add box, which files the new rule globally with no tier and no NOT-clause, whatever the old row had.

Builds on #18831 by @bhumin18.

Why it matters

A wrong rule is handed to every session until someone fixes it, and today the fix also loses the lesson's scope, workspace file, tier and NOT-clause unless the user retypes them through the CLI. In a store with dozens of lessons, finding the row to fix means scrolling a table that shows only the newest 20.

Not a goal

  • Changing a lesson's category, scope, tier or NOT-clause in place; the edit changes the rule text only.
  • Editing on the vector store: the Lessons card is hidden whenever vector memory is active, and those lessons are edited in the Semantic browser.
  • A new route, or an edit through the CLI or the learn_* MCP tools.
  • Searching lessons outside the window GET /api/lessons returns.

What changed (motivation → approach → change)

The Lessons card (website/src/pages/overview/MemoryTab.tsx) gets a search box and a per-row Edit. Typing in the box narrows the table to the lessons whose rule contains the text, across every row the list returned (its newest 50) rather than only the newest 20 the table shows without a query; a query that matches nothing shows the shared "no matches" line with a clear action.

Edit turns the rule cell into a text box with Save and Cancel. Save sends the new text through the same POST /api/lessons the Add box uses (createLesson in website/src/api/client/memory.ts takes the row as an optional third argument), carrying the row's category, scope / workspace and repo_scope, plus replaces: {rule, repo_scope} naming the row being edited, then re-reads the list. Reusing the add route keeps every guard it has (restricted sessions, the writes switch, validation, workspace ownership, the content screens, the audit). replaces is outside LEARN_ADD_SCHEMA, so the learn_add tool cannot send it.

With replaces, the route (src/kiro_crew/dashboard/handlers/cron_lessons.py, whose new helpers the cron.py facade lists) rewrites that one row and answers replaced, or refuses and writes nothing. The JSONL store does it in place under its lock (LessonStore.replace_rule in src/kiro_crew/learn.py): the row keeps its place, tier and the NOT-clause it holds at that moment, and the row count never changes, so a store at its 200-row cap evicts nothing. An add-then-delete would first have evicted an unrelated lesson. A replaced edit reports the old wording in superseded, so it is audited and announced to collaborators like any write that replaces a lesson, and it tells subscribed apps lessons.changed with action updated (lesson_write_action in src/kiro_crew/lesson_events.py). An edit naming a workspace that is not configured, or the reserved default, is refused with 400 workspace_unknown as DELETE already does, since an unmapped name would resolve to another file. An edit against a vector tier is refused (replace_vector_unsupported): the card is hidden there, and the vector write would dedup, enrich or supersede rows the edit never named. A V1 store holding no decodable lesson is the list's JSONL fallback, so the edit goes to the JSONL file the list read.

Edit Old row Draft
replaced rewritten (changed) closed
replaced, then the list re-read fails rewritten (added) closed, with "Edit saved, but the list could not be refreshed" and the error above the table
a change of letter case only rewritten like any edit (changed) closed
replace_source_missing: no row matches the old rule and scope exactly kept, nothing written (added) kept, with "This lesson changed or was removed. Reload the list and try again." above the table
replace_ambiguous: two rows share the old text and scope, so the selector cannot say which kept, nothing written (added) kept, with "Two lessons share this text, so this edit cannot choose one. Add the corrected wording as a new lesson instead." above the table
replace_collision: another row in that scope already holds the new text, and merging would drop one row's tier kept, nothing written (added) kept, with "Another lesson in this scope already says this. Change the text, or delete one of the two." above the table
replace_vector_unsupported: the list is the vector tier kept, nothing written (added) kept, with "Lessons in vector memory are edited in the Semantic browser." above the table
refused, deduped, unchanged, or the request fails kept (unchanged) kept, with the reason above the table

Legend: added, changed, unchanged.

An open edit counts as an unsaved draft in the tab's dirty state, so switching memory store, leaving the tab or reloading asks before the draft is lost, and one edit is open at a time: the other rows' Edit is disabled until Save or Cancel. The draft keeps the row as it was when Edit opened, so a search or a refresh that leaves the row out still shows it with its draft.

A rule the redaction chain changes is listed with a placeholder in it. Editing that text would store the placeholder, so GET /api/lessons marks such a row rule_editable: false and it offers no Edit; the route would refuse it anyway, because the listed text matches no stored row.

The Lesson type in website/src/types/index.capabilities.ts gains rule_editable. The new strings are in every catalog under website/src/i18n/locales/, and learn-cron-dashboard.md documents the search and the edit.

Backwards compatibility

Compatible: rule_editable is a new optional key on rows of GET /api/lessons, replaces is a new optional key on POST /api/lessons (without it the route behaves as on main), createLesson's third argument is optional, and the Add box sends the same body as before.

Removes nothing: no key, route or behaviour main has is removed.

Tests

  • test/test_lesson_edit_replace.py (new): an edit at the 200-row cap rewrites its row in place, keeps its tier and evicts nothing; an edit keeps a clause attached after the list was read; an edit onto another row's text, an edit of a row that is not stored (as a redacted listing is) and an edit whose old text names two rows all write nothing; an edit the content screens refuse for the row's stored clause names that reason, never capacity; a broken-scope row with the same text is not taken for the global row; an edit against a populated vector tier writes nothing, and one with an empty V1 vector store rewrites the listed JSONL row; a redacted rule is listed rule_editable: false.
  • website/src/test/OverviewMemoryTabCov80.test.tsx, MemoryTab — lesson search and edit (#17982):
    • the search narrows the rows to matching rules and shows the no-matches line when nothing matches;
    • Save sends one request with the row's scope, workspace, repo_scope and replaces, deletes nothing itself and re-reads the list;
    • a refused edit keeps the old row and the draft, and shows the reason;
    • an open edit raises the unload guard, and Cancel drops it;
    • while one row is in edit, every other row's Edit is disabled;
    • the row in edit and its draft stay shown under a search, across a refresh whose window no longer lists the row, and across one that lists no lessons at all (a Save on a row that is really gone is refused with "This lesson changed or was removed");
    • a case-only correction is saved, and an edit refusal shows its own sentence, not the reason code;
    • a row whose rule is redacted, whose repo_scope is null, or that comes from vector memory (it names no file tier) offers no Edit.
    • a saved edit whose list re-read fails closes and shows "Edit saved, but the list could not be refreshed" with the error, never the delete banner ("Lesson deleted, ...").

Determinism: the edit block (10 tests) ran 10 times in a row, all green, and the whole file once in a shuffled order (--sequence.shuffle, seed 51307), 68 of 68 green; the re-read test is red against 9d7e30b's MemoryTab.tsx, where the failed re-read was silent, and green here.

Proof: PROVEN test/test_lesson_edit_replace.py::test_an_edit_at_the_cap_rewrites_its_row_and_evicts_nothing, test/test_lesson_edit_replace.py::test_an_edit_onto_another_rows_text_changes_nothing, test/test_lesson_edit_replace.py::test_an_edit_of_a_row_that_is_not_stored_writes_nothing, test/test_lesson_edit_replace.py::test_an_edit_whose_text_names_two_rows_writes_nothing, test/test_lesson_edit_replace.py::test_an_edit_skips_a_broken_scope_row_with_the_same_text (head b0f455489a49)

Manual verification

Captured the Lessons card from this head (d3f23ca400) running in an isolated gateway on a seeded JSONL store, with scripted Playwright, light and dark: a search narrowing the rows, a row in edit with every other row's Edit disabled, a saved edit whose list re-read failed, an edit the server refused, and a search with no match. The list, the edit's POST /api/lessons, its replaced answer and its replace_ambiguous refusal are the gateway's own responses. Two responses are rewritten. GET /api/memory/embedding-status has its provider set to none: the gateway reports ollama there on every install, the Memory tab reads that as vector memory being active, and it hides the card whenever that is so. For the re-read capture, the GET /api/lessons that follows the saved edit answers 503, as it would during a gateway restart. The edit's rewrite against a real JSONL store, and its refusal on a real vector store, are covered by test/test_lesson_edit_replace.py.

Screenshots / video

Search narrowing the rows (light, dark):

Lessons search, light

Lessons search, dark

A row in edit, with Save and Cancel; every other row's Edit is disabled until Save or Cancel (light, dark):

Lesson edit, light, other rows' Edit disabled

Lesson edit, dark, other rows' Edit disabled

A saved edit whose list re-read failed: the editor is closed, and the notice says the edit was saved but the list could not be refreshed, with the error (light, dark):

Edit saved, list re-read failed, light

Edit saved, list re-read failed, dark

An edit the server refused (replace_ambiguous: two stored rows share the text and scope): the notice names the next step instead of the reason code, and the draft stays in the row:

Lesson edit refused, with its own sentence and the draft kept

A search with no match:

Lessons search, no match

Related Issues

Closes #17982

Sibling sweep

N/A — a feat PR.

Pattern harvest

N/A — a feat PR.

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

Contributed under the project's Apache-2.0 license (see CONTRIBUTING.md).

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 6, 2026 13:45
@bolichen97
bolichen97 requested a review from Zedmor November 6, 2026 13:45
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

No design-level concerns: an in-place rewrite under the store lock that reuses the add route's guards is the right shape, and nothing is taken away.

Notes

  • Edits that land on a vector-tier store are refused (replace_vector_unsupported) instead of being rewritten. That holds only while the card stays hidden whenever vector memory is active. If the card is ever shown there, this refusal becomes a dead end the user can see.

[DESIGN-REVIEWED] d3f23ca

Description read

[DESCRIPTION-READ] b0638a4a522412f199c14c228ecc50324840b93c47da52e811f9351388325b1c

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 6, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of d3f23ca4005e0d4ae029b0ae50cc7d444bdebc3f — 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: each item is new capability behind a stated harm (a typo fix loses scope, tier and NOT-clause, and can evict a row at the cap), and no default changes.

What this change ships

Inventory (8 items) — 8 justified

Intent: let a user find a lesson by its text and fix a rule's wording in the Memory tab without losing the row's scope, tier or clause — ADDITION.

  1. A search box on the Lessons card that filters rules across the 50 listed rows — justified
  2. An Edit button on each row, with Save and Cancel, for changing the rule text — justified
  3. An open edit counts as an unsaved draft for the store-switch, navigation and unload guards — justified
  4. Only one row can be in edit at a time; the other rows' Edit buttons are disabled — justified
  5. POST /api/lessons accepts replaces and rewrites the row in place in JSONL (LessonStore.replace_rule) — justified
  6. New refusal codes (replace_source_missing, replace_ambiguous, replace_collision, replace_vector_unsupported), each with its own user-facing sentence — justified
  7. Lesson list rows carry rule_editable: false when the rule text is redacted, and those rows offer no Edit — justified
  8. An edit sends lessons.changed with action updated, and the old wording is audited as superseded — justified

[FIRST-PRINCIPLES-REVIEWED] d3f23ca

Description read

[DESCRIPTION-READ] 6868cde0920496a10d36f768aba029122b5cb676c379c83f4daf11938d1ac957

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 6, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

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

UX-Verdict: PASS

Nothing blocks: the blind reader identified search, Edit, Save, Cancel and Clear filter correctly and said they would use each one. The issues left are on the rare refusal and refresh-failure paths.

Notes

  • After a save whose list re-read failed (shot-05), the row still shows the old text under "Edit saved, but the list could not be refreshed". The reader "can't tell whether my change was saved". The fix: in saveEdit, update the local row to text before calling loadLessons().
  • edit_ambiguous, "Two lessons share this text…", read as contradicting the two different rows on screen (shot-07). Suggested wording: "Two lessons had this lesson's original wording, so the edit can't tell which one to change. Add the corrected wording as a new lesson instead."
  • The single-line <Input> in the edit cell cuts long rules off ("…JavaScript r", shot-03), so the user can't see the whole rule they're correcting. Use an auto-growing textarea there.

[UX-REVIEWED] d3f23ca

Description read

[DESCRIPTION-READ] 5cd910e39fdc276773b5513278354ec2593825f35755f99e53c5e94a79d94ab4

That sha256 names everything this verdict read: the PR description, plus the 11 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 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] d3f23ca

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

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

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] d3f23ca

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

@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 Nov 6, 2026
@bolichen97
bolichen97 enabled auto-merge (squash) November 6, 2026 14:13
@bolichen97
bolichen97 force-pushed the fix/17982-lessons-search-edit branch from 7634f4e to 3ec8a4d Compare November 6, 2026 23:33
@bolichen97

Copy link
Copy Markdown
Contributor Author
  • span=bb73f995b19c Edit is offered on lessons whose rule text was redacted

fixed in 3ec8a4d: GET /api/lessons marks a row whose rule the redaction changed rule_editable: false, and the Memory tab offers no Edit on it, so the placeholder can never be saved.
The route also refuses (writes nothing, replace_source_missing) an edit whose replaces.rule matches no stored row, which a redacted listing never does. Tests: test_a_redacted_rule_is_listed_as_not_editable, test_an_edit_of_a_row_that_is_not_stored_writes_nothing.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • span=d5cd51f321e3 Create-then-delete can discard unrelated lessons or lose the edited lesson's tier

fixed in 3ec8a4d: the edit sends replaces and the JSONL store rewrites that one row in place under its lock (LessonStore.replace_rule), so the row count never changes and a full store evicts nothing; the row keeps its tier.
An edit onto another row's text (replace_collision), of two same-text rows (replace_ambiguous) or against a vector tier (replace_vector_unsupported) writes nothing. Tests in test/test_lesson_edit_replace.py, proven by reverting the fix.

@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 Nov 6, 2026
@bolichen97
bolichen97 force-pushed the fix/17982-lessons-search-edit branch from 3ec8a4d to 0f5e935 Compare November 7, 2026 00:10
@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 Nov 7, 2026
@bolichen97
bolichen97 force-pushed the fix/17982-lessons-search-edit branch from 0f5e935 to 9159c4b Compare November 7, 2026 00:52
@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 Nov 7, 2026
@bolichen97
bolichen97 force-pushed the fix/17982-lessons-search-edit branch from 9159c4b to b3dc4c6 Compare November 7, 2026 03: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 Nov 7, 2026
@bolichen97
bolichen97 force-pushed the fix/17982-lessons-search-edit branch from b3dc4c6 to 06dbb84 Compare November 7, 2026 03:44
@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: checking Automated validation is still running labels Nov 7, 2026

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

🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:

REQUEST_CHANGES at c95c70e. The behaviour is right; three statements describe a request shape the code no longer sends, and one of them is in shipped client code.

What it does for users: the Lessons card under Overview > Memory gets a search box over the listed window (newest 50) and a per-row Edit that rewrites one JSONL lesson's rule in place, keeping its position, file tier, applies-tier and NOT-clause, instead of delete-and-re-add, which lost all of those.

Blocking (false statements):

  1. website/src/api/client/memory.ts:204-205 says the edit sends the rule back "with the edited row's own file, scope, tier and NOT-clause". The row argument's type has no negative or applies field, MemoryTab.tsx saveEdit sends only scope, workspace, repo_scope and replaces, and the server keeps the stored clause and tier itself (learn.py replace_rule, and the route's own comment "the row's STORED clause, which the body never carries"). Please reword to what is sent: the row's file (scope / workspace), repo_scope and the replaces selector.
  2. The PR body's Tests section says "Save sends one request with the row's scope, workspace, repo_scope, tier, clause and replaces", and the test at website/src/test/OverviewMemoryTabCov80.test.tsx:777 is titled "carrying its own scope, tier and clause" while its assertion (line 786) checks a body with no clause and no applies-tier. Please retitle the test and fix the PR body line.
  3. The same file's test at line 880, "whose scope or NOT-clause cannot be sent back", names a NOT-clause condition that the Edit gate no longer has (MemoryTab.tsx gate: l.scope, l.repo_scope, l.rule_editable). Please drop "or NOT-clause".

Non-blocking:

  • MemoryTab.tsx:114-118: the "A lesson row's key" doc comment now sits above EDIT_REFUSALS instead of lessonKey (line 126). Move it down.

Evidence:

  • learn.py:474 LessonStore.replace_rule does the read-decide-write under one lock and writes only on replaced; the source row keeps ts, tier and negative, so the row count is unchanged at the cap.
  • Mutation: removing the ambiguous return at learn.py:511 reddens test/test_lesson_edit_replace.py::test_an_edit_whose_text_names_two_rows_writes_nothing (expected False, 'replace_ambiguous', got True, None).
  • Mutation: replacing the replace_vector_unsupported refusal at cron_lessons.py:419 with a pass reddens test_an_edit_against_a_populated_vector_tier_writes_nothing.
  • Mutation: dropping l.rule_editable !== false from the Edit gate reddens "offers no Edit on a row whose rule is redacted or whose scope or NOT-clause cannot be sent back".
  • Local runs: test/test_lesson_edit_replace.py plus test/test_lesson_changed_events.py, 46 passed; OverviewMemoryTabCov80.test.tsx, 67 passed. Full suites were not run locally.
  • Guards are reused, not bypassed: replaces is parsed after the restricted-session, writes-switch and LEARN_ADD_SCHEMA checks in api_lessons_create, and it stays outside LEARN_ADD_SCHEMA so the learn_add tool cannot send it. A named workspace must be configured and not "default" before the edit picks a file.
  • i18n: the nine new keys are in every manual catalog (en.json is generated and holds none of this card's keys, same as main).
  • Spec: learn-cron-dashboard.md updated in the same commit and matches the code.
  • CI at this head: 83 success, 11 skipped, 0 failing; PR Readiness success; all five bot lanes PASS with no HOLD; no human reviews; merges cleanly into main (merge-tree exit 0).

Source-only: the vector-store path beyond the refusal (MagicMock-backed in the test), and the screenshots.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: passed Eligible automated validation passed for the current revision labels Nov 7, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD (changes_requested) at c95c70e.

buluoray has an active CHANGES_REQUESTED review at this head, and PR Readiness is red on it. I checked the three statements that review names, and each is stale:

  • memory.ts L204 says the edit sends the row's tier and NOT-clause. It sends only scope, workspace, repo_scope and replaces.
  • The test at L777 is titled with tier and clause, but it asserts neither. The Tests line in the PR body has the same wording.
  • The test at L880 names a NOT-clause condition that the Edit gate no longer has.

To clear the hold, fix those three, then get buluoray to re-review or dismiss the request. A later commit needs a fresh review.

The behaviour itself looks sound. replace_rule rewrites one row in place under the store lock, so a full store evicts nothing. It refuses missing, ambiguous and colliding edits without writing. The replaces field sits outside LEARN_ADD_SCHEMA and is parsed after the route's existing guards (L238). Edits against a vector tier are refused. All five lanes pass at this head, the prior Opus and GPT findings are fixed, and every other check is green.

AI findings judged non-blocking:

  • First Principles Item 6: the superseded response field has no reader. It is unused type surface.
  • UX evidence gaps: screenshots 03, 04 and 05 predate HEAD. The disabled gate (MemoryTab.tsx L904) and the copy are in the diff and tested.
  • UX notes: an inline 'Add as new lesson' action and a wrapping edit box. These are polish.

— crew-pr-reviewer (r149)

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • Other rows' Edit disabled while one row is in edit (shots 03 and 04 predated HEAD)

fixed in c95c70e: shots 03 and 04 re-captured from this head running in an isolated gateway; while one row is in edit, every other row's Edit renders disabled (disabled={editing !== null}), light and dark.
New images in the description: https://github.com/user-attachments/assets/2d937e5b-2f67-4dce-b697-03fd5dd5d71e (light), https://github.com/user-attachments/assets/6d0eed15-54d1-47a8-b925-622039ed2e5c (dark).
The capture asserted 4 of 4 other rows' Edit disabled and Save enabled on the edited row before writing each frame; the search and no-match shots were re-captured from the same head.

[operator: bolichen97]

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • Refusal copy for replace_ambiguous (shot 05 predated HEAD)

fixed in c95c70e: shot 05 re-captured from this head; the gateway itself answered refused / replace_ambiguous to an edit of one of two stored rows sharing text and scope, and the notice reads the shipped sentence "Two lessons share this text, so this edit cannot choose one. Add the corrected wording as a new lesson instead.", with the draft kept in the row.
New image in the description: https://github.com/user-attachments/assets/98f7a403-0e4a-40ca-bcbf-7203b87a45f2; the "shot predates the reworded sentence" caveat is gone from the description.

[operator: bolichen97]

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 8, 2026
@bolichen97
bolichen97 force-pushed the fix/17982-lessons-search-edit branch from c95c70e to 9d7e30b Compare November 8, 2026 23:35
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/modules/learn-cron-dashboard.md, src/kiro_crew/dashboard/handlers/cron.py, src/kiro_crew/dashboard/handlers/cron_lessons.py, src/kiro_crew/lesson_events.py, website/src/types/index.capabilities.ts and the website/src/i18n/locales/ catalogs since this head went green (d27a5fd -> c4f4ce3); CI re-running.

The rebase cleared a merge conflict in learn-cron-dashboard.md. Main had added the PATCH /api/lessons clause to the same line, and the resolution keeps both texts. Head is now 9d7e30b.

[operator: bolichen97]

@bolichen97

Copy link
Copy Markdown
Contributor Author

resolution: narrowed -- this round fixes wording and removes two things, and adds no mechanism

  • Item 6: superseded? on createLesson's response type has no reader

removed in 9d7e30b: the field and its comment are gone from website/src/api/client/memory.ts. Nothing in website/src read it, and the route still returns superseded for its own audit.

[operator: bolichen97]

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] @buluoray thank you: all three statements were stale, and each is fixed at 9d7e30b. Wording only, no behaviour change:

  1. website/src/api/client/memory.ts: the comment now says what an edit sends, the row's file (scope / workspace) and repo_scope plus replaces, and that the server keeps the row's stored tier and NOT-clause.
  2. The test is titled "rewrites the row with one replace request carrying its own scope, workspace and repo_scope", and the body's Tests line names the same keys.
  3. The Edit-gate test reads "offers no Edit on a row whose rule is redacted or whose scope cannot be sent back".

Non-blocking: the "A lesson row's key" doc comment now sits above lessonKey.

The same push also:

  • removes the unused superseded? field from createLesson's response type. That was First Principles item 6, which the HOLD note above also lists.
  • stops an edit whose list re-read fails from showing the delete banner ("Lesson deleted, ..."). The re-read is left to the next refresh, as the Add box does, and a new test pins it.
  • rebases onto main to clear the conflict in learn-cron-dashboard.md.

The screenshots are re-captured from 9d7e30b. The two UX notes (an inline "Add as new lesson" action, and a wrapping edit box) are new scope, so they stay out of this PR.

Could you re-review at 9d7e30b when you have a moment?

@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Nov 8, 2026

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

🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:

REQUEST_CHANGES at 9d7e30b. Everything from my change request at c95c70e is fixed. I checked each item against the source at this head. One new gap remains, in code this push added. It is the one GPT 6.1 flagged, and I agree with it.

Fixed, each checked at 9d7e30b:

  1. website/src/api/client/memory.ts:210-214: the comment now says replaces names the edited row. The type sends only scope, workspace, repo_scope and replaces.
  2. OverviewMemoryTabCov80.test.tsx:777 is now titled "carrying its own scope, workspace and repo_scope", and the PR body's Tests line names the same keys.
  3. OverviewMemoryTabCov80.test.tsx:896 no longer names a NOT-clause condition.
  4. The "A lesson row's key" comment now sits above lessonKey (MemoryTab.tsx:122-126).

Blocking:

  1. A saved edit whose list re-read fails now shows nothing at all.
    • MemoryTab.tsx:604-607: after replaced, the editor closes and await loadLessons().catch(() => undefined) drops the error.
    • Trigger: Save returns replaced, then GET /api/lessons fails, for example during a gateway restart.
    • Outcome: the row still shows the old wording, with no notice. The user cannot tell a saved edit from a lost one. If they edit the same row again, the server no longer holds the old text. The retry is then refused with replace_source_missing, whose notice ("This lesson changed or was removed. Reload the list and try again.") is the first sign the first save worked.
    • At c95c70e this path showed the delete banner, which was wrong in the other direction. Dropping that banner was right; dropping every notice is the gap.
    • Smallest fix: keep the editor closed, and show the re-read failure through an ErrorNotice that says the edit was saved but the list could not be reloaded. Add one test with api.lessons rejecting after a replaced save, asserting that notice. The Add box has the same silent path on main, so leaving it alone is fine for this PR.
    • This is the GPT 6.1 finding on this head (errors-use-error-notice). Please fix it rather than override it.

Non-blocking:

  • The rebase, the removed superseded? field and the re-captured screenshots look fine.

CI at this head: 84 success, 11 skipped, 2 failing (GPT 6.1 Review, for the finding above; PR Readiness, which waits on it). Auto-merge is on, so once this is fixed and re-reviewed the PR merges on its own.

The Lessons card could list, sort and delete a lesson but not find one
by its text or correct one without deleting it and typing it again,
which also lost the row's scope, tier and NOT-clause.

A search box filters the listed lessons by rule text, and each row
gets an Edit. Save sends the new text through POST /api/lessons with
the row's scope and a `replaces` selector naming the row, and the
JSONL store rewrites that one row in place under its lock: the row
keeps its tier and NOT-clause, the row count never changes, and any
outcome other than `replaced` writes nothing and keeps the draft. A
list re-read that fails after a saved edit says the edit was saved.
A row whose listed rule is redacted offers no Edit.

Closes #17982
@bolichen97
bolichen97 force-pushed the fix/17982-lessons-search-edit branch from 9d7e30b to d3f23ca Compare November 10, 2026 15:02
@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: the edit's own ErrorNotice is titled for the step that failed (save or re-read), as the delete notice already is

  • span=d5cd51f321e3 Saved edits silently swallow list-refresh failures

fixed in d3f23ca: after a replaced save the editor stays closed and a rejected list re-read sets the edit notice with its own title, "Edit saved, but the list could not be refreshed", plus the error text; the delete banner is not used.
The extended test in OverviewMemoryTabCov80.test.tsx makes api.lessons reject after a replaced save and asserts that notice, the closed editor and no "Lesson deleted" text; it fails with the old .catch(() => undefined).
Class sweep: the only other .catch(() => undefined) under website/src/pages/overview/ (KiroCrewCfgTab.tsx) keeps a write chain alive while the caller still reports its own error.

[operator: bolichen97]

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] @buluoray thank you, agreed: a saved edit whose list re-read failed said nothing at all. Fixed at d3f23ca, as you suggested:

  • MemoryTab.tsx: after a replaced save the editor stays closed and the re-read runs in a try/catch. A rejected re-read sets the edit's own ErrorNotice, titled "Edit saved, but the list could not be refreshed", with the error text. The edit notice now carries the step that failed, the same way the delete notice does. It never uses the delete banner.
  • One new string, edit_saved_refresh_failed, in every catalog. The spec sentence in learn-cron-dashboard.md names it.
  • Test: the existing re-read test in OverviewMemoryTabCov80.test.tsx makes api.lessons reject after a replaced save. It asserts the notice, the error text, the closed editor, and that neither "Could not save the edit" nor "Lesson deleted" appears. It fails on 9d7e30b and passes here.

The Add box's silent re-read on main is unchanged, as you said. A re-capture of this new state is in the description.

@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 Nov 10, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

The review found nothing that blocks this head. It still needs a maintainer: the change request from buluoray is open. Its last blocker was a list re-read that failed silently after a saved edit. That now looks fixed at this head, because saveEdit catches the reload error and shows an error notice. buluoray, please re-review or dismiss when you can.

What the review checked on d3f23ca:

  • The edit path from POST /api/lessons through the replaces parser, the vector-tier refusal and LessonStore.replace_rule. replaces is parsed after the existing session, restricted-session, writes-switch and schema guards. The learn_add tool builds a fixed payload, so an agent cannot send it.
  • replace_rule refuses missing, ambiguous and colliding rows and writes nothing on a refusal. It keeps the row count, tier and stored clause, so an edit at the 200-row cap evicts nothing.
  • The backend tests use a real store on tmp_path and check each refusal by the state it leaves.
  • Every touched file stays under the line cap, all locale files are present, and the branch merges cleanly onto main.

Done well: the content screens run against the clause stored now, not the clause the client listed. A clause another writer attached therefore survives an edit.

Optional:

  • MemoryTab.tsx saveEdit sends the row's listed category back through the add schema. A JSONL row whose stored category is outside tool, preference and knowledge gets a 400 on every Save, even though replace_rule keeps the stored category. One fix is to skip or clamp the category when replaces is present.
  • In OverviewMemoryTabCov80.test.tsx, the two refresh tests wait for api.lessons calls to exceed 1. The two mount reads already pass that, so the tests do not wait for the refresh itself. Take a baseline count before the rerender, then wait for a row from the refreshed response.
  • The replaces_invalid, replaces_scope_mismatch and refused_volatile branches have no test, and neither does the V2 vector refusal. One parametrized test over malformed replaces values would pin them.

Once this merges, #18831 can be closed as superseded.

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

Approve on d3f23ca. Both of Ray's change requests (5 items over 2 reviews) are addressed at d3f23ca; the only delta since 9d7e30b is the saved-but-not-reloaded ErrorNotice plus its i18n key in all 13 manual catalogs, and the in-place replace still writes only on replaced with no lesson dropped or reordered. Each requested change is addressed: (1) memory.ts comment now states what is sent (memory.ts:204-206, type :211-214); (2) test title and PR body no longer claim scope/tier/clause (OverviewMemoryTabCov80.test.tsx:777 and the PR body Tests line); (3) test name matches the condition that exists (test :898, MemoryTab.tsx:907); (4) the lessonKey comment sits on lessonKey (MemoryTab.tsx:122-126); (5) saved-but-not-reloaded now shows an ErrorNotice (MemoryTab.tsx:604-612, :889) with its key in all 13 manual catalogs and a test (OverviewMemoryTabCov80.test.tsx:795-811). Decisive lines: website/src/pages/overview/MemoryTab.tsx:604-612, website/src/pages/overview/MemoryTab.tsx:889, website/src/test/OverviewMemoryTabCov80.test.tsx:795-811, src/kiro_crew/learn.py:474-531

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Thanks for the three optional notes on d3f23ca. I checked each one against the code. None of them changes this PR, which stays as approved:

  1. Category outside tool, preference and knowledge. Real, and rare. On the JSONL store the consolidation and task-runner writers save the extractor's category as given, and the list shows it unchanged. saveEdit then sends it back through LEARN_ADD_SCHEMA, whose enum refuses it with a 400. The Save is refused with a visible message, nothing is written, and delete-then-add still works. Tracked in Memory tab: saving a lesson edit is refused when the row's category is not tool, preference or knowledge #34720 (the smallest fix is to skip the category when replaces is set, since replace_rule keeps the stored one). It is not fixed here because a push would restart CI and review on an approved, green head for a Low.
  2. The two refresh tests' > 1 wait. Agreed: both mount effects call loadLessons, so the wait is already met before the rerender. The code is still right here. The edited row is appended from the edit's own editing.row whenever a refreshed window stops listing it (MemoryTab.tsx around line 383), so the draft cannot be dropped by a refresh. This is about how strong the test is, not a gap in the code, and it is left as is.
  3. Untested refusal branches (replaces_invalid, replaces_scope_mismatch, refused_volatile, the V2 vector refusal). True. Each one refuses a hand-built or racing request and writes nothing, and the Coverage Gate passes. Adding a parametrized test for them is coverage advice beyond this PR's goal, so it is left as is.

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.

Lessons table: add text search and inline edit of a rule

4 participants