memorix icon indicating copy to clipboard operation
memorix copied to clipboard

Hook writes call loadAll() of the full observation corpus

Open RaviTharuma opened this issue 3 months ago • 2 comments

Description

memorix hook / handleHookEvent called initObservations() which loadAll()'d the entire observation corpus (~44k rows) before writing a single hook capture. On a large store that made file.edited / command.executed / tool.execute.after too slow, so operators disabled OpenCode per-tool events (skipHookEvents) or set [memory] formation = "shadow".

Those are workarounds. The native path must write a hook observation without loading the corpus.

Steps to Reproduce

  1. Large SQLite store (~40k+ observations).
  2. printf '%s' '{"hook_event_name":"PostToolUse","cwd":"<git-project>","tool_name":"Write",...}' | memorix hook
  3. Time the process. On 1.6.0 this was ~8–11s in a full E2E (isolated ~0.9s after a write-only init).

Expected Behavior

Hook capture is write-only: persist the observation, exit in ~1s. Control plane picks the row up via ensureFresh. No Orama insert and no loadAll() on the hook process.

Actual Behavior

Hook init loaded the full corpus. OpenCode skipped per-tool events. formation=shadow was left as a short-circuit on some hosts.

Environment

  • Memorix 1.6.0
  • macOS + Linux
  • OpenCode plugin ~/.config/opencode/plugins/memorix.js
  • Cursor / Claude hooks via quiet-memorix-hook.sh

Additional Context

#205 (closed) covered hook processes that never exit. This issue is the remaining work on the happy path: loadAll() before a write. #214 adds initObservations(..., { skipCorpusLoad: true }) for hooks.

Related: #205, #125, #214.

RaviTharuma avatar Aug 17 '26 13:08 RaviTharuma

Fix is in PR https://github.com/AVIDS2/memorix/pull/214 — not on main yet, so leaving this issue open until that PR merges.

Relevant work:

  • 35358a1a4c — persist hook captures without loadAll() via skipCorpusLoad on hookObservationRuntimeOptions
  • Files: src/hooks/lifecycle.ts, src/memory/observations.ts, tests/memory/hook-write-without-corpus-load.test.ts

RaviTharuma avatar Aug 17 '26 16:08 RaviTharuma

Fixed by #214 and released in v1.6.2. Hook writes no longer load the full observation corpus on the foreground path. Closing as shipped.

AVIDS2 avatar Aug 18 '26 10:08 AVIDS2