Architecture & Benchmarks

The graph needs a clock.

Why static repo indexes and hand-written MEMORY.md files rot as code moves, and how immutable Rust generations keep agent context accurate across sessions.

Rhei Research · 3 min read

Coding agents rarely fail because the frontier model cannot reason. They fail because they start every session blind, burning tens of thousands of tokens grepping directories and re-discovering mistakes another agent already fixed yesterday.

We built Rhei so every harness you run shares one live codebase memory. On held-out tasks in OpenClaw (67,144 files), giving agents symbol-anchored orientation cuts prompt tokens by 96.8% while hitting 100% of required files.

Figure 1 · Context cost on held-out tasks
Lower is better

Rhei orient + expand

OpenClaw · 67,144 files · 100% file hit

-96.8% tokens

7,624 tok

Baseline file search

OpenClaw · unhinted held-out tasks

236,648 tok

-51.6%

Tokens per session

15 replayed sessions vs RepoPrompt

-89.6%

Tool calls

Direct seed pointers instead of grep loops

-33.5%

Wall-clock time

15 / 15 review quality matched

Why snapshots rot

Most context tools fall into one of two buckets: static code indexes that only know what exists right now, or markdown memory files (MEMORY.md, CLAUDE.md) that summarize past chats without checking whether the code underneath still exists.

In an active repository with multiple parallel agents, both break quickly. A file moves, an interface changes, or a workaround gets replaced, and yesterday's note becomes today's hallucination. Memory needs a clock tied directly to the code graph.

Generations & Delta

Rhei's Rust engine never mutates a live index in place. Every commit and file digest publishes a sealed, immutable generation, and records a typed Delta of which sessions, tests, and edits produced the change.

Cross-service and caller edges are admitted only when backed by syntax, symbol resolution, and callsite proof. Between sessions, Dream mode consolidates recurring fixes and pitfalls on-device so the next agent inherits verified pointers in under 600 tokens.

Figure 2 · How source changes, session failures, and idle consolidation feed the next agent

01 · SOURCE GRAPH

Repo edit

git mv src/api/stripe.ts

-> packages/billing/webhook.ts

↓indexed & verified

GENERATION G+1

verifyWebhook keeps symbol identity; 14 callers re-indexed in 94 ms

↓next session orient

✓ resolves new file path

✓ includes 3 covering tests

02 · SESSION DELTA

Prior failure

agent parsed JSON before

HMAC check -> test failed

↓indexed & verified

CAUTION ANCHOR

verifyWebhook: verify raw body signature before JSON.parse

↓next session orient

✓ surfaced on webhook tasks

✓ scoped to symbol, zero noise

03 · IDLE DREAM

Between sessions

3 agents touched auth +

billing across 12 commits

↓indexed & verified

CONSOLIDATED RULE

co-change spine mapped: route -> guard -> billing ledger

↓next session orient

✓ shared across Claude & Cursor

✓ under 600-token orient budget

Latency & scale

Keeping generations immutable stays fast because unchanged subgraphs share memory through lineage-proved overlays. Publishing a warm generation takes 94 ms at p95 instead of re-validating the full store, while the resident rheid daemon idles at 9.3 MiB of RAM.

Figure 3 · Rust generation kernel latency (p95)
Apple Silicon laptop · 671k graph edges

Prefix symbol search (p95)

20.2x faster
Before
188.7 ms
Now
9.3 ms

Natural-language search (p95)

23.2x faster
Before
220.7 ms
Now
9.5 ms

Warm generation publish (p95)

9.5x faster
Before
890.0 ms
Now
94.0 ms

~10 s

Cold index · 67k files

0.168 ms

Graph walk p95

0.978

Impact caller F1

9.3 MiB

Resident rheid RSS

Static files vs symbol anchors

To test durability under heavy churn, we flooded the memory benchmark with 500 commits and 10,000 distractor facts. File-based notes decay as paths shift; symbol-anchored cautions follow AST identity and only surface when relevant code is in play.

MEMORY.MD · STATIC TEXT NOTE

- Billing webhooks live in src/api/stripe.ts (line 84).
- Always check signature header before handler.

Fifty commits later, billing moves into packages/billing/webhook.ts. The markdown note stays loaded in every prompt, wasting tokens while pointing agents at a dead path.

✗ drifts silently when code moves

RHEI · SYMBOL + GENERATION ANCHOR

anchor: packages/billing/webhook.ts#verifyWebhook
caution: verify raw body HMAC before JSON.parse
status: verified · generation #418

Anchored to the compiler symbol rather than a prose line number. Follows file moves automatically, surfaces only when verifyWebhook or its callers are in scope, and retires when superseded.

✓ 1.000 recall MRR across 500-commit flood (10k distractors)