Skip to content

Auto-capture: no idempotency key (Stop/PreCompact re-capture loop) + PreCompact/task_context hooks still bypass dedup #80

Closed

Description

@RobertSigmundsson

Context: surreal-memory in production for our agent swarm (Uruboros), via stdio MCP + Claude Code Stop/PreCompact auto-capture. Open cards; fix ready on our fork.

Since #69 the Stop hook has embedding-based semantic dedup — good. Two gaps remain:

  1. No idempotency key at the source. The Stop hook fires after every assistant turn and PreCompact on each compaction; both re-read an overlapping transcript tail and re-run analyze_text_for_memories, re-encoding identical fragments across turns. The embedding dedup in stop.py operates within a single candidate batch, so it does not stop the cross-turn re-capture loop (the same fragment persisted last turn is re-encoded this turn).
  2. PreCompact and task_context hooks have no dedup at all — pre_compact.py and task_context.py still construct MemoryEncoder without any dedup pipeline.

Impact: the noisiest write path (auto-captured session summaries) accumulates near-duplicates — the memory-poisoning failure mode — on any host using the default Stop/PreCompact integration.

Fix we're offering (PR-ready on our fork, will align after our 2.11.0 rebase): an idempotency key at the source to break the re-capture loop; dedup wired into pre_compact + task_context; exact-content candidate lookup so exact dups can't escape the word-search window. On our deployment this dropped content_hash=0 fresh neurons from ~64% to ~0.25%.

Activity

  1. acidkill commented on Jul 28, 2026

    @acidkill
    Owner

    Re-verified against current main, not just the description — both gaps are still open:

    • _embedding_dedup exists only in hooks/stop.py (line 221). hooks/pre_compact.py and hooks/task_context.py still construct MemoryEncoder with no dedup pipeline.
    • No idempotency key anywhere in the write path (git grep idempot on main is empty).

    What changed today that you should rebase onto. #93 and #94 both landed and both touch this area from the other end:

    Those cut the junk auto-captures. They do not touch the duplicate ones — the fragment persisted last turn is still re-encoded this turn, because the gate is evaluating content quality, not prior existence. So your framing still holds: they are complementary, not overlapping.

    Please send the PR. Going from ~64% to ~0.25% content_hash=0 fresh neurons on a live deployment is the kind of number worth having, and near-duplicate accumulation in the noisiest write path is the memory-poisoning mode this project should care most about.

    One request: keep the idempotency key and the pre_compact/task_context dedup wiring as separate commits if that is natural. They are independently reviewable — the first is a behavioural contract, the second is plumbing an existing mechanism into two more call sites — and the first is the one I will want to read carefully.

    Worth noting for the rebase: #63 also landed, which brain-scopes every record-id fetch. If your exact-content candidate lookup fetches by id anywhere, it now needs the brain context set.

  2. acidkill commented on Jul 28, 2026

    @acidkill
    Owner

    Status update so nobody duplicates work: this one is yours — we are not implementing it on our side. You said the fix is PR-ready on your fork, and re-implementing it here would waste that and be a poor way to treat the report.

    No deadline pressure. When you rebase, the things that landed today and touch your area: #93 (write-gate modes; also edits hooks/pre_compact.py and hooks/stop.py — expect conflicts there), #94 (machine-noise denylist in quality_scorer), #63 (brain-scopes every record-id fetch — relevant if your exact-content lookup fetches by id), and #99 (bounds inline embedding in the write path with asyncio.wait_for, which touches encoder.py near where dedup runs).

    Ping here if any of those turns the rebase into more than a mechanical merge and we will sort it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions