Skip to content

fix(memory): extract bounded excerpts from oversized user messages - #17

Merged
w01fb0ss merged 3 commits into
w01fb0ss:mainfrom
agooll:fix/memory-extraction-oversized-message
Nov 24, 2026
Merged

w01fb0ss merged 3 commits into
w01fb0ss:mainfrom
agooll:fix/memory-extraction-oversized-message

Conversation

@agooll

@agooll agooll commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Fixes #16. Direct-chat memory extraction could skip an individually oversized human message and still advance its coverage cursor beyond it. The selector first chooses whole user turns with the original budget. If more room is needed for oversized excerpts, it shortens the largest selected user turns and keeps the smaller turns that already fit. It walks Unicode code points so it cannot split a surrogate pair. Group extraction continues to require complete statements for source validation.

An excerpt gives the extractor some of the skipped user's text and can still miss a detail elsewhere in the message.

Checks

  • One topic
  • pnpm verify passes locally
  • No new UI text or theme changes
  • No secrets, .env files or local paths
  • Commit signed off (DCO)

Before and after: I ran the same Vitest regression with the real SQLite migrations and repositories in a focused Windows harness (Node v24.12.0, Vitest 5.0.3). On 7ad34f0, the test fails because only 2 of 3 messages are selected. With the patch, all three contribute, the excerpt fits within the existing 12,000-token estimate, the next extraction excludes the already-covered input, and an oversized-only increment can still contribute. The fixture contains Chinese text and emoji. git diff --check passed.

Full desktop verification and live-model extraction were not run. AI assisted with the implementation and tests.

Review follow-up

At dfc5ae6, the two new tests reproduced the omissions from review: a near-full ordinary turn crowded out the oversized turn, and only the newest of two oversized turns contributed. At 1d5ecf9, both pass within the 12,000-token estimate, and the next incremental pass does not resend the covered input. The group regression confirms that only complete eligible statements appear as sources. Memory and storage suites: 54 passed. Biome and git diff --check passed.

Follow-up for the 11,968-token case

The latest review's exact sequence is covered at c5917af. At 1d5ecf9, the extraction input loses My timezone is UTC.. With the patch, that turn stays intact and both long turns contribute marked excerpts within the 12,000-token estimate. The next pass contains only the newly added turn.

Memory and storage suites: 55 passed. Biome and git diff --check passed.

Keep whole direct-chat messages first, then give one individually oversized message a chance to contribute before its coverage cursor advances.

Signed-off-by: agooll <141763834+agooll@users.noreply.github.com>

@w01fb0ss w01fb0ss left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. I verified that the regression case fails on the current v0.0.4 development code and passes with dfc5ae6. I also reproduced two cases where coverage still moves past an oversized user turn that never reaches extraction. When full user turns leave too little room for an excerpt, the only oversized turn can be skipped. When two oversized turns are pending, only the newest gets an excerpt. Could you adjust the selection or coverage logic so those turns receive a bounded excerpt or remain eligible for a later pass, while keeping the input budget and the existing group-source checks? Please include verification for both cases. This review is for the direct-chat fix linked from #16.

Share the direct-chat extraction budget between oversized turns and retain a marked excerpt of an ordinary turn when the reserve alone would displace it. Cover both cases from the review and verify that group evidence still uses full statements.

Signed-off-by: agooll <141763834+agooll@users.noreply.github.com>
@w01fb0ss

Copy link
Copy Markdown
Owner

Thanks for the update. I verified that both original cases now pass. I found one new regression with the default budget. If the conversation contains a short user turn (My timezone is UTC.), then an oversized turn, then an ASCII turn that uses 11,968 tokens, the previous code included the short turn. The updated code drops it and advances coverage past it. Could you preserve a bounded excerpt for the large turns while keeping that short turn eligible, and add this case to the regression checks?

@agooll

agooll commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for checking both cases and catching this regression. I see how the 11,968-token turn can fill the budget left after reserving space for the oversized turn, leaving no room for My timezone is UTC.

I’ll add your exact sequence as a regression test and adjust the selection so the short turn stays intact and the two long turns still contribute within the existing budget. I’ll also check that the next extraction pass doesn’t repeat those turns.

Choose whole user turns with the original budget before shortening the largest selected turns to fit the oversized excerpts. Reproduce the 11,968-token turn that previously crowded out the earlier timezone message.

Signed-off-by: agooll <141763834+agooll@users.noreply.github.com>
@w01fb0ss
w01fb0ss merged commit 5a4f5f9 into w01fb0ss:main Nov 24, 2026
6 of 7 checks passed
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.

Long-term memory extraction skips an oversized user message and advances past it

2 participants