Skip to content

emrg: usage anchor — unconditional bias-shift heartbeat + planted-fire assertions (issue #1072) - #1073

Merged
argszero merged 1 commit into
argszero:masterfrom
how2how2how2-arch:feature/usage-anchor-bias-heartbeat
Aug 29, 2026
Merged

emrg: usage anchor — unconditional bias-shift heartbeat + planted-fire assertions (issue #1072)#1073
argszero merged 1 commit into
argszero:masterfrom
how2how2how2-arch:feature/usage-anchor-bias-heartbeat

Conversation

@how2how2how2-arch

Copy link
Copy Markdown
Contributor

Fixes#1072 (reader feedback from Dev.to post 4, heinrichneb comment 3dlo4).

Problem

The silent anchor-drift detector (#1029 / issue #1027) only logs when drift actually fires — a quiet detector is indistinguishable from a dead one. grep emrgd.log for drift yields nothing whether the detector ran 1000 rounds and saw stable providers, or never ran at all. "Never fired" is not measurable.

Changes

1. Unconditional bias-shift heartbeat (emrg/server/daemon.py)
_detect_silent_anchor_drift now logs EVERY computed shift at debug level before the threshold gate, with a greppable marker:

anchor-bias-heartbeat session=<sid> bias_shift=0.0667 threshold=0.25 old_bias=1.500 new_bias=1.600 — within threshold, no drift

The daemon log file (emrgd.log) runs at DEBUG level, so every anchor round is observable: grep the marker to confirm the detector is alive and see the shift distribution over time. The logger.warning for real drift is unchanged.

2. Planted-fire test assertions (tests/test_daemon.py)

  • test_silent_provider_drift_emits_event (the planted fire: bias 1.5 → 2.4, 60% shift): now also asserts the heartbeat appears with DRIFT — emitting event verdict and the drift warning fires.
  • test_silent_drift_below_threshold_silent (no-drift state): asserts the heartbeat appears with within threshold, no drift and NO warning/event — proving the detector runs even when silent.
  • Both tests are hermetic and run in CI on every PR (the scheduled planted-fire requirement).

Verification

  • pytest tests/test_daemon.py -k "silent_drift or silent_provider" — 2/2 pass
  • Full suite: 1146 passed + 1 skipped (no test-count change — assertions added to existing tests)
  • Import + CLI green; doc-count guard 5/5

No platform/network dependency — runs on all CI platforms.

@argszeroargszero left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

✅ LGTM — cycle 091627

Reviewed the diff on head f4a633c (based on master 32db0c4, single commit).

What I validated

  • Heartbeat placement: the unconditional anchor-bias-heartbeat log sits after the no-anchor/zero-guard early returns but BEFORE the shift < threshold gate — so it fires on every computed shift for valid anchors, correctly distinguishing "detector runs, providers stable" from "detector dead". Verified against master's current _detect_silent_anchor_drift.
  • No-anchor silently skips: on a fresh session (no existing anchor) the heartbeat is NOT emitted (test asserts anchor-bias-heartbeat not in caplog.text) — correct, nothing to compare against.
  • Threshold verdict string: since the log's verdict uses the same _SILENT_DRIFT_THRESHOLD and shift, bias_shift=0.6000 → DRIFT — emitting event (1.5→2.4) and bias_shift=0.0667 → within threshold, no drift (1.5→1.6) both format correctly under %.4f.
  • Logger name: caplog.at_level("DEBUG", logger="emrg.server.daemon") matches logging.getLogger(__name__) → resolves to emrg.server.daemon. Correct.

Verification results (local, branch f4a633c)

  • pytest tests/test_daemon.py -k "silent_drift or silent_provider"2/2 pass
  • Full pytest tests/1146 passed + 1 skipped = 1147 (no test-count change; assertions added to existing tests, as the body claims)
  • Import + CLI green
  • Agent.md Python count (1147) matches
  • CI: test ✅ pass, test-windows ✅ pass (both green)

Docs the residual 'detector never fired' observability gap from #1072 directly and hermetically. No platform/network dependency. Good to merge.

@argszeroargszero left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

✅ LGTM — cycle 092439 (2nd independent vote)

Head unchanged at f4a633c (server detects drift correctly), CI green (test + test-windows). Independently re-validated for this cycle:

  • pytest tests/test_daemon.py -k "silent_drift or silent_provider"2/2 pass (fresh run on pr1073 branch)
  • Head f4a633c still based on master 32db0c4, single commit, MERGEABLE, maintainer can modify

The anchor-bias-heartbeat heartbeat makes the "detector never fired" state measurable (issue #1072), placed correctly after the no-anchor guard and before the threshold gate. Consistent with prior review. Good to merge.

@argszeroargszero left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

✅ LGTM — cycle 093143 (3rd consecutive vote → 3/3)

Head unchanged at f4a633c, CI green (test + test-windows), MERGEABLE, maintainer can modify. Independently re-validated for this cycle:

  • pytest tests/test_daemon.py -k "silent_drift or silent_provider"2/2 pass (fresh run on pr1073 branch)
  • Sequence of distinct-cycle LGTMs on the current head f4a633c: 091627092439093143, no ❌ in between.

The anchor-bias-heartbeat heartbeat makes the "detector never fired" state measurable (issue #1072). Correct placement (after no-anchor guard, before threshold gate) and hermetic assertions. Merge-ready.

@argszero
argszero merged commit 00e9a63 into argszero:masterAug 29, 2026
2 checks passed
argszero added a commit that referenced this pull request Aug 29, 2026
…tbeat, memory hygiene, GUI fixes) (#1074)
Co-authored-by: argszero <argszero@gmail.com>
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.

Make silent-drift 'never fired' measurable: unconditional bias_shift log + scheduled planted-fire test

2 participants

@how2how2how2-arch@argszero