Skip to content

feat(server): complete pending-memory auto-promotion sweep at session end#62

Open
ryantlee25-droid wants to merge 3 commits into
mainfrom
feat/pending-memory-sweep
Open

feat(server): complete pending-memory auto-promotion sweep at session end#62
ryantlee25-droid wants to merge 3 commits into
mainfrom
feat/pending-memory-sweep

Conversation

@ryantlee25-droid
Copy link
Copy Markdown
Owner

Summary

Completes a half-shipped feature. Migration 0054 added auto_save_threshold and the CLI writes to it, but the sweep that reads it and promotes pending memories to live was missing from session_end. This PR wires it end-to-end.

  • cache/sqlite.ts — adds promoteMemories(projectId, threshold) using a single SQL UPDATE (atomic, vs N round-trips).
  • tools/session-end.ts — accepts optional 6th param autoSaveThreshold; sweep runs only when non-null. Preserves prior "session_end doesn't auto-promote" default for callers that don't pass it.
  • index.ts:378 — wires the configured autoSaveThreshold (already in scope at line 95, populated from projectRow.auto_save_threshold at line 164) to the call site. Without this line the feature was unreachable end-to-end.
  • 8 new tests in __tests__/session-end-sweep.test.ts — below/at/above threshold, idempotency, empty pending, null-threshold opt-out. All 640 server tests pass.

Warnings from pre-PR review (non-blocking)

  • W1 (White): comment at __tests__/auto-save.test.ts:168 describes a "session_end does not sweep" invariant that's now architecturally false when a threshold is configured. Production is safe (default is null), but the doc-rot is misleading. Cheap follow-up: update the comment or add a session-end-sweep test at threshold=0.8 over session-extracted memories.
  • W2 (White): auto-save.ts::runAutoSaveSweepLocal and the new cache::promoteMemories are parallel implementations for the same logical op (different call surfaces — periodic vs session-end). Tracked tech debt, not a correctness issue.
  • Gray test-thoroughness gaps (suggestions, not required): no concurrent-invocation test, no threshold=0/=1.0/>1.0 edge tests, return-count not asserted, no test for "threshold set but zero pending."
  • Coverage tool not installed: @vitest/coverage-v8 isn't in the workspace; per-file coverage on changed files was not obtainable for this run.
  • Cross-worktree vitest glob: packages/server/vitest.config.ts does not exclude .claude/worktrees/**. Did not manifest as a failure here, but per a prior incident memory it can. Follow-up ticket worth opening.

Test plan

  • pnpm --filter @tages/server test passes locally (verified: 640 pass / 0 fail / 13 skipped)
  • pnpm --filter @tages/server typecheck passes (verified clean)
  • CI green
  • Set auto_save_threshold = 0.85 on a test project, run a session that produces pending memories, confirm session_end promotes those ≥ 0.85.

🤖 Generated with Claude Code

ryantlee25-droid and others added 3 commits May 15, 2026 14:48
Adds `SqliteCache.promoteMemories(projectId, threshold)` — a single UPDATE
that promotes all pending memories with confidence >= threshold to live,
setting verified_at and dirty=1. Idempotent: the WHERE clause filters on
status='pending' so already-live rows are never touched.

Wires the sweep into `handleSessionEnd` via an optional `autoSaveThreshold`
parameter (null = no sweep, preserving existing call-site behavior). The
guard `if (autoSaveThreshold != null)` matches the pattern in index.ts and
observe.ts; index.ts can pass the threshold in a follow-up without touching
this file.

8 tests in session-end-sweep.test.ts cover: below-threshold stays pending,
at/above-threshold promoted with verifiedAt set, already-live not re-promoted
(idempotent, two-run check), empty pending set is a no-op, null threshold
skips sweep entirely.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
handleSessionEnd accepted autoSaveThreshold (6th param) after 9d54467 but
the MCP tool registration in index.ts:378 dropped it on the floor, making
the pending-memory promotion sweep unreachable end-to-end.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dashboard Ready Ready Preview, Comment May 15, 2026 8:57pm

Request Review

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