Expand description
Edit-efficiency metering (#1008, honest-metering philosophy #361).
Anchored editing (ctx_patch) saves output tokens: the model references a
(line, hash) anchor instead of reproducing the replaced span byte-for-byte
the way a str_replace old_string requires. This module measures that claim
with real per-edit numbers instead of a marketing multiplier:
- avoided output tokens — per successful anchored op:
tokens(replaced span) − tokens(anchor args), floored at 0. The replaced span is exactly what a str_replace edit would have re-emitted asold_string; the anchor args are what the model actually sent instead. - conflict round-trips — stale-anchor
CONFLICTresponses (each one is an extra turn the anchored loop needed). - str_replace baseline — successful
ctx_editcalls with theold_stringtokens they really paid, plusold_string-miss round-trips.
This is a separate metric channel: values are never folded into the
read-gain ledger and never appear in tool output bodies (#498 determinism).
Consumers are ctx_metrics, the dashboard (/api/stats →
edit_efficiency) and the A/B eval harness.
Storage: ~/.lean-ctx/edit_metering.json, atomic write (tmp+rename),
loaded once per process, flushed every few records like edit_quality.
Structs§
- Edit
Metering Store - All-time counters for both edit paths. Small, append-only aggregates —
per-file/per-op detail intentionally lives in
edit_quality, not here.serde(default)keeps older/partial store files loadable field-by-field instead of silently resetting all counters viaunwrap_or_default.
Functions§
- flush
- metrics_
snapshot - Snapshot for
ctx_metricsand the dashboard/api/statspayload. - record_
anchored_ conflict - A stale-anchor
CONFLICTresponse (one extra self-heal round-trip). - record_
anchored_ success - A successful anchored patch:
opsapplied,avoided_tokensoutput tokens the model did not have to reproduce (already anchor-overhead-adjusted). - record_
str_ replace_ miss - An
old_string-not-found miss (one blind retry round-trip). - record_
str_ replace_ success - A successful str_replace edit and the
old_stringtokens it paid.