<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://mohinee.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://mohinee.github.io/" rel="alternate" type="text/html" /><updated>2026-10-23T16:06:09+00:00</updated><id>https://mohinee.github.io/feed.xml</id><title type="html">Mohinee Indurkar</title><subtitle>Senior software engineer with 14 years across React, C#/.NET, Java, and cloud infrastructure, currently building AI agents for Microsoft Teams. Notes on AI agents in production, multi-agent systems, and full-stack engineering.</subtitle><author><name>Mohinee Indurkar</name></author><entry><title type="html">Did it actually work? Measuring an AI deployment without fooling yourself</title><link href="https://mohinee.github.io/2026/did-it-actually-work/" rel="alternate" type="text/html" title="Did it actually work? Measuring an AI deployment without fooling yourself" /><published>2026-10-02T00:00:00+00:00</published><updated>2026-10-02T00:00:00+00:00</updated><id>https://mohinee.github.io/2026/did-it-actually-work</id><content type="html" xml:base="https://mohinee.github.io/2026/did-it-actually-work/"><![CDATA[<p>Every AI deployment eventually gets the same question from someone with a
budget: <em>did it work?</em> The easiest answer is a before-and-after chart. Tickets
were here, we launched, tickets went down. It is also the answer most likely to
be wrong, and the wrong answer usually flatters you.</p>

<p>I care about this for an unglamorous reason. If you overclaim impact, the
next person to look closely at the numbers will discount everything else you
say. If you can show the method behind a number, it survives scrutiny, and so
does your credibility with the people who’ll decide what you build next.</p>

<h2 id="decide-what-youre-measuring-before-launch">Decide what you’re measuring before launch</h2>

<p>Most bad impact numbers are decided after the fact, by whoever picks the
chart. Before the first user sees the feature, I write down:</p>

<ul>
  <li><strong>The outcome metric, in one sentence.</strong> “Support tickets in the categories
the agent handles,” not “support load.”</li>
  <li><strong>What counts as a success.</strong> For a self-service agent, a resolved
conversation is only a success if the person <em>didn’t</em> raise a ticket on the
same issue soon after. Define that window up front.</li>
  <li><strong>What counts as an incident.</strong> A wrong answer, a bad answer and a production
incident are different things. Decide which ones you’re promising zero of.</li>
  <li><strong>The comparison.</strong> What the metric would have done without the feature.
This is the hard part, and it gets its own section.</li>
</ul>

<h2 id="the-counterfactual-problem">The counterfactual problem</h2>

<p>A before-and-after chart assumes nothing else changed. In practice,
something always does. Seasons, team changes, a product launch, a policy
change, a holiday quarter. Any of these can move the metric in the same
direction as your feature, and the chart will credit you for all of it.</p>

<p>The cheapest fix I know is a <strong>control group that the feature doesn’t touch</strong>.
For a support agent that only handles some ticket categories, the categories it
<em>doesn’t</em> handle make a natural control. They live through the same seasons and
the same organisational changes. If they also dropped after launch, part of
your drop isn’t yours.</p>

<h2 id="a-small-simulation">A small simulation</h2>

<p>To show how much this matters, here is a simulation where I know the true
answer. The agent really removes <strong>20%</strong> of tickets in the categories it
covers. But the launch also happens to land at the start of a quieter quarter,
which reduces tickets in <em>every</em> category by about 15%.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">random</span>
<span class="kn">from</span> <span class="nn">statistics</span> <span class="kn">import</span> <span class="n">mean</span>

<span class="k">def</span> <span class="nf">weekly</span><span class="p">(</span><span class="n">base</span><span class="p">,</span> <span class="n">weeks</span><span class="p">,</span> <span class="n">season</span><span class="p">,</span> <span class="n">effect</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">noise</span><span class="o">=</span><span class="mf">0.06</span><span class="p">):</span>
    <span class="k">return</span> <span class="p">[</span><span class="n">base</span> <span class="o">*</span> <span class="n">season</span><span class="p">[</span><span class="n">w</span><span class="p">]</span> <span class="o">*</span> <span class="n">effect</span> <span class="o">*</span> <span class="n">random</span><span class="p">.</span><span class="n">uniform</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">noise</span><span class="p">,</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">noise</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">w</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">weeks</span><span class="p">)]</span>

<span class="n">random</span><span class="p">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">11</span><span class="p">)</span>
<span class="n">weeks</span> <span class="o">=</span> <span class="mi">12</span>
<span class="n">pre_season</span>  <span class="o">=</span> <span class="p">[</span><span class="mf">1.00</span><span class="p">]</span> <span class="o">*</span> <span class="n">weeks</span>
<span class="n">post_season</span> <span class="o">=</span> <span class="p">[</span><span class="mf">0.85</span><span class="p">]</span> <span class="o">*</span> <span class="n">weeks</span>          <span class="c1"># a quiet quarter hits every category
</span><span class="n">TRUE_EFFECT</span> <span class="o">=</span> <span class="mf">0.80</span>                    <span class="c1"># the agent really removes 20% of tickets
</span>
<span class="n">covered_pre</span>    <span class="o">=</span> <span class="n">weekly</span><span class="p">(</span><span class="mi">400</span><span class="p">,</span> <span class="n">weeks</span><span class="p">,</span> <span class="n">pre_season</span><span class="p">)</span>
<span class="n">covered_post</span>   <span class="o">=</span> <span class="n">weekly</span><span class="p">(</span><span class="mi">400</span><span class="p">,</span> <span class="n">weeks</span><span class="p">,</span> <span class="n">post_season</span><span class="p">,</span> <span class="n">effect</span><span class="o">=</span><span class="n">TRUE_EFFECT</span><span class="p">)</span>
<span class="n">uncovered_pre</span>  <span class="o">=</span> <span class="n">weekly</span><span class="p">(</span><span class="mi">250</span><span class="p">,</span> <span class="n">weeks</span><span class="p">,</span> <span class="n">pre_season</span><span class="p">)</span>
<span class="n">uncovered_post</span> <span class="o">=</span> <span class="n">weekly</span><span class="p">(</span><span class="mi">250</span><span class="p">,</span> <span class="n">weeks</span><span class="p">,</span> <span class="n">post_season</span><span class="p">)</span>

<span class="n">naive</span> <span class="o">=</span> <span class="n">mean</span><span class="p">(</span><span class="n">covered_post</span><span class="p">)</span> <span class="o">/</span> <span class="n">mean</span><span class="p">(</span><span class="n">covered_pre</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span>
<span class="n">control_drift</span> <span class="o">=</span> <span class="n">mean</span><span class="p">(</span><span class="n">uncovered_post</span><span class="p">)</span> <span class="o">/</span> <span class="n">mean</span><span class="p">(</span><span class="n">uncovered_pre</span><span class="p">)</span>
<span class="n">adjusted</span> <span class="o">=</span> <span class="p">(</span><span class="n">mean</span><span class="p">(</span><span class="n">covered_post</span><span class="p">)</span> <span class="o">/</span> <span class="n">mean</span><span class="p">(</span><span class="n">covered_pre</span><span class="p">))</span> <span class="o">/</span> <span class="n">control_drift</span> <span class="o">-</span> <span class="mi">1</span>
</code></pre></div></div>

<p>The output:</p>

<table>
  <thead>
    <tr>
      <th>Estimate</th>
      <th>Change</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Naive before/after on covered categories</td>
      <td>−32.3%</td>
    </tr>
    <tr>
      <td>Drift in uncovered categories (control)</td>
      <td>−13.6%</td>
    </tr>
    <tr>
      <td>Control-adjusted effect</td>
      <td>−21.6%</td>
    </tr>
    <tr>
      <td>True effect in the simulation</td>
      <td>−20.0%</td>
    </tr>
  </tbody>
</table>

<p>The naive number overstates the real effect by more than half. Nobody lied to
produce it. It is exactly what the dashboard would have shown. The
control-adjusted estimate lands within two points of the truth. That gap is
noise, and you shrink it with more weeks of data, not with a fancier method.</p>

<p>The adjustment here is a simple ratio form of difference-in-differences. It
rests on one assumption you should say out loud: without the agent, covered and
uncovered categories would have moved together. If you have reason to doubt
that (say the covered categories are seasonal in a different way) look at
several pre-launch periods to check that they really do track each other.</p>

<h2 id="other-ways-to-fool-yourself">Other ways to fool yourself</h2>

<ul>
  <li><strong>Deflection that is really delay.</strong> Someone gets an answer from the agent,
doesn’t raise a ticket today, and raises one next week. Count repeat contacts
within your success window, or you’re counting postponed tickets as solved.</li>
  <li><strong>Shifting volume to another channel.</strong> If tickets drop but direct messages
to the support team rise, the work moved. It didn’t go away.</li>
  <li><strong>Time saved, multiplied carelessly.</strong> “Hours saved” is usually tickets avoided
times average handling time. Use the handling time <em>for the categories the
agent covers</em>, which are often the quick ones. Using the overall average
inflates the figure.</li>
  <li><strong>Survivorship in feedback.</strong> Thumbs-up rates come from people who chose to
rate. They are a signal, not a measurement of the whole population.</li>
</ul>

<h2 id="reporting-it">Reporting it</h2>

<p>When I report impact now, the number comes with its method attached: the metric
definition, the comparison used, the time windows, and the assumptions. It
reads less like marketing. It also holds up when a finance partner or an
executive asks “how did you calculate that?”, and that question always comes
eventually.</p>

<p>That is the standard I want for anything I deploy. The work should hold up to
someone checking it, and so should the claims about it.</p>

<hr />

<p><em>All data in this post is simulated so the method can be shown end to end.
Nothing here reflects internal figures from any employer.</em></p>]]></content><author><name>Mohinee Indurkar</name></author><category term="ai" /><category term="measurement" /><category term="deployment" /><category term="analytics" /><category term="python" /><summary type="html"><![CDATA[A before-and-after chart is the easiest way to overstate what an AI deployment did. Baselines, control groups and defined terms, with a small simulation showing a naive estimate inflating a real effect by more than half.]]></summary></entry><entry><title type="html">When the experts push back: turning objections into requirements</title><link href="https://mohinee.github.io/2026/when-experts-push-back/" rel="alternate" type="text/html" title="When the experts push back: turning objections into requirements" /><published>2026-09-28T00:00:00+00:00</published><updated>2026-09-28T00:00:00+00:00</updated><id>https://mohinee.github.io/2026/when-experts-push-back</id><content type="html" xml:base="https://mohinee.github.io/2026/when-experts-push-back/"><![CDATA[<p>The hardest people to convince about an AI tool are experienced people who
know their own work very well and can see exactly what the tool would get
wrong.</p>

<p>I learned this introducing an LLM-based code reviewer into a team’s CI
pipeline. The goal was modest: catch untested edge cases before merge and take
some load off a review queue where pull requests waited days for attention. The
pushback came from the people whose time it was meant to save.</p>

<h2 id="the-objection">The objection</h2>

<p>The senior engineers didn’t argue that the reviewer would be inaccurate. Their
concern was sharper than that. Paraphrased, it went like this:</p>

<blockquote>
  <p>Experienced reviewers look at code differently. One of us might focus on
concurrency, another on API compatibility, another on how a change behaves
during an incident. A single agent will push the whole codebase toward one
default opinion, and we’ll lose the differences in perspective that catch
real bugs.</p>
</blockquote>

<p>It would have been easy to treat that as resistance to change and push through
it with metrics. That would have been a mistake, because they were right. A
reviewer configured only with general guidelines <em>does</em> produce one generic
opinion. The objection described a real failure mode of the design.</p>

<h2 id="reading-an-objection-as-a-requirement">Reading an objection as a requirement</h2>

<p>When experts push back, I’ve found it useful to translate the objection into
the requirement it implies. This one translated cleanly:</p>

<ul>
  <li><strong>Objection:</strong> “It will flatten our different perspectives.”</li>
  <li><strong>Requirement:</strong> “The reviewer must be able to represent a specific
reviewer’s standards, not only a team-wide average.”</li>
</ul>

<p>Once it was written as a requirement, it stopped being an argument and became a
design problem, and a better design than the one I’d started with.</p>

<h2 id="the-change">The change</h2>

<p>I added a way to configure the agent with an individual reviewer’s perspective
as its source of truth: the things that person consistently checks, the
patterns they reject, and the reasoning they usually give. Instead of one
generic reviewer, the team could run reviews in the voice of the specific
expertise a change needed.</p>

<p>If you build something similar, a few design choices make the difference
between a tool experts tolerate and one they adopt:</p>

<ul>
  <li><strong>Let experts own their own perspective.</strong> Provide the structure, but let the
content come from the people whose judgment it represents, in their words.
That keeps them in control of what the agent claims to know.</li>
  <li><strong>Make each comment traceable.</strong> When a review comment points back to the
rule or standard it came from, it is obvious whether a bad comment came from
the configuration or the model, and the right person can fix it.</li>
  <li><strong>Keep the gate narrow.</strong> Decide explicitly which few things the agent may
block on, and make everything else advisory. The approval decision stays with
people.</li>
</ul>

<h2 id="what-happened-next">What happened next</h2>

<p>The objection stopped being a reason to block the rollout and became part of
the design. Review turnaround dropped sharply, fewer bugs escaped to
production, and the tool was later rolled out well beyond the original team.
That expansion was possible because the people with the most to lose had their
concern built into the tool rather than overruled.</p>

<h2 id="what-i-took-from-it">What I took from it</h2>

<ul>
  <li><strong>Experts usually object to a specific failure mode, not to change itself.</strong>
Ask what exactly would go wrong, and listen for the requirement inside the
answer.</li>
  <li><strong>Give control to the people with the most to lose.</strong> A tool that encodes
someone’s judgment, under their control, is an extension of their expertise.
A tool that replaces it is a threat.</li>
  <li><strong>Make errors attributable.</strong> When people can see why the system said
something, they correct it. When they can’t, they stop trusting it.</li>
  <li><strong>Keep the decision with humans until the data says otherwise.</strong> Automation
can expand later, as evidence builds up. Starting narrow is what makes that
expansion possible.</li>
</ul>

<p>The general lesson goes beyond code review. Whenever I’m putting an AI system
into someone else’s workflow, the loudest objection is usually the most
valuable input I’ll get, as long as I treat it as a spec rather than an
obstacle.</p>

<hr />

<p><em>Generalised from my own work. No internal tooling, names or confidential
details from any employer are described here.</em></p>]]></content><author><name>Mohinee Indurkar</name></author><category term="ai" /><category term="adoption" /><category term="stakeholders" /><category term="code-review" /><category term="engineering" /><summary type="html"><![CDATA[When experienced people resist an AI tool, the objection is usually a requirement they haven't written down. A case study from introducing an LLM reviewer into CI, and how a design change turned resistance into adoption.]]></summary></entry><entry><title type="html">The first week inside someone else’s workflow</title><link href="https://mohinee.github.io/2026/first-week-inside-someone-elses-workflow/" rel="alternate" type="text/html" title="The first week inside someone else’s workflow" /><published>2026-09-23T00:00:00+00:00</published><updated>2026-09-23T00:00:00+00:00</updated><id>https://mohinee.github.io/2026/first-week-inside-someone-elses-workflow</id><content type="html" xml:base="https://mohinee.github.io/2026/first-week-inside-someone-elses-workflow/"><![CDATA[<p>Some of the most useful things I’ve built were not on anyone’s request list.</p>

<p>A few years ago I noticed that a marketing team I worked alongside waited on
engineering for every personalised campaign landing page. Nobody had filed that
as a problem; it was simply how launches worked. Engineers weren’t slow at
building the pages. Each campaign waited days in a queue for engineering time,
for work that was mostly configuration. The fix wasn’t more engineering time.
It was a self-serve tool that took engineering out of the loop, so a campaign
could go live in about half an hour instead of days.</p>

<p>I think about that often. When you build for a team you don’t belong to (an
internal customer, another department, an external client) the request you
receive is usually a proposed solution. Your first job is to find the problem
underneath it. This is how I spend the first week.</p>

<h2 id="day-one-separate-the-request-from-the-outcome">Day one: separate the request from the outcome</h2>

<p>Every request arrives as a solution: “we need a dashboard,” “can you add a
field,” “we want a chatbot for this.” I write the request down verbatim, and
then I ask one question repeatedly until I reach something measurable:</p>

<blockquote>
  <p>What would be different for you if this existed?</p>
</blockquote>

<p>“We need a dashboard” becomes “we want to see which orders are stuck.” That
becomes “we find out about stuck orders when the customer complains, two days
late.” The real outcome is <em>finding out sooner</em>. A dashboard is one way to get
there. An alert might be a better one.</p>

<p>I don’t argue with the proposed solution at this stage. I just make sure I
know which outcome it’s supposed to deliver, so I can judge alternatives against
it later.</p>

<h2 id="days-two-and-three-watch-the-work-dont-interview-about-it">Days two and three: watch the work, don’t interview about it</h2>

<p>Interviews tell you how people believe the process works. Watching tells you
how it actually works. The gap between the two is where most of the useful
discoveries are.</p>

<p>I ask to sit with someone while they do the real task, on real cases, and I
take notes on three things:</p>

<ul>
  <li><strong>Waits.</strong> Every point where the work stops because it is waiting for a
person, a system, an approval or a batch job. Waits are usually far longer
than the work itself, and they are invisible in process diagrams.</li>
  <li><strong>Workarounds.</strong> Spreadsheets kept next to the official system, sticky notes,
copy-paste between tabs, a message sent to “the person who knows.” Each one
marks a place where the official tooling doesn’t fit the real job.</li>
  <li><strong>Judgment calls.</strong> The moments where someone pauses and decides. These are
the parts that are hardest to automate, and the parts people are most
protective of. Knowing where they are early saves you from building something
that tries to take them away.</li>
</ul>

<h2 id="day-four-map-the-queue-not-the-process">Day four: map the queue, not the process</h2>

<p>By now I can draw the workflow as a sequence of steps, with the time spent
<em>working</em> and the time spent <em>waiting</em> at each one. It almost always looks the
same: a few minutes of work, separated by hours or days of waiting.</p>

<p>That picture usually points straight at the bottleneck, and it is rarely where
the request pointed. In the landing-page case, building pages faster would have saved
minutes. Removing the wait for an engineer saved days.</p>

<p>This is also where AI fits, or doesn’t. Models are good at shrinking the
<em>work</em> inside a step: drafting, classifying, summarising, extracting. They
don’t help with a wait caused by an approval that nobody needs or a hand-off
between teams. If the bottleneck is a wait, automating the work around it
changes very little. It’s worth being honest about this before proposing an
AI feature.</p>

<h2 id="day-five-play-it-back-then-propose">Day five: play it back, then propose</h2>

<p>Before proposing anything, I play my understanding back to the team: here’s
what I saw, here’s where the time goes, here’s what I think the real problem is.
Two things happen. They correct the parts I got wrong, which they always do,
and they start to trust that the eventual proposal is grounded in their actual
work rather than in a generic idea of it.</p>

<p>Then I propose the smallest thing that moves the outcome, and I tie it to a
number we agreed on. “Campaigns go live the same day” is a goal a team can
hold me to. “A better landing-page tool” isn’t.</p>

<h2 id="things-that-go-wrong">Things that go wrong</h2>

<ul>
  <li><strong>Discovery with the wrong people.</strong> Managers describe the process they
designed. The people doing the work describe the process that exists. You
need both, but the second matters more for what you build.</li>
  <li><strong>Discovery that never ends.</strong> A week is usually enough to find the
bottleneck. After that, a working prototype in their hands teaches you more
than another round of interviews.</li>
  <li><strong>Falling in love with the elegant solution.</strong> Sometimes the right fix is a
form, a permission change or a deleted approval step. If it moves the
outcome, ship it. Nobody downstream cares how interesting it was to build.</li>
</ul>

<h2 id="why-this-matters-more-with-ai">Why this matters more with AI</h2>

<p>AI makes it cheap to build something impressive, and that raises the risk of
building the wrong thing well. A slick agent that automates a step that was never the
bottleneck will demo beautifully and change nothing. A week of watching the
work is the cheapest insurance I know against that outcome.</p>

<hr />

<p><em>Examples are generalised from past projects and contain no confidential
details from any employer.</em></p>]]></content><author><name>Mohinee Indurkar</name></author><category term="engineering" /><category term="discovery" /><category term="product" /><category term="ai" /><category term="stakeholders" /><summary type="html"><![CDATA[The request you're handed is rarely the problem you need to solve. How I spend the first week with a team I'm building for: watching the work, mapping the waits, and finding the bottleneck before writing code.]]></summary></entry><entry><title type="html">Shadow mode: earning a skeptical team’s trust before a model makes a single decision</title><link href="https://mohinee.github.io/2026/shadow-mode-earning-trust/" rel="alternate" type="text/html" title="Shadow mode: earning a skeptical team’s trust before a model makes a single decision" /><published>2026-09-17T00:00:00+00:00</published><updated>2026-09-17T00:00:00+00:00</updated><id>https://mohinee.github.io/2026/shadow-mode-earning-trust</id><content type="html" xml:base="https://mohinee.github.io/2026/shadow-mode-earning-trust/"><![CDATA[<p>The fastest way to kill an AI rollout is to ask the people who own a process to
trust a model on day one. They know their process. They know the edge cases that
never made it into a spec. And they have usually seen at least one confident,
wrong demo.</p>

<p>What I do instead is <strong>run the model in shadow mode first</strong>. It sees every real input, makes every decision it would
make in production, and none of those decisions touch anything. A human keeps
doing the work exactly as before. You log both answers and compare.</p>

<p>This post covers how I set that up, what the comparison data is actually for,
and how to turn it into a confidence threshold you can defend in a room full of
skeptics.</p>

<h2 id="what-shadow-mode-buys-you">What shadow mode buys you</h2>

<p>A demo answers “can the model do this?” Shadow mode answers the questions the
process owner actually cares about:</p>

<ul>
  <li><strong>How often does it agree with us, on our real traffic?</strong> Not on a curated
eval set. On last Tuesday’s inputs, including the weird ones.</li>
  <li><strong>Where does it disagree, and who was right?</strong> Some disagreements are model
errors. Some turn out to be inconsistencies in how humans were doing the work.
Both are valuable, and the second kind tends to change the conversation.</li>
  <li><strong>Can we tell in advance which answers to trust?</strong> This is the one that
decides whether you ship at all.</li>
</ul>

<p>It also changes the social dynamics. You are no longer asking for trust. You are
handing over evidence and asking the owners to judge it. People who would have
blocked a launch become the reviewers of the diff, and reviewers have a stake in
the outcome.</p>

<h2 id="the-setup">The setup</h2>

<p>The mechanics are simple, and most of the value is in being disciplined about
them:</p>

<ol>
  <li><strong>Fork the input, not the output.</strong> The model receives the same request the
human does, at the same point in the workflow. Nothing it produces is written
anywhere a user or downstream system can see.</li>
  <li><strong>Log a comparable record.</strong> For each case: the input (or a reference to it),
the model’s answer, the model’s confidence, the human’s answer, and enough
metadata to slice by (category, source, time).</li>
  <li><strong>Decide what “agree” means up front.</strong> For a classification task it is exact
match. For free text you need a rubric, a reviewer, or an LLM judge that you
have spot-checked. Write this down before you look at results, or you will
move the goalposts without noticing.</li>
  <li><strong>Run it long enough to see the unusual cases.</strong> A week of traffic usually
misses month-end, quarter-end and the odd seasonal spike. Ask the process
owner when their weird weeks are, and make sure the shadow run covers at
least one.</li>
</ol>

<h2 id="confidence-threshold-routing">Confidence-threshold routing</h2>

<p>Shadow data rarely says “the model is good enough for everything.” It usually
says something more useful: the model is very reliable on some slice of inputs
and unreliable on the rest. If the model’s confidence score separates those
slices, you can route by it:</p>

<ul>
  <li><strong>Above the threshold:</strong> the model’s answer is used automatically.</li>
  <li><strong>Below the threshold:</strong> the case goes to a human, exactly as it does today.</li>
</ul>

<p>That turns a yes-or-no launch decision into a dial. You can start with a high
threshold that automates a small share of cases at very high precision, and
lower it as trust and evidence accumulate.</p>

<p>The trap is picking the threshold by eye from a chart. With small samples at the
high-confidence end, a slice that looks 97% accurate might be 90% accurate in
reality. So I pick it with a lower confidence bound instead of the raw
precision, and require a minimum sample size per slice.</p>

<h2 id="picking-the-threshold-from-shadow-data">Picking the threshold from shadow data</h2>

<p>Here is the small script I use. It takes <code class="language-plaintext highlighter-rouge">(confidence, agreed_with_human)</code> pairs
from the shadow log and finds the lowest threshold whose auto-accepted slice
still clears a precision target <strong>at the lower bound of a 95% Wilson interval</strong>.</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">import</span> <span class="nn">math</span>

<span class="k">def</span> <span class="nf">wilson_lower</span><span class="p">(</span><span class="n">successes</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="n">z</span><span class="o">=</span><span class="mf">1.96</span><span class="p">):</span>
    <span class="s">"""Lower bound of the 95% Wilson interval for a proportion."""</span>
    <span class="k">if</span> <span class="n">n</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
        <span class="k">return</span> <span class="mf">0.0</span>
    <span class="n">p</span> <span class="o">=</span> <span class="n">successes</span> <span class="o">/</span> <span class="n">n</span>
    <span class="n">denom</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">+</span> <span class="n">z</span> <span class="o">*</span> <span class="n">z</span> <span class="o">/</span> <span class="n">n</span>
    <span class="n">centre</span> <span class="o">=</span> <span class="n">p</span> <span class="o">+</span> <span class="n">z</span> <span class="o">*</span> <span class="n">z</span> <span class="o">/</span> <span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">n</span><span class="p">)</span>
    <span class="n">margin</span> <span class="o">=</span> <span class="n">z</span> <span class="o">*</span> <span class="n">math</span><span class="p">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">p</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="n">p</span><span class="p">)</span> <span class="o">/</span> <span class="n">n</span> <span class="o">+</span> <span class="n">z</span> <span class="o">*</span> <span class="n">z</span> <span class="o">/</span> <span class="p">(</span><span class="mi">4</span> <span class="o">*</span> <span class="n">n</span> <span class="o">*</span> <span class="n">n</span><span class="p">))</span>
    <span class="k">return</span> <span class="p">(</span><span class="n">centre</span> <span class="o">-</span> <span class="n">margin</span><span class="p">)</span> <span class="o">/</span> <span class="n">denom</span>

<span class="k">def</span> <span class="nf">pick_threshold</span><span class="p">(</span><span class="n">records</span><span class="p">,</span> <span class="n">target</span><span class="o">=</span><span class="mf">0.95</span><span class="p">,</span> <span class="n">min_n</span><span class="o">=</span><span class="mi">200</span><span class="p">):</span>
    <span class="s">"""records: (confidence, model_agreed_with_human) pairs from shadow mode.
    Returns the lowest threshold whose auto-accepted slice clears `target`
    precision at the Wilson lower bound, plus a table of every candidate."""</span>
    <span class="n">total</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">records</span><span class="p">)</span>
    <span class="n">table</span><span class="p">,</span> <span class="n">chosen</span> <span class="o">=</span> <span class="p">[],</span> <span class="bp">None</span>
    <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="p">[</span><span class="n">x</span> <span class="o">/</span> <span class="mi">100</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">50</span><span class="p">,</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">5</span><span class="p">)]:</span>
        <span class="n">accepted</span> <span class="o">=</span> <span class="p">[</span><span class="n">ok</span> <span class="k">for</span> <span class="n">conf</span><span class="p">,</span> <span class="n">ok</span> <span class="ow">in</span> <span class="n">records</span> <span class="k">if</span> <span class="n">conf</span> <span class="o">&gt;=</span> <span class="n">t</span><span class="p">]</span>
        <span class="n">n</span><span class="p">,</span> <span class="n">hits</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">accepted</span><span class="p">),</span> <span class="nb">sum</span><span class="p">(</span><span class="n">accepted</span><span class="p">)</span>
        <span class="n">lower</span> <span class="o">=</span> <span class="n">wilson_lower</span><span class="p">(</span><span class="n">hits</span><span class="p">,</span> <span class="n">n</span><span class="p">)</span>
        <span class="n">table</span><span class="p">.</span><span class="n">append</span><span class="p">((</span><span class="n">t</span><span class="p">,</span> <span class="n">n</span> <span class="o">/</span> <span class="n">total</span><span class="p">,</span> <span class="n">hits</span> <span class="o">/</span> <span class="n">n</span> <span class="k">if</span> <span class="n">n</span> <span class="k">else</span> <span class="mf">0.0</span><span class="p">,</span> <span class="n">lower</span><span class="p">,</span> <span class="n">n</span><span class="p">))</span>
        <span class="k">if</span> <span class="n">chosen</span> <span class="ow">is</span> <span class="bp">None</span> <span class="ow">and</span> <span class="n">n</span> <span class="o">&gt;=</span> <span class="n">min_n</span> <span class="ow">and</span> <span class="n">lower</span> <span class="o">&gt;=</span> <span class="n">target</span><span class="p">:</span>
            <span class="n">chosen</span> <span class="o">=</span> <span class="n">t</span>
    <span class="k">return</span> <span class="n">chosen</span><span class="p">,</span> <span class="n">table</span>
</code></pre></div></div>

<p>I ran it against 5,000 simulated shadow records from a model that is usually
confident and only roughly calibrated:</p>

<table>
  <thead>
    <tr>
      <th>Threshold</th>
      <th>Coverage</th>
      <th>Precision</th>
      <th>Lower 95% bound</th>
      <th>Cases</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>0.50</td>
      <td>89.8%</td>
      <td>82.3%</td>
      <td>81.1%</td>
      <td>4,492</td>
    </tr>
    <tr>
      <td>0.70</td>
      <td>57.8%</td>
      <td>87.2%</td>
      <td>85.9%</td>
      <td>2,892</td>
    </tr>
    <tr>
      <td>0.80</td>
      <td>35.5%</td>
      <td>90.1%</td>
      <td>88.7%</td>
      <td>1,773</td>
    </tr>
    <tr>
      <td>0.90</td>
      <td>11.4%</td>
      <td>94.7%</td>
      <td>92.6%</td>
      <td>568</td>
    </tr>
    <tr>
      <td>0.95</td>
      <td>3.4%</td>
      <td>97.0%</td>
      <td>93.2%</td>
      <td>168</td>
    </tr>
  </tbody>
</table>

<p>Three things in that table are worth noticing:</p>

<ul>
  <li><strong>A 95% target returns no threshold at all.</strong> The 0.95 slice looks like 97%,
but it holds only 168 cases, and its lower bound is 93%. Reading the chart
by eye would have shipped it. The script refuses, and that refusal is the
right answer to bring to the process owner.</li>
  <li><strong>At a 90% target it picks 0.90</strong>, which automates about 11% of cases. That
sounds small. It is also a real, defensible start, and every automated case
frees a person for the cases that need them.</li>
  <li><strong>Coverage and precision trade off smoothly.</strong> That gives the owner a real
choice. “How much do you want automated, and what error rate can your
process absorb?” is a business decision, and it should be theirs, made with
the numbers in front of them.</li>
</ul>

<h2 id="what-changes-when-you-present-it-this-way">What changes when you present it this way</h2>

<p>Bring the table, not a recommendation. In my experience the conversation shifts
from “should we trust the model?” to “which row do we start on?”, and that is a
conversation the people who own the process are comfortable having.</p>

<p>Bring the disagreements too. Pull twenty cases where the model and the human
differed and walk through them together. Some will be model errors you need to
fix. Some will be cases where two humans would also have disagreed. Those
usually lead to a clearer rule for the humans as well, which earns the model
more goodwill than any accuracy number.</p>

<h2 id="after-launch">After launch</h2>

<p>Shadow mode does not end at launch. It narrows:</p>

<ul>
  <li><strong>Keep sampling the auto-accepted slice.</strong> A small random sample still goes to
a human reviewer so precision is measured continuously, not assumed.</li>
  <li><strong>Re-run the threshold picker on fresh data</strong> when inputs drift, the model
changes, or the prompt changes. A threshold is a property of a model on a
distribution, and both of those move.</li>
  <li><strong>Treat a prompt change like a model change.</strong> Run it in shadow against the
current version before it takes traffic.</li>
</ul>

<p>None of this is sophisticated. It is mostly the discipline of not asking anyone
to take the model’s word for it. That discipline is what lets a model move from
an impressive demo to something a team relies on every day.</p>

<hr />

<p><em>The numbers above come from simulated data, generated so the script has
something realistic to chew on. The pattern itself is one I’ve used on
production AI work; nothing here describes any employer’s internal systems.</em></p>]]></content><author><name>Mohinee Indurkar</name></author><category term="ai" /><category term="deployment" /><category term="evaluation" /><category term="reliability" /><category term="python" /><summary type="html"><![CDATA[Nobody should be asked to trust a model on day one. Run it silently beside the process it will replace, show the diff, and let the data pick the confidence threshold. With code that picks the threshold for you.]]></summary></entry><entry><title type="html">Using AI to learn a new codebase fast, without trusting it blindly</title><link href="https://mohinee.github.io/2026/onboarding-unfamiliar-codebase-with-ai/" rel="alternate" type="text/html" title="Using AI to learn a new codebase fast, without trusting it blindly" /><published>2026-09-11T00:00:00+00:00</published><updated>2026-09-11T00:00:00+00:00</updated><id>https://mohinee.github.io/2026/onboarding-unfamiliar-codebase-with-ai</id><content type="html" xml:base="https://mohinee.github.io/2026/onboarding-unfamiliar-codebase-with-ai/"><![CDATA[<p>Opening a large, unfamiliar repository is disorienting no matter how long you’ve been doing this. You don’t know what matters, what everything else depends on, or what is legacy nobody dares touch. Reading top to bottom doesn’t work, because the thing you need to understand is rarely in one place.</p>

<p>AI coding agents help a lot here. They can read a hundred files while you read three. But they also produce confident, fluent, plausible-sounding descriptions of code that are sometimes wrong, and in a codebase you don’t know yet, you are the worst-placed person to notice.</p>

<p>The workflow below aims for the speed without the risk. One rule runs through all of it: <strong>the model proposes, the repository and its history decide.</strong></p>

<h2 id="phase-1-a-metadata-pass">Phase 1: A metadata pass</h2>

<p>Before any code, gather the material people wrote <em>about</em> the code, and have the AI synthesize it: README and docs, CONTRIBUTING, architecture decision records, CI configuration, the build files, dependency manifests, deployment config, and issue templates.</p>

<p>Ask for concrete artifacts, not summaries:</p>

<ul>
  <li>What are the deployable units, and how are they built and released?</li>
  <li>What are the external dependencies (databases, queues, third-party APIs)?</li>
  <li>What is the test strategy, and how do I run it locally?</li>
  <li>What conventions does this repository state explicitly?</li>
</ul>

<p>This phase is cheap and the failure mode is mild: docs go stale, so treat the output as a claim to check. Anything it says about <em>how things are supposed to work</em> is a lead, not a fact.</p>

<h2 id="phase-2-trace-flows-dont-read-modules">Phase 2: Trace flows, don’t read modules</h2>

<p>Reading a codebase module by module gives you a catalog of parts. What you need is how a request moves through them.</p>

<p>Pick two or three concrete scenarios, such as “a user signs in,” “an order is placed,” or “a background job retries,” and have the agent trace each from entry point to persistence, naming every file it passes through.</p>

<p>Two practices help:</p>

<ul>
  <li><strong>Use read-only exploration.</strong> Give the tool permission to search and read, not to edit. Onboarding is not the time for surprise diffs.</li>
  <li><strong>Parallelize.</strong> Independent questions (“trace the auth flow,” “map the module boundaries,” “where is configuration loaded?”) can run as separate agent sessions at the same time, then you merge the answers. If your tool supports subagents for exploration, this is what they are for.</li>
</ul>

<p>Ask for file paths and line references with every claim. A trace you can click through is checkable. A trace written as prose is not.</p>

<h2 id="phase-3-mine-the-history-for-the-why">Phase 3: Mine the history for the <em>why</em></h2>

<p>Code tells you what the system does. It rarely tells you why it is shaped that way, and “why” is what stops you from breaking something.</p>

<p>Version control is the best source. A few commands that reliably pay off:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Which files change most? (a proxy for where the action is)</span>
git log <span class="nt">--since</span><span class="o">=</span><span class="s2">"12 months ago"</span> <span class="nt">--name-only</span> <span class="nt">--pretty</span><span class="o">=</span>format: <span class="se">\</span>
  | <span class="nb">grep</span> <span class="nt">-v</span> <span class="s1">'^$'</span> | <span class="nb">sort</span> | <span class="nb">uniq</span> <span class="nt">-c</span> | <span class="nb">sort</span> <span class="nt">-rn</span> | <span class="nb">head</span> <span class="nt">-20</span>

<span class="c"># Who has been working here?</span>
git shortlog <span class="nt">-sn</span> <span class="nt">--no-merges</span> <span class="nt">--since</span><span class="o">=</span><span class="s2">"12 months ago"</span> HEAD

<span class="c"># When did this string or symbol appear or disappear?</span>
git log <span class="nt">-S</span><span class="s1">'someSymbol'</span> <span class="nt">--oneline</span> <span class="nt">--</span> path/to/file

<span class="c"># Why is this line the way it is?</span>
git blame <span class="nt">-w</span> <span class="nt">-C</span> path/to/file
</code></pre></div></div>

<p>The pickaxe search (<code class="language-plaintext highlighter-rouge">-S</code>) is especially good: it shows the commits where the <em>number of occurrences</em> of a string changed, so you find the commit that introduced a constant or removed a check. Then read that commit message and the pull request behind it.</p>

<p>Feed the AI those results, along with postmortems, incident write-ups, and long-running issue threads, and ask it to reconstruct causal stories: “this retry logic exists because of X.” Then verify each story against the actual commit or document it cites.</p>

<h2 id="phase-4-build-a-risk-map-and-write-it-down">Phase 4: Build a risk map and write it down</h2>

<p>By now you have enough to identify where a change is dangerous. A useful map has four signals:</p>

<ul>
  <li><strong>High fan-in.</strong> Files or functions that many others depend on.</li>
  <li><strong>High churn.</strong> Files that change constantly, which often means unstable design or a merge-conflict magnet.</li>
  <li><strong>Low test coverage,</strong> particularly where fan-in is high.</li>
  <li><strong>Sparse or contradictory comments,</strong> which often mark places where the original author was uncertain.</li>
</ul>

<p>The overlap of high fan-in and low coverage is the part to be careful with.</p>

<p>Persist what you learned. Most agent tools support a project-level memory or instructions file that they load on every session, such as a <code class="language-plaintext highlighter-rouge">CLAUDE.md</code> or <code class="language-plaintext highlighter-rouge">AGENTS.md</code>. Put the verified findings in there: how to build and test, the request flow, the areas to be careful with. That turns a one-time exploration into something every later session, yours or a teammate’s, starts from. Keep it to things you have confirmed.</p>

<h2 id="phase-5-choose-a-low-blast-radius-first-change">Phase 5: Choose a low-blast-radius first change</h2>

<p>The fastest way to test whether you really understand a codebase is to change it in a small way and see what happens. Good first contributions have a few properties:</p>

<ul>
  <li>Isolated, with well-defined inputs and outputs</li>
  <li>Covered by existing tests, so you get fast feedback</li>
  <li>Reviewed by someone who knows the area</li>
  <li>Similar enough to existing code that you can copy its idioms</li>
</ul>

<p>Let the AI help you find the <em>idiomatic</em> way to do it here, by showing you three existing examples of the same kind of change. The goal is to look like you have always worked in this repository, which means matching local conventions instead of importing your own.</p>

<h2 id="the-critique-pass-and-where-it-goes-wrong">The critique pass, and where it goes wrong</h2>

<p>Once you have a working model, an AI can quickly generate a list of code smells, inconsistencies, and things that look wrong. That list is useful, and it is also where newcomers get into trouble.</p>

<p>Every item on it is a <strong>hypothesis</strong>. Some are real problems. Many are decisions with context you don’t have yet: a workaround for a vendor bug, a constraint from another team, a deliberate trade-off that was argued over in a design review two years ago.</p>

<p>Before you repeat any of them in a code review, a design discussion, or a standup:</p>

<ol>
  <li>Check the history for the reason (Phase 3 again).</li>
  <li>Ask the people who own the area.</li>
  <li>Only then decide whether it is a real issue.</li>
</ol>

<p>Nothing damages a newcomer’s credibility faster than confidently calling something a mistake that turns out to be deliberate. An AI is very good at producing that kind of confident claim, and it has no idea what your team decided last spring.</p>

<h2 id="two-practical-cautions">Two practical cautions</h2>

<ul>
  <li><strong>Check your organization’s policy on AI tools first.</strong> Pointing an external service at a private repository may be restricted, or allowed only for approved tools. This is a two-minute question that avoids a serious problem.</li>
  <li><strong>Don’t let the tool’s summary replace reading.</strong> For the handful of files that are truly central, read them yourself, line by line. A summary tells you where to look. It doesn’t replace looking.</li>
</ul>

<h2 id="the-workflow-in-one-glance">The workflow in one glance</h2>

<table>
  <thead>
    <tr>
      <th>Phase</th>
      <th>What you ask for</th>
      <th>How you verify</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1. Metadata</td>
      <td>Build, deploy, dependencies, conventions</td>
      <td>Cross-check against CI config</td>
    </tr>
    <tr>
      <td>2. Flow tracing</td>
      <td>End-to-end paths with file references</td>
      <td>Click through the references</td>
    </tr>
    <tr>
      <td>3. History</td>
      <td>Causal stories for surprising code</td>
      <td>Read the cited commits and PRs</td>
    </tr>
    <tr>
      <td>4. Risk map</td>
      <td>Fan-in, churn, coverage overlap</td>
      <td>Compare with actual coverage and git data</td>
    </tr>
    <tr>
      <td>5. First change</td>
      <td>Idiomatic examples to copy</td>
      <td>Existing tests and reviewer feedback</td>
    </tr>
  </tbody>
</table>

<p>AI makes it much faster to form a mental model of a new codebase. The verification steps are what keep that model from being wrong, and making them habitual matters more than which tool you use.</p>]]></content><author><name>Mohinee Indurkar</name></author><category term="ai" /><category term="developer-productivity" /><category term="engineering" /><category term="onboarding" /><category term="code-review" /><summary type="html"><![CDATA[AI coding tools can compress the first weeks in an unfamiliar repository into days, if you use them as hypothesis generators rather than oracles. A five-phase workflow.]]></summary></entry><entry><title type="html">Designing resumable large-file uploads in the browser</title><link href="https://mohinee.github.io/2026/resumable-large-file-uploads-browser/" rel="alternate" type="text/html" title="Designing resumable large-file uploads in the browser" /><published>2026-08-28T00:00:00+00:00</published><updated>2026-08-28T00:00:00+00:00</updated><id>https://mohinee.github.io/2026/resumable-large-file-uploads-browser</id><content type="html" xml:base="https://mohinee.github.io/2026/resumable-large-file-uploads-browser/"><![CDATA[<p>A single <code class="language-plaintext highlighter-rouge">fetch</code> with a <code class="language-plaintext highlighter-rouge">FormData</code> body is fine for a profile picture. It is the wrong tool for a 5 GB video. One dropped connection at 98% means starting over, the browser may try to hold the whole thing in memory, and the user has no way to pause or cancel meaningfully.</p>

<p>The fix is well known: split the file into chunks and upload them separately. The hard part is everything else that has to be right for that to work.</p>

<h2 id="the-four-constraints">The four constraints</h2>

<ol>
  <li><strong>Memory must be bounded</strong>, regardless of file size.</li>
  <li><strong>Failure must be local.</strong> A failed chunk retries alone. It does not restart the upload.</li>
  <li><strong>The upload must be resumable</strong>, including after a page reload.</li>
  <li><strong>The user must be able to cancel</strong>, and cancel must actually stop work and clean up.</li>
</ol>

<p>Everything below serves one of these.</p>

<h2 id="never-read-the-whole-file">Never read the whole file</h2>

<p>A <code class="language-plaintext highlighter-rouge">File</code> is a <code class="language-plaintext highlighter-rouge">Blob</code>, and blobs are lazy. <code class="language-plaintext highlighter-rouge">file.slice(start, end)</code> returns a new blob without copying anything. Only when you call <code class="language-plaintext highlighter-rouge">.arrayBuffer()</code> on the slice do those bytes enter memory.</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">MiB</span> <span class="o">=</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">1024</span><span class="p">;</span>

<span class="k">export</span> <span class="kd">function</span> <span class="nx">planChunks</span><span class="p">(</span><span class="nx">size</span><span class="p">,</span> <span class="nx">chunkSize</span> <span class="o">=</span> <span class="mi">8</span> <span class="o">*</span> <span class="nx">MiB</span><span class="p">)</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="nx">chunks</span> <span class="o">=</span> <span class="p">[];</span>
  <span class="k">for</span> <span class="p">(</span><span class="kd">let</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">start</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">start</span> <span class="o">&lt;</span> <span class="nx">size</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">,</span> <span class="nx">start</span> <span class="o">+=</span> <span class="nx">chunkSize</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">chunks</span><span class="p">.</span><span class="nx">push</span><span class="p">({</span> <span class="na">index</span><span class="p">:</span> <span class="nx">i</span><span class="p">,</span> <span class="nx">start</span><span class="p">,</span> <span class="na">end</span><span class="p">:</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">min</span><span class="p">(</span><span class="nx">start</span> <span class="o">+</span> <span class="nx">chunkSize</span><span class="p">,</span> <span class="nx">size</span><span class="p">)</span> <span class="p">});</span>
  <span class="p">}</span>
  <span class="k">return</span> <span class="nx">chunks</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>

<p>The plan is just numbers. No data is touched until a worker is ready to send a chunk. The anti-pattern to avoid is <code class="language-plaintext highlighter-rouge">await file.arrayBuffer()</code> “to make things simpler,” which will hold the entire file in memory at once.</p>

<p><strong>Choosing a chunk size</strong> is a tradeoff. Small chunks make retries cheap but multiply request overhead and the number of parts you track. Large chunks are efficient but make each failure expensive. If your storage backend is S3-style multipart, it constrains you: parts must be at least 5 MiB (except the last), an upload can have at most 10,000 parts, and an object can be at most 5 TiB. That means a fixed 5 MiB chunk cannot exceed about 48 GiB, so very large files need a larger chunk size computed from the file size.</p>

<h2 id="integrity-per-chunk">Integrity per chunk</h2>

<p><code class="language-plaintext highlighter-rouge">SubtleCrypto.digest</code> hashes a buffer in one call. It has no streaming interface. That is actually convenient here, because hashing one bounded chunk at a time is exactly what keeps memory flat.</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">export</span> <span class="k">async</span> <span class="kd">function</span> <span class="nx">sha256Hex</span><span class="p">(</span><span class="nx">buf</span><span class="p">)</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="nx">d</span> <span class="o">=</span> <span class="k">await</span> <span class="nx">crypto</span><span class="p">.</span><span class="nx">subtle</span><span class="p">.</span><span class="nx">digest</span><span class="p">(</span><span class="dl">"</span><span class="s2">SHA-256</span><span class="dl">"</span><span class="p">,</span> <span class="nx">buf</span><span class="p">);</span>
  <span class="k">return</span> <span class="p">[...</span><span class="k">new</span> <span class="nb">Uint8Array</span><span class="p">(</span><span class="nx">d</span><span class="p">)].</span><span class="nx">map</span><span class="p">(</span><span class="nx">b</span> <span class="o">=&gt;</span> <span class="nx">b</span><span class="p">.</span><span class="nx">toString</span><span class="p">(</span><span class="mi">16</span><span class="p">).</span><span class="nx">padStart</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="dl">"</span><span class="s2">0</span><span class="dl">"</span><span class="p">)).</span><span class="nx">join</span><span class="p">(</span><span class="dl">""</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Send the digest with each chunk, and have the server recompute and reject on mismatch. This catches corruption that TCP’s checksum can miss and gives you a precise error: “chunk 41 failed verification,” not “the file is broken.”</p>

<p>A whole-file hash is a separate problem. Since the Web Crypto API cannot hash incrementally, you either use a JS library that supports incremental hashing, or let the server compute the final hash by combining chunk results. Decide up front which one your integrity guarantee depends on.</p>

<h2 id="bounded-concurrency-is-a-memory-limit-in-disguise">Bounded concurrency is a memory limit in disguise</h2>

<p>Uploading one chunk at a time wastes bandwidth. Uploading all of them at once defeats the point. A worker pool with a fixed size does both jobs: it keeps the pipe busy and it puts a ceiling on how many chunks are ever in memory.</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">export</span> <span class="k">async</span> <span class="kd">function</span> <span class="nx">uploadAll</span><span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="nx">send</span><span class="p">,</span> <span class="p">{</span> <span class="nx">concurrency</span> <span class="o">=</span> <span class="mi">3</span><span class="p">,</span> <span class="nx">signal</span><span class="p">,</span> <span class="nx">alreadyDone</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">Set</span><span class="p">()</span> <span class="p">}</span> <span class="o">=</span> <span class="p">{})</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="nx">queue</span> <span class="o">=</span> <span class="nx">planChunks</span><span class="p">(</span><span class="nx">file</span><span class="p">.</span><span class="nx">size</span><span class="p">).</span><span class="nx">filter</span><span class="p">(</span><span class="nx">c</span> <span class="o">=&gt;</span> <span class="o">!</span><span class="nx">alreadyDone</span><span class="p">.</span><span class="nx">has</span><span class="p">(</span><span class="nx">c</span><span class="p">.</span><span class="nx">index</span><span class="p">));</span>
  <span class="kd">const</span> <span class="nx">ctl</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">AbortController</span><span class="p">();</span>
  <span class="nx">signal</span><span class="p">?.</span><span class="nx">addEventListener</span><span class="p">(</span><span class="dl">"</span><span class="s2">abort</span><span class="dl">"</span><span class="p">,</span> <span class="p">()</span> <span class="o">=&gt;</span> <span class="nx">ctl</span><span class="p">.</span><span class="nx">abort</span><span class="p">(</span><span class="nx">signal</span><span class="p">.</span><span class="nx">reason</span><span class="p">),</span> <span class="p">{</span> <span class="na">once</span><span class="p">:</span> <span class="kc">true</span> <span class="p">});</span>

  <span class="k">async</span> <span class="kd">function</span> <span class="nx">worker</span><span class="p">()</span> <span class="p">{</span>
    <span class="k">while</span> <span class="p">(</span><span class="nx">queue</span><span class="p">.</span><span class="nx">length</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">ctl</span><span class="p">.</span><span class="nx">signal</span><span class="p">.</span><span class="nx">aborted</span><span class="p">)</span> <span class="p">{</span>
      <span class="kd">const</span> <span class="nx">chunk</span> <span class="o">=</span> <span class="nx">queue</span><span class="p">.</span><span class="nx">shift</span><span class="p">();</span>
      <span class="k">try</span> <span class="p">{</span> <span class="k">await</span> <span class="nx">uploadChunk</span><span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="nx">chunk</span><span class="p">,</span> <span class="nx">send</span><span class="p">,</span> <span class="nx">ctl</span><span class="p">.</span><span class="nx">signal</span><span class="p">);</span> <span class="p">}</span>
      <span class="k">catch</span> <span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span> <span class="nx">ctl</span><span class="p">.</span><span class="nx">abort</span><span class="p">(</span><span class="nx">e</span><span class="p">);</span> <span class="k">throw</span> <span class="nx">e</span><span class="p">;</span> <span class="p">}</span>   <span class="c1">// first hard failure stops the siblings</span>
    <span class="p">}</span>
  <span class="p">}</span>

  <span class="k">await</span> <span class="nb">Promise</span><span class="p">.</span><span class="nx">all</span><span class="p">(</span><span class="nb">Array</span><span class="p">.</span><span class="k">from</span><span class="p">({</span> <span class="na">length</span><span class="p">:</span> <span class="nx">concurrency</span> <span class="p">},</span> <span class="nx">worker</span><span class="p">));</span>
  <span class="nx">ctl</span><span class="p">.</span><span class="nx">signal</span><span class="p">.</span><span class="nx">throwIfAborted</span><span class="p">();</span>               <span class="c1">// a user abort must reject, not resolve quietly</span>
<span class="p">}</span>
</code></pre></div></div>

<p>With three workers and 8 MiB chunks, peak chunk memory is about 24 MiB whether the file is 100 MB or 100 GB. In a simulated run the pool never exceeded its cap of 3 in-flight chunks.</p>

<p>Why three? Browsers limit concurrent connections per host on HTTP/1.1 (typically six), and other requests on the page share that budget. HTTP/2 multiplexes, so the limit is softer. A fixed small number is a sensible default. If you want to go further, adjust concurrency up while throughput improves and errors stay low, and back off when either turns.</p>

<h2 id="retries-know-which-failures-are-worth-retrying">Retries: know which failures are worth retrying</h2>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">backoff</span> <span class="o">=</span> <span class="nx">attempt</span> <span class="o">=&gt;</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span> <span class="o">*</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">min</span><span class="p">(</span><span class="mi">10</span><span class="nx">_000</span><span class="p">,</span> <span class="mi">500</span> <span class="o">*</span> <span class="mi">2</span> <span class="o">**</span> <span class="nx">attempt</span><span class="p">);</span>  <span class="c1">// full jitter</span>

<span class="k">async</span> <span class="kd">function</span> <span class="nx">uploadChunk</span><span class="p">(</span><span class="nx">file</span><span class="p">,</span> <span class="nx">chunk</span><span class="p">,</span> <span class="nx">send</span><span class="p">,</span> <span class="nx">signal</span><span class="p">,</span> <span class="nx">maxAttempts</span> <span class="o">=</span> <span class="mi">4</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">for</span> <span class="p">(</span><span class="kd">let</span> <span class="nx">attempt</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="p">;</span> <span class="nx">attempt</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">try</span> <span class="p">{</span>
      <span class="kd">const</span> <span class="nx">buf</span> <span class="o">=</span> <span class="k">await</span> <span class="nx">file</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="nx">chunk</span><span class="p">.</span><span class="nx">start</span><span class="p">,</span> <span class="nx">chunk</span><span class="p">.</span><span class="nx">end</span><span class="p">).</span><span class="nx">arrayBuffer</span><span class="p">();</span>
      <span class="kd">const</span> <span class="nx">checksum</span> <span class="o">=</span> <span class="k">await</span> <span class="nx">sha256Hex</span><span class="p">(</span><span class="nx">buf</span><span class="p">);</span>
      <span class="k">return</span> <span class="k">await</span> <span class="nx">send</span><span class="p">({</span> <span class="p">...</span><span class="nx">chunk</span><span class="p">,</span> <span class="na">body</span><span class="p">:</span> <span class="nx">buf</span><span class="p">,</span> <span class="nx">checksum</span><span class="p">,</span> <span class="nx">signal</span> <span class="p">});</span>
    <span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
      <span class="k">if</span> <span class="p">(</span><span class="nx">signal</span><span class="p">.</span><span class="nx">aborted</span> <span class="o">||</span> <span class="o">!</span><span class="nx">e</span><span class="p">.</span><span class="nx">retryable</span> <span class="o">||</span> <span class="nx">attempt</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">&gt;=</span> <span class="nx">maxAttempts</span><span class="p">)</span> <span class="k">throw</span> <span class="nx">e</span><span class="p">;</span>
      <span class="k">await</span> <span class="nx">sleep</span><span class="p">(</span><span class="nx">backoff</span><span class="p">(</span><span class="nx">attempt</span><span class="p">),</span> <span class="nx">signal</span><span class="p">);</span>
    <span class="p">}</span>
  <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<ul>
  <li><strong>Retry</strong> network errors, timeouts, <code class="language-plaintext highlighter-rouge">5xx</code>, and <code class="language-plaintext highlighter-rouge">429</code>. Honor <code class="language-plaintext highlighter-rouge">Retry-After</code> if the server sends it.</li>
  <li><strong>Do not retry</strong> <code class="language-plaintext highlighter-rouge">4xx</code> responses such as <code class="language-plaintext highlighter-rouge">403</code> and <code class="language-plaintext highlighter-rouge">413</code>. They will fail the same way every time, and retrying wastes the user’s time.</li>
  <li><strong>Use jitter.</strong> Without it, every client that failed together retries together, which is how a brief blip becomes a sustained outage.</li>
  <li><strong>Re-read the slice on each attempt.</strong> Holding the buffer across retries keeps memory pinned during the backoff sleep.</li>
  <li>If the chunk URL is pre-signed, it can expire mid-upload. A <code class="language-plaintext highlighter-rouge">403</code> from an expired signature is one of the few <code class="language-plaintext highlighter-rouge">4xx</code> cases where you refresh credentials and try again.</li>
</ul>

<h2 id="resume">Resume</h2>

<p>Resumability needs a server-side record of which chunks arrived, and a chunk endpoint that is <strong>idempotent</strong>: uploading chunk 7 twice must be harmless.</p>

<p>On resume, the client asks the server for the set of completed chunk indices, then feeds that set into <code class="language-plaintext highlighter-rouge">alreadyDone</code>. In a simulated run with chunks 0 to 3 already stored, only chunks 4, 5, and 6 were sent.</p>

<p>Two practical points:</p>

<ul>
  <li>The upload needs a stable identity. Derive it from something like file name, size, and last-modified time, or issue a server-side upload ID and keep it in <code class="language-plaintext highlighter-rouge">localStorage</code>. If the user picks a different file, that must not resume the old upload.</li>
  <li>Trust the server’s list, not the client’s memory. The client may believe chunk 5 succeeded when the response never arrived.</li>
</ul>

<h2 id="cancel-means-cleanup">Cancel means cleanup</h2>

<p><code class="language-plaintext highlighter-rouge">AbortController</code> is how you make cancel real. Pass the signal into <code class="language-plaintext highlighter-rouge">fetch</code> so in-flight requests are actually torn down, and into the backoff sleep so a cancelled upload is not sitting in a timer.</p>

<p>Cancel also has a server half. Abandoned partial uploads consume storage forever unless something removes them. Have the client send an explicit abort (for S3-style multipart, the AbortMultipartUpload call), and back that up with a lifecycle rule that expires incomplete uploads after some number of days, because the client is not always around to clean up: tabs close, phones die.</p>

<h2 id="a-bug-from-my-own-first-draft">A bug from my own first draft</h2>

<p>My first version of the pool looked correct and passed a happy-path test. When I simulated a user cancelling mid-upload, <code class="language-plaintext highlighter-rouge">uploadAll</code> <strong>resolved successfully</strong> with only some chunks sent.</p>

<p>The reason: on abort, each worker’s <code class="language-plaintext highlighter-rouge">while</code> condition became false and the loop simply ended. <code class="language-plaintext highlighter-rouge">Promise.all</code> saw workers finish without error and returned normally. From the caller’s perspective, a cancelled upload looked like a finished one. The fix is the single <code class="language-plaintext highlighter-rouge">throwIfAborted()</code> line at the end of the function above.</p>

<p>The general lesson is that “the loop stopped” and “the work completed” are different facts. Any code that stops early on a signal has to tell its caller which of the two happened.</p>

<h2 id="ui-state-is-not-transport-state">UI state is not transport state</h2>

<p>One last design point, which saves trouble later. Keep two models:</p>

<ul>
  <li><strong>Transport state:</strong> chunk indices, retry counts, checksums, upload IDs, signed URLs. This is internal and changes constantly.</li>
  <li><strong>UI state:</strong> <code class="language-plaintext highlighter-rouge">queued</code>, <code class="language-plaintext highlighter-rouge">hashing</code>, <code class="language-plaintext highlighter-rouge">uploading</code>, <code class="language-plaintext highlighter-rouge">paused</code>, <code class="language-plaintext highlighter-rouge">completing</code>, <code class="language-plaintext highlighter-rouge">done</code>, <code class="language-plaintext highlighter-rouge">failed</code>, plus a single progress number.</li>
</ul>

<p>The UI subscribes to the second model only. Otherwise every chunk completion triggers renders across the screen, and any change to your chunking strategy becomes a change to your components.</p>

<h2 id="checklist">Checklist</h2>

<ul>
  <li>Slice lazily and never read the whole file</li>
  <li>Chunk size chosen against the backend’s limits</li>
  <li>Per-chunk SHA-256, verified server-side</li>
  <li>Fixed-size worker pool, which is also your memory ceiling</li>
  <li>Retry only retryable errors, with backoff and jitter</li>
  <li>Idempotent chunk endpoint and a server-side “what do you have?” call for resume</li>
  <li><code class="language-plaintext highlighter-rouge">AbortController</code> end to end, plus server-side cleanup</li>
  <li>Aborts reject; they do not resolve</li>
  <li>Separate UI state from transport state</li>
</ul>]]></content><author><name>Mohinee Indurkar</name></author><category term="frontend" /><category term="architecture" /><category term="javascript" /><category term="system-design" /><category term="reliability" /><summary type="html"><![CDATA[Uploading a 5 GB file is not a bigger version of uploading a 5 MB file. Chunking, per-chunk checksums, bounded concurrency, resume, and abort, and the bug I introduced in my own first draft.]]></summary></entry><entry><title type="html">P90 just jumped: a playbook for latency regressions</title><link href="https://mohinee.github.io/2026/latency-regression-playbook/" rel="alternate" type="text/html" title="P90 just jumped: a playbook for latency regressions" /><published>2026-08-13T00:00:00+00:00</published><updated>2026-08-13T00:00:00+00:00</updated><id>https://mohinee.github.io/2026/latency-regression-playbook</id><content type="html" xml:base="https://mohinee.github.io/2026/latency-regression-playbook/"><![CDATA[<p>A latency graph steps up after a release. Everyone opens the profiler.</p>

<p>That’s the wrong first move. Profiling is slow, it answers “where is the time going?” rather than “what changed?”, and users keep getting the slow experience while you do it. This is the order I follow instead. None of the steps are clever, but this order gets to the cause fastest.</p>

<h2 id="1-confirm-it-then-slice-it">1. Confirm it, then slice it</h2>

<p>Before theorizing, establish what you are actually looking at.</p>

<ul>
  <li><strong>Which percentile?</strong> A p50 shift usually means every request got slower: a code path, a dependency, a bundle. A p90 or p99 shift with a flat median usually means a <em>subset</em> got slower: a cohort, a cold path, a cache miss, a tail effect.</li>
  <li><strong>Which slice?</strong> Break the metric down by release ring, region, browser, device class, tenant, route, and logged-in versus anonymous. A regression that appears in only one slice is already half-diagnosed.</li>
  <li><strong>Is the measurement itself sound?</strong> Check that the instrumentation, sampling rate, and definition of the metric did not change in the same release. Some “regressions” are a new timer starting earlier.</li>
</ul>

<p>The output of this step is one sentence: “p90 of X rose by Y for cohort Z starting at time T.” Without that sentence you are debugging a feeling.</p>

<h2 id="2-correlate-with-change">2. Correlate with change</h2>

<p>Regressions are caused by something that changed. Line up the start of the step with:</p>

<ul>
  <li>Deploys and their contents</li>
  <li>Feature flag flips and rollout percentage changes</li>
  <li>Dependency or infrastructure changes</li>
  <li>Traffic shape changes (a new customer, a campaign, a bot)</li>
</ul>

<p>Flags deserve special attention because they change behavior <em>without</em> a deploy, so they don’t appear in your release notes. If your flag system has an audit log, check it before you check the diff.</p>

<h2 id="3-mitigate-before-you-diagnose">3. Mitigate before you diagnose</h2>

<p>If the timing points at a specific change and you can revert it safely, revert it. Turn the flag off, roll back the release ring, halt the ramp.</p>

<p>This feels like giving up on understanding the bug. It is the opposite. Rollback buys you a quiet system to investigate in, and it gives you the most valuable piece of evidence there is: <strong>if the metric recovers, you have confirmed the cause without profiling anything.</strong> If it doesn’t recover, you have eliminated a suspect just as cheaply.</p>

<h2 id="4-localize-client-or-server">4. Localize: client or server?</h2>

<p>Only now do you need to find where the time went. The question at this stage is a coarse one: is the added time before the request leaves the client, in the network and server, or after the response arrives?</p>

<ul>
  <li><strong>Distributed tracing</strong> with a shared trace ID from the browser through every service answers this directly.</li>
  <li><strong><code class="language-plaintext highlighter-rouge">Server-Timing</code> response headers</strong> let the server report its own processing time to the browser, for example <code class="language-plaintext highlighter-rouge">Server-Timing: db;dur=53, render;dur=21</code>. Chrome DevTools shows these in the request’s Timing tab, and they’re readable from <code class="language-plaintext highlighter-rouge">PerformanceResourceTiming.serverTiming</code> in RUM code. Cross-origin responses also need <code class="language-plaintext highlighter-rouge">Timing-Allow-Origin</code> or the browser hides them.</li>
  <li><strong>Resource Timing and Navigation Timing</strong> entries give you the client-side split between DNS, connect, request, and response.</li>
</ul>

<p>If the server side is flat, the regression is in the client, which is where the rest of this post lives.</p>

<h2 id="5-client-side-causes-in-rough-order-of-likelihood">5. Client-side causes, in rough order of likelihood</h2>

<p>When I have narrowed a regression to the frontend, this is the order I check, because it is the order things have most often turned out to be true:</p>

<ol>
  <li><strong>Bundle growth.</strong> A new dependency, a barrel-file import that defeated tree-shaking, or a chunk that used to be lazy and is now loaded eagerly. Compare the output of <code class="language-plaintext highlighter-rouge">webpack-bundle-analyzer</code>, <code class="language-plaintext highlighter-rouge">rollup-plugin-visualizer</code>, or <code class="language-plaintext highlighter-rouge">source-map-explorer</code> between the good and bad builds. It takes five minutes and explains more regressions than you’d expect.</li>
  <li><strong>A request waterfall.</strong> Two calls that used to run in parallel now run in sequence, often because one now depends on the other’s result, or because an <code class="language-plaintext highlighter-rouge">await</code> was added inside a loop.</li>
  <li><strong>Broken memoization causing render explosions.</strong> A selector or hook that used to return a stable reference now returns a new object on every call, so every consumer re-renders on every store update. Turn on “Record why each component rendered while profiling” in the React DevTools Profiler settings and it will tell you which prop or hook changed.</li>
  <li><strong>Unstable keys or remounting.</strong> List items whose keys changed to something non-stable will unmount and remount instead of updating.</li>
  <li><strong>Synchronous main-thread work.</strong> A large JSON parse, a sort, a regex, or a synchronous layout read inside a loop. Look for long tasks (over 50ms) in the Performance panel, or collect them from real users with a <code class="language-plaintext highlighter-rouge">PerformanceObserver</code> on <code class="language-plaintext highlighter-rouge">longtask</code> or, in Chromium, <code class="language-plaintext highlighter-rouge">long-animation-frame</code> entries.</li>
  <li><strong>Preload or prefetch coupling.</strong> An optimization that starts speculative work on a user gesture, such as hover, but is tied so tightly to the interaction that it now delays the thing the user asked for.</li>
  <li><strong>Memory growth.</strong> Leaks show up as latency that worsens over the life of a session, not as a step change. If the graph is a slope rather than a cliff, look here.</li>
</ol>

<p>The theme is that most frontend regressions are not slow code. They are <em>more</em> code, <em>more</em> work, or <em>the same work in a worse order</em>.</p>

<h2 id="6-measure-before-and-after-every-fix">6. Measure before and after every fix</h2>

<p>Whatever you change, capture the metric before and after, on the same slice, on the same kind of traffic. A fix you have not measured is a hypothesis. It is also worth checking that the fix didn’t just move the cost elsewhere: an optimization that speeds up one interaction while quietly slowing a neighboring one is common when code paths are shared.</p>

<p>Shared code paths are also why a “quick patch” is not always quick. If the slow code is used by more than one surface, a change that helps one can regress another. A staged rollout, one surface at a time behind a flag, is slower to start and much faster to finish than a patch you have to un-ship.</p>

<h2 id="7-make-the-next-one-cheaper">7. Make the next one cheaper</h2>

<p>The biggest payoff comes after the incident:</p>

<ul>
  <li><strong>Performance budgets in CI.</strong> Fail the build when bundle size or a key synthetic metric crosses a threshold (<code class="language-plaintext highlighter-rouge">size-limit</code> for bundles, Lighthouse CI budgets for page metrics), so regressions show up in the pull request instead of on a dashboard.</li>
  <li><strong>Real-user monitoring alerts per release ring.</strong> If canary users see a p90 step, the alert fires before the change reaches everyone.</li>
  <li><strong>Canary and ring-based rollouts.</strong> Regressions found at 1% of traffic are a nuisance. At 100% they are an incident.</li>
  <li><strong>Profiler checks in tests</strong> for the components you know are hot.</li>
</ul>

<h2 id="the-short-version">The short version</h2>

<ol>
  <li>Confirm and slice the metric.</li>
  <li>Correlate with deploys, flags, dependencies, and traffic.</li>
  <li>Roll back or switch off first, diagnose second.</li>
  <li>Localize client versus server.</li>
  <li>Check the likely client causes in order: bundle, waterfall, renders, keys, main thread, preloads, memory.</li>
  <li>Measure before and after.</li>
  <li>Add the guardrail that would have caught it.</li>
</ol>

<p>Which tool you use at each step barely matters. The order you go in does.</p>]]></content><author><name>Mohinee Indurkar</name></author><category term="performance" /><category term="frontend" /><category term="observability" /><category term="debugging" /><category term="engineering" /><summary type="html"><![CDATA[When a latency graph steps up, the instinct is to open the profiler. The order you investigate in matters more than the tools. A sequence that finds causes faster and breaks fewer things.]]></summary></entry><entry><title type="html">Why Math.random() breaks your feature flag rollouts</title><link href="https://mohinee.github.io/2026/feature-flags-deterministic-bucketing/" rel="alternate" type="text/html" title="Why Math.random() breaks your feature flag rollouts" /><published>2026-07-30T00:00:00+00:00</published><updated>2026-07-30T00:00:00+00:00</updated><id>https://mohinee.github.io/2026/feature-flags-deterministic-bucketing</id><content type="html" xml:base="https://mohinee.github.io/2026/feature-flags-deterministic-bucketing/"><![CDATA[<p>The first version of a feature flag service is about 20 lines. A correct one is about 60, and almost all of the difference is in one function: the one that decides whether <em>this</em> user is in the 10%.</p>

<h2 id="the-naive-version">The naive version</h2>

<div class="language-ts highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">enabled</span> <span class="o">=</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span> <span class="o">&lt;</span> <span class="mf">0.10</span><span class="p">;</span>
</code></pre></div></div>

<p>It works in every demo, and it fails in three ways that only show up in production:</p>

<ol>
  <li><strong>Flicker.</strong> The same user gets a different answer on every evaluation. They see the new checkout on page load and the old one after a refresh.</li>
  <li><strong>Corrupted experiments.</strong> If a user can be in both arms across sessions, your A/B analysis is comparing populations that overlap, and the result is meaningless.</li>
  <li><strong>Untestable.</strong> You cannot write a test that says “user 42 gets the new flow” because the answer is different each run.</li>
</ol>

<p>The requirement is that the assignment is a pure function of stable inputs, so the same user and flag always produce the same answer with no stored state.</p>

<h2 id="deterministic-bucketing">Deterministic bucketing</h2>

<p>Hash the user into one of N buckets and compare the bucket to the rollout percentage.</p>

<div class="language-ts highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">enc</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">TextEncoder</span><span class="p">();</span>

<span class="c1">// 32-bit FNV-1a over UTF-8 bytes</span>
<span class="k">export</span> <span class="kd">function</span> <span class="nx">fnv1a</span><span class="p">(</span><span class="nx">input</span><span class="p">:</span> <span class="kr">string</span><span class="p">):</span> <span class="kr">number</span> <span class="p">{</span>
  <span class="kd">let</span> <span class="nx">h</span> <span class="o">=</span> <span class="mh">0x811c9dc5</span><span class="p">;</span>
  <span class="k">for</span> <span class="p">(</span><span class="kd">const</span> <span class="nx">byte</span> <span class="k">of</span> <span class="nx">enc</span><span class="p">.</span><span class="nx">encode</span><span class="p">(</span><span class="nx">input</span><span class="p">))</span> <span class="p">{</span>
    <span class="nx">h</span> <span class="o">^=</span> <span class="nx">byte</span><span class="p">;</span>
    <span class="nx">h</span> <span class="o">=</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">imul</span><span class="p">(</span><span class="nx">h</span><span class="p">,</span> <span class="mh">0x01000193</span><span class="p">);</span>
  <span class="p">}</span>
  <span class="k">return</span> <span class="nx">h</span> <span class="o">&gt;&gt;&gt;</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>

<span class="c1">// 0..9999, so rollouts can be as fine-grained as 0.01%</span>
<span class="k">export</span> <span class="kd">const</span> <span class="nx">bucket</span> <span class="o">=</span> <span class="p">(</span><span class="nx">flagKey</span><span class="p">:</span> <span class="kr">string</span><span class="p">,</span> <span class="nx">userId</span><span class="p">:</span> <span class="kr">string</span><span class="p">)</span> <span class="o">=&gt;</span>
  <span class="nx">fnv1a</span><span class="p">(</span><span class="s2">`</span><span class="p">${</span><span class="nx">flagKey</span><span class="p">}</span><span class="s2">:</span><span class="p">${</span><span class="nx">userId</span><span class="p">}</span><span class="s2">`</span><span class="p">)</span> <span class="o">%</span> <span class="mi">10</span><span class="nx">_000</span><span class="p">;</span>

<span class="kd">const</span> <span class="nx">inRollout</span> <span class="o">=</span> <span class="nx">bucket</span><span class="p">(</span><span class="nx">flag</span><span class="p">.</span><span class="nx">key</span><span class="p">,</span> <span class="nx">user</span><span class="p">.</span><span class="nx">id</span><span class="p">)</span> <span class="o">&lt;</span> <span class="nx">flag</span><span class="p">.</span><span class="nx">rollout</span><span class="p">.</span><span class="nx">percent</span> <span class="o">*</span> <span class="mi">100</span><span class="p">;</span>
</code></pre></div></div>

<p>Three details matter here:</p>

<p><strong>Hash the UTF-8 bytes, not <code class="language-plaintext highlighter-rouge">charCodeAt</code>.</strong> JavaScript strings are UTF-16. If you hash code units, a Go or Python SDK evaluating the same flag will compute a different bucket for any non-ASCII ID, and your server and client will disagree about who is in the rollout. Hashing bytes makes the algorithm portable.</p>

<p><strong>Salt with the flag key.</strong> Without <code class="language-plaintext highlighter-rouge">flagKey:</code> in the hash input, a user’s bucket is the same for every flag. Then “10% of users get new checkout” and “10% of users get dark mode” are the <em>same</em> 10% of users. Every experiment is confounded with every other, and the unlucky 10% bear the risk of every rollout at once.</p>

<p><strong>A non-cryptographic hash is fine here.</strong> You want speed and uniformity, not collision resistance. FNV-1a is a few lines and has no dependencies, which is handy for a browser SDK. Any well-distributed hash works. Just pick one and never change it, because changing the hash reshuffles every user in every rollout.</p>

<h2 id="measuring-it">Measuring it</h2>

<p>I ran 100,000 synthetic user IDs through this code to check the claims rather than assume them:</p>

<table>
  <thead>
    <tr>
      <th>Check</th>
      <th>Result</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Actual size of a 10% rollout</td>
      <td>10.09%</td>
    </tr>
    <tr>
      <td>Same user evaluated twice</td>
      <td>always identical</td>
    </tr>
    <tr>
      <td>Users in at 10% who are still in at 20%</td>
      <td>100%</td>
    </tr>
    <tr>
      <td>Overlap of two salted 10% flags</td>
      <td>1.07% (expected about 1%)</td>
    </tr>
    <tr>
      <td>Overlap of two <em>unsalted</em> 10% flags</td>
      <td>10.04%, the same users every time</td>
    </tr>
  </tbody>
</table>

<p>The last two rows are the salting argument in numbers. The third row is a property worth calling out: because the bucket is fixed per user, raising a rollout from 10% to 20% only <em>adds</em> users. Nobody who already has the feature loses it mid-ramp.</p>

<h2 id="evaluation-order-is-a-design-decision">Evaluation order is a design decision</h2>

<p>A flag can be disabled globally, targeted at specific users, and rolled out by percentage, all at the same time. The order you check these in decides what happens when they conflict:</p>

<div class="language-ts highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">export</span> <span class="kd">function</span> <span class="nx">evaluate</span><span class="p">(</span><span class="nx">flag</span><span class="p">:</span> <span class="nx">Flag</span><span class="p">,</span> <span class="nx">user</span><span class="p">:</span> <span class="nx">User</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">if</span> <span class="p">(</span><span class="nx">flag</span><span class="p">.</span><span class="nx">killed</span><span class="p">)</span> <span class="k">return</span> <span class="nx">flag</span><span class="p">.</span><span class="nx">defaultValue</span><span class="p">;</span>                    <span class="c1">// 1. kill switch</span>
  <span class="k">for</span> <span class="p">(</span><span class="kd">const</span> <span class="nx">rule</span> <span class="k">of</span> <span class="nx">flag</span><span class="p">.</span><span class="nx">rules</span> <span class="o">??</span> <span class="p">[])</span> <span class="p">{</span>                         <span class="c1">// 2. targeting, first match wins</span>
    <span class="k">if</span> <span class="p">(</span><span class="nx">rule</span><span class="p">.</span><span class="nx">attr</span> <span class="k">in</span> <span class="nx">user</span> <span class="o">&amp;&amp;</span> <span class="nx">user</span><span class="p">[</span><span class="nx">rule</span><span class="p">.</span><span class="nx">attr</span><span class="p">]</span> <span class="o">===</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">equals</span><span class="p">)</span> <span class="k">return</span> <span class="nx">rule</span><span class="p">.</span><span class="nx">value</span><span class="p">;</span>
  <span class="p">}</span>
  <span class="k">if</span> <span class="p">(</span><span class="nx">flag</span><span class="p">.</span><span class="nx">rollout</span><span class="p">)</span> <span class="p">{</span>                                            <span class="c1">// 3. percentage rollout</span>
    <span class="k">return</span> <span class="nx">bucket</span><span class="p">(</span><span class="nx">flag</span><span class="p">.</span><span class="nx">key</span><span class="p">,</span> <span class="nx">user</span><span class="p">.</span><span class="nx">id</span><span class="p">)</span> <span class="o">&lt;</span> <span class="nx">flag</span><span class="p">.</span><span class="nx">rollout</span><span class="p">.</span><span class="nx">percent</span> <span class="o">*</span> <span class="mi">100</span>
      <span class="p">?</span> <span class="nx">flag</span><span class="p">.</span><span class="nx">rollout</span><span class="p">.</span><span class="nx">value</span>
      <span class="p">:</span> <span class="nx">flag</span><span class="p">.</span><span class="nx">defaultValue</span><span class="p">;</span>
  <span class="p">}</span>
  <span class="k">return</span> <span class="nx">flag</span><span class="p">.</span><span class="nx">defaultValue</span><span class="p">;</span>                                      <span class="c1">// 4. default</span>
<span class="p">}</span>
</code></pre></div></div>

<ul>
  <li><strong>The kill switch is first, and beats everything</strong>, including explicit targeting. At 2 a.m. during an incident, “turn it off for everyone” must mean everyone.</li>
  <li><strong>Targeting beats the percentage.</strong> If you have explicitly listed an internal tester, they should get the feature regardless of which bucket they hash into.</li>
  <li><strong>A rule referencing a missing attribute must skip, not crash.</strong> The <code class="language-plaintext highlighter-rouge">rule.attr in user</code> guard handles the case where a caller did not supply that attribute.</li>
</ul>

<h2 id="the-part-in-memory-no-database-hides">The part “in-memory, no database” hides</h2>

<p>If you keep flag state in process memory, everything above works on a single instance. The moment you run two, you have a coordination problem: a write to instance A must reach instance B. “No database” does not remove that requirement. It moves it somewhere else.</p>

<p>Options, roughly in order of complexity:</p>

<ul>
  <li><strong>Poll a source of truth</strong> on an interval. Simple and robust, but changes take up to one interval to propagate.</li>
  <li><strong>Publish changes over pub/sub</strong> (Redis, a message bus) so instances update within milliseconds, with periodic full reconciliation as a safety net for missed messages.</li>
  <li><strong>A single writer</strong> that everything else follows.</li>
</ul>

<p>Whichever you choose, write the limitation down. If a design only works with one process, the design should say so.</p>

<h2 id="getting-flags-to-the-browser">Getting flags to the browser</h2>

<p>For a React app, a context provider holding a flag snapshot works well. The snapshot should be delivered in one of two ways:</p>

<ul>
  <li><strong>Embedded in the initial HTML</strong> (for example on <code class="language-plaintext highlighter-rouge">window.__FLAGS__</code>) when server-rendering, so the first paint is already correct and nothing flickers.</li>
  <li><strong>Streamed via Server-Sent Events</strong> for live updates. Flag changes are one-directional, server to client, so SSE is a better fit than WebSockets: it reconnects automatically and works through ordinary HTTP infrastructure.</li>
</ul>

<p>Bulk evaluation matters here. Have the server expose an <code class="language-plaintext highlighter-rouge">evaluateAll(user)</code> that returns every flag’s value for that user in one call, rather than the client asking flag by flag.</p>

<h2 id="failure-behavior">Failure behavior</h2>

<p>Decide in advance what a flag returns when the flag service is unreachable, and encode it as each flag’s compiled-in default, not as a global “fail open” or “fail closed.” A kill switch for a risky feature should default to <em>off</em>. A flag guarding a long-shipped safety check should default to <em>on</em>. The SDK should serve the last known value if it has one, and the default if it does not.</p>

<h2 id="checklist">Checklist</h2>

<ul>
  <li>Deterministic hash over UTF-8 bytes, chosen once and never changed</li>
  <li>Flag key mixed into the hash input</li>
  <li>Kill switch, then rules, then percentage, then default</li>
  <li>Rollouts are monotonic: ramping up never removes anyone</li>
  <li>A multi-instance propagation story, stated explicitly</li>
  <li>Per-flag safe defaults for when the service is down</li>
</ul>

<p>All of the code above fits in one file, and reproducing the checks table takes a few lines of test code. Run something like it before you trust any flag system, including one you wrote.</p>]]></content><author><name>Mohinee Indurkar</name></author><category term="architecture" /><category term="feature-flags" /><category term="typescript" /><category term="backend" /><category term="frontend" /><summary type="html"><![CDATA[Percentage rollouts look trivial until users flicker between variants and your A/B metrics stop meaning anything. Deterministic hashing, salting, and evaluation order, with code you can run.]]></summary></entry><entry><title type="html">Learning Go by fanning out to many APIs at once</title><link href="https://mohinee.github.io/2026/learning-go-concurrent-fanout/" rel="alternate" type="text/html" title="Learning Go by fanning out to many APIs at once" /><published>2026-07-14T00:00:00+00:00</published><updated>2026-07-14T00:00:00+00:00</updated><id>https://mohinee.github.io/2026/learning-go-concurrent-fanout</id><content type="html" xml:base="https://mohinee.github.io/2026/learning-go-concurrent-fanout/"><![CDATA[<p>If you already write TypeScript, C# or Java, you can learn Go’s syntax in an afternoon. Unlearning your habits takes longer. Go has no exceptions, no <code class="language-plaintext highlighter-rouge">async/await</code>, and no inheritance. It has small structural interfaces, errors as ordinary values, and goroutines.</p>

<p>The quickest way I’ve found to learn all of that is a small project that needs every one of them. I picked a CLI that sends one prompt to several LLM provider APIs at once, waits for whoever answers, and reports the successes and the failures separately. It’s about 100 lines, and most of them involve a choice you’d make differently in another language.</p>

<h2 id="the-shape-of-the-problem">The shape of the problem</h2>

<p>Fan-out with partial failure shows up constantly in real systems. Anything that queries multiple backends (search shards, price feeds, model providers) has the same three requirements:</p>

<ol>
  <li>Run all calls concurrently, so total latency is roughly the slowest call, not the sum.</li>
  <li>Bound the whole operation with one deadline.</li>
  <li>One provider failing must not discard the answers that succeeded.</li>
</ol>

<h2 id="decision-1-put-the-error-inside-the-response">Decision 1: Put the error inside the response</h2>

<p>Coming from exception-based languages, my first instinct was two channels, one for results and one for errors. That makes aggregation awkward, because you now have to <code class="language-plaintext highlighter-rouge">select</code> across both and keep counts in sync.</p>

<p>The idiomatic move is to make the failure part of the data:</p>

<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">type</span> <span class="n">Response</span> <span class="k">struct</span> <span class="p">{</span>
	<span class="n">Provider</span> <span class="kt">string</span>
	<span class="n">Text</span>     <span class="kt">string</span>
	<span class="n">Latency</span>  <span class="n">time</span><span class="o">.</span><span class="n">Duration</span>
	<span class="n">Err</span>      <span class="kt">error</span>
<span class="p">}</span>

<span class="k">type</span> <span class="n">Provider</span> <span class="k">interface</span> <span class="p">{</span>
	<span class="n">Name</span><span class="p">()</span> <span class="kt">string</span>
	<span class="n">Complete</span><span class="p">(</span><span class="n">ctx</span> <span class="n">context</span><span class="o">.</span><span class="n">Context</span><span class="p">,</span> <span class="n">prompt</span> <span class="kt">string</span><span class="p">)</span> <span class="p">(</span><span class="kt">string</span><span class="p">,</span> <span class="kt">error</span><span class="p">)</span>
<span class="p">}</span>
</code></pre></div></div>

<p>One channel now carries every outcome, and the receiver reads exactly <code class="language-plaintext highlighter-rouge">len(providers)</code> values. Note that <code class="language-plaintext highlighter-rouge">Provider</code> is an interface any type can satisfy without declaring it, exactly like a TypeScript structural type. That is what makes the fake provider in the tests trivial.</p>

<h2 id="decision-2-size-the-channel-so-nobody-can-get-stuck">Decision 2: Size the channel so nobody can get stuck</h2>

<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">func</span> <span class="n">FanOut</span><span class="p">(</span><span class="n">ctx</span> <span class="n">context</span><span class="o">.</span><span class="n">Context</span><span class="p">,</span> <span class="n">providers</span> <span class="p">[]</span><span class="n">Provider</span><span class="p">,</span> <span class="n">prompt</span> <span class="kt">string</span><span class="p">)</span> <span class="p">[]</span><span class="n">Response</span> <span class="p">{</span>
	<span class="n">out</span> <span class="o">:=</span> <span class="nb">make</span><span class="p">(</span><span class="k">chan</span> <span class="n">Response</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">providers</span><span class="p">))</span> <span class="c">// buffered</span>

	<span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">p</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">providers</span> <span class="p">{</span>
		<span class="k">go</span> <span class="k">func</span><span class="p">()</span> <span class="p">{</span>
			<span class="n">start</span> <span class="o">:=</span> <span class="n">time</span><span class="o">.</span><span class="n">Now</span><span class="p">()</span>
			<span class="n">text</span><span class="p">,</span> <span class="n">err</span> <span class="o">:=</span> <span class="n">p</span><span class="o">.</span><span class="n">Complete</span><span class="p">(</span><span class="n">ctx</span><span class="p">,</span> <span class="n">prompt</span><span class="p">)</span>
			<span class="n">out</span> <span class="o">&lt;-</span> <span class="n">Response</span><span class="p">{</span><span class="n">p</span><span class="o">.</span><span class="n">Name</span><span class="p">(),</span> <span class="n">text</span><span class="p">,</span> <span class="n">time</span><span class="o">.</span><span class="n">Since</span><span class="p">(</span><span class="n">start</span><span class="p">),</span> <span class="n">err</span><span class="p">}</span>
		<span class="p">}()</span>
	<span class="p">}</span>

	<span class="n">results</span> <span class="o">:=</span> <span class="nb">make</span><span class="p">([]</span><span class="n">Response</span><span class="p">,</span> <span class="m">0</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">providers</span><span class="p">))</span>
	<span class="k">for</span> <span class="k">range</span> <span class="n">providers</span> <span class="p">{</span>
		<span class="n">results</span> <span class="o">=</span> <span class="nb">append</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="o">&lt;-</span><span class="n">out</span><span class="p">)</span>
	<span class="p">}</span>
	<span class="k">return</span> <span class="n">results</span>
<span class="p">}</span>
</code></pre></div></div>

<p>The buffer is not a performance tweak. It is what guarantees every goroutine can complete its send and exit, even if the receiver stops reading.</p>

<p>I confirmed that by breaking it on purpose. I made the channel unbuffered and had the collector return early when the context expired. After the function returned, the goroutine count went from 2 to 5 in a test. Three senders were blocked on a send that would never be received. That is a goroutine leak, and in a long-running service it is a slow memory leak with no stack trace pointing at it.</p>

<p>Two smaller things in that snippet:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">for _, p := range providers { go func() { ... p ... }() }</code> is only safe on Go 1.22 or later, where each iteration gets its own copy of the loop variable. On older versions all goroutines would see the last provider. The behavior is controlled by the <code class="language-plaintext highlighter-rouge">go</code> directive in <code class="language-plaintext highlighter-rouge">go.mod</code>, not by which compiler you have installed. If a module still says <code class="language-plaintext highlighter-rouge">go 1.21</code>, you get the old semantics.</li>
  <li><code class="language-plaintext highlighter-rouge">for range providers</code> iterates purely for the count. There is no need for an index variable.</li>
</ul>

<h2 id="decision-3-cancellation-is-cooperative-so-build-the-fake-first">Decision 3: Cancellation is cooperative, so build the fake first</h2>

<p><code class="language-plaintext highlighter-rouge">context.Context</code> does not kill anything. It is a signal, and the callee has to watch for it. A provider that ignores the context will happily run past your deadline.</p>

<p>So before touching a real HTTP client, I wrote a fake provider that honors the context the way a real one must:</p>

<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">func</span> <span class="p">(</span><span class="n">f</span> <span class="n">Fake</span><span class="p">)</span> <span class="n">Complete</span><span class="p">(</span><span class="n">ctx</span> <span class="n">context</span><span class="o">.</span><span class="n">Context</span><span class="p">,</span> <span class="n">prompt</span> <span class="kt">string</span><span class="p">)</span> <span class="p">(</span><span class="kt">string</span><span class="p">,</span> <span class="kt">error</span><span class="p">)</span> <span class="p">{</span>
	<span class="k">select</span> <span class="p">{</span>
	<span class="k">case</span> <span class="o">&lt;-</span><span class="n">time</span><span class="o">.</span><span class="n">After</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">Delay</span><span class="p">)</span><span class="o">:</span>
		<span class="k">if</span> <span class="n">f</span><span class="o">.</span><span class="n">Fail</span> <span class="p">{</span>
			<span class="k">return</span> <span class="s">""</span><span class="p">,</span> <span class="n">ErrBoom</span>
		<span class="p">}</span>
		<span class="k">return</span> <span class="n">f</span><span class="o">.</span><span class="n">ID</span> <span class="o">+</span> <span class="s">" says: "</span> <span class="o">+</span> <span class="n">prompt</span><span class="p">,</span> <span class="no">nil</span>
	<span class="k">case</span> <span class="o">&lt;-</span><span class="n">ctx</span><span class="o">.</span><span class="n">Done</span><span class="p">()</span><span class="o">:</span>
		<span class="k">return</span> <span class="s">""</span><span class="p">,</span> <span class="n">ctx</span><span class="o">.</span><span class="n">Err</span><span class="p">()</span>
	<span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p>When you later swap in real HTTP, the equivalent is <code class="language-plaintext highlighter-rouge">http.NewRequestWithContext(ctx, ...)</code>. The pattern is the same: the slow thing races the context, and the context wins.</p>

<p>I would also write the sequential version first and time it. Then the concurrent version has a baseline to beat, and you can see the difference instead of assuming it.</p>

<h2 id="decision-4-partial-failure-is-data-and-errors-should-still-compose">Decision 4: Partial failure is data, and errors should still compose</h2>

<p>After the fan-out, I split results into successes and one combined error:</p>

<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">func</span> <span class="n">Summarize</span><span class="p">(</span><span class="n">results</span> <span class="p">[]</span><span class="n">Response</span><span class="p">)</span> <span class="p">(</span><span class="n">ok</span> <span class="p">[]</span><span class="n">Response</span><span class="p">,</span> <span class="n">err</span> <span class="kt">error</span><span class="p">)</span> <span class="p">{</span>
	<span class="k">var</span> <span class="n">errs</span> <span class="p">[]</span><span class="kt">error</span>
	<span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">r</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">results</span> <span class="p">{</span>
		<span class="k">if</span> <span class="n">r</span><span class="o">.</span><span class="n">Err</span> <span class="o">!=</span> <span class="no">nil</span> <span class="p">{</span>
			<span class="n">errs</span> <span class="o">=</span> <span class="nb">append</span><span class="p">(</span><span class="n">errs</span><span class="p">,</span> <span class="n">fmt</span><span class="o">.</span><span class="n">Errorf</span><span class="p">(</span><span class="s">"%s: %w"</span><span class="p">,</span> <span class="n">r</span><span class="o">.</span><span class="n">Provider</span><span class="p">,</span> <span class="n">r</span><span class="o">.</span><span class="n">Err</span><span class="p">))</span>
			<span class="k">continue</span>
		<span class="p">}</span>
		<span class="n">ok</span> <span class="o">=</span> <span class="nb">append</span><span class="p">(</span><span class="n">ok</span><span class="p">,</span> <span class="n">r</span><span class="p">)</span>
	<span class="p">}</span>
	<span class="k">return</span> <span class="n">ok</span><span class="p">,</span> <span class="n">errors</span><span class="o">.</span><span class="n">Join</span><span class="p">(</span><span class="n">errs</span><span class="o">...</span><span class="p">)</span>
<span class="p">}</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">%w</code> wraps the cause and keeps the provider name as context. <code class="language-plaintext highlighter-rouge">errors.Join</code> (Go 1.20+) bundles them, and <code class="language-plaintext highlighter-rouge">errors.Is</code> still sees through the whole thing. That lets the CLI decide what to do with <code class="language-plaintext highlighter-rouge">errors.Is(err, context.DeadlineExceeded)</code> without string matching.</p>

<p>The test that pins this behavior uses three fakes: one fast, one that fails, one that is far slower than the deadline.</p>

<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">ctx</span><span class="p">,</span> <span class="n">cancel</span> <span class="o">:=</span> <span class="n">context</span><span class="o">.</span><span class="n">WithTimeout</span><span class="p">(</span><span class="n">context</span><span class="o">.</span><span class="n">Background</span><span class="p">(),</span> <span class="m">100</span><span class="o">*</span><span class="n">time</span><span class="o">.</span><span class="n">Millisecond</span><span class="p">)</span>
<span class="k">defer</span> <span class="n">cancel</span><span class="p">()</span>

<span class="n">results</span> <span class="o">:=</span> <span class="n">FanOut</span><span class="p">(</span><span class="n">ctx</span><span class="p">,</span> <span class="p">[]</span><span class="n">Provider</span><span class="p">{</span>
	<span class="n">Fake</span><span class="p">{</span><span class="n">ID</span><span class="o">:</span> <span class="s">"fast"</span><span class="p">,</span> <span class="n">Delay</span><span class="o">:</span> <span class="m">10</span> <span class="o">*</span> <span class="n">time</span><span class="o">.</span><span class="n">Millisecond</span><span class="p">},</span>
	<span class="n">Fake</span><span class="p">{</span><span class="n">ID</span><span class="o">:</span> <span class="s">"broken"</span><span class="p">,</span> <span class="n">Delay</span><span class="o">:</span> <span class="m">10</span> <span class="o">*</span> <span class="n">time</span><span class="o">.</span><span class="n">Millisecond</span><span class="p">,</span> <span class="n">Fail</span><span class="o">:</span> <span class="no">true</span><span class="p">},</span>
	<span class="n">Fake</span><span class="p">{</span><span class="n">ID</span><span class="o">:</span> <span class="s">"slow"</span><span class="p">,</span> <span class="n">Delay</span><span class="o">:</span> <span class="m">2</span> <span class="o">*</span> <span class="n">time</span><span class="o">.</span><span class="n">Second</span><span class="p">},</span>
<span class="p">},</span> <span class="s">"hi"</span><span class="p">)</span>

<span class="n">ok</span><span class="p">,</span> <span class="n">err</span> <span class="o">:=</span> <span class="n">Summarize</span><span class="p">(</span><span class="n">results</span><span class="p">)</span>
<span class="c">// ok has exactly one entry ("fast")</span>
<span class="c">// errors.Is(err, ErrBoom)                  == true</span>
<span class="c">// errors.Is(err, context.DeadlineExceeded) == true</span>
<span class="c">// and the whole call returned in ~100ms, not 2s</span>
</code></pre></div></div>

<p>Run it with <code class="language-plaintext highlighter-rouge">go test -race</code>. It’s one flag. The race detector does slow things down (the Go docs put it at 2–20x CPU and 5–10x memory), which is why it belongs in tests and CI rather than production builds, but it’s the best protection Go offers for this kind of code.</p>

<h2 id="what-transferred-and-what-didnt">What transferred, and what didn’t</h2>

<p>Mapping from what I already knew:</p>

<table>
  <thead>
    <tr>
      <th>Familiar idea</th>
      <th>Go’s version</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">Promise.allSettled</code> / <code class="language-plaintext highlighter-rouge">Task.WhenAll</code></td>
      <td>goroutines + a buffered channel, collected by count</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">AbortController</code> / <code class="language-plaintext highlighter-rouge">CancellationToken</code></td>
      <td><code class="language-plaintext highlighter-rouge">context.Context</code>, passed as the first argument by convention</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">try/catch</code></td>
      <td><code class="language-plaintext highlighter-rouge">if err != nil</code>, plus wrapping with <code class="language-plaintext highlighter-rouge">%w</code></td>
    </tr>
    <tr>
      <td>Structural typing (TS)</td>
      <td>Interfaces, satisfied implicitly</td>
    </tr>
  </tbody>
</table>

<p>What didn’t transfer was how I thought about lifetimes. In a language with a runtime that manages async work for you, “what happens to the losers when I stop waiting?” is rarely your problem. In Go it always is. Every goroutine you start needs a story for how it ends.</p>

<h2 id="if-you-want-to-build-it">If you want to build it</h2>

<p>A sequence that worked for me:</p>

<ol>
  <li>Interface and fake provider (with <code class="language-plaintext highlighter-rouge">select</code> on <code class="language-plaintext highlighter-rouge">ctx.Done()</code>).</li>
  <li>Sequential baseline, timed.</li>
  <li>Concurrent <code class="language-plaintext highlighter-rouge">FanOut</code> with the buffered channel.</li>
  <li><code class="language-plaintext highlighter-rouge">context.WithTimeout</code> at the top level.</li>
  <li><code class="language-plaintext highlighter-rouge">Summarize</code> with <code class="language-plaintext highlighter-rouge">errors.Join</code>.</li>
  <li>Real HTTP providers behind the same interface.</li>
  <li>Table-driven tests under <code class="language-plaintext highlighter-rouge">-race</code>, then break the buffer deliberately and watch the leak.</li>
</ol>

<p>Don’t skip step 7. Watching the leak happen is what made the rest make sense to me.</p>]]></content><author><name>Mohinee Indurkar</name></author><category term="go" /><category term="concurrency" /><category term="backend" /><category term="learning" /><category term="llm" /><summary type="html"><![CDATA[A small Go CLI that calls several LLM APIs concurrently teaches goroutines, channels, context cancellation and error handling in one sitting. Here are the design decisions that mattered.]]></summary></entry><entry><title type="html">The three-panel workspace: why UI structure is an architecture decision</title><link href="https://mohinee.github.io/2026/three-panel-workspace/" rel="alternate" type="text/html" title="The three-panel workspace: why UI structure is an architecture decision" /><published>2026-06-14T00:00:00+00:00</published><updated>2026-06-14T00:00:00+00:00</updated><id>https://mohinee.github.io/2026/three-panel-workspace</id><content type="html" xml:base="https://mohinee.github.io/2026/three-panel-workspace/"><![CDATA[<p>Most split-pane developer tools treat their panels as a layout question: how
wide each one is, how resizing works, how to theme them consistently. There’s
one application underneath, and the panes are windows onto it.</p>

<p>The Genesis workspace has three panels: chat, a Monaco code editor, and a live
preview. I designed them as three separate failure domains that happen to share
a screen, not as three views of one app.</p>

<p>That choice set the security model, the error handling, and what happens when
any one part breaks.</p>

<h2 id="the-three-panels">The three panels</h2>

<p><strong>Chat</strong> is where the user talks to the agent pipeline. They describe what they
want, and the agents reply with questions, status updates, and progress. This
is the control surface. It’s fully trusted and runs in the main Vue app.</p>

<p><strong>Code editor</strong> is a Monaco instance showing the current generated files. The
user can read and edit the code before it runs. I treat it as semi-trusted: the
content came from a model and may be wrong, but it’s only text. Nothing in the
editor executes.</p>

<p><strong>Live preview</strong> is an iframe running the generated app. It’s <strong>explicitly
untrusted</strong> and isolated accordingly.</p>

<h2 id="the-preview-sandbox">The preview sandbox</h2>

<p>The preview iframe uses <code class="language-plaintext highlighter-rouge">sandbox="allow-scripts"</code> without <code class="language-plaintext highlighter-rouge">allow-same-origin</code>.
Scripts can run, so the generated app works, but the frame gets an opaque
origin, so it can’t touch the parent page’s DOM, cookies, storage, or the
user’s session. I go through the details, and the gaps the sandbox doesn’t
cover, in <a href="/2026/building-secure-ai-app-builder/">the Genesis security post</a>.</p>

<p>What matters for this post is the result: whatever the generated code does, it
can’t reach into the chat or the editor. If it crashes, hangs, or turns out to
be malicious, the damage stays inside the preview.</p>

<h2 id="separate-failure-domains">Separate failure domains</h2>

<p>The broader principle is that each panel should be able to fail on its own.</p>

<p>If the preview crashes (an unhandled exception, an infinite loop, a blank
render), chat and the editor keep working. The user can read the error, fix the
code, and regenerate the preview without losing the conversation or the
pipeline state.</p>

<p>If the agent pipeline fails or stops responding (a timeout, a rate limit, an
instruction it can’t resolve), the editor still shows the last good output and
the user can still edit it.</p>

<p>If the editor loses state (a dropped connection, a sync failure with
Firestore), the conversation can be recovered separately, because it lives in
its own Firestore collection and isn’t derived from the editor.</p>

<p>Ships use the same idea with bulkheads: if one compartment floods, the others
stay dry. The goal is to contain failures, not only to prevent them.</p>

<h2 id="how-the-panels-communicate">How the panels communicate</h2>

<p>Separate failure domains still need to coordinate. In Genesis the panels never
hold references to each other. They communicate through defined channels.</p>

<p><strong>Chat to editor.</strong> Chat doesn’t modify the editor’s content. Pipeline output is
written to Firestore, and the editor subscribes to those documents. If a write
fails, the editor doesn’t receive a partial update. It just doesn’t change until
a write succeeds.</p>

<p><strong>Editor to preview.</strong> The editor doesn’t push into the iframe. When the user
asks for a preview, the current files are serialized, sent through a Cloud
Function that checks they’re well-formed, and rendered into the iframe. That
check means malformed output produces a clear error instead of an unpredictable
crash.</p>

<p><strong>Preview to anything.</strong> Nothing. The preview has no channel back to chat or
the editor, on purpose. It’s output only. If the user wants to change something
they see in the preview, they say so in chat.</p>

<p>Data flows chat → editor → preview and never backwards. That’s what makes the
isolation easy to reason about: for any component, you can list exactly what
it’s able to affect.</p>

<h2 id="why-monaco-and-what-it-costs">Why Monaco, and what it costs</h2>

<p>The editor is Monaco, the editor component from VS Code. I chose it for its
text model. Monaco keeps the document in its own model, separate from the DOM,
applies changes as edits to that model, and only renders the lines currently on
screen. When the pipeline streams several hundred lines into a file, Monaco
applies them incrementally instead of re-rendering the whole document. For
large files and fast streaming, that’s the difference between smooth and janky.</p>

<p>The cost is size. Monaco is several megabytes of JavaScript plus web workers
for language services, so it’s worth loading lazily. It’s worth it for Genesis because
the editor is a main surface, open for most of the session. If reading code were
occasional, something lighter like CodeMirror 6 would be the better choice.</p>

<h2 id="streaming-into-an-editor-the-user-can-also-type-in">Streaming into an editor the user can also type in</h2>

<p>The pipeline streams over Server-Sent Events, so as the Developer agent writes
code, it shows up in the editor live instead of all at once at the end.</p>

<p>That raises a question: what happens when the stream and the user edit the same
file at the same time?</p>

<p>Genesis avoids the question with a simple rule. While a pipeline run is active,
the editor is read-only and only the stream writes to it. When the run
finishes, the editor becomes editable again, and the user can edit the code or
steer the next run from chat.</p>

<p>That isn’t clever conflict resolution. It removes the conflict. When there’s no
good way to resolve a problem, sometimes the right move is to make sure it
can’t happen.</p>

<h2 id="a-typical-session">A typical session</h2>

<ol>
  <li>The user types a feature request in chat.</li>
  <li>The Planner and Architect run, and chat shows their progress.</li>
  <li>The Developer runs, and code streams into the editor, which is read-only for now.</li>
  <li>The Developer finishes, and the Tester and Reviewer run in the background.</li>
  <li>If the Reviewer approves, the editor becomes editable and the preview
refreshes with the new code.</li>
  <li>If the Reviewer blocks, chat lists the critical issues, the editor is
editable, and the user can change the code and run the pipeline again.</li>
</ol>

<p>A failure at any step stays in its panel. If the preview crashes at step 5,
the chat notification from step 6 still arrives. If chat loses its SSE
connection during step 2, the pipeline state is fine, because the agents write
to Firestore, not to the stream.</p>

<h2 id="the-principle">The principle</h2>

<p>Splitting a UI into panels is easy. Making those panels separate failure
domains, with defined channels between them, one-way data flow, and trust
levels enforced at each boundary, means treating the UI as an architecture
problem rather than a layout problem.</p>

<p>The sandbox setting on the preview is one attribute. The reason for it, that
AI-generated code is untrusted and has to be contained, shapes everything else.</p>

<p>The most important UI decisions in Genesis weren’t about fonts, colors, or
breakpoints. They were about where the trust boundaries go and what happens
when something fails.</p>]]></content><author><name>Mohinee Indurkar</name></author><category term="ai" /><category term="ux" /><category term="frontend" /><category term="architecture" /><category term="vue" /><category term="security" /><category term="design" /><summary type="html"><![CDATA[The Genesis workspace (chat, code editor, live preview) was designed as three separate failure domains with different trust levels, not three panes onto one app.]]></summary></entry></feed>