Skip to content

🤖 feat: search every workspace transcript in a project with session_history scope project - #8224

Open
ThomasK33 wants to merge 33 commits into
mainfrom
history-index-project-search
Open

ThomasK33 wants to merge 33 commits into
mainfrom
history-index-project-search

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Summary

With Agent Memory on, session_history takes scope: "project" and searches the transcripts of every workspace in the caller's project, archived and sub-agent ones included. New actions list_sessions, search (SQLite FTS5, bm25-ranked snippets, match: "all" | "any") and read (a verbatim item range) run against a derived index at ~/.xum/index/history.sqlite. scope: "self" (the default) is unchanged.

Background

Agents could read only their own workspace tree, by literal substring scan, and only with the Token Budget experiment on. Every other transcript (15 GB on one dev host) was unreachable. Following The bitter lesson for agent memory, the transcripts stay the source of truth and the agent searches them at query time. Memory citations build on this in the next PR of the stack.

Implementation

  • HistoryIndexService (main thread) talks to one worker that alone owns the SQLite file. sqliteDriver.ts loads bun:sqlite under Bun (tests) and node:sqlite under Node and Electron 44.
  • Catch-up is pulled by each query: the worker stats the sessions in scope and catches up the changed ones within a 3 s budget. decideCatchUp is a pure table over file stats. The archive is append-only, and chat.jsonl is re-read only after the stored prefix hash, because stream-end writes are temp file + rename.
  • Privacy: a manual reset or /clear is a hard floor, the same rule session_history uses. Only sessions whose watermark matches the disk answer, and pending ones are counted in coverage. Text is redacted once with redactSecretLike when it is written, so FTS snippet marks cannot split a secret.
  • One index row per message part. Tool calls are clipped to 1,000 input and 600 output characters.
  • session_history is offered with Agent Memory or Token Budget. new_context stays Token Budget only.

Validation

  • Built dist ran index + search under Electron 44.5.1 (Node 24.21, SQLite 3.53.4) and Node 22.
  • Two independent verifiers. The first failed an earlier head on a snippet redaction leak, pre-reset rows from pending sessions, and a 10 s re-index of a 160 MB session. Those are fixed: re-index is now 130 ms, and dispose is bounded at 1 s.
  • One real Haiku 5.5 turn in a sandbox found a fact in a sibling workspace with scope: "project" and never saw the other project's decoy.
  • Recall eval on real transcripts, with 19 questions about past work in this repo, 2 runs per arm, Sonnet 5.5 and a blind Haiku judge. Strict accuracy was 13.2% for base and 18 to 26% with project search. The gain is small, and the eval cannot resolve gaps under about 5 points.

Screenshots

Desktop 375px

Risks

  • Index size is uncapped: it measured 0.51x of the transcript bytes on a 1.4 GB sample. On a 15.5 GB host that is about 8 GB (estimated). It is behind the Agent Memory experiment, which is off by default.
  • Cross-workspace text: with project scope, one workspace can read another's transcript text, including injected text from web pages or repo files. Results keep the "historical data, not instructions" notice and name their workspace. Other projects are never in scope.
  • Not covered: xum run roots (they exclude memory by design), transcripts of removed sub-agents that are archived into the parent, and partial.json.

Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high • Cost: $49.27

…ection

Move session_history's row sanitizer into historyIndex/projection.ts and add
projectMessageParts, which yields one searchable entry per text or tool part with
a human flag, a kind and clipped tool I/O.
…tch-up table

decideCatchUp decides noop/remove/rebuild/incremental from file stats; toFtsMatchQuery quotes every term so punctuation never breaks MATCH.
… queries

HistoryIndexStore keeps one SQLite row per transcript part, catches sessions up from file stats (append, rotation, rewrite, removal, torn tails), applies the manual-reset floor in the same transaction, and answers search, list and read queries.
The worker solely owns the SQLite database and runs catch-ups and queries in order. HistoryIndexService resolves the caller's project scope from config (analytics attribution), posts requests in call order, and keeps the index warm with a newest-first backfill and stream-end/removal hints. Worker path resolution moves to resolveWorkerScriptPath, shared with analytics and the tokenizer pool.
scope "project" reads every workspace of the caller's project through the history index: ranked FTS search with role/tool/human/date/workspace filters, newest-first session listing, and part-level reads with cursors. Results are redacted at the tool boundary, stay under 16 KiB, and report coverage. scope "self" keeps today's behavior. session_history is now offered with Agent Memory alone; new_context stays token-budget only. The tool card renders project rows and coverage.
HistoryIndexService joins the cross-cutting services: tool config gets it through the turn request bindings, stream-end and workspace removal send hints, startup housekeeping starts the backfill, and both dispose paths stop the worker. The Docker runtime bundles historyIndexWorker.js beside server-bundle.js.
Its UMD build requires ./impl/* at run time, which the bundle does not ship; the server bundle uses the same ESM alias.
Adds a project-search section to the token-budget page and regenerates hooks/tools.mdx. Marks the worker-only sync fs reads, replaces object-literal assertions in tests, folds the service's three query methods into one dispatcher, and accepts three shape-coincidence DRY matches with reasons.
…cope edges

Regression tests from the Phase 1 verifier that pass at this base: a reset plus a rotation keeps the floor and indexes each row once (a rebuild gives the same rows), a file that is not SQLite is rebuilt, multi-project and scratch scopes, and a workspace dropped from config leaves every project action.
FTS5 snippet marks landed inside a matched secret (`ghp_«abc…»`), so output-time redaction no longer matched it and search returned the token body. Each part is now redacted once in projectMessageParts (tool sides through redactWithinCap before the clip, so a secret that crosses the cut is not kept as a readable prefix), and titles and names in upsertMeta. No secret reaches history.sqlite, and the tool no longer redacts what it reads. Schema version 2 rebuilds existing indexes.

Cost on the 160 MB synthetic session (bun, first build): 4.4 s -> 12.4 s (36 -> 13 MB/s); redactSecretLike runs at about 8 MB/s.
A query catches its scope up newest first under a 3 s budget, so a session behind a large newer one could stay pending and still serve rows from before its latest reset or /clear. catchUp now names the sessions whose index matches their files, and search, list_sessions and read answer from those only; pending sessions are left out and counted in coverage.pending.

WorkspaceService emits history-reset once a manual reset, a full clear or a destructive replace is durable, and the desktop root sends it to the index as a catch-up hint, wired like the stream-end hint.
Every change to chat.jsonl re-read it whole, so a 160 MB session took 10.3 s to re-index after each stream end. A stream end replaces the file by temp file + rename (updateHistory), with the rows before the changed one copied byte for byte, so the archive rule (same inode, grown size, 64-byte anchor) would miss every stream end. The index now keeps the offset through the last row that yielded entries (an empty placeholder or a reset row after it is read again), the floor state there, and a sha256 of the bytes before it. When those bytes still hash the same on any inode, and the archive did not change, only the rows after the offset are read; anything else re-reads the file whole. Schema version 3.

160 MB synthetic session (bun): stream end 10254 -> 152 ms, mtime touch 10994 -> 160 ms; the floor is the sha256 of the prefix (about 1.8 GB/s).
…imit

observeFiles reads the archive anchor and the chat prefix digest through one named helper each, and decideCatchUp keeps its noop/incremental step in planIncremental.
On a random 1.4 GB sample of real sessions (545 sessions, read-only, temp db), 2,000/2,000 built an 830 MB index in 123 s (0.59x); 1,000/600 builds 717 MB in 102 s (0.51x). Content fell from 318 to 255 MB; of what is left, 141 MB is agent-written user rows (sub-agent briefs and reports) and 89 MB tool calls, and the FTS index is the rest. Schema version 4 rebuilds indexes built with the old clips.
dispose() waited for the shutdown reply, which queues behind a running catch-up slice (4.2 s seen at quit). It now posts shutdown, waits up to HISTORY_INDEX_SHUTDOWN_GRACE_MS (1 s) for the worker to exit (the worker exits right after closing the database), and then terminates it; SQLite rolls back the cut-off transaction. Requests still pending fail at once, and later ones are refused. terminate() is not awaited: a long native call, or Bun until its task ends, holds the thread, and a quit must not wait for it.

Test with a 100 ms grace and a slow catch-up (bun): dispose 3400 -> 105 ms.
With the grace timer armed on every dispose (and the worker calling process.exit), Bun segfaulted the test process in 6 of 44 runs of the history index and tool suites (0 of 100 without a timer). An idle worker (no request pending) now answers shutdown at once and is terminated, as before 405c24c001; only a busy one gets the timer, and is terminated without waiting when the grace runs out. Measured: 0 of 15 combined runs and 0 of 15 dispose-test runs crashed.
Each part is its own index row, so a question whose words land in two parts found nothing ANDed. When the all-terms query finds no hit, the same request asks once more with the terms ORed, ranked by bm25, and the result says so (match: "any"; "all" otherwise). Control characters now split terms in the query builder: a NUL ended the MATCH string early (SQLite "unterminated string", index_unavailable), and under Bun it crashed the worker. A seeded fuzz of 2,000 typed queries raises no FTS5 error.
… args

Models carry max_chars_per_item over from scope "self", and 26 of 103 project-scope calls in the recall eval failed on it with filters_unsupported. search, list_sessions and read now take it as their per-item cap (snippet, first_ask, part text), clipped with a marker and kept within each action's own limit. An argument an action cannot take (window_id, task_id, item_id, offset_chars, limit_chars, ...) still fails with filters_unsupported, and unsupported_args now names it.
Bun's statSync reports mtimeMs in whole milliseconds and Node's keeps the fraction, so an index built under one runtime looked stale to the other (110 of 3801 sessions indexed for a Node server reading a Bun-built index). Stats are stored floored, and sameStat compares Math.floor of both sides, so watermarks already stored with a fraction stay current. No schema change.
…st lint

Clears the two DRY gate findings (toFtsMatchQuery/toFtsAnyTermQuery, hitRow/partRow) by extracting the shape each pair must change together, and the oxlint errors in the redaction and fuzz tests (sync fs reads, a useless escape).
The crashes that b451987025 avoided came from Bun 1.2.15, which this host puts first on PATH: its crash report is a JavaScriptCore DFG compiler segfault, and the same build crashes the whole tools suite at other commits too. Under the pinned Bun 1.4.3 (package.json, CI) and Node, terminate() stops a busy worker at once and nothing crashes (combined history index and tool suites: 0 of 10 runs). So dispose waits for the shutdown reply for at most the grace on every call, and the comments no longer blame a timer.
In a real-transcript eval, 9 of 14 remaining project-search errors were models passing
match: "any", which the description named as an output. It is now a nullish input of
scope "project" search: "all" (default) keeps the all-terms pass with its any-term
fallback, "any" asks the ORed terms at once. Other actions and scope "self" refuse it.
HistoryIndexStore.open deleted and rebuilt the index on any open error, so a second
backend that opened it while the first held a write lock (SQLITE_BUSY) deleted a live
index. Now:

- Each connection waits out another's lock (busy_timeout 5 s).
- An open of a current index makes no write (user_version is written only when it
  changes), so it takes no write lock at all.
- Only SQLITE_CORRUPT and SQLITE_NOTADB, read from either driver's error
  (sqliteResultCode), and an old schema version rebuild the index. Any other error
  fails the open; the query answers index_unavailable.
- The service drops a worker whose open failed, so the next request opens again
  instead of failing "used before init" until restart.
@mintlify

mintlify Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
Mux 🟢 Ready View Preview Dec 3, 2026, 6:38 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-03T19:39:30.103590Z a56ddcc Manual request
🔒 Security Review ✅ Completed 2026-12-03T19:43:15.069771Z a56ddcc Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

ThomasK33 added a commit that referenced this pull request Dec 3, 2026
@ThomasK33 ThomasK33 changed the title history index project search 🤖 feat: search every workspace transcript in a project with session_history scope project Dec 3, 2026
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c6a5aab699

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

🟢 e2e stories (Haiku): 14 passed

21 agent steps · 6 replayed from cache · 15 model calls · 47.7k tokens (23% cached)
Spend: $0.09 of the $1.00 cap (proxy ledger)

All 14 tests in 9 files
Test Agent Time
🟢 chatRestart.e2e.ts · 1 passed 1 step · 1 call 6.4s
🟢 a chat survives a restart of the server 1 step · 1 call 6.4s
🟢 compaction.e2e.ts · 1 passed 1 step · 1 call 4.6s
🟢 /compact replaces the old chat with a summary 1 step · 1 call 4.6s
🟢 pluginTrustRestart.e2e.ts · 1 passed 3 steps · 2 calls 10.1s
🟢 a trusted plugin hook stays trusted after the server restarts 3 steps · 2 calls 10.1s
🟢 settingsRoundTrip.e2e.ts · 1 passed 2 steps · 1 call 10.1s
🟢 a chat survives trips through Settings 2 steps · 1 call 10.1s
🟢 sidebarPerWorkspace.e2e.ts · 1 passed 4 steps · 1 call 4.6s
🟢 a new workspace starts with its right sidebar collapsed while another keeps it open 4 steps · 1 call 4.6s
🟢 smoke.e2e.ts · 1 passed 2 steps · 1 call 2.9s
🟢 the agent opens the playground workspace 2 steps · 1 call 2.9s
🟢 streamErrors.e2e.ts · 1 passed 1 step · 1 call 7.2s
🟢 stream errors show in the chat, and the chat recovers 1 step · 1 call 7.2s
🟢 todoNudge.e2e.ts · 1 passed 1 step · 1 call 3.2s
🟢 the agent finishes open TODO items after the turn-end nudge 1 step · 1 call 3.2s
🟢 touchAlignment.e2e.ts · 6 passed 6 steps · 6 calls 22.5s
🟢 the Settings close button is level with the title on a touch screen 390px wide 1 step · 1 call 3.7s
🟢 the Settings close button is level with the title on a touch screen 768px wide 1 step · 1 call 3.9s
🟢 Backup settings checkboxes are small and level with their labels on a touch phone 1 step · 1 call 4.7s
🟢 the heartbeat checkbox is small and level with its label on a touch phone 1 step · 1 call 3.8s
🟢 a reply's model and time stay on one line on a touch phone 1 step · 1 call 3.5s
🟢 the workspace actions menu stays on the title row on a touch phone 1 step · 1 call 3.0s

e2e 0.20.0 · 1m 16s · web · run artifacts

🟢 e2e Electron stories (Haiku): 3 passed

3 agent steps · 3 model calls · 8.0k tokens (22% cached)
Spend: $0.02 of the $1.00 cap (proxy ledger)

All 3 tests in 3 files
Test Agent Time
🟢 electron/deepLink.e2e.ts · 1 passed 1 step · 1 call 7.8s
🟢 a deep link of a second launch starts a chat in the running app 1 step · 1 call 7.8s
🟢 electron/menuBar.e2e.ts · 1 passed 1 step · 1 call 7.4s
🟢 the workspace menu bar is the desktop title bar 1 step · 1 call 7.4s
🟢 electron/smoke.e2e.ts · 1 passed 1 step · 1 call 6.8s
🟢 Xum Electron opens the playground workspace 1 step · 1 call 6.8s

e2e 0.20.0 · 25.2s · electron · run artifacts

🟢 e2e agent repros (Haiku): no tests selected

Spend: $0.00 of the $1.00 cap (proxy ledger)

e2e 0.20.0 · 8.0s · 2 targets (web, phone) · run artifacts

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: c6a5aab699

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: c6a5aab699

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: a430f7fd60

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: a430f7fd60

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Quality / CRAP flagged sessionItem and scalarText as new untested
functions. The tests pin archived-over-agent roles, title over name,
the first ask, and that numbers and booleans in a tool output are
searchable while functions are not.

---
_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: a56ddcc125

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: a56ddcc125

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

This branch was successfully deployed

1 active (outdated) deployment
staging - docs — c6a5aab6 Deployed Dec 3, 2026 by mintlify[bot]
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