[GH-ISSUE #1534] [Issue]: Long-Term Memory: an extraction fails outright when a dropped unit belongs to a note id with a digit after the prefix #1509

Closed
opened 2026-10-22 04:02:49 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @Promansis on GitHub.

Summary

An extraction can fail outright, and nothing from that source is kept, when a unit belongs to a note whose id has a digit right after the prefix (an older note such as rel_96dfe1cd8f75, or a new character named "2B", char_2_b), and validation then drops that unit. Removing the prefix leaves 96dfe1cd8f75 as the unit's subjectId. That id is invalid, so when the dropped unit is stored as a recoveryCandidate, the identifier rule rejects the whole draft. This is a cause of #1040 that is still there: the #1040 fix normalizes case and punctuation, not a leading digit.

Affected package

long-term-memory 1.4.69 (upstream/staging 5984f0784).

S = packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory
SH = packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory

Expected behavior

  • When validation drops a unit matched to any valid note id, the copy kept for Review has a subjectId that passes the identifier rule and maps back to the same note id.
  • The draft is still written. The dropped unit appears as a rejected suggestion, as it does for every other note.

Actual behavior

  • subjectIdForTarget (S/identity/subject-identity.ts:2555; called at :1356 and :1433) removes char_ or rel_ and keeps whatever is left. subjectIdForResolvedNoteId (S/extraction/scoped-targets.ts:208) does the same.
  • For rel_96dfe1cd8f75, the rest is 96dfe1cd8f75. The identifier rule (SH/schema.ts:465-469, ^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$) requires a leading letter.
  • While the unit is kept, nothing fails, because mutations use the canonical note id. Three runs updated that note normally.
  • When validation drops the unit (here relationship_state_missing_caused_by), it is stored as extractionOutcome.droppedCandidates[n].recoveryCandidate. The recoveryCandidate.subjectId preprocess (SH/schema.ts:2209-2222, the #1040 fix) lowercases the id and replaces punctuation, but leaves the leading digit. ltmExtractionDraftSchema.safeParse in S/drafts/draft-store.ts:164 fails, so the draft is never written. #1057's debug event recovery_subject_id_validation_failed records the value.
  • Error: ZodError: extractionOutcome.droppedCandidates[2].recoveryCandidate.subjectId: Identifier must be lowercase snake_case.
  • Not only older notes: canonicalNoteIdForEntries builds char_<name slug>, so a character whose name starts with a digit (2B → char_2_b) hits the same failure when its unit is dropped. subjectIdForResolvedNoteId applies to every bucket's prefix (timeline_, thread_, world_, tone_, rel_, char_).
  • The structured-summary normalizer strips the prefix too (stripUnitSubjectPrefix, S/extraction/structured-summary-normalizer.ts:1774, via normalizeTargetShapeUnit and normalizeUnit). It runs before identity (S/extraction/source-extraction.ts:554) and again inside compileEvidenceUnitExtraction (S/extraction/evidence-unit-extraction.ts:1506) right before validation, so a fixed identity result is stripped again before the drop. The first pass matters too: identity rejects an untrusted subject with that unit as its recovery candidate.

Evidence

Private vault, private PL-1 harness (responses cached, so the run reproduces exactly). 1 of 16 runs failed this way. The vault has one note whose id has a digit after rel_ or char_: a relationship note from an older version. Only aggregate facts are shared.

Steps to reproduce

  1. Use a vault with a note whose id has a digit right after its prefix: an older note such as rel_96dfe1cd8f75, or a new character named "2B" (char_2_b).
  2. Run an extraction in which a unit resolves to that note and validation then drops that unit (in the failed run, relationship_state_missing_caused_by).
  3. The draft is never written: ltmExtractionDraftSchema.safeParse fails with ZodError: extractionOutcome.droppedCandidates[2].recoveryCandidate.subjectId: Identifier must be lowercase snake_case, and the debug event recovery_subject_id_validation_failed records the value. Nothing from that source is kept.

Minimal fix

Change only the copy of a dropped unit that becomes its recoveryCandidate: when its subjectId does not start with a letter, use the full note id (noteIdForEvidenceUnit) instead. Kept units keep the stripped form, because their subjectId feeds candidate reconciliation's identity key (S/extraction/candidate-reconciliation.ts:278, :291), validation's alias guard (S/extraction/evidence-unit-validation.ts:214) and a warning (:390); changing it there causes duplicates, a guard that fails open and a false warning.

  • One helper in S/extraction/evidence-unit-validation.ts, recoveryCandidateForUnit(unit): the unit unchanged when its subjectId starts with a letter, otherwise a copy with subjectId: noteIdForEvidenceUnit(unit).
  • Use it at the four places a unit becomes a recoveryCandidate: droppedCandidate in validation, dropLocalCharactersOutsideRoleplay and closeSourceEventGraph in S/extraction/evidence-unit-extraction.ts, and subjectRejection in S/identity/subject-identity.ts (identity rejects an unknown, untrusted or ambiguous subject with the unit as its recovery candidate, before the normalizer's second pass).
  • The full id names the same note: noteIdForEvidenceUnit (S/extraction/evidence-unit-validation.ts:748) calls prefixed(), which keeps a subjectId that already starts with rel_ / char_. So rel_96dfe1cd8f75 maps back to itself, and it passes the identifier rule.
  • Leave the recoveryCandidate.subjectId preprocess alone. Adding a letter there would point the suggestion at a note that doesn't exist.

CHANGELOG (user-visible): "An extraction no longer fails as a whole when it leaves out a memory about a note whose id has a digit right after its prefix. This hit older notes with ids such as rel_96dfe1cd8f75, and new characters whose name starts with a digit, such as "2B". The left-out suggestion couldn't be saved, so nothing from that source was kept. The left-out memory now appears as a rejected suggestion, like any other."

Regression proof

Write first; it must fail on the current code.

In tests/long-term-memory-storage.regression.ts, after the #1040/#1057 cases (:924, :975, :1484), add:

  • A vault with a relationship note rel_<digit…>. A relationship unit resolves to it and is then dropped by validation. Expect the draft to be written, the dropped candidate's recoveryCandidate.subjectId to equal rel_<digit…>, and no recovery_subject_id_validation_failed event.
  • The same drop-then-draft check for a "2B" developments fact (char_2_b, dropped as source_event_graph_open), and both cases against a structured summary as well as the unstructured source.
  • An identity drop: a unit naming 3_c with no subject names is rejected by identity, and its recovery copy has char_3_c. This fails if only identity keeps the old code.
  • A guard: a kept unit resolved to the same note still updates rel_<digit…> and creates no rel_rel_… note. It passes today.

Environment

  • Marinara Engine version: 2.5.1 (staging 87d1ccadc)
  • Package version: long-term-memory 1.4.69 (upstream/staging 5984f0784)
  • Install type: source (code reading; a cached harness run on a private vault)
  • OS + version: not platform-specific
  • Browser or app shell: any

Logs, screenshots, or video

The error is quoted under Actual behavior. The failing run used a private vault, so only aggregate facts are shared.

Additional context

Tracker item EX-I12, found during the PL-1 harness run. It is a remaining cause of #1040; #1057 added the recovery_subject_id_validation_failed debug event.

A separate, pre-existing follow-up: a canonical id whose slug starts with the prefix word loses it. Roster "Char Aznable" gives char_char_aznable, subjectIdForTarget strips it to char_aznable, and prefixed() keeps that, so compile creates char_aznable.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Promansis on GitHub (Oct 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1534 Originally assigned to: @Promansis on GitHub. ## Summary An extraction can fail outright, and nothing from that source is kept, when a unit belongs to a note whose id has a digit right after the prefix (an older note such as `rel_96dfe1cd8f75`, or a new character named "2B", `char_2_b`), and validation then drops that unit. Removing the prefix leaves `96dfe1cd8f75` as the unit's `subjectId`. That id is invalid, so when the dropped unit is stored as a `recoveryCandidate`, the identifier rule rejects the whole draft. This is a cause of #1040 that is still there: the #1040 fix normalizes case and punctuation, not a leading digit. ## Affected package `long-term-memory` 1.4.69 (`upstream/staging` 5984f0784). `S` = `packages/long-term-memory/src/engine/packages/server/src/services/long-term-memory` `SH` = `packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memory` ## Expected behavior - When validation drops a unit matched to any valid note id, the copy kept for Review has a `subjectId` that passes the identifier rule and maps back to the same note id. - The draft is still written. The dropped unit appears as a rejected suggestion, as it does for every other note. ## Actual behavior - `subjectIdForTarget` (`S/identity/subject-identity.ts:2555`; called at `:1356` and `:1433`) removes `char_` or `rel_` and keeps whatever is left. `subjectIdForResolvedNoteId` (`S/extraction/scoped-targets.ts:208`) does the same. - For `rel_96dfe1cd8f75`, the rest is `96dfe1cd8f75`. The identifier rule (`SH/schema.ts:465-469`, `^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$`) requires a leading letter. - While the unit is kept, nothing fails, because mutations use the canonical note id. Three runs updated that note normally. - When validation drops the unit (here `relationship_state_missing_caused_by`), it is stored as `extractionOutcome.droppedCandidates[n].recoveryCandidate`. The `recoveryCandidate.subjectId` preprocess (`SH/schema.ts:2209-2222`, the #1040 fix) lowercases the id and replaces punctuation, but leaves the leading digit. `ltmExtractionDraftSchema.safeParse` in `S/drafts/draft-store.ts:164` fails, so the draft is never written. #1057's debug event `recovery_subject_id_validation_failed` records the value. - Error: `ZodError: extractionOutcome.droppedCandidates[2].recoveryCandidate.subjectId: Identifier must be lowercase snake_case`. - Not only older notes: `canonicalNoteIdForEntries` builds `char_<name slug>`, so a character whose name starts with a digit (`2B` → `char_2_b`) hits the same failure when its unit is dropped. `subjectIdForResolvedNoteId` applies to every bucket's prefix (`timeline_`, `thread_`, `world_`, `tone_`, `rel_`, `char_`). - The structured-summary normalizer strips the prefix too (`stripUnitSubjectPrefix`, `S/extraction/structured-summary-normalizer.ts:1774`, via `normalizeTargetShapeUnit` and `normalizeUnit`). It runs before identity (`S/extraction/source-extraction.ts:554`) and again inside `compileEvidenceUnitExtraction` (`S/extraction/evidence-unit-extraction.ts:1506`) right before validation, so a fixed identity result is stripped again before the drop. The first pass matters too: identity rejects an untrusted subject with that unit as its recovery candidate. ### Evidence Private vault, private PL-1 harness (responses cached, so the run reproduces exactly). 1 of 16 runs failed this way. The vault has one note whose id has a digit after `rel_` or `char_`: a relationship note from an older version. Only aggregate facts are shared. ## Steps to reproduce 1. Use a vault with a note whose id has a digit right after its prefix: an older note such as `rel_96dfe1cd8f75`, or a new character named "2B" (`char_2_b`). 2. Run an extraction in which a unit resolves to that note and validation then drops that unit (in the failed run, `relationship_state_missing_caused_by`). 3. The draft is never written: `ltmExtractionDraftSchema.safeParse` fails with `ZodError: extractionOutcome.droppedCandidates[2].recoveryCandidate.subjectId: Identifier must be lowercase snake_case`, and the debug event `recovery_subject_id_validation_failed` records the value. Nothing from that source is kept. ## Minimal fix Change only the copy of a dropped unit that becomes its `recoveryCandidate`: when its `subjectId` does not start with a letter, use the full note id (`noteIdForEvidenceUnit`) instead. Kept units keep the stripped form, because their `subjectId` feeds candidate reconciliation's identity key (`S/extraction/candidate-reconciliation.ts:278`, `:291`), validation's alias guard (`S/extraction/evidence-unit-validation.ts:214`) and a warning (`:390`); changing it there causes duplicates, a guard that fails open and a false warning. - One helper in `S/extraction/evidence-unit-validation.ts`, `recoveryCandidateForUnit(unit)`: the unit unchanged when its `subjectId` starts with a letter, otherwise a copy with `subjectId: noteIdForEvidenceUnit(unit)`. - Use it at the four places a unit becomes a `recoveryCandidate`: `droppedCandidate` in validation, `dropLocalCharactersOutsideRoleplay` and `closeSourceEventGraph` in `S/extraction/evidence-unit-extraction.ts`, and `subjectRejection` in `S/identity/subject-identity.ts` (identity rejects an unknown, untrusted or ambiguous subject with the unit as its recovery candidate, before the normalizer's second pass). - The full id names the same note: `noteIdForEvidenceUnit` (`S/extraction/evidence-unit-validation.ts:748`) calls `prefixed()`, which keeps a `subjectId` that already starts with `rel_` / `char_`. So `rel_96dfe1cd8f75` maps back to itself, and it passes the identifier rule. - Leave the `recoveryCandidate.subjectId` preprocess alone. Adding a letter there would point the suggestion at a note that doesn't exist. **CHANGELOG** (user-visible): "An extraction no longer fails as a whole when it leaves out a memory about a note whose id has a digit right after its prefix. This hit older notes with ids such as `rel_96dfe1cd8f75`, and new characters whose name starts with a digit, such as "2B". The left-out suggestion couldn't be saved, so nothing from that source was kept. The left-out memory now appears as a rejected suggestion, like any other." ## Regression proof Write first; it must fail on the current code. In `tests/long-term-memory-storage.regression.ts`, after the #1040/#1057 cases (`:924`, `:975`, `:1484`), add: - A vault with a relationship note `rel_<digit…>`. A relationship unit resolves to it and is then dropped by validation. Expect the draft to be written, the dropped candidate's `recoveryCandidate.subjectId` to equal `rel_<digit…>`, and no `recovery_subject_id_validation_failed` event. - The same drop-then-draft check for a "2B" `developments` fact (`char_2_b`, dropped as `source_event_graph_open`), and both cases against a structured summary as well as the unstructured source. - An identity drop: a unit naming `3_c` with no subject names is rejected by identity, and its recovery copy has `char_3_c`. This fails if only identity keeps the old code. - A guard: a kept unit resolved to the same note still updates `rel_<digit…>` and creates no `rel_rel_…` note. It passes today. ## Environment - Marinara Engine version: 2.5.1 (`staging` 87d1ccadc) - Package version: long-term-memory 1.4.69 (`upstream/staging` 5984f0784) - Install type: source (code reading; a cached harness run on a private vault) - OS + version: not platform-specific - Browser or app shell: any ## Logs, screenshots, or video The error is quoted under Actual behavior. The failing run used a private vault, so only aggregate facts are shared. ## Additional context Tracker item EX-I12, found during the PL-1 harness run. It is a remaining cause of #1040; #1057 added the `recovery_subject_id_validation_failed` debug event. A separate, pre-existing follow-up: a canonical id whose slug starts with the prefix word loses it. Roster "Char Aznable" gives `char_char_aznable`, `subjectIdForTarget` strips it to `char_aznable`, and `prefixed()` keeps that, so compile creates `char_aznable`. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-22 04:02:49 +07:00
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#1509
No description provided.