Commit Graph

3 Commits

Author SHA1 Message Date
shitratgit[bot] ca3f4d9636 fix(memory): recover and quarantine capture backlog 2026-07-30 00:26:33 -07:00
Joel Hooks 7e2fb01252 fix: stop session-capture prefix inflation at the source
Capture clients (pi, claude, codex) send byte-accurate from_offset,
to_offset, jsonl_sha256, and deterministic source_identity. Stale
cursors coalesce into one pending outbox segment under one Run ID.
capture-outbox-replay.ts is the only replay implementation; the audit
script fails closed on legacy flags and the scheduled nas-backup caller
is migrated. Raw Run writes reject divergent redelivery; a larger
proven-prefix body returns accepted_prefix without overwrite.

Verified adversarially (multi-byte offsets, repeated stale cursors,
fixture-only replay): 20 bun tests + 2 vitest + tsc clean. Receipts in
.brain/projects/typesense-reboot-recovery/patch-verification.svx.
2026-07-19 20:10:39 -07:00
Joel Hooks e357bcc609 feat(memory): Phase 1 slice — embed priority lanes (ADR-0243 Rule 9a)
Validates ADR-0243 Rule 9a with a decisive contention test. Priority-lane
embed scheduling measured at 338ms query latency with 98 ingest-bulk embeds
queued — a ~25x improvement over the 8-10s observed in the spike without
priority discipline.

@joelclaw/inference-router
  - new src/embeddings.ts — PriorityEmbedClient with single-writer queue
    honoring query > ingest-realtime > ingest-bulk; embed() returns queued_ms,
    compute_ms, total_ms for observability
  - new __tests__/embeddings-priority.test.ts — drives 100 ingest-bulk embeds
    then submits one query-priority embed mid-stream; asserts query < 3s
    (observed 338ms); skips gracefully when Ollama is unreachable
  - vitest added as devDependency; tests pass under vitest 4

@joelclaw/memory
  - new __tests__/chunking.test.ts — 12 tests locking in the tool_result
    role detection fix that landed during the spike, format detection
    (claude-code vs pi), meta-entry filtering, thinking-content handling,
    oversized-turn sub-chunk splitting, and malformed-JSON tolerance

packages/system-bus
  - memory/embed.requested + memory/embed.completed event contracts added
    to Events map
  - new functions/memory/embed.ts — Inngest durable wrapper, concurrency:1
    (matches Ollama internal serialization), priority.run expression mapping
    the three lanes to numeric scheduling scores, OTEL emission + fanout
    completed event; calls @joelclaw/inference-router under the hood

Query path bypasses Inngest and calls the router directly (fast, no
durability needed). Only ingest paths fire memory/embed.requested. Both
converge on the same priority queue — that's where the contention is
resolved.

ADR-0243 status: accepted.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 18:15:21 -07:00