Skip to content

emrg: emit anchor-bias-heartbeat with explicit anchored state every round (issue #1078) - #1079

Merged
argszero merged 1 commit into
masterfrom
feature/anchor-heartbeat-anchored-reasons
Aug 30, 2026
Merged

emrg: emit anchor-bias-heartbeat with explicit anchored state every round (issue #1078)#1079
argszero merged 1 commit into
masterfrom
feature/anchor-heartbeat-anchored-reasons

Conversation

@argszero

Copy link
Copy Markdown
Owner

Fixes#1078

Problem

The anchor-bias-heartbeat (added in #1073, consumed by #1076's calibration) was emitted per anchored round FROM INSIDE _detect_silent_anchor_drift — so anything that stops anchored rounds entirely yields zero heartbeat lines, byte-identical to the detector having stopped. Reader comment 3dn6k by vinhnguyenthanhdn: "that is the same ambiguity you removed one level down with anchor_loss, reappearing one level up at the call site."

Failure modes that went fully silent on master 981f037:

  • final_usage missing/empty → detector never called → no heartbeat
  • prompt_tokens missing/zero → same
  • no anchor yet / anchor invalid / estimate or bias non-positive → early return before the heartbeat

Change

"Log unconditionally, alert conditionally" moves one level up — every round now emits exactly one anchor-bias-heartbeat line with an explicit state:

  • Extracted the round-loop usage-refresh block (L2589-2606) into _refresh_usage_anchor, which emits anchored=false reason=no_usage / reason=no_prompt_tokens on the outer skip paths and passes through to the detector when prompt_tokens arrives.
  • Detector early returns now emit labeled anchored=false heartbeats: reason=no_anchor, reason=invalid_estimate, reason=invalid_bias (the combined early return is split so each reason is distinguishable).
  • The success heartbeat gains anchored=true (the inside-detector case, unchanged fields otherwise).
  • Greppable marker anchor-bias-heartbeat and debug level unchanged — existing grep "anchor-bias-heartbeat" workflows keep working; only the reason field is new.

Verification

  • Tests assert each state (positive + negative per repo verification rules): no_usage (None + empty dict), no_prompt_tokens (missing + zero), no_anchor, invalid_estimate, invalid_bias, and the anchored=true success path with re-anchor + observation event.
  • Local: pytest 1177 passed + 1 skipped (Agent.md count synced 1177 → 1178), import + CLI green.

…ound (issue #1078)
The heartbeat used to live only inside _detect_silent_anchor_drift, so a
round that skipped the detector (no usage, no prompt_tokens, no anchor,
invalid estimate) produced zero heartbeat lines — byte-identical to the
detector having stopped (Dev.to 3dn6k — vinhnguyenthanhdn via pm25coder).
- Extract the round-loop usage-refresh block into _refresh_usage_anchor
so every round emits exactly one anchor-bias-heartbeat line:
anchored=false reason=no_usage / no_prompt_tokens on the outer skip
paths, and pass-through to the detector when prompt_tokens arrives
- Detector early returns now emit labeled anchored=false heartbeats
(no_anchor / invalid_estimate / invalid_bias) instead of bare returns
- Success heartbeat gains the anchored=true field (grep marker and debug
level unchanged)
- Tests: assert each skip state (positive + negative per repo rules) and
the anchored=true success path; Agent.md Python count 1177 -> 1178
@pm25coder

Copy link
Copy Markdown
Collaborator

Verified PR #1079 against issue #1078's acceptance criteria (reviewed the diff and the head ref `feature/anchor-heartbeat-anchored-reasons`; CI `test` passing, `test-windows` pending at the time of writing) and found the implementation complete:

@argszeroargszero left a comment

Copy link
Copy Markdown
OwnerAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle

Reviewed the full diff:

  • _refresh_usage_anchor helper cleanly extracts the round-loop usage path; every round now emits exactly one anchor-bias-heartbeat with an explicit state.
  • Skip paths are first-class labeled observations: anchored=false reason=no_usage / reason=no_prompt_tokens (round loop), reason=no_anchor / invalid_estimate / invalid_bias (detector early returns).
  • Success path now labeled anchored=true, preserving the #1072 bias_shift/threshold heartbeat and the #1027 silent-drift detection (old anchor still in place before overwrite).
  • Tests: new test_anchor_heartbeat_every_round_labeled covers all 5 states; updated tests assert anchored=true; caplog.set_level persistence fix avoids silent DEBUG→WARNING restoration.
  • CI: test and test-windows both pass (run 33310636543).

The observability gap from issue #1078 (skipped rounds indistinguishable from a stopped detector) is closed. LGTM 1/3.

@argszeroargszero left a comment

Copy link
Copy Markdown
OwnerAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle (2/3)

Independent re-review in this cycle:

  • Head 2051a82 unchanged since LGTM 1/3; diff still matches the issue #1078 design exactly.
  • CI: test and test-windows both pass (run 33310636543) — actionlint gate and doc-count guard (Agent.md 1178) covered.
  • _refresh_usage_anchor emits exactly one labeled heartbeat per round on all paths (anchored=false reason=no_usage/no_prompt_tokens/no_anchor/invalid_estimate/invalid_bias; anchored=true on success), closing the observability gap: skipped rounds are now labeled observations, not absence.
  • Tests cover all 5 states with persistent caplog.set_level; MERGEABLE.

LGTM 2/3.

@argszeroargszero left a comment

Copy link
Copy Markdown
OwnerAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM — cycle (3/3)

Third consecutive approval from a distinct cycle:

  • Head 2051a82 still byte-identical to the LGTM 1/3 review (no drift since submission).
  • CI: test + test-windows both pass on run 33310636543; MERGEABLE/CLEAN.
  • Implementation fully satisfies issue #1078's acceptance criteria: exactly one labeled anchor-bias-heartbeat per round across all paths (anchored=false reason=no_usage/no_prompt_tokens/no_anchor/invalid_estimate/invalid_bias; anchored=true on success), with tests covering all 5 states.

3 consecutive ✅ (12:15:18Z, 12:22:24Z, this review) — merging.

@argszero
argszero merged commit 41f75cd into masterAug 30, 2026
2 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emit the anchor-bias heartbeat from the round loop with an explicit anchored:false reason

2 participants

@argszero@pm25coder