fix(tokens): restore token_phase_flush re-baseline; drop stray block from gate_token_check
The per-gate functions were inserted immediately after token_phase_flush's log line, which split the function: its trailing re-baseline block (the 'if next_phase_id is not None: ...' that re-seeds the per-phase baseline for the next phase, or finalizes when None) was orphaned onto the end of gate_token_check, where next_phase_id is undefined. The watchdog therefore crashed with NameError on the first tick of every start. Move that block back into token_phase_flush (where next_phase_id/cur/sf are in scope) and end gate_token_check at its log line. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UWTdUq2bsic7JZGqJp3nD6
This commit is contained in:
12
agents.py
12
agents.py
@ -757,6 +757,12 @@ def token_phase_flush(cfg, next_phase_id):
|
|||||||
fh.write(json.dumps(rec) + "\n")
|
fh.write(json.dumps(rec) + "\n")
|
||||||
parts = ", ".join(f"{n}={per_agent[n]['total']:,}" for n in per_agent)
|
parts = ", ".join(f"{n}={per_agent[n]['total']:,}" for n in per_agent)
|
||||||
log(f"[log_tokens] phase {rec['phase_id']}: {total['total']:,} tok in {dur}s ({parts})")
|
log(f"[log_tokens] phase {rec['phase_id']}: {total['total']:,} tok in {dur}s ({parts})")
|
||||||
|
if next_phase_id is not None:
|
||||||
|
sf.write_text(json.dumps({"phase_id": next_phase_id,
|
||||||
|
"started": datetime.now().isoformat(timespec="seconds"),
|
||||||
|
"baseline": cur}))
|
||||||
|
else:
|
||||||
|
sf.unlink(missing_ok=True)
|
||||||
|
|
||||||
# ── token logging granularity: per phase, or also per GATE (log_tokens) ────────────
|
# ── token logging granularity: per phase, or also per GATE (log_tokens) ────────────
|
||||||
# Phases are tracked per phase (token_phase_begin/flush). With token_granularity="gate" (the default)
|
# Phases are tracked per phase (token_phase_begin/flush). With token_granularity="gate" (the default)
|
||||||
@ -844,12 +850,6 @@ def gate_token_check(cfg):
|
|||||||
"started": datetime.now().isoformat(timespec="seconds"),
|
"started": datetime.now().isoformat(timespec="seconds"),
|
||||||
"baseline": _token_cumulative(cfg)}))
|
"baseline": _token_cumulative(cfg)}))
|
||||||
log(f"[log_tokens] tracking gate: {current}")
|
log(f"[log_tokens] tracking gate: {current}")
|
||||||
if next_phase_id is not None:
|
|
||||||
sf.write_text(json.dumps({"phase_id": next_phase_id,
|
|
||||||
"started": datetime.now().isoformat(timespec="seconds"),
|
|
||||||
"baseline": cur}))
|
|
||||||
else:
|
|
||||||
sf.unlink(missing_ok=True)
|
|
||||||
|
|
||||||
def phase_advance_check(cfg):
|
def phase_advance_check(cfg):
|
||||||
"""On heavy tick: if the current phase is DONE, advance (or finish the sequence).
|
"""On heavy tick: if the current phase is DONE, advance (or finish the sequence).
|
||||||
|
|||||||
Reference in New Issue
Block a user