ClawVM: Harness-Managed Virtual Memory for Stateful Tool-Using LLM Agents
Organizations: Independent Researcher Switzerland · Max Planck Institute for Software Systems Saarbrücken, Saarland, Germany
Abstract
Stateful tool-using LLM agents treat the context window as working memory, yet today's agent harnesses manage residency and durability as best-effort, causing recurring failures: lost state after compaction, bypassed flushes on reset, and destructive writeback. We present ClawVM, a virtual memory layer that manages state as typed pages with minimum-fidelity invariants, multi-resolution representations under a token budget, and validated writeback at every lifecycle boundary. Because the harness already assembles prompts, mediates tools, and observes lifecycle events, it is the natural enforcement point; placing the contract there makes residency and durability deterministic and auditable. Across synthetic workloads, 12 real-session traces, and adversarial stress tests, ClawVM eliminates all policy-controllable faults whenever the minimum-fidelity set fits within the token budget, confirmed by an offline oracle, and adds median <50 microseconds of policy-engine overhead per turn.
Figures & tables
| Type | Min. fidelity | Scope | Degradation path |
|---|---|---|---|
| Bootstrap | Struct. after compact, reset | P/S | F St |
| Constraint | Hard-pinned at struct. | S | F St |
| Plan | Goal + step | S | F St Pt |
| Preference | Scope, prov. | P | F C St Pt |
| Evidence | Ptr resolves det. | S | F C St Pt |
| Conversation | Span ID + time | S | F C St Pt |
| Policy | Pin | Pref. | WB-C | WB-R | Upgrade | Resolve |
|---|---|---|---|---|---|---|
| Retrieval | – | – | – | – | none | – |
| Retr.+Cache | – | – | – | – | none | ✓ |
| Comp-Hybrid | – | ✓ | ✓ | – | recency | ✓ |
| ClawVM | ✓ | ✓ | ✓ | ✓ | utility | ✓ |
| Oracle ( ) | ✓ | ✓ | ✓ | ✓ | oracle | ✓ |
| Scenario | Assertion |
|---|---|
| Post-compaction bootstrap | Bootstrap fault observable after compaction |
| Reset dirty-page flush miss | Flush-miss fault at reset boundary |
| Threshold jump race | Flush-miss fault from skipped pre-compaction commit |
| Silent recall visibility | Silent-recall fault from deny/error with reason code |
| Unsafe persistence rejection | Writeback rejected with DESTRUCTIVE_OP reason |
| Evidence churn duplicate tool | Duplicate-tool fault from repeated equivalent call |
| Baseline | Explicit | % | Thrash | % |
|---|---|---|---|---|
| Retrieval | 67.8 | 100% | 3.993 | 77.4% |
| Retr.+Cache | 10.8 | 100% | 1.642 | 45.2% |
| Comp-Hybrid | 1.5 | 100% | 1.017 | 11.4% |
| ClawVM | 0.0 | — | 0.901 | — |
| Oracle ( ) | 0.0 | 0.0% | 0.901 | 0.0% |
| Variant | Boot. | Flush | D+R | Total |
|---|---|---|---|---|
| baseline | 20 | 23 | 228 | 271 |
| +pin | 0 | 23 | 228 | 251 |
| +resolve | 20 | 23 | 0 | 43 |
| +WB-C | 20 | 3 | 228 | 251 |
| +WB-R | 20 | 20 | 228 | 268 |
| +upgrade | 7 | 23 | 42 | 72 |
| Variant | Boot. | Flush | D+R | Total |
|---|---|---|---|---|
| ClawVM | 0 | 0 | 0 | 0 |
| pin | 9 | 0 | 0 | 9 |
| resolve | 0 | 0 | 126 | 126 |
| WB-C | 0 | 20 | 0 | 20 |
| WB-R | 0 | 3 | 0 | 3 |
| upgrade | 0 | 0 | 0 | 0 |
| Comp-Hybrid | ClawVM | ||||
|---|---|---|---|---|---|
| Type | 180 | 300 | 180 | 300 | |
| coding | 9 | 9/9 | 9/9 | 9/9 | 9/9 |
| debugging | 8 | 1/8 | 8/8 | 8/8 | 8/8 |
| writing | 2 | 2/2 | 2/2 | 2/2 | 2/2 |
| ops | 11 | 11/11 | 11/11 | 11/11 | 11/11 |
| total | 30 | 23/30 | 30/30 | 30/30 | 30/30 |
| Policy | Budget | Success | Faults | Tok/task | Thrash | ( s) |
|---|---|---|---|---|---|---|
| Comp-Hybrid | 180 | 76.7% | 0.23 | 1607 | 1.36 | 170 |
| Comp-Hybrid | 300 | 100.0% | 0.00 | 2649 | 1.36 | 164 |
| ClawVM | 180 | 100.0% | 0.00 | 1605 | 1.36 | 167 |
| ClawVM | 300 | 100.0% | 0.00 | 2639 | 1.36 | 166 |
| Scenario | Policy | Boot. | Pin | Flush | D+R | Total |
|---|---|---|---|---|---|---|
| starvation | Retrieval | 0 | 10 | 0 | 0 | 10 |
| Comp-Hybrid | 0 | 10 | 0 | 0 | 10 | |
| ClawVM | 0 | 10 | 0 | 0 | 10 | |
| churn | Retrieval | 9 | 0 | 9 | 280 | 298 |
| Comp-Hybrid | 9 | 0 | 0 | 0 | 9 | |
| ClawVM | 0 | 0 | 0 | 0 | 0 |
Appendix figures & tables2 assets
Supplementary material from the paper’s appendix.
Appendix
| Policy | Turns | Median (range) | Thrash |
|---|---|---|---|
| Retrieval | 100 | 51 (49–77) | 0.677 |
| Retrieval | 200 | 83 (71–109) | 0.527 |
| Comp-Hybrid | 100 | 1 (1–1) | 0.047 |
| Comp-Hybrid | 200 | 0 (0–0) | 0.029 |
| ClawVM | 100 | 0 (0–0) | 0.032 |
| ClawVM | 200 | 0 (0–0) | 0.032 |
| Policy | Success | Faults | Mean time (s) |
|---|---|---|---|
| Comp-Hybrid | 20/20 | 0 | 16.9 |
| ClawVM | 20/20 | 0 | 16.6 |
LLM Context Management
Large language model context management studies how to select, compress, retrieve, and organize information within bounded model inputs.
See all 248 papers