Skip to content

fix(server): project memory recall is bounded and reports a timeout - #133

Merged
ScriptedAlchemy merged 12 commits into
mainfrom
t3/project-memory-fixes
Nov 17, 2026
Merged

ScriptedAlchemy merged 12 commits into
mainfrom
t3/project-memory-fixes

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Why

T3 Code saves project facts so a later agent can use them, and almost none arrive. Recall often passes 150 ms and returns nothing, with no log and no record. This change bounds the lookup and records a timeout when the lookup does not finish.

What changed

  • Recall returns an attached, skipped, or omitted outcome instead of null.
  • The lookup reads at most 40 full-text matches on the reader connection and stops after 1 second.
  • A timeout or a failure is stored as the existing recall_failed omission, and the turn still starts.
  • The 40 are chosen from facts the thread can still receive. Facts it has already been shown, or that came from it, are excluded before the limit, so a long thread still gets recall.
  • Equal text matches are ordered by trust before recency.

Scope

This covers recall arriving in time and a timeout that is visible. It leaves the relevance rule and explicit search as they are. How memory learns is a later change.

Tradeoffs

A stalled database can add up to 1 second before the turn starts. The bounded read on a reader should rarely reach that limit. The turn starts without facts, and the omission is on the delivery.

The 40 candidates are the best full-text matches among facts the thread can still receive, ordered by bm25 with ties broken by trust. A fact that the full ranking would place first can fall outside them when many near-duplicate facts quote the query. A reviewer built that case with 40 stale near-duplicates and one current decision. On the real export the delivered facts did not change. The next PR removes the native scorer from recall, after which the bound can be raised cheaply.

Blast Radius

Every provider turn that recalls project memory. Explicit search still uses the previous candidate set. On a replay of a real export, the delivered fact ids did not change.

Verification

  • The timeout, the 40-fact bound, the reader connection, and the turn-start omission were failing tests and now pass.
  • Four adversarial reviewers ran repros against this branch. They proved two defects, both fixed here with failing tests first: recall returned nothing once a thread had seen the 40 best matches, and the replay script's live-data guard could be bypassed by path case or a symlink.
  • 444-fact lookup p50 327 ms before, 41 ms after, median of 3 interleaved runs, range 39 to 44 ms after. Lookups over 150 ms went from 185 to 0. Measured at the first head of this PR; on that replay the delivered fact ids did not change.
  • After the exclusion moved into the query, three more interleaved runs against the first head: p50 27.9 ms then 29.5 ms, inside the 2.5 ms spread, same delivered ids. Two of three runs had a higher p99 (60 and 70 ms against 47 to 50 ms). A reviewer measured the query at about 1 ms of that on this data, and about 32 ms at 5,000 matching facts with 500 seen ids, so the p99 movement is treated as run noise. The replay was not rerun after the trust tie-break.

🤖 Generated with Claude Code

ScriptedAlchemy and others added 3 commits November 16, 2026 09:16
The 150ms cutoff drops slow lookups before the tail or the ranked facts can be recorded. This replay calls the real recall path and writes the gate, the stage times, and the top candidates.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…acts

A store read that never finishes returns null once 150ms passes. A newer fact that shares no term is still scored, and the lookup SQL uses the writer.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Recall now returns whether it attached facts, skipped, or omitted the lookup. The lookup reads at most 40 matching facts on the reader connection and stops after one second, and the turn still starts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot

changeset-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7983f9e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

ScriptedAlchemy and others added 9 commits November 16, 2026 10:46
A thread that was shown the best matching facts, or that produced the closer ones, receives nothing when those facts fill the candidate limit.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
The candidate limit now drops facts this thread has seen or produced before it keeps forty, so a page of those facts no longer hides an older match.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
The live-data guard compares resolved strings, so a differently cased state path or a symlink into it is accepted.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
The guard follows the nearest existing directory and compares its identity, so a case change or a symlink cannot write results into the state directory.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
The test reads directory identity through the file stat. The realpath import stays, with the diagnostic off, because that is how a symlink resolves to the state directory.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…ound match equally

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@ScriptedAlchemy
ScriptedAlchemy merged commit 735ed97 into main Nov 17, 2026
20 checks passed
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