Skip to content

Official Codebase of 3DCodeVerse

Python

review follow-ups: two reviews, twenty findings, four that were real

gaoypengf59ce7e6ae83
diff --git a/harness/codeverse/cost/reconstruct.py b/harness/codeverse/cost/reconstruct.py
index eb872630..4f22f57f 100644
--- a/harness/codeverse/cost/reconstruct.py
+++ b/harness/codeverse/cost/reconstruct.py
@@ -43,7 +43,12 @@ from codeverse.proc import read_json_or_none, read_jsonl_lenient
log = logging.getLogger(__name__)
#: events whose cost duplicates rows we already emit
-_AGGREGATE_EVENTS = frozenset({"round.done", "run.done", "texture.done"})
+#: events whose ``cost_usd`` RESTATES money the per-call rows already carry — turning one into a
+#: priced row double-counts. ``candidate.done`` repeats its own round's total and
+#: ``candidate.selected`` the sum over every candidate, so a best-of-N run reconstructed from
+#: events alone billed its candidates two to three times (2026-08-30).
+_AGGREGATE_EVENTS = frozenset({"round.done", "run.done", "texture.done",
+ "candidate.done", "candidate.selected"})
def _read_json(path: Path) -> dict[str, Any]:
diff --git a/harness/codeverse/languages/_ast_lint.py b/harness/codeverse/languages/_ast_lint.py
index e67a89c4..41d0943a 100644
--- a/harness/codeverse/languages/_ast_lint.py
+++ b/harness/codeverse/languages/_ast_lint.py
@@ -87,6 +87,12 @@ def check_imports(
"""
out: list[GateFinding] = []
for mod, line in imports.items():
+ if not mod:
+ # `from . import helpers` has no top-level module to police: ast gives
+ # `node.module is None` and every visitor records "". Reporting it produced
+ # "import of '' is unexpected" — a finding the agent cannot act on — in all
+ # three languages that share this helper (2026-08-30).
+ continue
if mod in forbidden:
out.append(make_finding("forbidden", mod, line))
elif mod not in allowed:
diff --git a/harness/docs/COST.md b/harness/docs/COST.md
index c49d00ab..1c63ee53 100644
--- a/harness/docs/COST.md
+++ b/harness/docs/COST.md
@@ -461,8 +461,10 @@ recorded turns were labelled `api-agent:baseline:tN`). A session row is filed b
KIND through `cost.types.stage_for_label` (candidate → candidate, zone → zones, compose →
assemble, rebuild → repair, asset / asset_fix → assets); before 2026-08-29 the scene kinds
landed in `other`. Candidate generation sessions carry `stage=candidate` with labels
-`baseline_c<k>`; candidate judge money is booked `stage=judge role=judge round_index=0`
-and the pairwise tie-break `stage=judge label=pairwise`. `audit.lost_candidate` counts
+`baseline_c<k>`; candidate judge money is booked `stage=judge`, and the pairwise tie-break
+`stage=pairwise` (its ledger row carries `role=judge`, label `pairwise:…`). Role, label and
+round live on the `CallCost` row, never on the guard — `BudgetGuard.charge/add` take
+`(usage, *, stage, enforce)` only since 2026-08-30 (D45). `audit.lost_candidate` counts
generator sessions only and reads both label forms — `baseline_c<k>` (live) and
`c<k>:baseline` (reconstructed).
@@ -471,10 +473,12 @@ generator sessions only and reads both label forms — `baseline_c<k>` (live) an
`bench/run_bench.py` opens one per prompt and `bench/compare_backends.py` one per
cell (plus a nested one for a harness arm's own run, and one for the pairwise
arena). The batteries produce most of the runs in this repo, so until wave 3
-most priced rows were going to the per-process fallback log. `run_ledger` nests
-(it restores the outer ledger and run binding instead of clearing them) and binds
-context-locally with a process-wide fallback, so `--parallel N` keeps N ledgers
-apart while a fan-out worker thread that inherited no context still finds its run.
+most priced rows were going to the per-process fallback log. `run_ledger` nests by holding
+ContextVar tokens (`bound_run` / `bound_ledger`); there is no process-wide default, so
+`--parallel N` keeps N ledgers apart. A thread that may bill a model must therefore be
+spawned through `proc.fan_out`, which copies the context — never a bare pool (D45(b): the
+old save-and-restore republished a sibling’s run the moment the first cell exited). A call
+with no run context still lands in the per-process log under `cache_dir/cost/`.
The row carries run, round, stage, role, label, backend/provider/model, the four
token counts, the three **unit prices actually used** plus their provenance
diff --git a/harness/docs/DECISIONS.md b/harness/docs/DECISIONS.md
index 9844538d..9341ce3b 100644
--- a/harness/docs/DECISIONS.md
+++ b/harness/docs/DECISIONS.md
@@ -299,7 +299,19 @@ written) that were accepted because the code works that way and the tests pin it
(c) **A paid verdict is never re-bought or reversed.** `PairwiseNote` moved into
`contracts/run.py` and onto `RoundRecord`; `reconcile_resume` replays it
(`candidates.replay_best_round`). Reconciliation may re-rank; it may not undo a comparison the
- run paid for (18 run dirs on disk carried a divergent verdict).
+ run paid for. **The guarantee is forward-only** — 0 of the 1 466 `rounds/rNN.json` on disk carry
+ the field, so for every existing run `replay_best_round` degenerates to the pre-2026-08-30
+ `BestSelector().pick`, which is why nothing on disk changed behaviour. Of the 30 recorded dirs
+ whose stored best disagrees with a plain re-rank, exactly one is re-enterable by `3dcv resume`
+ (20 are `plateau`, refused without `--force`; 9 name generator kinds deleted 2026-08-28).
+ KNOWN DIVERGENCE, unresolved: on the re-judge path `_promote_best` runs TWICE for one index
+ (`lifecycle._round_loop`) — once with `judgment=None`, which lets `choose_best_round`'s
+ `score is None` branch move the incumbent onto a round an earlier pairwise kept out, and again
+ after `rejudge_round`. `replay_best_round` models one promotion per index, so after a judge
+ outage the live loop and the replay can pick different rounds (reproduced: live r1, replay r0).
+ Replay's answer is the one that honours the earlier verdict; the live loop is what reverses it
+ inside the unscored window. Fixing the LIVE side is the change this law implies, and it is not
+ made here.
(d) **One render-cache authority.** `spatial/tool_common.py` may name a deterministic out_dir;
only `spatial/render.py` decides a PNG is still good. The deleted `renderset.json` marker keyed
on GLB size+mtime alone: it served stale views after a same-size rebuild, ignored a rig edit,
diff --git a/harness/docs/INTERFACES.md b/harness/docs/INTERFACES.md
index ee879164..eea1c27b 100644
--- a/harness/docs/INTERFACES.md
+++ b/harness/docs/INTERFACES.md
@@ -112,8 +112,9 @@ from codeverse.cost.instrument import (run_ledger, metered_chat_model, metered_a
MeteredAgent, MeteredChatModel, metering_enabled)
with run_ledger(ws.root, run=slug): # binds the run, points record_call at <run>/telemetry/cost.jsonl
... # (+ a <run>/cost_ledger.jsonl symlink for the run-layout alias)
- # NESTS (restores the outer ledger + run binding on exit) and is context-local first, so
- # bench.run_bench / compare_backends can hold one ledger per prompt across N threads.
+ # NESTS by holding ContextVar tokens (bound_run / bound_ledger) — context-local ONLY, no
+ # process-wide default — so bench.run_bench / compare_backends hold one ledger per prompt
+ # across N threads, and a thread that may bill a model goes through proc.fan_out.
# BaseTrack.run opens `run_ledger(ws.root, run=ws.root.name)` ITSELF, so a track run started
# outside the CLI/bench still meters; the CLI/bench ledger for the same run dir is the same file.
# models.get_chat_model returns a MeteredChatModel → ONE row per ChatModel.generate