Skip to content

feat(memory): add semantic maintenance rebuild - #631

Merged
delete-cloud merged 2 commits into
mainfrom
feat/semantic-memory-rebuild-command
Jun 26, 2026
Merged

delete-cloud merged 2 commits into
mainfrom
feat/semantic-memory-rebuild-command

Conversation

@delete-cloud

@delete-cloud delete-cloud commented Jun 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add a SemanticMemoryMaintainer service for destructive semantic memory rebuild/status operations
  • require an authoritative topic store before full rebuild so existing topic docs are not cleared from a partial source set
  • add paginated PGTopicStore.list_topics(..., offset=...) support with stable created_at, topic_id ordering
  • cover pagination, unstable scan detection, missing topic-store safety, and status reporting

Verification

  • uv run ruff check src/coding_agent/topics/semantic_maintenance.py src/coding_agent/topics/store.py tests/coding_agent/test_semantic_maintenance.py tests/coding_agent/test_topic_store.py
  • uv run pytest tests/coding_agent/test_semantic_maintenance.py tests/coding_agent/test_topic_store.py tests/coding_agent/test_semantic_sync.py -q
  • uv run pytest tests/coding_agent/ -q
  • local subagent review loop: first pass found P1/P2, fixes applied; second pass found no P0/P1/P2

Notes

  • This PR intentionally stops at the reusable maintenance service and topic-store pagination layer. CLI/user-facing rebuild commands can build on this in a follow-up PR.

Summary by CodeRabbit

  • New Features

    • Added semantic memory maintenance tools to rebuild and inspect topic memory health.
    • Topic lists now support paginated browsing with offset-based navigation.
  • Bug Fixes

    • Improved stability checks during semantic rebuilds to prevent inconsistent results.
    • Added validation for pagination and batch-size values to catch invalid inputs early.
  • Tests

    • Expanded coverage for semantic maintenance flows, status reporting, and topic pagination behavior.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@delete-cloud, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 50 minutes and 22 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 84e1bb16-81d1-4373-bac3-44c8d25cf942

📥 Commits

Reviewing files that changed from the base of the PR and between 9297526 and 54c6493.

📒 Files selected for processing (4)
  • coding-agent/src/coding_agent/topics/semantic_maintenance.py
  • coding-agent/src/coding_agent/topics/store.py
  • coding-agent/tests/coding_agent/test_semantic_maintenance.py
  • coding-agent/tests/coding_agent/test_topic_store.py
📝 Walkthrough

Walkthrough

Adds a semantic memory maintainer for rebuilding and reporting semantic memory state, adds offset-based topic listing to the topic store, and extends tests for paginated rebuilds, unstable scans, status reporting, and query ordering.

Changes

Semantic maintenance and pagination

Layer / File(s) Summary
Maintainer contracts and rebuild
coding-agent/src/coding_agent/topics/semantic_maintenance.py
Defines topic and reviewed-memory listing protocols and a semantic memory status shape, then implements rebuild and status reporting with paged topic scans.
Offset pagination in topic listing
coding-agent/src/coding_agent/topics/store.py, coding-agent/tests/coding_agent/test_topic_store.py
Adds offset to PGTopicStore.list_topics, passes it into the SQL query, and updates topic-store tests for paginated results, tie-breaking order, and OFFSET $5 checks.
Maintainer tests
coding-agent/tests/coding_agent/test_semantic_maintenance.py
Adds in-memory fakes and async tests for paginated rebuilds, unstable scans, status counts, and batch-size validation.

Sequence Diagram(s)

sequenceDiagram
  participant SemanticMemoryMaintainer
  participant TopicListingStore
  participant ReviewedMemoryListingStore
  participant SemanticMemorySyncer
  SemanticMemoryMaintainer->>TopicListingStore: list_topics(limit=batch_size, offset=0)
  loop scan finalized topics
    TopicListingStore-->>SemanticMemoryMaintainer: TopicRecord page
    SemanticMemoryMaintainer->>TopicListingStore: list_topics(limit=batch_size, offset=next_offset)
  end
  SemanticMemoryMaintainer->>ReviewedMemoryListingStore: list_memories
  SemanticMemoryMaintainer->>SemanticMemorySyncer: rebuild(topics, reviewed_memories)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hopped through pages, one by one,
With offset steps beneath the sun.
I tucked away each topic bright,
Then rebuilt memory burrows tight.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding semantic memory maintenance rebuild support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/semantic-memory-rebuild-command

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@coding-agent/src/coding_agent/topics/semantic_maintenance.py`:
- Around line 95-116: The full rebuild scan in semantic_maintenance.py is using
offset-based paging, which causes repeated rescans and poor scaling in large
finalized-topic sets. Update the rebuild loop in the topic scan logic (the
iterator around list_topics in the semantic maintenance flow) to use
keyset/cursor pagination or a snapshot-aware iterator instead of offset +=
len(page), and keep the duplicate-topic safety check in place while switching to
a stable resume key such as created_at/topic_id or an equivalent cursor from the
topic store.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d007165b-d01f-4b31-ba90-970b83acc9c2

📥 Commits

Reviewing files that changed from the base of the PR and between 25ee39c and 9297526.

📒 Files selected for processing (4)
  • coding-agent/src/coding_agent/topics/semantic_maintenance.py
  • coding-agent/src/coding_agent/topics/store.py
  • coding-agent/tests/coding_agent/test_semantic_maintenance.py
  • coding-agent/tests/coding_agent/test_topic_store.py

@delete-cloud
delete-cloud merged commit 2aa48fe into main Jun 26, 2026
2 checks passed
@delete-cloud
delete-cloud deleted the feat/semantic-memory-rebuild-command branch June 26, 2026 02:11
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