Skip to content

fix(memory-lifecycle): make compaction and expiry cleanup complete under scale — prevent duplicate summaries and stale records - #776

Closed
unohee wants to merge 3 commits into
mainfrom
swarm/AGT-3471-fix-memory-lifecycle-make-compaction-and
Closed

unohee wants to merge 3 commits into
mainfrom
swarm/AGT-3471-fix-memory-lifecycle-make-compaction-and

Conversation

@unohee

@unohee unohee commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Published because this run stopped and needs a human: autonomous execution failed 4 times

It has not been reviewed and is very likely incomplete — this PR is a draft on purpose. It exists so the work is reviewable instead of sitting on a branch that was never pushed.

Change shape

417 file(s): 208 source · 189 test · 3 docs · 17 other

Base freshness

Branch base is 171 commit(s) behind main at publication.

⚠ Conflicts with main in: src/memory/memoryOps.ts
GitHub runs no pull_request workflows on a PR it cannot merge, so any green checks here are not the verification gate. Opened as a draft; rebase before review.

⚠️ File overlap with in-flight work

This branch changes files that other open PRs / active branches also touch. Coordinate before merging to avoid divergent parallel edits (INT-2388 #3):

Linear

Closes AGT-3471


🤖 Generated with OpenSwarm

unohee pushed a commit that referenced this pull request Sep 28, 2026
…past the first page

Salvaged from draft PRs #772 and #776.

Compaction, expiry cleanup, consolidation, and statistics all read the memory
table with a single capped query, so larger stores were silently truncated:
compaction refused outright at its 100k safety limit, while cleanupExpired,
consolidateMemories and getMemoryStats quietly processed only the first 10k
rows. They now read the complete table through memoryCore's paginated
fetchAllTableRows / offset-limit pages.

Deduplication is now bucket-based (stable FNV-1a hash of repo, type,
derivedFrom and canonical metadata) instead of an O(n^2) pairwise scan, which
matters now that the full record set is considered at once. Bucketing also
guarantees duplicate pairs that straddle a page boundary meet: with the old
page-by-page filtering they could not be compared. Within a bucket, records
are ranked by importance then recency so the survivor is independent of page
order.

Also fixes the type defect in #772 where cosineSimilarity was declared
: boolean while returning a similarity score, which broke the >= threshold
comparison at the consolidation call site.

Dropped from the drafts: getTable(tempTableName)/db.renameTable() (neither
exists in the current memoryCore/lancedb API), the removals of
withMemoryMutationLock/saveConversation/getRecentConversations/
runBackgroundCognition/getMemoryStats (main's API, still called by discordCore,
support/chatMemory and support/web), package.json version churn, and the
unconditional error-swallowing catch in compactMemoryTable that main
deliberately rethrows.
unohee pushed a commit that referenced this pull request Sep 28, 2026
…past the first page

Salvaged from draft PRs #772 and #776.

Compaction, expiry cleanup, consolidation, and statistics all read the memory
table with a single capped query, so larger stores were silently truncated:
compaction refused outright at its 100k safety limit, while cleanupExpired,
consolidateMemories and getMemoryStats quietly processed only the first 10k
rows. They now read the complete table through memoryCore's paginated
fetchAllTableRows / offset-limit pages.

Deduplication is now bucket-based (stable FNV-1a hash of repo, type,
derivedFrom and canonical metadata) instead of an O(n^2) pairwise scan, which
matters now that the full record set is considered at once. Bucketing also
guarantees duplicate pairs that straddle a page boundary meet: with the old
page-by-page filtering they could not be compared. Within a bucket, records
are ranked by importance then recency so the survivor is independent of page
order.

Also fixes the type defect in #772 where cosineSimilarity was declared
: boolean while returning a similarity score, which broke the >= threshold
comparison at the consolidation call site.

Dropped from the drafts: getTable(tempTableName)/db.renameTable() (neither
exists in the current memoryCore/lancedb API), the removals of
withMemoryMutationLock/saveConversation/getRecentConversations/
runBackgroundCognition/getMemoryStats (main's API, still called by discordCore,
support/chatMemory and support/web), package.json version churn, and the
unconditional error-swallowing catch in compactMemoryTable that main
deliberately rethrows.
unohee pushed a commit that referenced this pull request Sep 28, 2026
…past the first page

Salvaged from draft PRs #772 and #776.

Compaction, expiry cleanup, consolidation, and statistics all read the memory
table with a single capped query, so larger stores were silently truncated:
compaction refused outright at its 100k safety limit, while cleanupExpired,
consolidateMemories and getMemoryStats quietly processed only the first 10k
rows. They now read the complete table through memoryCore's paginated
fetchAllTableRows / offset-limit pages.

Deduplication is now bucket-based (stable FNV-1a hash of repo, type,
derivedFrom and canonical metadata) instead of an O(n^2) pairwise scan, which
matters now that the full record set is considered at once. Bucketing also
guarantees duplicate pairs that straddle a page boundary meet: with the old
page-by-page filtering they could not be compared. Within a bucket, records
are ranked by importance then recency so the survivor is independent of page
order.

Also fixes the type defect in #772 where cosineSimilarity was declared
: boolean while returning a similarity score, which broke the >= threshold
comparison at the consolidation call site.

Dropped from the drafts: getTable(tempTableName)/db.renameTable() (neither
exists in the current memoryCore/lancedb API), the removals of
withMemoryMutationLock/saveConversation/getRecentConversations/
runBackgroundCognition/getMemoryStats (main's API, still called by discordCore,
support/chatMemory and support/web), package.json version churn, and the
unconditional error-swallowing catch in compactMemoryTable that main
deliberately rethrows.
unohee added a commit that referenced this pull request Sep 28, 2026
…past the first page (#785)

Salvaged from draft PRs #772 and #776.

Compaction, expiry cleanup, consolidation, and statistics all read the memory
table with a single capped query, so larger stores were silently truncated:
compaction refused outright at its 100k safety limit, while cleanupExpired,
consolidateMemories and getMemoryStats quietly processed only the first 10k
rows. They now read the complete table through memoryCore's paginated
fetchAllTableRows / offset-limit pages.

Deduplication is now bucket-based (stable FNV-1a hash of repo, type,
derivedFrom and canonical metadata) instead of an O(n^2) pairwise scan, which
matters now that the full record set is considered at once. Bucketing also
guarantees duplicate pairs that straddle a page boundary meet: with the old
page-by-page filtering they could not be compared. Within a bucket, records
are ranked by importance then recency so the survivor is independent of page
order.

Also fixes the type defect in #772 where cosineSimilarity was declared
: boolean while returning a similarity score, which broke the >= threshold
comparison at the consolidation call site.

Dropped from the drafts: getTable(tempTableName)/db.renameTable() (neither
exists in the current memoryCore/lancedb API), the removals of
withMemoryMutationLock/saveConversation/getRecentConversations/
runBackgroundCognition/getMemoryStats (main's API, still called by discordCore,
support/chatMemory and support/web), package.json version churn, and the
unconditional error-swallowing catch in compactMemoryTable that main
deliberately rethrows.

Co-authored-by: openSwarm <openswarm@local>
@unohee

unohee commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator Author

Closing: superseded — the salvageable work in this draft was rebased onto current main, verified, and re-published as a reviewed PR: absorbed into #785. Closing the stale draft instead of merging it, because it was 170-250 commits behind, carried scratch files, and (in several cases) reverted main's later hardening.

@unohee unohee closed this Sep 28, 2026
@unohee
unohee deleted the swarm/AGT-3471-fix-memory-lifecycle-make-compaction-and branch September 28, 2026 07:02
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.

1 participant