mirror of
https://github.com/Pasta-Devs/Marinara-Agents.git
synced 2026-12-03 18:55:07 +07:00
[GH-ISSUE #1512] [Issue]: Long-Term Memory: extraction requests repeat the link rules and ask the model for values the server sets #1499
Labels
No labels
agent: chess
agent: conversation-calls
agent: eightball
agent: haptic
agent: hierarchical-maps
agent: hierarchical-maps
agent: illustrator
agent: poker
agent: rock-paper-scissors
agent: tic-tac-toe
agent: uno
artifacts
bug
bugfix
build
catalog
ci
client
dependencies
docs
documentation
enhancement
feature
fixed-in-staging
in-pr
normal-scope
packages
pull-request
qol
regression
roadmap
scope-risk
server
soup
upstream
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Agents#1499
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Promansis on GitHub (Oct 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/1512
Originally assigned to: @Promansis on GitHub.
Summary
Every extraction request repeats itself and asks the model for values the server sets anyway:
validationRules, and again insidetargetNoteRules. The mode prompts restate them on top of that.sourceHashand the source evidence, which the server then overwrites or fills in.Removing this makes each request about 3,100 characters (about 775 tokens) shorter. In a live test with Claude Haiku 5.5 it also cut the answer by about a fifth per unit (233 to 184 visible tokens, mean of five and six runs). Today 17–19% of Haiku's answer text is copied
sourceHashand evidence, and 3–8 of 15 answers (6 on average) run past the 8,192-token default output cap. After the change, 2–3 do.On Claude Sonnet 5.5 the change passed the quality rule set in advance. On Haiku the final wording first missed that rule narrowly, judged against only two runs of today's code. A re-check with three fresh runs of each, under a rule written before it ran, passed. One signal is left for the PR. Haiku drops more units for an unknown character (29 against 24 per run on average), and the harness can't check names against the Engine's character list (see the open questions).
It also fixes three contract problems:
evidencelist, a blanktitleor anulloptional field drops the whole unit (F6).A broader world-note line was also measured on top of this change. It failed its pre-set rule on both models, so it is not part of this issue, and EX-I10 stays the path for world-note splitting (see "Broader world-note wording" below).
Affected package
long-term-memory1.4.55 (upstream/staging8b72729f1). Line references are at that commit.S=packages/long-term-memory/src/engine/packages/server/src/services/long-term-memorySH=packages/long-term-memory/src/engine/packages/shared/src/features/agents/long-term-memoryExpected behavior
sourceHash,evidence), and it does not send keys no rule uses, or scope ids.evidence: [],title: "",dimensions: null) is kept.response_formatstill tells the model the link object shape and the allowed relations.Actual behavior
serverEnforcedLinkPromptputs them in the system message (S/extraction/evidence-unit-extraction.ts:1193). They come back in the user JSON asvalidationRules(:1274), and a third time insidetargetNoteRules(:1294). The roleplay prompt restates them again (SH/constants.ts:79-81), and so do the core rules (:49).sourceHashand the source evidence (SH/constants.ts:71,:158,:163,:211,:217). The user JSON sends both too, asunitFields.evidence,sourceNote.evidence,sourceNote.sourceHashandrequiredEvidence(:1243,:1280-1284).normalizedEvidenceUnitRecordthen overwritessourceHash(:669) and fills inevidencewhen it is missing (:670).allowedStatuses,allowedImportance,streamAllowedStatuses,streamScanOrderandmodes. The scope also goes out twice, assourceNote.scopeandscope, which carry chat, group, character and persona ids.allowedTimelineRelations(:1262) names 9 of the 12 relations and leaves outextracted_from, which every event needs. A provider that ignoresresponse_formatsees no link object shape anywhere. Among the Engine's providers, only openai, google and the local sidecar send the schema.evidence: [](minimum 1), fortitle: "", and fornullin any optional field.Measurement
Method:
prepareLongTermMemorySource. That covers the catalog, recall window, provider call, parse, identity, reconciliation and compile. Nothing was applied, and package-default extraction settings were used.claude-haiku-5-5andclaude-sonnet-5-5throughclaude -p, effort low, with no response schema, like the Engine's Anthropic providers.Request size (deterministic): the proposed request is 2,862–3,466 characters shorter per source (mean 3,097, about 775 tokens). That is 15–25% of the text that is not the source, and 9–15% of the whole request. Each link rule appears once, and
sourceHashandrequiredEvidenceare gone.Haiku (
claude-haiku-5-5), 15 sources per run.reducedwas fixed in advance;reduced2andreduced3were shaped after seeing results (exploratory).reduced3is the fix proposed below.sectionKeysourceHash/evidenceSonnet (
claude-sonnet-5-5), 15 sources per run:sourceHash/evidenceWhat the variants taught:
reduced(fixed in advance) passes on Sonnet and fails on Haiku.{"responseContract": …}, and one of those also lacked its closing brace.nullfor optional fields on 17 units.sectionKeyon whole streams.reduced2names the top-level keys instead and treatsnullas absent. Run a passes, but run b lostsectionKeyon whole streams in two answers. Each time, these were the streams that the new "omit subjectNames" wording told to drop the field next tosectionKey; today's wording (all other streams: []) never lost it in 1,005 Haiku units.reduced3keeps today'ssubjectNameswording. No unit lostsectionKeyand no answer was wrapped in 45 Haiku and 15 Sonnet answers. It passes on Sonnet. On Haiku it misses the strict rule narrowly in all three runs:…],"},{…). Today's code had none in 45 Haiku answers.Kept units and link-caused drops are inside the rule in all three Haiku runs.
Haiku re-check. Three fresh runs of today's code against three of
reduced3. The rule was written before the runs (private pass-rules file, "Haiku re-check"): no more than one extra unusable answer in total, and on average no more rejections or link-caused drops than the worst run of today's code, with kept units at least 90% of its lowest run. Unknown-character drops are counted separately, because the harness has no character list. It passes every rule.sectionKeyAcross all runs of the same prompt (five of today's code, six of
reduced3), Haiku drops 24.2 units per run for an unknown character with today's code and 28.7 with the fix. The spread is wide (22–40 with the fix, 22–29 today). The harness can't tell whether those names would resolve against a real install's characters.Limits:
claude -padds about 640 tokens of Claude Code preamble, and it cannot set temperature or an output cap. The table counts visible tokens against the cap.Steps to reproduce
evidence_unit_requestprompt. "Every link target must resolve" appears three times, and bothrequiredEvidenceandsourceNote.evidenceare present with the same list.parseEvidenceUnitPayloada unit withevidence: []ortitle: "". It is dropped asinvalid_format.Minimal fix
One PR, patch bump. This is the
reduced3variant measured above, except where noted.S/extraction/evidence-unit-extraction.tsserverEnforcedLinkRules(:85-100): this stays the only place the link rules are stated. The system prompt carries them throughserverEnforcedLinkPrompt(:1193). For EX-I11, rule 2 (:88) becomes:'Every non-timeline unit with claimKind "change" must link to a timeline_event unit in this same response; if that event is not in the response yet, add it. Static units …'. The rest of the line stays.evidenceUnitMessages(:1164), user JSON:validationRules(:1274) and...validationRulesinsidetargetNoteRules(:1294). These are the second and third copies of the link rules.allowedStatuses(:1255),allowedImportance(:1256; the importance values are already listed inunitFields.importance),streamAllowedStatusesandstreamScanOrder(:1258-1261).allowedTimelineRelations(:1262-1272) withallowedLinkRelations: LTM_EXTRACTION_LINK_RELATIONS(:57). The response schema already allows all twelve relations at:500. The old list named nine of them and left outextracted_from, which every event must use.sourceNotetoidandtitle. Remove itsstatus,tags,scope,evidenceandsourceHash(:1278-1282), and the top-levelrequiredEvidence,scopeandmodes(:1284-1286). The chat, character and persona ids no longer go to the provider.unitFields:evidence(:1243);subjectNames(:1234) as it is (all other streams: []). Telling Haiku to omit the field made it drop the neighbouringsectionKeyfor whole streams in 3 of 45 answers (63 units);status(:1246) becomes'"active"; only thread units may use "resolved", when the open loop is closed';links(:1248) becomes'array of {"target": note id, "relation": one allowedLinkRelations value}; real links only, otherwise []'. This gives providers withoutresponse_formatthe link shape (F5 g).filteredScanOrder(:1166) andLTM_EXTRACTION_BUCKET_SCAN_ORDER(:46). Nothing else uses them.evidenceUnitResponseFormat(:426-528): remove theevidenceproperty (:475) and the two link descriptions that restate the rule (:487,:498). KeepsubjectNamesinrequired(:460). The live test never exercised the schema path, so the token saving there is not worth an untested risk to character facts (see open questions).normalizedEvidenceUnitRecord(:617) (F6)::624, buildrecordwithout null-valued keys. No field inltmEvidenceUnitSchemais nullable, so a null only ever turns an optional field into a rejection.title: undefinedfor a blank title.:670, setevidenceto the trusted list whenever one exists, instead of only when the field is missing. The harness merged trusted and provider strings, but no measured answer sent evidence, so the simpler rule behaves the same here. It also stops a provider from adding evidence strings the source never supplied.SH/constants.ts:56: "Return only one JSON object with the top-level keys summary and units. Do not output markdown, explanations, analysis, or thinking tags." Do not nameresponseContracthere. The first reduced wording did, and Haiku wrapped the whole answer in it twice.:71(evidence and sourceHash),:158and:211(evidence), and:163and:217(sourceHash).:79-81with'- Every timeline_event uses sectionKey "event".'and "- A relationship change uses claimKind change. If its concrete cause is supported but has no event unit, emit one compact timeline_event for that cause." The link rules themselves now live only in the server block.:160stays as it is, for the same reason assubjectNamesabove.:49, which repeats server rule 3.CHANGELOG under
## Unreleased: one bullet. "Extraction requests no longer repeat the link rules or send values the server sets itself, so each one is about 3,100 characters shorter. A unit with an empty evidence list, a blank title or a null optional field is no longer dropped."Not included
parseEvidenceUnitPayload. The wording change removes the cause.Regression proof
tests/long-term-memory-extraction-graph.regression.ts:1280-1292: today this pinsextractionPrompt.validationRules(the #1362 same-response caused_by rule) andallowedTimelineRelations(planted_in,paid_off_infor #1138). Move both assertions to the system message: the same-response rule appears exactly once, andallowedLinkRelationsincludesplanted_in,paid_off_inandextracted_from.evidenceUnitMessages. Assert that every server link rule string occurs exactly once across system and user content (a copy in the user JSON counted in its escaped form), and thatsourceHash,requiredEvidence,scopeandmodesare absent.parseEvidenceUnitPayloadkeeps a unit withevidence: [], one withtitle: ""and one withdimensions: null, and each kept unit carries the trusted evidence.:1703(required.includes("subjectNames")) stays as is.tests/long-term-memory-routes.regression.ts:4505-4508builds the fixture unit's evidence fromrequiredEvidence ?? source_note:<id>; delete it and the unit'sevidenceline, since the server sets evidence.:4500-4502), which reached the request only through the evidence lists. Key them on each summary's text instead. The backup check's rejected-suggestion count (:5728) drops from 11 to 4: the fixture answers every source withsource_note:source_route_extractevidence, so 8 units from four other sources were rejected asmissing_source_note_evidence. With server-owned evidence, 7 are kept and 1 is rejected for an unknown link instead. For the same reason the imports scenario's imported summary (:4179) is nowcurrentinstead ofextraction_incompletewhen the scenario runs on its own; the full run still drops one unit for an ambiguous Mara, and asserts that code (ambiguous_subject_identity).Environment
upstream/staging8b72729f1)Logs, screenshots, or video
None. Only aggregate counts from a private harness are shared.
Additional context
Tracker items EX-I5 (extraction stages audit F5, F6), RT-7 (the live before/after check that #1417 never ran) and EX-I11 (F7 part 2, decided to be handled here and measured).
EX-I11: link losses per variant and model
EX-I11 asked for two counts per variant and model:
caused_by) links that point at an event the same answer never created.caused_byto a missing eventcaused_bylink pointed at a missing event in any run, the re-check included.reduced3re-check, every non-timeline change unit linked to an event in its own answer. r2 has one thread change unit that links only to the source note (kept, nothing dropped). r3 has 4 change units whose 7caused_bylinks name an event of the same answer by its bare subjectId instead of thetimeline_…id.timeline_event_…form. No run of today's code used it, norreduced3a–c, r1 or r2.reduced3r3 used it 9 times andreduced3-worldHaiku b 11 times. Every one of those links named an event in the same answer, and none was dropped as an unknown target.caused_bylinks to events that exist nowhere, two of them throughtimeline_event_…ids. They probably came from another provider, or from older prompt text. The rule-2 wording in the fix ("add it if it is not in the response yet") is cheap insurance, but this run cannot show that it helps.S/extraction/structured-summary-normalizer.ts:1258). The same drops occur in every variant, so this is a separate server-side issue, not a prompt one. Drafted separately as the structured-summary backfill issue (EX-I11a). Separately, 6 drops across the tenreduced2/reduced3runs came from the server puttingtimeline_in front of a model link to the source note's bare id; that is the bare source note link issue (OT-7), not the backfill.reduced3run a) are anchors whoseplanted_inlink names an event that the summary declares (event_id: …) but the answer left out. That is the case decision D covers: a link to an event the model didn't write. Rule 1 (:87) already forbids it. The vault happens to hold those events from an earlier extraction of the same source, under the per-source suffix (…_e6e62f372f,normalizeSourceEventGraph,structured-summary-normalizer.ts:300). Adding that suffix on the server would save 1 of these 5 drops. The other events are outside the notes the extraction loads, and finding them is the rejected option B. No separate issue. Moving the "add it if it is not in the response yet" clause from rule 2 to rule 1 would cover anchors too, but that wording was not measured.reduced2.haiku.bare a knock-on effect: the events they linked to were rejected for a missingsectionKey.source_event_graph_open) run 0–3 per run in every variant, including today's code. Not traced further.World notes per source (for PL-1 / EX-I10)
PL-1 found that both models split one source into 4–11 small world notes instead of adding to the broad existing one.
The full per-source table is in the private T6 report. The summary is below. "Created" means a new world note, and "extended" means an existing world note that received a section or link.
The EX-I5 changes leave this unchanged: the prompt cleanup does not touch what a world note is. Under every variant, 7–10 of 15 sources produce 4 or more new world notes (6 in the
reducedHaiku run, which lost two answers), and the largest is 8–11. The re-extraction also shows the split directly. One source already has 2 world notes in the vault, yet a re-run creates 7–11 more. Another has 5, yet a re-run creates 5 new ones and adds to none. A broader world line was measured and failed (below), so granularity stays with EX-I10.Broader world-note wording (measured, not proposed)
Before deciding EX-I10, one prompt line was measured. Variant
reduced3-worldisreduced3plus one sentence at the end of the three world lines inSH/constants.ts(roleplay:106, conversation:152, game:204): "Add details about an existing place to that place's memory (reuse its subjectId); make a new world memory only for a new place, group or important object." The "(reuse its subjectId)" part was added to the agreed wording, because a model can add to a note only by giving the same subjectId.The rule was written before any run (private pass-rules file). To pass, the median number of new world notes per source had to fall to half of
reduced3's or less, and more existing world notes had to be extended. Errors, parser rejections, parser and validation drops other than unknown characters, and link drops each had to stay within the baseline limit. Kept units had to stay at 90% or more of the lowest baseline run. World-fact coverage could fall no more than 0.05 below the run-to-run figure. Each model ran 15 sources twice. The baseline is the sixreduced3Haiku runs and the onereduced3Sonnet run.The line changes little. On Sonnet, 10 of 15 sources make the same number of new world notes, and on Haiku most move by less than one. In one source, Sonnet now adds two parts of a place to that place's note instead of giving each part its own note. Haiku already did that without the line. A few sources drop by 2–3 new notes (two on Haiku, three on Sonnet), and one Sonnet source rises by 1.5. Judging by their ids, most of the remaining new world notes are running jokes, nicknames, quoted lines, people and one-off objects, not places. The line doesn't stop those. The prompts already have an
anchorstream for recurring motifs and inside jokes, yet both models file many of them as world facts.Haiku's two limit misses come from one conversation answer. It left out
sectionKeyon a whole stream (24 units) and lost 4 more units to links into that stream. The same failure appeared once inreduced2.About a fifth of the "new" world notes in every run (9–14) are copies, not new subjects. The bench re-extracts sources the vault already holds. The model gave the subjectId of a world note from the earlier extraction, but that note was saved with a scope that also names a character. Today a chat summary writes with a chat-only scope (
resolveChatLtmWriteScope,S/identity/chat-scope.ts:74), so the existing note can't be updated (canUpdateLtmScopedTarget,S/extraction/scoped-targets.ts:33-44), and the server writes a copy with a scope suffix. In one source, every world note in every run is such a copy, under today's code and every variant. No prompt line changes this. It is not traced further, and it's an input for EX-I10. The report counts these copies but doesn't score them.PL-1 world pairs (private PL-1 recall-floor harness with the
reduced3-worldcode, 4 pairs × 2 models × 2 runs; results in a private report). PL-1's baseline is today's code, notreduced3, so this also includes the rest of the EX-I5 change.reduced3-world, Haiku / SonnetHaiku is unchanged. On Sonnet, one pair moves to matched, the three duplicates become absent, and the two baseline failures (the whole extraction failed on EX-I12) now run and come out absent. Both models still put a source's details into 4–13 new small notes instead of the broad place notes PL-1 expects. The PL-1 report header names commit
40ff75368because the patched copy isn't a git checkout, sogit logread the enclosing checkout. The code under test is the bench source (b1873710f) with thereduced3-worldpatches, and the prompt hashes differ from the baseline cache.Not proposed. The wording failed on both models, so it is not part of this fix, and EX-I10 stays the path. The request never shows the model the existing world notes. It lists only trusted character names (
trustedLtmSubjectPromptCatalog,S/identity/subject-identity.ts:703). A model therefore reuses a world id only when it happens to pick the same name, so a prompt line alone can't route new details into the existing places.Open questions
:72-73, thesubjectNamesfield text and the two subject-name target rules are unchanged. What the model no longer sees is the scope ids, the source note's tags and evidence, and the link-rule copies that sat intargetNoteRulesnext to the subject rules.subjectNamesrequired in the response schema, the safe choice. Dropping it would save tokens on openai, google and local sidecar models, but it needs a live check on one of them first.evidenced_by, which the server turns intotimeline_source_…and validation drops (tracker OT-7, the bare source note link issue, left out of EX-I11a). Count those separately in the live comparison, or land OT-7 first.Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked: