Repository navigation
Conversation
added 4 commits
September 28, 2026 19:46
… initial reindex session_start calls reindex on every attach. With a remote embedder (ollama bge-m3, 128 chunks) each call re-embedded the entire memory file — 7.3-7.8s per round on this machine — because chunkReindex embeds unconditionally and nothing tracks what was last indexed. - Add a content fingerprint (sha256 of sorted ids+contents + embedder identity) persisted in the meta table; handleReindex short-circuits on a match and returns skipped: "fingerprint_match" - Expose get/setLastReindexFingerprint on VecStore (db is private) - Make the initial reindexScheduler.runNow() in bootstrapSidecar fire-and-forget: session_start must not block on a full re-embed; preflight already falls back to MEMORY.md while the index rebuilds - Empty-document reindex never fingerprint-skips (explicit clear path) Measured: repeated reindex ~7.3-7.8s -> ~2ms; session startup cost attributable to pi-memory drops by ~7s per attach / new chat.
…MemoryCap When the sidecar is unavailable (e.g. after a panel restart that killed the spawned sidecar of a surviving session), the episodic preflight falls back to injecting the full MEMORY.md — which sessionMemoryCap already injected in the same request. Measured: two nearly-identical private_memory blocks (~15K chars of duplicated context) in the same user message. runEpisodicPreflight now reports usedFallback, and both merge sites skip the episodic payload when it is a fallback product — the cap already carries that content. True semantic recalls (sidecar healthy) are unaffected.
- H1: skip episodic fallback result when it duplicates sessionMemoryCap (sidecar unavailable after panel restart used to double-inject MEMORY.md, ~15K chars per request) - I1: consolidation merge prompt gains superseded-semantics rule — stale tails in older entries get rewritten when a newer entry states the outcome; [user]-authored lines remain untouchable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two fixes for context-bloat and memory-staleness issues we hit running pi-web-ui with 9 MCP servers (318 tools, all deferred) plus a large MEMORY.md:
1. Skip episodic fallback result when it duplicates sessionMemoryCap
When the sidecar is unavailable (e.g. after a panel restart kills the spawned sidecar of a surviving session), the episodic preflight falls back to injecting the full MEMORY.md — which
sessionMemoryCapalready injected in the same request. Measured: two nearly-identicalprivate_memoryblocks (~15K chars duplicated) in one user message.runEpisodicPreflightnow reportsusedFallback2. Consolidation merge prompt gains a superseded-semantics rule
buildConsolidateMergePromptnow instructs the LLM: when a newer entry states X is done/decided/executed, rewrite older entries' stale tails about X (e.g. "X pending/未拍板") to reflect the newer state — keeping still-valid parts.[user]-authored lines remain untouchable (existing rule preserved).Real-world case: a work session completed three decisions, but older entries kept injecting "X pending" tails until the next consolidation cycle — the rule lets consolidation reconcile them automatically.
Verification
tsc --noEmitclean;npm run buildpasses; 3 pre-existing env-sensitive test failures (scheduler/ollama-detection) are identical with and without this patch (verified via stash)npm pack --dry-run: 318 files, no secrets