[GH-ISSUE #1930] [Issue]: Long-Term Memory: every later chat piece's thread and relationship updates must be accepted one at a time #1825

Closed
opened 2026-11-07 16:36:56 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Promansis on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1930

Originally assigned to: @Promansis on GitHub.

Summary

Since #1782, each chat-messages piece after the first sees the previous piece's open threads and continues them in place. Apply treats such an in-place section update as a "rewrite", and a rewrite may not be applied together with anything else. So accepting a later piece's draft in one go applies the safe rows and leaves every continued thread and every relationship state change behind a red "blocked" notice, to be accepted one by one. Auto-apply (API only) applies nothing from such a draft.

Affected package

long-term-memory (1.5.15)

Expected behavior

A section the extractor replaces on purpose is that section's normal way of changing, not a destructive edit:

  • a thread's sections (the compiler's rolling_until_resolved lifecycle),
  • a relationship's state, a character's items and progression (superseding).

Accepting a draft with several rows, including such updates, applies them together. The row still shows as Rewrite with its before/after diff, so the reader sees what is replaced. The one-at-a-time rule stays for the changes that remove or re-label something: set_status (archive, resolve), set_title, set_subjects, and any section update on an anchor note.

Actual behavior

Review queue, a chat with two imported pieces, the second piece's draft has 6 rows: 4 new events, 1 thread continuation (update_section on the existing thread's section), 1 relationship state update. Select all, Accept:

  • preflight marks both update rows blocked with destructive_disposition_requires_explicit_review; the panel turns red with "Destructive disposition requires explicit review: Rewrite and other destructive changes must be reviewed and applied one at a time." (there is no label key for the code, so the raw message shows);
  • the 4 events apply; the thread and the relationship wait;
  • the user accepts the thread row alone, then the relationship row alone: three Accepts for one draft, and every later piece of the chat repeats it.

With auto-apply on (autoApplyLowRiskOnly, API only): apply throws the same 409 for the whole batch; source-processing.ts catches it since #1782 and leaves the entire draft for review, so none of the piece's rows apply, not even the new events (the OT-3 case).

Where the rule lives

  • Disposition: server/src/services/long-term-memory/drafts/draft-projector.ts dispositionForMutation (~403), mirrored by drafts/reconciliation.ts fallbackDisposition (~235): update_section/append_section is a "rewrite" whenever isAdditiveLtmSection (draft-projector.ts ~158) is false, which is exactly the set of sections the compiler replaces on purpose plus any section on an anchor-tagged note.
  • Compiler: extraction/evidence-unit-compiler.ts lifecycleForUnit (~537) gives threads rolling_until_resolved and relationship state / items / progression superseding; shouldAppend (~525) then emits update_section (~185) instead of append_section. The rewrite is the design, not a model mistake.
  • Guard, preflight: reconciliation.ts ~611: bulkApply = selected.length > 1 and disposition === "rewrite" → blocker on the row.
  • Guard, apply: reconciliation.ts ~955: userSelectedCount > 1 and any projected row with disposition === "rewrite" → LtmDraftApplyError 409 for the whole batch.
  • Client: client/src/features/long-term-memory/review/ReviewQueue.tsx ~1256 sends only readyMutationIds, so the UI already applies the safe rows and keeps the blocked ones.

Minimal fix

One helper next to isAdditiveLtmSection in draft-projector.ts:

// A thread's sections and a relationship's state (items, progression too) are replaced on purpose by every
// later piece; only an anchor note's sections and status, title or subject changes still apply one at a time.
export function isDestructiveLtmRewrite(note: Pick<LtmNote, "tags"> | null, mutation: LtmDraftMutation, disposition: LtmMutationDisposition)

returns false unless disposition === "rewrite"; for update_section/append_section returns Boolean(note?.tags.includes("anchor")); for every other kind returns true.

Both guard sites in reconciliation.ts test it instead of disposition === "rewrite":

  • preflight (~611): isDestructiveLtmRewrite(existing.get(mutationTargetId(mutation)) ?? null, mutation, disposition); existing already holds the targets (~601).
  • apply (~955): over the projected rows, with the row's mutation from selected and the group's existing note (the projector's before; or fetch the targets with storage.getNotesByIds as preflight does).

DESTRUCTIVE_DISPOSITION_MESSAGE, the error code, the disposition values and the client stay as they are. source-processing.ts ~473 keeps its catch (status changes and anchor rewrites still need it); shorten its comment to say which cases remain.

Changelog (## Unreleased, patch): "Review: a later chat piece's thread and relationship updates apply together with the rest of the draft instead of one at a time."

Regression

tests/long-term-memory-storage.regression.ts, in the destructive block (~2650–2750, destructiveTarget is a thread with a set_status row):

  1. A draft with an update_section on the thread's section plus an add_link: preflightLongTermMemoryDraft with both ids has no blockers and the update row still reports disposition: "rewrite"; applyLongTermMemoryDraft with both ids applies both and the section text is replaced.
  2. The same update_section on a note tagged anchor, selected with another row: still blocked with destructive_disposition_requires_explicit_review, apply still rejects.
  3. The existing set_status + add_link case keeps its blocker and rejection (already asserted ~2725–2740).

Steps to reproduce

  1. Import a chat long enough for two pieces (over 24,000 characters) with the Standard setting; let piece 1 create a thread and a relationship.
  2. Open Review for piece 2's draft, select all rows, Accept.
  3. The thread and relationship rows stay blocked with the one-at-a-time message; the rest applies. Accept each remaining row by itself.

Environment

  • Marinara Engine version: staging
  • Package version: long-term-memory 1.5.15
  • Install type: source
  • OS + version: any
  • Browser or app shell: any

Logs, screenshots, or video

Preflight row blocker: { code: "destructive_disposition_requires_explicit_review", message: "Rewrite and other destructive changes must be reviewed and applied one at a time." }. Apply: HTTP 409 with the same code.

Additional context

  • Non-goal of #1782 (its draft lists this rule as a separate issue). Tracker OT-23.
  • Narrows OT-3 (auto-apply fails the whole source): with this change an auto-applied piece whose rewrites are thread or relationship updates applies in full. A piece with a status change or an anchor rewrite still leaves its whole draft for review; that remainder stays with OT-3 until the app exposes auto-apply.
  • Alternatives considered:
    • Only when the update comes from the next piece of the same chat. Needs provenance on the section's last contribution and leaves a chat-summary import or a second chat updating the same relationship with the same friction. The section's lifecycle already says the replacement is intended, whatever the source.
    • A new disposition value ("update"): changes a shared enum the client labels and filters on; the before/after diff already tells the reader what happens.
    • Drop the guard entirely. Status, title and subject changes and anchor edits are the cases it was written for; keep those.
  • Non-goals: the wording and red styling of the blocked notice; a label key for the code; relationship state's medium unit risk (evidence-unit-validation.ts ~93), which keeps it out of auto-apply on its own.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1930 Originally assigned to: @Promansis on GitHub. ## Summary Since #1782, each chat-messages piece after the first sees the previous piece's open threads and continues them in place. Apply treats such an in-place section update as a "rewrite", and a rewrite may not be applied together with anything else. So accepting a later piece's draft in one go applies the safe rows and leaves every continued thread and every relationship state change behind a red "blocked" notice, to be accepted one by one. Auto-apply (API only) applies nothing from such a draft. ## Affected package `long-term-memory` (1.5.15) ## Expected behavior A section the extractor replaces on purpose is that section's normal way of changing, not a destructive edit: - a thread's sections (the compiler's `rolling_until_resolved` lifecycle), - a relationship's `state`, a character's `items` and `progression` (`superseding`). Accepting a draft with several rows, including such updates, applies them together. The row still shows as **Rewrite** with its before/after diff, so the reader sees what is replaced. The one-at-a-time rule stays for the changes that remove or re-label something: `set_status` (archive, resolve), `set_title`, `set_subjects`, and any section update on an anchor note. ## Actual behavior Review queue, a chat with two imported pieces, the second piece's draft has 6 rows: 4 new events, 1 thread continuation (`update_section` on the existing thread's section), 1 relationship `state` update. Select all, Accept: - preflight marks both update rows `blocked` with `destructive_disposition_requires_explicit_review`; the panel turns red with "Destructive disposition requires explicit review: Rewrite and other destructive changes must be reviewed and applied one at a time." (there is no label key for the code, so the raw message shows); - the 4 events apply; the thread and the relationship wait; - the user accepts the thread row alone, then the relationship row alone: three Accepts for one draft, and every later piece of the chat repeats it. With auto-apply on (`autoApplyLowRiskOnly`, API only): apply throws the same 409 for the whole batch; `source-processing.ts` catches it since #1782 and leaves the entire draft for review, so none of the piece's rows apply, not even the new events (the OT-3 case). ### Where the rule lives - Disposition: `server/src/services/long-term-memory/drafts/draft-projector.ts` `dispositionForMutation` (~403), mirrored by `drafts/reconciliation.ts` `fallbackDisposition` (~235): `update_section`/`append_section` is a "rewrite" whenever `isAdditiveLtmSection` (`draft-projector.ts` ~158) is false, which is exactly the set of sections the compiler replaces on purpose plus any section on an anchor-tagged note. - Compiler: `extraction/evidence-unit-compiler.ts` `lifecycleForUnit` (~537) gives threads `rolling_until_resolved` and relationship state / items / progression `superseding`; `shouldAppend` (~525) then emits `update_section` (~185) instead of `append_section`. The rewrite is the design, not a model mistake. - Guard, preflight: `reconciliation.ts` ~611: `bulkApply = selected.length > 1` and `disposition === "rewrite"` → blocker on the row. - Guard, apply: `reconciliation.ts` ~955: `userSelectedCount > 1` and any projected row with `disposition === "rewrite"` → `LtmDraftApplyError` 409 for the whole batch. - Client: `client/src/features/long-term-memory/review/ReviewQueue.tsx` ~1256 sends only `readyMutationIds`, so the UI already applies the safe rows and keeps the blocked ones. ### Minimal fix One helper next to `isAdditiveLtmSection` in `draft-projector.ts`: ```ts // A thread's sections and a relationship's state (items, progression too) are replaced on purpose by every // later piece; only an anchor note's sections and status, title or subject changes still apply one at a time. export function isDestructiveLtmRewrite(note: Pick<LtmNote, "tags"> | null, mutation: LtmDraftMutation, disposition: LtmMutationDisposition) ``` returns `false` unless `disposition === "rewrite"`; for `update_section`/`append_section` returns `Boolean(note?.tags.includes("anchor"))`; for every other kind returns `true`. Both guard sites in `reconciliation.ts` test it instead of `disposition === "rewrite"`: - preflight (~611): `isDestructiveLtmRewrite(existing.get(mutationTargetId(mutation)) ?? null, mutation, disposition)`; `existing` already holds the targets (~601). - apply (~955): over the projected rows, with the row's mutation from `selected` and the group's existing note (the projector's `before`; or fetch the targets with `storage.getNotesByIds` as preflight does). `DESTRUCTIVE_DISPOSITION_MESSAGE`, the error code, the disposition values and the client stay as they are. `source-processing.ts` ~473 keeps its catch (status changes and anchor rewrites still need it); shorten its comment to say which cases remain. Changelog (`## Unreleased`, patch): "Review: a later chat piece's thread and relationship updates apply together with the rest of the draft instead of one at a time." ### Regression `tests/long-term-memory-storage.regression.ts`, in the destructive block (~2650–2750, `destructiveTarget` is a thread with a `set_status` row): 1. A draft with an `update_section` on the thread's section plus an `add_link`: `preflightLongTermMemoryDraft` with both ids has no blockers and the update row still reports `disposition: "rewrite"`; `applyLongTermMemoryDraft` with both ids applies both and the section text is replaced. 2. The same `update_section` on a note tagged `anchor`, selected with another row: still blocked with `destructive_disposition_requires_explicit_review`, apply still rejects. 3. The existing `set_status` + `add_link` case keeps its blocker and rejection (already asserted ~2725–2740). ## Steps to reproduce 1. Import a chat long enough for two pieces (over 24,000 characters) with the Standard setting; let piece 1 create a thread and a relationship. 2. Open Review for piece 2's draft, select all rows, Accept. 3. The thread and relationship rows stay blocked with the one-at-a-time message; the rest applies. Accept each remaining row by itself. ## Environment - Marinara Engine version: staging - Package version: long-term-memory 1.5.15 - Install type: source - OS + version: any - Browser or app shell: any ## Logs, screenshots, or video Preflight row blocker: `{ code: "destructive_disposition_requires_explicit_review", message: "Rewrite and other destructive changes must be reviewed and applied one at a time." }`. Apply: HTTP 409 with the same code. ## Additional context - Non-goal of #1782 (its draft lists this rule as a separate issue). Tracker OT-23. - Narrows OT-3 (auto-apply fails the whole source): with this change an auto-applied piece whose rewrites are thread or relationship updates applies in full. A piece with a status change or an anchor rewrite still leaves its whole draft for review; that remainder stays with OT-3 until the app exposes auto-apply. - Alternatives considered: - **Only when the update comes from the next piece of the same chat.** Needs provenance on the section's last contribution and leaves a chat-summary import or a second chat updating the same relationship with the same friction. The section's lifecycle already says the replacement is intended, whatever the source. - **A new disposition value** (`"update"`): changes a shared enum the client labels and filters on; the before/after diff already tells the reader what happens. - **Drop the guard entirely.** Status, title and subject changes and anchor edits are the cases it was written for; keep those. - Non-goals: the wording and red styling of the blocked notice; a label key for the code; relationship state's `medium` unit risk (`evidence-unit-validation.ts` ~93), which keeps it out of auto-apply on its own. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-11-07 16:36:56 +07:00
  • closed this issue
  • added the
    bug
    label
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Agents#1825
No description provided.