Skip to content

feat(memory-ingest): EXP-08 — scheduled consolidation every N turns#10

Draft
moralespanitz wants to merge 1 commit intoexperiment/phase2-combined-stackfrom
feature/exp-08-scheduled-consolidation
Draft

feat(memory-ingest): EXP-08 — scheduled consolidation every N turns#10
moralespanitz wants to merge 1 commit intoexperiment/phase2-combined-stackfrom
feature/exp-08-scheduled-consolidation

Conversation

@moralespanitz
Copy link
Copy Markdown
Contributor

Summary

Auto-triggers consolidation-service.executeConsolidation after every scheduledConsolidationTurnInterval (default 50) ingested turns per user_id. Targets BEAM SUM ability — currently 0/2 to 1/2 across all 15 sprint-2 iters with no other planned fix.

Implementation

  • New src/services/scheduled-consolidation.ts (81 LOC) — process-local Map<user_id, turn_count>, fires when count % interval === 0
  • 3 call sites in memory-ingest.ts (performIngest, performQuickIngest, performWorkspaceIngest) each await recordIngestTurn(...) after the actual ingest completes
  • 2 new config keys: scheduledConsolidationEnabled (bool, default false), scheduledConsolidationTurnInterval (number, default 50)
  • Both follow the existing pattern: typed RuntimeConfig field + env loader + INTERNAL_POLICY_CONFIG_FIELDS allowlist + IngestRuntimeConfig

Tests

6 new cases in __tests__/scheduled-consolidation.test.ts, all pass:

  • defaults-off: 200 ingests, zero triggers
  • interval 50 over 100 turns: exactly 2 triggers
  • llmModel forwarded to executeConsolidation
  • per-user_id counter isolation
  • thrown errors logged but not propagated
  • interval=0 never triggers (guard)

Typecheck clean.

⚠️ Known issue flagged for reviewer

executeConsolidation calls softDeleteMemory on cluster members — it does archive originals despite the EXP-18-lite spec note "Don't archive originals." There's no alternative entry point that just synthesizes without archiving. If "no archive" is a hard requirement we'd need a new executeConsolidationNoArchive variant.

For now this PR uses the existing API as-is. Audit logs will show both synth and archive events.

Caveat

In-memory turn counter does not survive process restarts. Acceptable for tuning heuristics, fine for the BEAM-experiment use case where the runtime is short-lived. Documented in file header.

Test plan

  • Unit tests pass (6/6)
  • Typecheck clean
  • Stage-7 dryrun with this config enabled — measure SUM ability movement
  • Audit log inspection: confirm consolidation runs every 50 turns + originals get soft-deleted

Stacked on experiment/phase2-combined-stack.

Triggers consolidation-service automatically after every
scheduledConsolidationTurnInterval ingested turns per user_id.
Default off; default interval 50 turns. Targets BEAM SUM ability
which is 0/2 to 1/2 across all 15 sprint-2 iters and has no other
planned fix.

Failure mode: if consolidation throws, the ingest continues and the
error is logged. No silent retry, no cascade.

New config keys (defaults-off):
- scheduledConsolidationEnabled: false
- scheduledConsolidationTurnInterval: 50

Behind feature flag. Defaults preserve current behavior.
moralespanitz added a commit that referenced this pull request May 6, 2026
The same magic 10 lived in two places: `tll-retrieval.ts:expandViaTLL`
sliced its input ids before entity lookup, and `memory-search.ts`
re-declared a private `TLL_SEED_CANDIDATE_COUNT = 10` for the same
purpose. Defined the constant once in `tll-retrieval.ts` and re-used it
from both call sites so a tuning change can't drift between them.

Updated the unit test to reference the exported constant directly
instead of asserting against the literal 10.
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