Skip to content

Commit 6fb595a

Browse files
cursoragentDJLougen
andcommitted
fix(rule_fast): keep literal constant assignments in file skeletons
The LLM-in-the-loop eval caught what the substring benchmark scored at 50%: file-read compression kept signatures but dropped body values, so a real model scored 0% QA on 'what value is assigned to limit?'. Keep literal constant assignments (numeric/string RHS, one line each) in the skeleton. Computed expressions stay dropped. Measured after the fix: - substring: file_read retention 50% -> 100%; overall 92.9% -> 99.1%, all-facts rate 78.6% -> 98.5%, token reduction unchanged (83.6%) - LLM eval (Qwen2.5-0.5B CPU): file_read QA 0% -> 50% (parity with raw at 308 vs 1128 tokens); overall compressed now BEATS raw 69.2% vs 67.7% at 66% fewer tokens Regression floors raised: overall retention >= 97%, file_read == 100%. Co-authored-by: Daniel <DJLougen@users.noreply.github.com>
1 parent fababb1 commit 6fb595a

7 files changed

Lines changed: 271 additions & 258 deletions

File tree

README.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ the *same* token budget:
5555

5656
| Metric (rule_fast, seed=42) | Before fidelity fixes | Current | Naive truncation |
5757
|---|---|---|---|
58-
| Token reduction | 95.4% | 83.7% | 83.7% (matched) |
59-
| Critical-fact retention | 40.7% | **92.9%** | 28.7% |
60-
| Messages with *all* facts intact | 26.4% | **78.6%** | 41.3% |
58+
| Token reduction | 95.4% | 83.6% | 83.6% (matched) |
59+
| Critical-fact retention | 40.7% | **99.1%** | 28.7% |
60+
| Messages with *all* facts intact | 26.4% | **98.5%** | 41.3% |
6161

6262
Per category (fact retention at the shown token reduction):
6363

@@ -67,7 +67,7 @@ Per category (fact retention at the shown token reduction):
6767
| command/build output | 75.7% | 100% (error line + exit code) |
6868
| tracebacks | 0% (kept verbatim by design) | 100% |
6969
| search results | 5.5% | 92.5% |
70-
| file reads | 82.7% | 50% (signatures kept, bodies dropped) |
70+
| file reads | 82.6% | 100% (signatures + literal constants kept) |
7171

7272
Honest caveats, measured not asserted:
7373

@@ -76,9 +76,9 @@ Honest caveats, measured not asserted:
7676
- **Search results barely compress** (5.5%). The compressor cannot know which
7777
hit is the answer, so it keeps all hit locations. Dense grep output has
7878
little safely-removable bloat.
79-
- **File reads lose body detail by design** (50% substring retention, 0% LLM
80-
QA accuracy on a 0.5B CPU model): signatures survive so the agent can
81-
re-read a precise range, but a value inside a function body does not.
79+
- **File reads keep signatures and literal constants, not full bodies**:
80+
computed expressions inside functions are dropped; the agent re-reads a
81+
precise range when it needs one.
8282
- **Still not measured**: multi-step task success (SWE-bench resolve rate
8383
with Hive on vs. off) and `busybee` routing accuracy.
8484

@@ -97,14 +97,19 @@ Run on CPU with `Qwen/Qwen2.5-0.5B-Instruct` (31 messages, seed=7):
9797

9898
| Metric | Raw context | Compressed context |
9999
|---|---|---|
100-
| QA accuracy (graded facts) | 67.7% | 60.0% |
101-
| Messages fully answered | 32.3% | 38.7% |
102-
| Avg prompt tokens | 657 | 220 (**-66.5%**) |
103-
104-
Per category: pytest logs and search results hold accuracy at **90% fewer
105-
tokens**; file reads drop to 0% QA accuracy (signatures survive, body
106-
values do not — matches the substring benchmark); command output actually
107-
*improves* (58% vs 50%) because compression strips noise.
100+
| QA accuracy (graded facts) | 67.7% | **69.2%** |
101+
| Messages fully answered | 32.3% | **38.7%** |
102+
| Avg prompt tokens | 657 | 221 (**-66.4%**) |
103+
104+
Compressed context matches or beats raw in **every category** at 66% fewer
105+
tokens: pytest logs hold 82.4% at a tenth of the tokens; file reads hold
106+
parity (50%) at 308 vs 1128 tokens; command output *improves* (58.3% vs
107+
50.0%) because compression strips noise a small model trips over.
108+
109+
An earlier run of this same eval caught a real defect: file reads scored
110+
**0%** because the skeleton kept signatures but dropped body values. Keeping
111+
literal constant assignments (one line each) closed the gap — the
112+
benchmark-fix-rerun loop working as intended.
108113

109114
Reproduce: `pip install torch transformers && python3 scripts/llm_fidelity_eval.py`
110115

docs/benchmarks/fidelity.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ report measures whether it is *safe*.
88
- Corpus: 201 messages (seed=42, 40/category + real captured fixtures)
99
- Baseline: head-truncation of the raw message to the **same** token budget
1010
- Machine: x86_64 / x86_64 / Linux
11-
- Commit: `0fed7e6` — 2026-06-09T22:33:48+00:00
11+
- Commit: `fababb1` — 2026-06-09T22:53:39+00:00
1212

1313
## Overall
1414

1515
| Metric | rule_fast | naive truncation (same budget) |
1616
|---|---|---|
17-
| Token reduction | 83.7% | 83.7% (matched) |
18-
| Fact retention | **92.9%** | 28.7% |
19-
| Messages with *all* facts intact | **78.6%** | 41.3% |
17+
| Token reduction | 83.6% | 83.6% (matched) |
18+
| Fact retention | **99.1%** | 28.7% |
19+
| Messages with *all* facts intact | **98.5%** | 41.3% |
2020

21-
Throughput on this machine: 2,120 msg/s (single core).
21+
Throughput on this machine: 2,369 msg/s (single core).
2222

2323
## By category
2424

2525
| Category | Msgs | Token reduction | Fact retention | All-facts rate | Naive retention |
2626
|---|---|---|---|---|---|
2727
| pytest_log | 41 | 97.4% | 100.0% | 100.0% | 4.3% |
2828
| traceback | 40 | 0.0% | 100.0% | 100.0% | 100.0% |
29-
| file_read | 40 | 82.7% | 50.0% | 0.0% | 15.0% |
29+
| file_read | 40 | 82.6% | 100.0% | 100.0% | 15.0% |
3030
| search_results | 40 | 5.5% | 92.5% | 92.5% | 92.5% |
3131
| command_output | 40 | 75.7% | 100.0% | 100.0% | 7.5% |
3232

@@ -35,7 +35,7 @@ Throughput on this machine: 2,120 msg/s (single core).
3535
| Source | Msgs | Token reduction | Fact retention | All-facts rate |
3636
|---|---|---|---|---|
3737
| real | 1 | 77.0% | 100.0% | 100.0% |
38-
| synthetic | 200 | 83.7% | 92.9% | 78.5% |
38+
| synthetic | 200 | 83.6% | 99.1% | 98.5% |
3939

4040
## How to read this
4141

docs/benchmarks/llm-fidelity.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ Grading is automatic against corpus ground truth.
88
- Corpus: 31 messages (seed=7, 6/category + real fixture, scale=0.2)
99
- Compressor: rule_fast via `HiveStack.compress`
1010
- Machine: x86_64 / Linux / 4 cores
11-
- Commit: `1010e8e` — 2026-06-09T22:51:26+00:00
11+
- Commit: `fababb1` — 2026-06-09T22:56:36+00:00
1212

1313
## Overall
1414

1515
| Metric | Raw context | Compressed context |
1616
|---|---|---|
17-
| QA accuracy (graded facts) | 67.7% | **60.0%** |
17+
| QA accuracy (graded facts) | 67.7% | **69.2%** |
1818
| Messages fully answered | 32.3% | 38.7% |
19-
| Avg prompt tokens | 657 | 220 (**-66.5%**) |
19+
| Avg prompt tokens | 657 | 221 (**-66.3%**) |
2020

2121
## By category (QA accuracy)
2222

2323
| Category | Raw | Compressed | Raw tokens | Compressed tokens |
2424
|---|---|---|---|---|
2525
| command_output | 50.0% | 58.3% | 302 | 209 |
26-
| file_read | 50.0% | 0.0% | 1128 | 298 |
26+
| file_read | 50.0% | 50.0% | 1128 | 308 |
2727
| pytest_log | 82.4% | 82.4% | 1286 | 132 |
2828
| search_results | 91.7% | 91.7% | 206 | 218 |
2929
| traceback | 58.3% | 58.3% | 256 | 256 |

hive/rule_fast/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,16 @@ def _classify(role: str, content_type: str, content: str = "") -> str:
166166
_MAX_SKELETON_LINES = 200
167167

168168
_RE_ERRORISH = re.compile(r"error|fail|fatal|denied|exception|timed? ?out", re.I)
169+
# Skeleton keeps: signatures, imports, top-level assignments, and *literal*
170+
# constant assignments inside bodies (`limit = 1234`, `URL = "..."`). The
171+
# LLM fidelity eval showed body values are what agents go looking for in
172+
# file reads; literal assignments are one line each and carry most of that
173+
# signal. Computed assignments (`x = payload.get(...)`) stay dropped.
169174
_RE_SIGNATURE = re.compile(
170-
r"^\s*(?:async\s+def|def|class|pub fn|fn|function|export)\b|^[A-Za-z_]\w*\s*=\s|^(?:import|from)\s"
175+
r"^\s*(?:async\s+def|def|class|pub fn|fn|function|export)\b"
176+
r"|^[A-Za-z_]\w*\s*=\s"
177+
r"|^(?:import|from)\s"
178+
r"|^\s+[A-Z_a-z]\w*\s*(?::[^=]+)?=\s*(?:-?\d|[\"'])[^(]*$"
171179
)
172180

173181

0 commit comments

Comments
 (0)