Skip to content

fix: skip duplicate episodic fallback injection + consolidation superseded-semantics rule - #20

Open
wu546526 wants to merge 4 commits into
chendpoc:mainfrom
wu546526:fix/h1-i1-consolidation
Open

wu546526 wants to merge 4 commits into
chendpoc:mainfrom
wu546526:fix/h1-i1-consolidation

Conversation

@wu546526

Copy link
Copy Markdown

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 sessionMemoryCap already injected in the same request. Measured: two nearly-identical private_memory blocks (~15K chars duplicated) in one user message.

  • runEpisodicPreflight now reports usedFallback
  • 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

2. Consolidation merge prompt gains a superseded-semantics rule

buildConsolidateMergePrompt now 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 --noEmit clean; npm run build passes; 3 pre-existing env-sensitive test failures (scheduler/ollama-detection) are identical with and without this patch (verified via stash)
  • deploy: session injection went from duplicated blocks to a single block; stale tails reconciled on disk
  • npm pack --dry-run: 318 files, no secrets

wdl-ai 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
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