an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions
HTML agent-harnessagent-orchestrationagentsai-agentsautonomous-agentsclaude-codecodexcoding-agentsdesktop-appdeveloper-toolselectrongemini-cliharnessharness-engineeringlocal-firstmemorymulti-agentopencodeorchestrationtypescript
<!doctype html>
<html lang="en">
<head>
<!-- Google tag (gtag.js), Google Ads AW-18388216863. Loaded only when Do Not Track is
off, so it follows the same rule as the PostHog block on this site. -->
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }
if (navigator.doNotTrack !== '1') {
var gtagScript = document.createElement('script');
gtagScript.async = true;
gtagScript.src = 'https://www.googletagmanager.com/gtag/js?id=AW-18388216863';
document.head.appendChild(gtagScript);
gtag('js', new Date());
gtag('config', 'AW-18388216863');
}
</script>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Spend Counter That Went Back to Zero — Munder Difflin Blog</title>
<meta name="description" content="Our own floor was under reporting what it cost by 59 percent. The counter was cumulative since process start, the app restarts, and the session id stayed the same. Here is how a monotonic invariant let us recover the real number from an append-only log." />
<link rel="canonical" href="https://munderdiffl.in/blog/the-spend-counter-that-went-back-to-zero/" />
<link rel="icon" type="image/png" href="https://munderdiffl.in/logo.png" />
<link rel="apple-touch-icon" href="https://munderdiffl.in/logo.png" />
<meta name="theme-color" content="#F5F2E8" />
<!-- Open Graph -->
<meta property="og:site_name" content="Munder Difflin Blog" />
<meta property="og:type" content="article" />
<meta property="og:title" content="The Spend Counter That Went Back to Zero — Munder Difflin Blog" />
<meta property="og:description" content="Our own floor was under reporting what it cost by 59 percent. The counter was cumulative since process start, the app restarts, and the session id stayed the same. Here is how a monotonic invariant let us recover the real number from an append-only log." />
<meta property="og:url" content="https://munderdiffl.in/blog/the-spend-counter-that-went-back-to-zero/" />
<meta property="og:image" content="https://munderdiffl.in/blog/assets/media/the-spend-counter-that-went-back-to-zero/hero.png" />
<meta property="og:image:width" content="1600" />
<meta property="og:image:height" content="900" />
<meta property="og:image:alt" content="A yellow bean stands beside a desk where a spend meter's needle has swung back to zero, holding up a long paper log, while a whiteboard shows a sawtooth counter under a steadily climbing total." />
<meta property="og:locale" content="en_US" />
<meta property="article:published_time" content="2026-08-22T00:00:00.000Z" />
<meta property="article:author" content="Chaitanya Giri" />
<meta property="article:tag" content="Internals" />
<meta property="article:tag" content="Cost" />
<meta property="article:tag" content="Telemetry" />
<meta property="article:tag" content="Debugging" />
<meta property="article:tag" content="Postmortem" />
<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="The Spend Counter That Went Back to Zero — Munder Difflin Blog" />
<meta name="twitter:description" content="Our own floor was under reporting what it cost by 59 percent. The counter was cumulative since process start, the app restarts, and the session id stayed the same. Here is how a monotonic invariant let us recover the real number from an append-only log." />
<meta name="twitter:image" content="https://munderdiffl.in/blog/assets/media/the-spend-counter-that-went-back-to-zero/hero.png" />
<meta name="twitter:image:alt" content="A yellow bean stands beside a desk where a spend meter's needle has swung back to zero, holding up a long paper log, while a whiteboard shows a sawtooth counter under a steadily climbing total." />
<link rel="alternate" type="application/atom+xml" title="Munder Difflin Blog" href="https://munderdiffl.in/blog/feed.xml" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,[email protected],500;9..144,600;9..144,700;9..144,900&family=Source+Serif+4:opsz,[email protected],400;8..60,600;8..60,700&family=Space+Grotesk:wght@500;600;700&family=JetBrains+Mono:wght@400;600&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="/blog/assets/blog-press.css" />
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BlogPosting",
"headline": "The Spend Counter That Went Back to Zero",
"description": "Our own floor was under reporting what it cost by 59 percent. The counter was cumulative since process start, the app restarts, and the session id stayed the same. Here is how a monotonic invariant let us recover the real number from an append-only log.",
"image": ["https://munderdiffl.in/blog/assets/media/the-spend-counter-that-went-back-to-zero/hero.png"],
"datePublished": "2026-08-22T00:00:00.000Z",
"dateModified": "2026-08-22T00:00:00.000Z",
"author": { "@type": "Person", "name": "Chaitanya Giri" },
"publisher": {
"@type": "Organization",
"name": "Munder Difflin",
"logo": { "@type": "ImageObject", "url": "https://munderdiffl.in/logo.png" }
},
"mainEntityOfPage": { "@type": "WebPage", "@id": "https://munderdiffl.in/blog/the-spend-counter-that-went-back-to-zero/" },
"keywords": "ai agent cost tracking bug, cumulative counter reset, append-only ledger recovery, electron main thread blocking read, monotonic counter invariant, agent spend tracking",
"articleSection": "Internals",
"inLanguage": "en-US",
"url": "https://munderdiffl.in/blog/the-spend-counter-that-went-back-to-zero/"
}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{ "@type": "ListItem", "position": 1, "name": "Home", "item": "https://munderdiffl.in/" },
{ "@type": "ListItem", "position": 2, "name": "Blog", "item": "https://munderdiffl.in/blog/" },
{ "@type": "ListItem", "position": 3, "name": "The Spend Counter That Went Back to Zero", "item": "https://munderdiffl.in/blog/the-spend-counter-that-went-back-to-zero/" }
]
}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{ "@type": "Question", "name": "What was wrong with cost reporting in Munder Difflin?", "acceptedAnswer": { "@type": "Answer", "text": "The per-agent spend figure counted from the moment the app process started, not from the moment the agent started. Restarting the app rebuilt the in-memory accumulator empty, so the counter began again at zero under the same session id. Anything reading the latest value read one app session's worth of spend and called it the total. On our own floor that hid 59 percent of it." } },
{ "@type": "Question", "name": "Why did nobody notice a number that was wrong by more than half?", "acceptedAnswer": { "@type": "Answer", "text": "Because it never looked wrong. Inside any single run the counter only climbed, so it behaved exactly like a lifetime total. Nothing threw, nothing went negative, nothing came back NaN. The reset is only visible if you look at the whole history at once, and the number is the kind you glance at rather than reconcile." } },
{ "@type": "Question", "name": "How do you recover a total from a counter that resets?", "acceptedAnswer": { "@type": "Answer", "text": "You use the invariant the counter already gives you. Within one agent and one session the value can only go up, so any decrease is a restart and nothing else. Lifetime is the sum of the high-water mark of each segment that a reset closed, plus the high-water mark of the segment still open. Every sample was already on disk in an append-only ledger, so the past was recoverable without a migration." } },
{ "@type": "Question", "name": "Why not ignore small drops as noise?", "acceptedAnswer": { "@type": "Answer", "text": "We looked at that and rejected it. Real restarts in our own ledger fall from peaks under a dollar straight to zero, so a one dollar threshold would have silently missed them. A cumulative counter has no legitimate reason to fall at all, so the threshold bought tidiness and cost coverage. Any decrease counts, with a float epsilon and nothing more." } }
]
}
</script>
<script>
// Anonymous blog analytics (PostHog) — same posture as the main site and the
// app's TELEMETRY.md: public write-only token ('' = inert), anonymous-only
// (person_profiles 'never'), no autocapture/recording, DNT respected.
(function () {
var PH_KEY = 'phc_qJzsokwcbtTGHemnvywR3nSqivNNgMjHeNVEWkZNydFB';
if (!PH_KEY || navigator.doNotTrack === '1') return;
var s = document.createElement('script');
s.async = true;
s.src = 'https://us-assets.i.posthog.com/static/array.js';
s.onload = function () {
if (!window.posthog) return;
window.posthog.init(PH_KEY, {
api_host: 'https://us.i.posthog.com',
person_profiles: 'never',
autocapture: false,
before_send: function (event) {
// PostHog fills $ip from the connection unless the event carries one.
// Null it here and disable the GeoIP lookup so no IP, city, postal
// code or lat/long is ever derived or stored for this page view.
if (event && event.properties) {
event.properties.$ip = null;
event.properties.$geoip_disable = true;
}
return event;
},
disable_session_recording: true,
respect_dnt: true
});
};
document.head.appendChild(s);
})();
</script>
</head>
<body class="theme-press">
<a class="skip-link" href="#main">Skip to content</a>
<nav id="nav">
<a class="brand" href="https://munderdiffl.in" aria-label="Munder Difflin home">
<img class="brand-logo" src="https://munderdiffl.in/logo.png" width="1318" height="840" alt="Munder Difflin, Inc. — Multi-Agent Harness" />
</a>
<span class="spacer"></span>
<div class="links">
<a href="/blog/">Latest</a>
<a href="/blog/topics/">Topics</a>
<a href="/blog/about/">About</a>
<a href="https://munderdiffl.in">↗ Product</a>
</div>
<div class="nav-actions">
<a class="btn sm" href="https://munderdiffl.in/blog/feed.xml" aria-label="RSS feed">⤵ RSS</a>
<a class="btn sm primary" href="https://munderdiffl.in/#install">⤓ Download</a>
</div>
</nav>
<main id="main">
<article class="t-internals">
<header class="post-head wrap">
<nav class="crumbs" aria-label="Breadcrumb">
<a href="/blog/">Blog</a>
<span>/</span>
<a href="/blog/topics/internals/">Internals</a>
</nav>
<h1>The Spend Counter That Went Back to Zero</h1>
<p class="dek">Our own floor was under reporting what it cost by 59 percent. The counter was cumulative since process start, the app restarts, and the session id stayed the same. Here is how a monotonic invariant let us recover the real number from an append-only log.</p>
<div class="byline">
<span class="av" aria-hidden="true">CG</span>
<strong>Chaitanya Giri</strong>
<span class="dot" aria-hidden="true">·</span>
<time datetime="2026-08-22">Aug 22, 2026</time>
<span class="dot" aria-hidden="true">·</span>
<span>10 min read</span>
<span class="tag kind">Internals</span>
</div>
</header>
<div class="hero-wrap wrap"><figure class="fig fig-hero"><img src="/blog/assets/media/the-spend-counter-that-went-back-to-zero/hero.png" alt="A yellow bean stands beside a desk where a spend meter's needle has swung back to zero, holding up a long paper log, while a whiteboard shows a sawtooth counter under a steadily climbing total." loading="lazy" decoding="async" /></figure></div>
<div class="post-wrap wrap">
<div class="prose">
<div class="callout tldr"><span class="ic">TL;DR</span><p>Munder Difflin tells you what your
floor of agents costs. That number was wrong by <strong>59 percent</strong>, and it had been
wrong quietly, because it was a counter that measured from process start while its label said
lifetime. Restart the app and it began again at zero under the same session id. The fix is not a
new counter. It is reading the reset back out of the log we already had, using the one property a
cumulative counter cannot break: it only goes up.</p></div>
<p>You can build an agent harness that does everything right and still hand people a number that
lies. Ours did. Every agent card on the floor carried a dollar figure, <code>fleet.json</code> carried it
for Michael, and the LIVE ROSTER line every agent reads carried it too. It was the number you
would look at to decide whether to hire another worker or send everyone home.</p>
<p>It was under reporting by more than half.</p>
<p>This is the postmortem, because the bug is not really about money. It is about what happens when
a value’s name describes something more permanent than the thing that computes it.</p>
<h2 id="what-the-number-was-supposed-to-mean" tabindex="-1">What the number was supposed to mean <a class="anchor" href="#what-the-number-was-supposed-to-mean" aria-hidden="true">#</a></h2>
<p>Each agent reports usage as it works. The collector folds those samples into a per-agent record
with tokens in, tokens out, cache reads, cache creation, and a dollar figure. That record is
written into <code>fleet.json</code> on a timer, which is what the orchestrator and every agent read when
they want to know the shape of the floor.</p>
<p>The contract everyone assumed was simple: <code>usd</code> is what this agent has cost you.</p>
<h2 id="what-it-actually-meant" tabindex="-1">What it actually meant <a class="anchor" href="#what-it-actually-meant" aria-hidden="true">#</a></h2>
<p><code>AgentUsageSample.usd</code> is cumulative since <strong>process start</strong>. Not since the agent started. Since
the app started.</p>
<p>The collector accumulates into in-memory maps. An app restart builds those maps fresh, so every
running total goes back to zero. The agent itself does not go back to zero, because the agent
resumes: same worker, same work, same <code>session_id</code>. Only our accumulator forgot.</p>
<p>So the sequence on disk looks like this. The counter climbs through a session. The app restarts.
The counter appears again at almost nothing, under the same session id, and starts climbing
again. Anything that reads the latest value is reading spend since the most recent restart and
reporting it as spend, full stop.</p>
<p>The longer an agent lives, the more restarts it survives, and the more wrong its number gets. The
agents you have invested the most in are the ones whose cost you understate the worst.</p>
<h2 id="why-this-survived-in-plain-sight" tabindex="-1">Why this survived in plain sight <a class="anchor" href="#why-this-survived-in-plain-sight" aria-hidden="true">#</a></h2>
<p>Here is the uncomfortable part. Every check you would write against this number passes.</p>
<p>The value is never negative. It is never NaN. Nothing throws, nothing warns, no read fails.
Within any single run of the app the counter is perfectly monotonic, which is exactly how a
lifetime total behaves, so a person watching it for an hour sees nothing suspicious. It is
plausible in magnitude: too small to be absurd, too large to be obviously stubbed.</p>
<p>And the reset itself is invisible from where the number is consumed. Restarting an app is the
single most normal thing a user does. Nobody restarts and then reconciles a dollar figure against
what it read before, because the app was closed in between and closing an app is allowed to
change what is on screen.</p>
<p>The signature only exists in the history. You cannot see it in a value. You can only see it in a
sequence, and only if you look at the whole sequence at once.</p>
<figure class="fig fig-placeholder t-internals fig-inline" role="img" aria-label="Hand-drawn sketch from “The Spend Counter That Went Back to Zero”"><div class="ph-art" aria-hidden="true"><span class="ph-glyph">✶</span><span class="ph-note">illustration on its way</span></div><figcaption>The counter climbs, the app restarts, the counter starts over. Every single value is fine. Only the sequence is wrong.</figcaption></figure>
<h2 id="the-data-was-never-lost" tabindex="-1">The data was never lost <a class="anchor" href="#the-data-was-never-lost" aria-hidden="true">#</a></h2>
<p>The thing that made this fixable rather than merely diagnosable: the ledger is append-only.</p>
<p>Every usage sample ever emitted is a line in <code>cost-ledger.jsonl</code>, and lines are never rewritten.
The pre-reset peaks were all still sitting on disk. The bug was in what we read out of that file,
not in what we put into it, which means the past could be corrected rather than written off.</p>
<p>That distinction is worth more than the fix. A bug in a derived read is recoverable. The same
bug in the write path would have meant a number that starts being right today and is wrong
forever behind you.</p>
<h2 id="reading-a-reset-out-of-a-monotonic-counter" tabindex="-1">Reading a reset out of a monotonic counter <a class="anchor" href="#reading-a-reset-out-of-a-monotonic-counter" aria-hidden="true">#</a></h2>
<p>Within one agent and one session, the counter can only climb. That is not a convention, it is
what cumulative means. So a decrease is not ambiguous. It is not a rounding artifact, or a
correction, or a refund. <strong>A decrease is a restart, and it is the only thing a decrease can be.</strong></p>
<p>That gives the whole algorithm. Walk the ledger. For each agent and session, hold two numbers:
the high-water mark of the segment currently open, and the sum of the high-water marks of every
segment a reset has already closed. When the value drops, the open segment just ended at its
peak, so commit the peak and open a new segment at the new value.</p>
<pre class="language-ts"><code class="language-ts"><span class="token keyword">if</span> <span class="token punctuation">(</span>usd <span class="token operator"><</span> s<span class="token punctuation">.</span>peak <span class="token operator">-</span> <span class="token constant">EPS</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token comment">// Counter went backwards: the previous segment ended at its peak.</span>
s<span class="token punctuation">.</span>committed <span class="token operator">+=</span> s<span class="token punctuation">.</span>peak<span class="token punctuation">;</span>
s<span class="token punctuation">.</span>peak <span class="token operator">=</span> usd<span class="token punctuation">;</span>
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>usd <span class="token operator">></span> s<span class="token punctuation">.</span>peak<span class="token punctuation">)</span> <span class="token punctuation">{</span>
s<span class="token punctuation">.</span>peak <span class="token operator">=</span> usd<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre>
<p>Lifetime is then <code>committed + peak</code>, summed across every session an agent has had. That is the
entire recovery. It is a handful of arithmetic, because the invariant did the hard part.</p>
<p>The general shape is worth keeping: <strong>if a value is only allowed to move one way, every move the
other way is a free detector you already have on disk.</strong> You do not need to have instrumented the
event. You need to have recorded enough that the event leaves a shadow.</p>
<h2 id="the-threshold-we-deliberately-did-not-add" tabindex="-1">The threshold we deliberately did not add <a class="anchor" href="#the-threshold-we-deliberately-did-not-add" aria-hidden="true">#</a></h2>
<p>The tempting version of this code ignores small drops. Float noise, out-of-order samples, a
rounding difference somewhere upstream: surely you want a floor before you call something a
restart. A dollar sounds sensible. Ten cents sounds cautious.</p>
<p>We looked at our own ledger and found real restarts falling from peaks <strong>under a dollar</strong> straight
to zero. A one dollar threshold misses those completely, and it misses them silently, which is
the same failure we were already fixing wearing a different hat.</p>
<p>So the threshold is a float epsilon and nothing else. A cumulative counter has no legitimate
reason to go down by any amount, so there is no band of “probably fine” to carve out. The magic
number bought tidiness and cost coverage, and coverage was the entire point.</p>
<p>If you find yourself picking a threshold to suppress a signal, check whether the signal has any
legitimate instances at all. If it does not, the right threshold is zero and the number you were
about to type is just a hole.</p>
<h2 id="doing-it-without-freezing-the-app" tabindex="-1">Doing it without freezing the app <a class="anchor" href="#doing-it-without-freezing-the-app" aria-hidden="true">#</a></h2>
<p>Munder Difflin is an Electron app, and the ledger is append-only, which is a polite way of saying
it grows forever. A full pass over it is not something you want on the main thread. Block that
thread and the whole UI stops: the floor, the terminals, the window itself.</p>
<p>So the fold is async and incremental. It keeps a byte offset and reads only what has been
appended since the last pass, which in steady state is a few hundred bytes. Three details in
there are load bearing.</p>
<p><strong>The trailing partial line is held as bytes, not text.</strong> A read boundary can land in the middle
of a multi-byte character, and decoding half of one produces a replacement character that no
longer parses as JSON. Buffering the tail as a <code>Buffer</code> and only decoding up to the last newline
means the split is invisible.</p>
<p><strong>Each pass is capped.</strong> A cold start on a large ledger would otherwise be one enormous read. It
reads a bounded chunk, keeps its segment state, and resumes on the next tick.</p>
<p><strong>Truncation is detected, not assumed away.</strong> If the file is smaller than the offset we hold, the
file was rotated or replaced under us, and every segment we are carrying is suspect. That case
resets the reader instead of reading garbage from a stale position.</p>
<p>The reader never writes to the ledger, and a ledger it cannot read leaves the last good totals in
place rather than throwing into a timer.</p>
<h2 id="a-cold-zero-is-worse-than-an-admitted-unknown" tabindex="-1">A cold zero is worse than an admitted unknown <a class="anchor" href="#a-cold-zero-is-worse-than-an-admitted-unknown" aria-hidden="true">#</a></h2>
<p>Until the first full pass completes, the fold genuinely does not know what an agent has cost.
There are two things you can publish at that moment: zero, or nothing.</p>
<p>Zero is a lie with a confident face. Somebody reads it, believes an agent is free, and the
mistake propagates. So <code>usdFor</code> returns <code>null</code> until a pass has actually reached the end of the
file, and there is an explicit <code>warm</code> flag behind it so a caller can tell “no spend” apart from
“not read yet”.</p>
<p><code>fleet.json</code> uses that to fall back to the old session figure while the fold is cold, and swaps
to lifetime the moment it is warm. The old number is still there permanently as <code>sessionUsd</code>,
because “what has this agent cost me since I opened the app” is a real question, it just is not
the one the field named <code>usd</code> was being asked.</p>
<p>Nullable is not a nuisance here. It is the type telling the truth about what is known.</p>
<h2 id="checking-a-number-you-recovered-by-inference" tabindex="-1">Checking a number you recovered by inference <a class="anchor" href="#checking-a-number-you-recovered-by-inference" aria-hidden="true">#</a></h2>
<p>This is a computed answer with no ground truth to compare it against. There is no invoice that
says what an agent cost. The number is only as good as the reasoning that produced it, which
means a passing test proves the code matches the assumptions, not that the assumptions are right.</p>
<p>So the ledger was folded a second time by a separately written implementation and the two were
compared. They agree to the cent, with no per-agent disagreement anywhere in the set. That is not
proof, but two independent implementations agreeing on every agent is a very different level of
confidence than one implementation agreeing with itself.</p>
<p>For any number you recover by inference rather than measurement, write it twice. It is cheap and
it is the only check that tests the reasoning instead of the typing.</p>
<h2 id="what-we-did-not-fix-and-why-we-said-so" tabindex="-1">What we did not fix, and why we said so <a class="anchor" href="#what-we-did-not-fix-and-why-we-said-so" aria-hidden="true">#</a></h2>
<p>The circuit breaker has a floor-wide cost cap, and it reads the same resetting counter.</p>
<p>That means the cap re-arms to zero on every restart and is, in effect, measuring one app session
rather than lifetime. That is not a bug in the same sense. It is an unanswered question about what
a spending cap should mean. Is it “stop the floor when it has spent this much today”, or “ever”?
Those are different products, and one of them is a policy the founder gets to choose, not a
default an agent should quietly change while fixing something else.</p>
<p>So it is written up rather than patched. <strong>A fix that silently rewrites a policy is not a fix, it
is a decision taken by whoever happened to be in the file.</strong></p>
<figure class="fig fig-placeholder t-internals fig-inline" role="img" aria-label="Hand-drawn sketch from “The Spend Counter That Went Back to Zero”"><div class="ph-art" aria-hidden="true"><span class="ph-glyph">✶</span><span class="ph-note">illustration on its way</span></div><figcaption>Same counter, second consumer. Fixing the display without fixing the cap would have been half a fix that looked whole.</figcaption></figure>
<h2 id="what-we-wrote-down" tabindex="-1">What we wrote down <a class="anchor" href="#what-we-wrote-down" aria-hidden="true">#</a></h2>
<ul>
<li><strong>A counter named for a lifetime should not be scoped to a process.</strong> If the value resets when
something restarts, the name has to say so. Ours now ships as <code>usd</code> and <code>sessionUsd</code> side by
side, and the ambiguity is gone because both answers exist.</li>
<li><strong>A monotonic invariant is a detector you already own.</strong> If a value can only move one way, every
move the other way is an event you can recover after the fact, with no new instrumentation.</li>
<li><strong>Append-only logs let you fix the past.</strong> The write path being correct is what made this a
read-side fix instead of a line in the changelog apologising for old data.</li>
<li><strong>Check whether your threshold has any legitimate instances.</strong> If nothing real lives below the
cutoff, the cutoff is only hiding things you wanted to see.</li>
<li><strong>Never publish a confident zero for a value you have not read yet.</strong> Return null, keep a warm
flag, and let callers decide.</li>
<li><strong>Write the second implementation.</strong> For inferred numbers it is the only verification that
tests the reasoning rather than the code.</li>
</ul>
<p>The failure class here is the same one behind
<a href="/blog/the-newline-that-silenced-windows-agents/">the newline that silenced every Windows agent</a>
and <a href="/blog/why-our-auto-update-never-ran/">the auto-update that never ran</a>: nothing errored,
every health check passed, and the product was quietly not doing the thing it said it did.
Loud failures get fixed in an afternoon. These are the ones that need somebody to go and
<a href="/blog/how-ai-agents-verify-their-own-work/">verify the claim</a> rather than the absence of an
exception.</p>
<h2 id="the-rest-of-v045" tabindex="-1">The rest of v0.4.5 <a class="anchor" href="#the-rest-of-v045" aria-hidden="true">#</a></h2>
<p>This shipped in <strong>v0.4.5</strong>, alongside two other things that were quietly wrong: semantic memory
never worked on Apple Silicon, where CoreML overflowed the quantized embedding graph and returned
NaN for every vector, and agents did not reliably reach each other, which now has an inbox wake
watchdog behind it and bounces mail to a missing inbox instead of dropping it. Plus weekday
scheduling for triggers, clickable paths everywhere in terminal output, one editor instead of
two, one click updates, and 23 community pull requests.</p>
<p>The full notes are on the
<a href="https://github.com/chaitanyagiri/munder-difflin/releases/latest">releases page</a>, and if you want
the wider version of this argument, the
<a href="/blog/the-multi-agent-cost-playbook/">multi-agent cost playbook</a> is about spending less rather
than counting it correctly. Both matter. Counting it correctly comes first, because you cannot
manage a number you are not actually reading.</p>
<section class="faq" aria-label="Frequently asked questions">
<h2 id="faq">FAQ</h2>
<div class="qa">
<p class="q">What was wrong with cost reporting in Munder Difflin?</p>
<p class="a">The per-agent spend figure counted from the moment the app process started, not from the moment the agent started. Restarting the app rebuilt the in-memory accumulator empty, so the counter began again at zero under the same session id. Anything reading the latest value read one app session's worth of spend and called it the total. On our own floor that hid 59 percent of it.</p>
</div>
<div class="qa">
<p class="q">Why did nobody notice a number that was wrong by more than half?</p>
<p class="a">Because it never looked wrong. Inside any single run the counter only climbed, so it behaved exactly like a lifetime total. Nothing threw, nothing went negative, nothing came back NaN. The reset is only visible if you look at the whole history at once, and the number is the kind you glance at rather than reconcile.</p>
</div>
<div class="qa">
<p class="q">How do you recover a total from a counter that resets?</p>
<p class="a">You use the invariant the counter already gives you. Within one agent and one session the value can only go up, so any decrease is a restart and nothing else. Lifetime is the sum of the high-water mark of each segment that a reset closed, plus the high-water mark of the segment still open. Every sample was already on disk in an append-only ledger, so the past was recoverable without a migration.</p>
</div>
<div class="qa">
<p class="q">Why not ignore small drops as noise?</p>
<p class="a">We looked at that and rejected it. Real restarts in our own ledger fall from peaks under a dollar straight to zero, so a one dollar threshold would have silently missed them. A cumulative counter has no legitimate reason to fall at all, so the threshold bought tidiness and cost coverage. Any decrease counts, with a float epsilon and nothing more.</p>
</div>
</section>
<hr />
<div class="share">
<span class="lbl">Tags</span>
<a class="tag" href="/blog/tags/internals/">Internals</a><a class="tag" href="/blog/tags/cost/">Cost</a><a class="tag" href="/blog/tags/telemetry/">Telemetry</a><a class="tag" href="/blog/tags/debugging/">Debugging</a><a class="tag" href="/blog/tags/postmortem/">Postmortem</a>
</div>
</div>
<aside class="toc-rail" aria-label="Table of contents">
<div class="tt">On this page</div>
<ol>
<li class="lvl-2"><a href="#what-the-number-was-supposed-to-mean">What the number was supposed to mean</a></li><li class="lvl-2"><a href="#what-it-actually-meant">What it actually meant</a></li><li class="lvl-2"><a href="#why-this-survived-in-plain-sight">Why this survived in plain sight</a></li><li class="lvl-2"><a href="#the-data-was-never-lost">The data was never lost</a></li><li class="lvl-2"><a href="#reading-a-reset-out-of-a-monotonic-counter">Reading a reset out of a monotonic counter</a></li><li class="lvl-2"><a href="#the-threshold-we-deliberately-did-not-add">The threshold we deliberately did not add</a></li><li class="lvl-2"><a href="#doing-it-without-freezing-the-app">Doing it without freezing the app</a></li><li class="lvl-2"><a href="#a-cold-zero-is-worse-than-an-admitted-unknown">A cold zero is worse than an admitted unknown</a></li><li class="lvl-2"><a href="#checking-a-number-you-recovered-by-inference">Checking a number you recovered by inference</a></li><li class="lvl-2"><a href="#what-we-did-not-fix-and-why-we-said-so">What we did not fix, and why we said so</a></li><li class="lvl-2"><a href="#what-we-wrote-down">What we wrote down</a></li><li class="lvl-2"><a href="#the-rest-of-v045">The rest of v0.4.5</a></li>
</ol>
</aside>
</div>
<footer class="post-foot wrap"><div class="prevnext">
<a class="pn prev" href="/blog/agents-ran-our-launch-week-analytics/"><span class="k">← Older</span><span class="t">Our Agents Ran Our Launch-Week Analytics</span></a>
<a class="pn next" href="/blog/launching-munder-difflin-v0-4-6/"><span class="k">Newer →</span><span class="t">Launching Munder Difflin v0.4.6: It Speaks Chinese and Arabic Now</span></a>
</div>
<section class="related">
<h2>Related in Internals</h2>
<div class="post-grid">
<article class="card t-internals">
<a class="thumb t-internals" href="/blog/the-newline-that-silenced-windows-agents/" aria-hidden="true" tabindex="-1"><img src="/blog/assets/media/the-newline-that-silenced-windows-agents/hero.png" alt="" loading="lazy" decoding="async" /></a>
<div class="body">
<div class="meta">
<time datetime="2026-08-19">Aug 19, 2026</time>
<span class="dot" aria-hidden="true"></span>
<span>4 min</span>
</div>
<h3><a href="/blog/the-newline-that-silenced-windows-agents/">The Newline That Silenced Every Windows Agent</a></h3>
<p class="dek">A cmd.exe parsing rule from the 1980s meant Windows agents received exactly one line of their multi-line startup protocol — and nothing errored. The anatomy of our worst silent failure, and the fix.</p>
<div class="foot">
<span class="tag kind">Internals</span>
<a class="more" href="/blog/the-newline-that-silenced-windows-agents/" aria-label="Read: The Newline That Silenced Every Windows Agent">Read →</a>
</div>
</div>
</article>
<article class="card t-internals">
<a class="thumb t-internals" href="/blog/why-our-auto-update-never-ran/" aria-hidden="true" tabindex="-1"><img src="/blog/assets/media/why-our-auto-update-never-ran/hero.png" alt="" loading="lazy" decoding="async" /></a>
<div class="body">
<div class="meta">
<time datetime="2026-08-08">Aug 8, 2026</time>
<span class="dot" aria-hidden="true"></span>
<span>5 min</span>
</div>
<h3><a href="/blog/why-our-auto-update-never-ran/">Our Auto-Update Never Ran Once: A CommonJS Export That Vanished Into an ESM Namespace</a></h3>
<p class="dek">Munder Difflin shipped auto-update in v0.3.4 and it silently never worked in a single packaged build. The cause was one destructuring assignment across the CommonJS/ESM boundary — and a catch block that threw the evidence away. Here's how we found it, and what v0.3.7 changes.</p>
<div class="foot">
<span class="tag kind">Internals</span>
<a class="more" href="/blog/why-our-auto-update-never-ran/" aria-label="Read: Our Auto-Update Never Ran Once: A CommonJS Export That Vanished Into an ESM Namespace">Read →</a>
</div>
</div>
</article>
<article class="card t-internals">
<a class="thumb t-internals" href="/blog/hire-manifest-untrusted-input/" aria-hidden="true" tabindex="-1"><img src="/blog/assets/media/hire-manifest-untrusted-input/hero.png" alt="" loading="lazy" decoding="async" /></a>
<div class="body">
<div class="meta">
<time datetime="2026-06-15">Jun 15, 2026</time>
<span class="dot" aria-hidden="true"></span>
<span>12 min</span>
</div>
<h3><a href="/blog/hire-manifest-untrusted-input/">Treating a Hire Manifest as Untrusted Input</a></h3>
<p class="dek">A shareable agent-config manifest is attacker input. How Munder Difflin's import pipeline stays inert: no auto-spawn, default-deny flags, and an SSRF-safe bounded fetch.</p>
<div class="foot">
<span class="tag kind">Internals</span>
<a class="more" href="/blog/hire-manifest-untrusted-input/" aria-label="Read: Treating a Hire Manifest as Untrusted Input">Read →</a>
</div>
</div>
</article>
</div>
</section>
</footer>
</article>
</main>
<footer class="site-foot">
<div class="wrap">
<div class="foot-top">
<a class="foot-brand brand" href="https://munderdiffl.in" aria-label="Munder Difflin home">
<img class="brand-logo" src="https://munderdiffl.in/logo.png" width="1318" height="840" alt="Munder Difflin, Inc. — Multi-Agent Harness" />
</a>
<div class="foot-links">
<a href="/blog/">Latest</a>
<a href="/blog/topics/">Topics</a>
<a href="/blog/about/">About</a>
<a href="https://munderdiffl.in/blog/feed.xml">RSS</a>
<a href="https://github.com/chaitanyagiri/munder-difflin">GitHub</a>
<a href="https://munderdiffl.in">munderdiffl.in ↗</a>
</div>
</div>
<div class="foot-meta">
© 2026 Munder Difflin · Local-first · MIT-licensed ·
Built on <a href="https://munderdiffl.in">Electron, React, Pixi.js, xterm.js & node-pty</a>.
Run an office of agents while you sleep.
</div>
</div>
</footer>
<script>
// sticky-nav border on scroll
(function () {
var nav = document.getElementById('nav');
if (!nav) return;
var onScroll = function () { nav.classList.toggle('scrolled', window.scrollY > 8); };
onScroll(); window.addEventListener('scroll', onScroll, { passive: true });
})();
// YouTube click-to-load: thumbnail button → youtube-nocookie iframe
(function () {
document.addEventListener('click', function (e) {
var btn = e.target.closest('.yt-load');
if (!btn) return;
var box = btn.closest('.yt');
var id = box && box.getAttribute('data-yt');
// Only an 11 character YouTube video id may reach the iframe URL.
if (!id || !/^[A-Za-z0-9_-]{11}$/.test(id)) return;
var frame = document.createElement('iframe');
frame.src = 'https://www.youtube-nocookie.com/embed/' + encodeURIComponent(id) + '?autoplay=1';
frame.title = box.getAttribute('data-title') || 'YouTube video';
frame.allow = 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share';
frame.setAttribute('allowfullscreen', '');
box.replaceChildren(frame);
});
})();
</script>
</body>
</html>