feat: index reasoning, and close the two-minute freshness gap #19

Merged
david merged 1 commits from feat/session-freshness into main 2026-11-05 03:39:17 +00:00
Owner

Closes #18.

Index reasoning

The model's own justification lives in reasoning parts, which were deliberately excluded ("reasoning and tool parts are not indexed"). That made "why did we do this" unsearchable — the half of the transcript a reader never sees but most needs to recall.

They are also enormous: the largest parts in this store are 175 KB. So:

  • each part truncated to 1.2 KB,
  • each session budgeted 4 KB,
  • included in content (FTS) but excluded from summary, which is what search results and MCP output show.

The existing test asserted the old contract (content leaked "thinking hard"); it now asserts the new one — reasoning present in content, absent from summary, ContentHash set.

The bug this uncovered

Sessions were skipped when created_at and summary matched. Content that gained reasoning behind unchanged prose was therefore never written — the feature would have been a no-op for existing sessions. IngestResult now carries a content hash and sessionNeedsWrite compares it. The observation layer already used that signal internally; only the watcher's pre-check bypassed it.

Close the freshness gap

The watcher polls every 2 minutes, so a finished turn stayed unsearchable for up to that long.

Path Cost
Full ingest (knox ingest) 59 s — all sources, not viable per turn
Session sweep, no watermark 21 s — re-reads all 59k messages
Session sweep with watermark 45 ms

IngestSessionsNow is extracted so the watcher and the CLI share one implementation. It sweeps only sessions newer than opencode_sync_max_updated, and only advances the watermark after a completed pass, so a failed run re-reads its range.

The plugin calls knox ingest sessions at prompt admission, fire-and-forget, with an overlap guard. It never delays the turn that triggers it.

Side effect worth having: the watcher's own 2-minute sweep drops from ~20 s of CPU to ~45 ms.

Verification

  • go vet ./..., go test ./... green
  • measured: 45 ms warm / 21 s cold on this store
  • plugin tsc --strict clean and reports active
  • not yet observed in production: the prompt hook firing inside the server; that lands on the next user turn
Closes #18. ## Index reasoning The model's own justification lives in `reasoning` parts, which were deliberately excluded ("reasoning and tool parts are not indexed"). That made "why did we do this" unsearchable — the half of the transcript a reader never sees but most needs to recall. They are also enormous: the largest parts in this store are **175 KB**. So: - each part truncated to 1.2 KB, - each session budgeted 4 KB, - included in `content` (FTS) but **excluded from `summary`**, which is what search results and MCP output show. The existing test asserted the old contract (`content leaked "thinking hard"`); it now asserts the new one — reasoning present in content, absent from summary, `ContentHash` set. ### The bug this uncovered Sessions were skipped when `created_at` and `summary` matched. Content that gained reasoning behind unchanged prose was therefore **never written** — the feature would have been a no-op for existing sessions. `IngestResult` now carries a content hash and `sessionNeedsWrite` compares it. The observation layer already used that signal internally; only the watcher's pre-check bypassed it. ## Close the freshness gap The watcher polls every 2 minutes, so a finished turn stayed unsearchable for up to that long. | Path | Cost | |---|---| | Full ingest (`knox ingest`) | 59 s — all sources, not viable per turn | | Session sweep, no watermark | 21 s — re-reads all 59k messages | | Session sweep with watermark | **45 ms** | `IngestSessionsNow` is extracted so the watcher and the CLI share one implementation. It sweeps only sessions newer than `opencode_sync_max_updated`, and only advances the watermark after a completed pass, so a failed run re-reads its range. The plugin calls `knox ingest sessions` at prompt admission, fire-and-forget, with an overlap guard. It never delays the turn that triggers it. Side effect worth having: the watcher's own 2-minute sweep drops from ~20 s of CPU to ~45 ms. ## Verification - `go vet ./...`, `go test ./...` green - measured: 45 ms warm / 21 s cold on this store - plugin `tsc --strict` clean and reports `active` - **not yet observed in production:** the prompt hook firing inside the server; that lands on the next user turn
david added 1 commit 2026-11-05 03:39:07 +00:00
feat: index reasoning and close the session freshness gap (#18)
build / test (push) Has been cancelled
build / image (push) Has been cancelled
4dd1c2be09
Two changes that make the index reflect work as it happens.

Reasoning is now indexed. The model's own justification is where a decision is
explained, and it never appears in the text a reader sees. It is also enormous —
individual parts reach 175 KB — so each part is truncated to 1.2 KB and each
session is budgeted 4 KB. It lands in content (searchable) but stays out of the
summary, which is what search results and MCP output show.

Capturing it exposed a dedupe bug: sessions were skipped when created_at and
summary matched, so content that gained reasoning behind unchanged prose was
never recorded. IngestResult now carries a content hash and the sweep compares
it, which is what the observation layer already used internally.

Freshness: the watcher polls every two minutes, so a finished turn stayed
unsearchable that long. IngestSessionsNow shares the watcher's logic, sweeps
only sessions newer than a stored watermark, and runs in ~45 ms steady state
(a full sweep is ~21 s for 59k messages). The plugin calls it at prompt
admission, fire-and-forget.
david merged commit 84f30f293b into main 2026-11-05 03:39:17 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: david/knox#19