Skip to content

Instantly share code, notes, and snippets.

View tonydzi's full-sized avatar

Anton Dziatkovskii tonydzi

View GitHub Profile
@tonydzi
tonydzi / _test_audit.py
Created September 5, 2026 20:22
Cross-file dedupe exposure in Claude Code transcripts: measure the loss, split the loser shapes, and price the proposed zero-record guard
#!/usr/bin/env python3
"""Control example for crossfile_dedupe_audit.py.
Builds a synthetic transcript corpus with known answers and checks the tool
reports them. Two of the four cases are planted defects the tool MUST see;
two are traps it must NOT report.
"""
import json
import os
import shutil
@tonydzi
tonydzi / README.md
Created September 4, 2026 04:32
firefox_places_doctor -- audit a Firefox places.sqlite you wrote into (url_hash / origin_id / ANALYZE), plus a verified reference implementation of Firefox's url_hash

firefox_places_doctor

If you write rows into Firefox's places.sqlite by hand, this tells you in 30 seconds whether Firefox will actually use them — or quietly pin a CPU core instead.

The pain

You migrated history or bookmarks into a Firefox profile (from Chrome, Arc, Safari, another profile, your own exporter). The rows are there. SELECT count(*) looks right. And then:

  • "Firefox sits at 100% CPU after I imported my history and I can't tell why."
  • "The URLs are in moz_places but the address bar never suggests them."
@tonydzi
tonydzi / README.md
Created September 3, 2026 21:32
Which cap actually binds your Claude Code MEMORY.md index (UTF-16 units, not bytes) and what it silently drops

Which cap actually binds your MEMORY.md, and what it silently drops

The Claude Code auto-memory index is loaded through a truncation step with two caps: 200 lines and 25,000 size units. Three things about that step are easy to get wrong, and all three cost you content you never see go missing.

1. The size cap is not counted in bytes. The implementation measures trimmed.length on a JavaScript string, which is UTF-16 code units. The field is named byteCount, the cap is named byteCap, and the user-facing message formats it with a byte formatter. If your index is not pure ASCII, the number you are shown is not the number on disk, and the error always runs in the direction of compacting more than needed.

For a Cyrillic index at 1.38 bytes per unit, the real ceiling is around 34,500 bytes on disk, not 25,000. For CJK it is higher still.

2. Truncation is line-first, then size. The line cap is applied, and only then is the survivor cut at the last newline before the size cap. When bo

@tonydzi
tonydzi / task_session_map.py
Created September 1, 2026 12:35
Recover the scheduled-task taskId -> executing sessionId link from Claude Code transcripts (read-only, stdlib)
#!/usr/bin/env python3
"""task_session_map.py - recover the taskId -> sessionId link for Claude Code
scheduled tasks (routines) deterministically, without cwd/title/time heuristics.
Why this works: when a scheduled task fires, the harness injects its prompt into
the executing session's transcript as a record whose content opens with
<scheduled-task name="..." file="...">
and that record carries the executing session's own sessionId. So the transcript
itself states which task produced it.
@tonydzi
tonydzi / README.md
Last active August 31, 2026 21:58
Google Takeout MyActivity.html renders in the export-time timezone: two exports of one account don't dedupe (measured: 62,367 rows, 0 residual). Zero-dep UTC normalizer + selftest.

Takeout MyActivity.html renders in the export-time timezone, so two exports of one account don't dedupe

A ~90-line, zero-dependency Python helper that normalizes Google Takeout MyActivity.html timestamps to UTC, so importing a second export of the same account doesn't silently double your database.

The symptom

You imported your Takeout activity history months ago. You export again to top it up, run the same importer, and:

  • your row count roughly doubles instead of growing by a few thousand;
  • every old event is now in there twice, exactly one hour apart;
@tonydzi
tonydzi / llm_batch_fuses.py
Last active September 2, 2026 17:31
Four fuses + detector-agreement cascade for batch LLM jobs (fail-cache, circuit breaker, per-run cap, cheap-detectors-first). Measured: 887 calls/night -> <=40; 0.2% error on 1012 golden verdicts.
#!/usr/bin/env python3
"""llm_batch_fuses.py -- four fuses + a detector-agreement cascade for batch LLM jobs.
WHY
---
Any nightly job that calls an LLM once per item (classify sessions, summarize
transcripts, label records) will eventually meet the same four failure modes:
1. An item that always fails gets retried every night, forever.
2. A fatal condition (auth expired, usage limit) fails EVERY item, one call at
@tonydzi
tonydzi / Test-Ps1Encoding.ps1
Created August 31, 2026 10:57
Test-Ps1Encoding.ps1: find .ps1 files that Windows PowerShell 5.1 silently mis-parses (UTF-8 without BOM read as ANSI; a smart-quote byte terminates the string early). Scheduled, such a script fails with 0x80070001 and writes no log at all. Read-only scan, -Fix adds a BOM, -SelfTest included.
# Test-Ps1Encoding.ps1
#
# Find .ps1 files that Windows PowerShell 5.1 will MIS-PARSE, and optionally fix
# them by adding a UTF-8 BOM.
#
# ---------------------------------------------------------------------------
# The bug this catches
# ---------------------------------------------------------------------------
# Windows PowerShell 5.1 (powershell.exe - not pwsh 7) decides a script's
# encoding from its BOM. No BOM means "this is ANSI", i.e. the machine's legacy
@tonydzi
tonydzi / headroom_v208_residual_check.py
Created August 26, 2026 21:21
headroom v2.0.8: simulate the shipped MessageDeduper against a log tree and classify what survives it (replay + partial-snapshot classes)
"""Verify headroom v2.0.8's MessageDeduper against a Windows hub log tree.
Simulates the shipped O(1) rule (drop a usage record whose message.id equals the
PREVIOUS record's message.id) and measures what inflation survives it, then
classifies the survivors:
A REPLAY - the identical record (same uuid) is written again later in the file
B PARTIAL - one message.id carries DIFFERENT usage payloads (streaming snapshots)
Ground truth for "how many real messages" = distinct uuid, since uuid is unique
per written record and a replay repeats it verbatim.
0 LLM tokens, read-only.
@tonydzi
tonydzi / api_wait_gaps.py
Created August 25, 2026 07:57
Measure API-wait stalls across a whole Claude Code transcript corpus (stdlib only, read-only)
#!/usr/bin/env python3
"""api_wait_gaps.py - measure API-wait stalls across a whole Claude Code transcript corpus.
A "stall" here = wall-clock time in which the RUNTIME owed the next event and no bytes
arrived. Only two record pairs qualify:
tool_result -> assistant (tool came back, model has not spoken yet)
assistant -> assistant (mid-stream continuation)
Why the restriction matters: a naive "every gap >= 60s" scan over a corpus is dominated by
@tonydzi
tonydzi / README.md
Last active August 26, 2026 21:18
scheduled-tasks-doctor: find and restore Claude Desktop routines that vanished from the Routines list (registry is per-account; prompts survive on disk)

scheduled-tasks-doctor

Your Claude Desktop routines vanished from the Routines list — after an app update, after signing in with a different account, or for no visible reason at all. This finds them and puts them back.

They are almost certainly not deleted. The app splits a routine across two places:

what where survives an app update?