[rebase w2] src/rune/token_optimizer.py::CacheEntry.CacheEntry.to_dict #770

Closed
opened 2026-09-29 08:07:25 +01:00 by conductor · 3 comments
Owner

Identity (from the Wave 0 inventory — machine-generated)

  • File: src/rune/token_optimizer.py
  • Unit: CacheEntry.CacheEntry.to_dict
  • Signature: def CacheEntry.CacheEntry.to_dict(self) (async: False)
  • Line range: 45–52
  • Decorators: none
  • Internal call edges (callers/callees inside the repo, from inventory):
    • (no internal call edges in range)

Current behaviour

One honest paragraph from READING THE CODE at the line range above — what it
actually does, not what the docstring promises. Write this at disposition
time; the factory does not fabricate it.

The three questions — each answered WITH EVIDENCE

  1. IMPROVE? Can the unit be improved within its scope? Evidence or "no — because …".
    (Bounded to unit scope; larger findings spawn NEW issues, never expand this one.)
  2. FIX? Is it broken, buggy, or failing its expected outcome? Evidence: a failing
    test, a reproduced fault, or a code-level defect citation. A "no" needs evidence too.
  3. MISSING CONNECTORS? Are there expected outcomes this unit should connect to but
    doesn't (unwired events, dead parameters, promised-but-absent calls)? Evidence required.

A silent skip on any question is a factory bug — answer all three.

Language verdict (per tranche R1 §6 rubric — evidence beats instinct)

Choose exactly one, with the evidence line:

  • KEEP-PYTHON — one sentence of justification.
  • RECODE- — rubric scores (all 7 dimensions) + benchmark-gate plan: the compiled
    replacement must beat the Python original on the MEASURED hot path, or the recode is
    rejected and recorded. No win, no recode.
  • MERGE-into: — name the target and why.
  • DEPRECATE — name the caller that no longer needs it.

Go is NOT pre-decided. Python is not pre-decided. The rubric decides.

Constraint context

  • henxels structural contract: this unit's module ≤ 1,200 lines (or on the debt table's
    exception list — check before adding lines).
  • Spine: any module-surface change requires store/spine/current.json regen with the code
    change (test_manifest_maps_every_module is the arbiter for new top-level modules).
  • Debt table: docs/structural-contract.md.

Pipeline plan

  1. Branch issue-<N> from current master (existing issue-N convention).
  2. Scaffolding activation for any construction (construction_mode/decision per unit change).
  3. Research rounds are MANDATORY for any RECODE verdict (research-stage-headless; ≥2
    live-verified external sources per claim; per-source lessons; kill test per candidate).
  4. Implementation behind the interop contract (R1 §5): compiled units are standalone
    binaries — argv in, JSON on stdout, non-zero exit on failure, --version mandatory;
    Python wraps in a thin adapter; store stays the shared truth.
  5. Local gates: pytest + ruff + spine-store regen (if surface changed) + henxels.
  6. PR → pipeline-gate + ci + required checks → merge-robot → auto-version.

Verification

  • The specific test proving this unit's change: (write at disposition).
  • The keep-green set it must not break: full suite must stay green; named
    keep-green tests for this unit's callers.

Provenance

  • Tranche: tranche R1 language rebase (2026-09-29), ~/.config/opencode/tranches/2026-09-29-language-rebase-tranche-R1.md
  • Wave: 2 (leaf utilities & canaries)
  • Inventory: docs/rebase-inventory.json (regenerate with scripts/rebase_inventory.py — never hand-edit)
  • Factory: scripts/rebase_issue_factory.py
## Identity (from the Wave 0 inventory — machine-generated) - **File**: `src/rune/token_optimizer.py` - **Unit**: `CacheEntry.CacheEntry.to_dict` - **Signature**: `def CacheEntry.CacheEntry.to_dict(self)` (async: False) - **Line range**: 45–52 - **Decorators**: none - **Internal call edges** (callers/callees inside the repo, from inventory): - (no internal call edges in range) ## Current behaviour One honest paragraph from READING THE CODE at the line range above — what it actually does, not what the docstring promises. Write this at disposition time; the factory does not fabricate it. ## The three questions — each answered WITH EVIDENCE 1. **IMPROVE?** Can the unit be improved within its scope? Evidence or "no — because …". (Bounded to unit scope; larger findings spawn NEW issues, never expand this one.) 2. **FIX?** Is it broken, buggy, or failing its expected outcome? Evidence: a failing test, a reproduced fault, or a code-level defect citation. A "no" needs evidence too. 3. **MISSING CONNECTORS?** Are there expected outcomes this unit should connect to but doesn't (unwired events, dead parameters, promised-but-absent calls)? Evidence required. A silent skip on any question is a factory bug — answer all three. ## Language verdict (per tranche R1 §6 rubric — evidence beats instinct) Choose exactly one, with the evidence line: - **KEEP-PYTHON** — one sentence of justification. - **RECODE-<lang>** — rubric scores (all 7 dimensions) + benchmark-gate plan: the compiled replacement must beat the Python original on the MEASURED hot path, or the recode is rejected and recorded. No win, no recode. - **MERGE-into:<module>** — name the target and why. - **DEPRECATE** — name the caller that no longer needs it. Go is NOT pre-decided. Python is not pre-decided. The rubric decides. ## Constraint context - henxels structural contract: this unit's module ≤ 1,200 lines (or on the debt table's exception list — check before adding lines). - Spine: any module-surface change requires `store/spine/current.json` regen with the code change (`test_manifest_maps_every_module` is the arbiter for new top-level modules). - Debt table: docs/structural-contract.md. ## Pipeline plan 1. Branch `issue-<N>` from current master (existing issue-N convention). 2. Scaffolding activation for any construction (construction_mode/decision per unit change). 3. Research rounds are MANDATORY for any RECODE verdict (research-stage-headless; ≥2 live-verified external sources per claim; per-source lessons; kill test per candidate). 4. Implementation behind the interop contract (R1 §5): compiled units are standalone binaries — argv in, JSON on stdout, non-zero exit on failure, `--version` mandatory; Python wraps in a thin adapter; store stays the shared truth. 5. Local gates: pytest + ruff + spine-store regen (if surface changed) + henxels. 6. PR → pipeline-gate + ci + required checks → merge-robot → auto-version. ## Verification - The specific test proving this unit's change: (write at disposition). - The keep-green set it must not break: full suite must stay green; named keep-green tests for this unit's callers. ## Provenance - Tranche: tranche R1 language rebase (2026-09-29), ~/.config/opencode/tranches/2026-09-29-language-rebase-tranche-R1.md - Wave: 2 (leaf utilities & canaries) - Inventory: docs/rebase-inventory.json (regenerate with scripts/rebase_inventory.py — never hand-edit) - Factory: scripts/rebase_issue_factory.py

⚠️ Priority gate: this issue has no priority. Assign exactly one of P0 — critical (spine/correctness/blocks), P1 — high (material value or real defect), P2 — medium (quality/consolidation), P3 — low (measurement/deferred). An issue without a priority is not filed.

⚠️ **Priority gate:** this issue has no priority. Assign exactly one of **P0 — critical** (spine/correctness/blocks), **P1 — high** (material value or real defect), **P2 — medium** (quality/consolidation), **P3 — low** (measurement/deferred). An issue without a priority is not filed.
gitea-actions Bot added the bugcustodiangrowthidentityinfrastructurememory labels 2026-09-29 08:21:35 +01:00
Author
Owner

Disposition — CacheEntry.to_dict (46–58) — FIXED, bug-fix contract discharged

Current behaviour (from code read, post-fix): serialises the dataclass to a plain dict for persistence in _save ("cache": {key: entry.to_dict() ...}). Post-fix the dict carries all six fields including the required content; line numbers shifted +5 from the inventory's pre-fix citation.

  1. IMPROVE? No — post-fix it is the dataclass's own field set, one-to-one; a dataclasses.asdict swap would be cosmetic.
  2. FIX? YES — real defect, red-test-first, root-caused, fixed, frozen. The pre-fix dict omitted content, which CacheEntry requires → _load's CacheEntry(**entry_data) raised TypeError on EVERY reload → the blanket except in _load silently discarded the whole cache on every process restart, with no error anywhere. Evidence chain: red repro (TypeError: __init__() missing 1 required positional argument: 'content' → empty cache, produced fire #58 before any fix); frozen regression contract tests/test_token_optimizer_cache.py — 3 tests (save_persists_content, roundtrip_restores_content, corrupt_storage_degrades_to_empty_cache), all green post-fix; first red run's test-shape bug (flush-on-never-dirty second instance) corrected so the frozen tests drive the honest mutation path (_mark_dirty → flush); red re-attributed to the defect itself by replaying the pre-fix to_dict shape against a correct on-disk file. Full suite re-run in progress at disposition time; commit carries test + fix together.
  3. MISSING CONNECTORS? No — to_dict's only consumers are _save and get_cache_stats, both wired; the roundtrip connector to _load is now test-frozen.

Language verdict (rebase R1 §6 rubric): KEEP-PYTHON. The wave's heaviest work in this module is 2 re.sub per turn (rubric :280) — no hot loop exists here; every candidate compiled crossing costs ~658 µs (14,000× the cost of the work it would replace), and this unit is already on the CPython 3.11+ PEP 659 shape the rubric awards (rubric :282). No benchmark gate is owed: no measured hot path exists to beat. Zero RECODE.

## Disposition — `CacheEntry.to_dict` (46–58) — **FIXED, bug-fix contract discharged** **Current behaviour (from code read, post-fix):** serialises the dataclass to a plain dict for persistence in `_save` (`"cache": {key: entry.to_dict() ...}`). Post-fix the dict carries all six fields including the required `content`; line numbers shifted +5 from the inventory's pre-fix citation. 1. **IMPROVE?** No — post-fix it is the dataclass's own field set, one-to-one; a `dataclasses.asdict` swap would be cosmetic. 2. **FIX?** **YES — real defect, red-test-first, root-caused, fixed, frozen.** The pre-fix dict omitted `content`, which `CacheEntry` requires → `_load`'s `CacheEntry(**entry_data)` raised `TypeError` on EVERY reload → the blanket `except` in `_load` silently discarded the whole cache on every process restart, with no error anywhere. Evidence chain: red repro (`TypeError: __init__() missing 1 required positional argument: 'content'` → empty cache, produced fire #58 before any fix); frozen regression contract `tests/test_token_optimizer_cache.py` — 3 tests (`save_persists_content`, `roundtrip_restores_content`, `corrupt_storage_degrades_to_empty_cache`), all green post-fix; first red run's test-shape bug (flush-on-never-dirty second instance) corrected so the frozen tests drive the honest mutation path (`_mark_dirty` → `flush`); red re-attributed to the defect itself by replaying the pre-fix `to_dict` shape against a correct on-disk file. Full suite re-run in progress at disposition time; commit carries test + fix together. 3. **MISSING CONNECTORS?** No — `to_dict`'s only consumers are `_save` and `get_cache_stats`, both wired; the roundtrip connector to `_load` is now test-frozen. **Language verdict (rebase R1 §6 rubric): KEEP-PYTHON.** The wave's heaviest work in this module is 2 `re.sub` per turn (rubric `:280`) — no hot loop exists here; every candidate compiled crossing costs ~658 µs (14,000× the cost of the work it would replace), and this unit is already on the CPython 3.11+ PEP 659 shape the rubric awards (rubric `:282`). No benchmark gate is owed: no measured hot path exists to beat. Zero RECODE.
Author
Owner

Folded into epic #2303 — per-file epic for src/rune/token_optimizer.py (w2). Absorbed child; closing as absorbed (content preserved, reversible by reopen).

Folded into epic #2303 — per-file epic for `src/rune/token_optimizer.py` (w2). Absorbed child; closing as absorbed (content preserved, reversible by reopen).
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: conductor/rune#770