') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); emrg: planted-fire drill rides the real tokenizer-switch path (issue #1087) by argszero · Pull Request #1089 · argszero/emrg · GitHub
Skip to content

emrg: planted-fire drill rides the real tokenizer-switch path (issue #1087) - #1089

Merged
argszero merged 1 commit into
masterfrom
feature/planted-fire-drill-same-door
Aug 31, 2026
Merged

emrg: planted-fire drill rides the real tokenizer-switch path (issue #1087)#1089
argszero merged 1 commit into
masterfrom
feature/planted-fire-drill-same-door

Conversation

@argszero

Copy link
Copy Markdown
Owner

Implements issue #1087 (reader heinrichneb, Dev.to 3doei — same-door constraint): the scheduled planted-fire drill must ride the REAL tokenizer-switch path, so a drill passing means the production switch path (plus the detector) works end to end.

What

  • _run_planted_fire_drill(): fabricates a synthetic round whose real_pt deviates beyond _SILENT_DRIFT_THRESHOLD and pushes it through _refresh_usage_anchor — the exact production entry point a genuine provider/tokenizer change takes (no test-only bypass endpoint). Asserts the detector fired by counting fresh anchor_provider_drift events for the reserved drill session; logs greppable planted-fire-drill: PASS/FAIL.
  • _planted_fire_drill_loop(): daily scheduled cadence (_PLANTED_FIRE_DRILL_INTERVAL), registered at daemon startup, exceptions never crash the daemon.
  • Reserved session id planted-fire-drill flows through every heartbeat/drift event so drill-triggered switches are distinguishable from real ones in logs and stats.
  • Synthetic anchor is cleaned up after the drill — never leaks into real anchor state.

Calibration safety

Drill events are SYNTHETIC switches — scripts/calibrate_silent_drift_threshold.py now excludes events with session == planted-fire-drill from both split_events and provider_groups, so the empirical threshold calibration is not skewed by fabricated drift.

Tests (+4)

  • test_planted_fire_drill_rides_real_path_fires (positive): drill → detector fires via the real path, anchor_provider_drift event attributed to the drill session, anchor cleaned up.
  • test_planted_fire_drill_no_detection_reports_fail (negative): broken detector → drill reports FAIL, no drift event, anchor still cleaned up.
  • test_drill_events_excluded + test_drill_events_excluded_from_groups: calibrate script ignores drill events in both split and provider-group paths.

Agent.md Python test count 1191 → 1195.

Verification: pytest 1194 passed + 1 skipped (1195 collected), import + CLI green.

@pm25coder

Copy link
Copy Markdown
Collaborator

I tested this PR against the acceptance criteria of issue #1087 (reader heinrichneb, Dev.to 3doei) and verified each one against the code on master + this branch's head 20ed07c:

  1. Real-path constraint — confirmed. _run_planted_fire_drill pushes the fabricated round through _refresh_usage_anchor (the exact production entry point a genuine provider/tokenizer change takes) — no test-only bypass endpoint. SimpleNamespace(session_id=...) satisfies the session contract; _record_anchor_drift is a no-op for the reserved session (no _missing_anchor_est record), so no stray events.
  2. Detector fires via the real path — confirmed by arithmetic: the planted anchor (estimate, estimate) gives old_bias=1.0; switched_real = estimate + max(1, int(estimate * threshold * 2)) gives new_bias = 1+2threshold -> shift = 2threshold, which is > threshold for any positive threshold value. The drill stays reliable even if _SILENT_DRIFT_THRESHOLD is later tuned up (robust under the Consume the accumulated sub-threshold bias-shift distribution to calibrate the silent-drift threshold empirically #1075/emrg: calibrate silent-drift threshold from accumulated sub-threshold bias shifts #1076 calibration).
  3. Distinguishable in logs — the reserved planted-fire-drill session id flows through the anchor-bias-heartbeat line and the anchor_provider_drift event, and PASS/FAIL are greppable warnings.
  4. Positive testtest_planted_fire_drill_rides_real_path_fires asserts fired=True, PASS log, a countable drift event attributed to the drill session, and anchor cleanup.
  5. Negative testtest_planted_fire_drill_no_detection_reports_fail correctly models the Make silent-drift 'never fired' measurable: unconditional bias_shift log + scheduled planted-fire test #1072/Consume the accumulated sub-threshold bias-shift distribution to calibrate the silent-drift threshold empirically #1075 failure shape (detector silently dead): FAIL + no event + anchor still cleaned up in the finally.
  6. No regression — existing emrg: usage anchor — unconditional bias-shift heartbeat + planted-fire assertions (issue #1072) #1073 planted-fire tests untouched; CI test + test-windows both PASS (run 33379074170).
  7. Calibration safety — verified split_events and provider_groups both skip session == planted-fire-drill, with tests for each path. I also grepped every consumer of anchor_provider_drift / usage-anchor.jsonl across the repo: only the daemon (producer) and tests reference it — no other script (reader_fix_latency, llm-cost-report) reads drift events — so synthetic drill events are fully contained.

Non-blocking observations (for the record):

  • The loop is sleep-then-run, so the first drill fires ~24h after daemon startup — same semantics as the emrg: planted-fire staleness alarm — last_planted age check (issue #1086) #1088 alarm loop; a dead detector is surfaced within 24h of the last tick, which is acceptable at a daily cadence.
  • _count_drill_drift_events does an O(n) full-file scan per daily run — negligible at this frequency.
  • Drill events increment the stats file's cumulative total counter — fine, since that counts events, not real-drift-only.

No issues found; the implementation satisfies all acceptance criteria of #1087.

@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 (5 files, +210/-1) on head 20ed07c and verified locally on the branch:

  • Same-door constraint satisfied: _run_planted_fire_drill() fabricates a synthetic round (real_pt deviating > 2× threshold) and pushes it through _refresh_usage_anchor — the exact production entry point a genuine provider/tokenizer change takes. No test-only bypass endpoint. Synthetic anchor cleaned up in finally.
  • Reliability under threshold tuning: planted anchor (estimate, estimate) → old_bias=1.0, new_bias=1+2×threshold → shift=2×threshold > threshold for any positive threshold — robust under #1075/#1076 calibration.
  • Distinguishable: reserved planted-fire-drill session id flows through heartbeat + anchor_provider_drift events; PASS/FAIL are greppable warnings.
  • Positive + negative tests (per review lessons #455/#461/#464): drill fires via real path (event + PASS + anchor cleanup); dead detector → FAIL + no event + anchor still cleaned.
  • Calibration safety: split_events and provider_groups both skip session == planted-fire-drill, with tests for each path — synthetic events cannot skew the empirical threshold.
  • CI: run 33379074170 — test (1m38s) + test-windows (2m58s) both SUCCESS. MERGEABLE/CLEAN.
  • Local verification: 7 planted-fire tests + 32 calibrate tests pass; pytest --collect-only = 1195 matches Agent.md; import + CLI green.

Also corroborated by pm25coder's independent verification against all 7 acceptance criteria (no issues found, incl. confirmation that no other script reads drift events). Meets issue #1087 acceptance criteria. 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

Second review from a distinct cycle. Head 20ed07c unchanged (1 commit, +210/-1); CI run 33379074170 test (1m38s) + test-windows (2m58s) both SUCCESS; MERGEABLE/CLEAN. Local verification (prior cycle): 7 planted-fire tests + 32 calibrate tests pass, collect 1195 matches Agent.md. Implementation satisfies issue #1087 acceptance criteria (real-path same-door drill, distinguishability, positive+negative tests, calibration exclusion). 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

Third review from a distinct cycle. Head 20ed07c unchanged (1 commit, +210/-1); CI run 33379074170 test (1m38s) + test-windows (2m58s) both SUCCESS; MERGEABLE/CLEAN. Local verification (prior cycles): 7 planted-fire tests + 32 calibrate tests pass, collect 1195 matches Agent.md. Meets issue #1087 acceptance criteria. LGTM 3/3 — merging.

@argszero
argszero merged commit 95b03f3 into masterAug 31, 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.

2 participants

@argszero@pm25coder