<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Purnachandra Patro on Medium]]></title>
        <description><![CDATA[Stories by Purnachandra Patro on Medium]]></description>
        <link>https://medium.com/@purnachandra?source=rss-3caf6482dda1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Mtz1M7Dh6G7U1vB5.jpg</url>
            <title>Stories by Purnachandra Patro on Medium</title>
            <link>https://medium.com/@purnachandra?source=rss-3caf6482dda1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 17:42:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@purnachandra/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Loop Engineering on a Mobile App: What My AI Agent Runs, What It Reads, What Ends It, and When It…]]></title>
            <link>https://medium.com/@purnachandra/loop-engineering-on-a-mobile-app-what-my-ai-agent-runs-what-it-reads-what-ends-it-and-when-it-c9f3ad58a20a?source=rss-3caf6482dda1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9f3ad58a20a</guid>
            <category><![CDATA[ai-engineering]]></category>
            <category><![CDATA[claude-code]]></category>
            <category><![CDATA[loop-engineering]]></category>
            <dc:creator><![CDATA[Purnachandra Patro]]></dc:creator>
            <pubDate>Tue, 15 Sep 2026 16:10:29 GMT</pubDate>
            <atom:updated>2026-09-15T16:10:29.464Z</atom:updated>
            <content:encoded><![CDATA[<h3>Loop Engineering on a Mobile App: What My AI Agent Runs, What It Reads, What Ends It, and When It Asks Me</h3><p><em>Harness engineering for mobile developers, part 5 of 5. Loop engineering means deciding those four things in advance and in writing, instead of letting the agent decide on the fly. The six loops I run, how they nest, and the check that said “done” for its whole life while catching nothing.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZuNQOy14A4IxNrrS8kwFEA.png" /></figure><p>Give an agent “make the login test pass” and nothing else, and it designs the loop itself, on the fly. One of two things happens. It retries until something, anything, goes green — including a test that now checks less. Or it reads its own log, sees no error, and declares the work done. Both are loops. Both were chosen by the model in the moment, by whatever it happened to read.</p><p><strong>Loop engineering is taking that design away from the model.</strong> You decide, in advance and in writing, what runs, what it reads to decide, what ends it, and when it must stop and ask you. An <a href="https://medium.com/@purnachandra/i-asked-claude-which-of-my-rules-it-could-break-the-answer-was-all-but-one-5fb51ce16353">earlier post</a> coined the term; this is what it looks like on a phone.</p><p>The setup, since each part stands alone: I build a voice-messaging app for Android and iOS, mostly by directing Claude Code. The agent works in its own git worktree (a separate checkout, one per session), builds the app, installs it on an emulator, drives the UI through Maestro (a YAML test runner that reads the screen’s accessibility tree — the labelled controls the OS exposes), and commits. None of the loops below depend on my app; they depend on having an agent that can act and then look.</p><h3>A loop is four answers</h3><p>Parts 1–4 were about the harness — the tools, files, devices and rules that decide what the agent can see and do. This part is about what the agent does with them over time.</p><p>The smallest loop in this series: tap a button, read the accessibility tree, check that the expected label appeared; if it hasn’t, wait and read again; give up and go red after ten seconds. Every loop in an agent setup, from that one up to “is this feature done,” has to answer four questions:</p><ol><li><strong>What runs?</strong></li><li><strong>What does it read to decide?</strong></li><li><strong>What ends it?</strong></li><li><strong>When does it stop and ask a human?</strong></li></ol><p>If you can’t answer all four, you don’t have a loop. You have a script that runs once and hopes. Answer them for every loop your agent runs, and you have done loop engineering. That is the whole discipline; the rest of this post is examples.</p><p>Here is loop 3 — sign-in — with the four answers marked on the real helper. Every state-dependent test flow starts with it:</p><pre>- launchApp:<br>    stopApp: true                    # 1. what runs: a cold launch, every time<br>- retry:<br>    maxRetries: 3                    # 3. what ends it: Home on screen, or three tries<br>    commands:<br>      - runFlow:<br>          when:<br>            visible:<br>              text: &quot;Continue&quot;       # 2. what it reads: the Login screen&#39;s button<br>          file: login.yaml           #    -&gt; sign in only if it&#39;s showing<br>      - runFlow: assert-home.yaml    #    -&gt; then prove Home is on screen<br># 4. when it asks a human: never. A fourth failure is red, and red is the answer.</pre><p>The retry exists for a physical reason: right after a cold start, the splash screen hides both Login and Home for about three seconds, so the first pass may see neither. Three tries is the bound. “Retry until Home appears” would hang forever on a broken build; a bound of three absorbs a slow boot and still lets a real failure go red.</p><h3>The six loops my agent runs</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OrwUDQySF9z_ZovbNgDUVQ.png" /><figcaption><em>The six loops, and the four answers each one gives.</em></figcaption></figure><p>They’re ordered from smallest to largest, and they nest: loop 1 runs dozens of times inside every test, every test runs inside a two-device run, every run inside a commit’s checks, every commit inside a slice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dOlsELx-kBdNlXAuvRHuIg.png" /><figcaption><em>Loops inside loops. The innermost one is the one to build first; everything outside it assumes it works.</em></figcaption></figure><p>Loops 1, 3 and 6 each got their own part (linked at the end). The other three:</p><p><strong>Loop 2 is a bounded retry.</strong> The first cold build in a fresh worktree can fail inside the Kotlin compiler on cold caches. The rule, one line in the agent’s memory file: retry once before blaming the change under test. The bound matters. “Retry until green” would hide a real break; “retry once” turns a known flake into a non-event and a second failure into a real signal.</p><p><strong>Loop 4 is the pre-commit hook</strong>, and with no CI in this repo it’s the only loop that runs automatically on every change. It’s fail-closed — if gitleaks, the secret scanner, isn&#39;t installed, there is no commit — and it runs the gates&#39; own tests before the gates, because a gate that can&#39;t find its inputs prints OK. Trimmed:</p><pre>#!/bin/sh<br>set -u<br>if ! command -v gitleaks &gt;/dev/null 2&gt;&amp;1; then<br>    echo &quot;pre-commit: gitleaks not found — refusing to commit without a secret scan.&quot; &gt;&amp;2<br>    exit 1<br>fi<br>gitleaks git --pre-commit --staged --redact --no-banner || exit 1</pre><pre># The gates&#39; own tests run first: a discovery bug produces no answer,<br># after which every gate iterates an empty list and prints OK.<br>python3 ./scripts/test_gates.py &gt;/dev/null 2&gt;&amp;1 || exit 1</pre><pre>for gate in check_string_parity audit_hardcoded_strings; do<br>    [ -x &quot;./scripts/$gate.sh&quot; ] &amp;&amp; { &quot;./scripts/$gate.sh&quot; || exit 1; }<br>done</pre><p><strong>Loop 5 is the outer loop per unit of work.</strong> A slice is one small, shippable piece of a feature. Every slice goes through four steps: <em>propose</em> (write the change record — what, why, and the acceptance criteria), <em>apply</em> (implement it), <em>verify</em> (check the implementation against that record), <em>archive</em> (sync the specs and close it). Verify is its own step with its own output — not a sentence at the end of the implementation saying “tests pass.” The agent that wrote the code is not the only thing that says it works. The human checkpoints are written down in a table — which decisions the agent makes alone, which it must ask about — and the rule behind the table is one sentence: “if reversing costs more than ~1 day of rework, ask first.” An agent that skips a step must stop, say why, and get approval.</p><p>What feeds back between loops, across sessions, is the agent’s memory: a folder of short notes that Claude Code re-reads at the start of every session — 52 of them today, each a rule like loop 2’s. Without it, the next session re-runs the same diagnosis, because the agent has no memory of the last one.</p><h3>When the check lies, the loop ends early</h3><p>Every one of those loops ends when a check says “done.” A check that can say done while catching nothing breaks the loop without any sign. Five times in this repo:</p><p><strong>The gate could not fail.</strong> My localization gate — a script that blocks a commit when it finds English text hardcoded in the UI instead of coming from the string catalogue — had a filter called filter_animation_labels. It was meant to drop only the hits that looked like animation labels. It tested window ~ tagbuilder inside awk, and awk was never passed a tagbuilder. An unset awk variable is &quot;&quot;, and window ~ &quot;&quot; matches everything. So the filter dropped every hit it ever found, not just the animation ones. The gate had never fired in its life.</p><p>It hid 49 hardcoded strings across 14 files of the app’s emergency feature, including an English contentDescription on the SOS button while the translated string sat unused. Every real localization defect in that feature was found by screenshotting the app on a device. None was found by a gate. That gate was the end condition of loop 4: for the two days it existed, every commit passed through it, and it caught nothing.</p><p><strong>The gate ran nowhere.</strong> “The build SHALL fail” was in the specs and wired to nothing — there’s no CI. And the first version of the hook did exec gitleaks, which replaces the shell, so anything after it could never have run.</p><p><strong>The hook fired on everything.</strong> Claude Code hooks can be limited to specific commands with an if: pattern. One meant to run only after gh pr create had the pattern Bash(gh pr create *) — one word too specific. Patterns longer than a bare command name fail open on $(), $VAR, and heredocs. Fix: if: Bash(gh *), with the script itself filtering the command from stdin.</p><p><strong>The suite passed while testing nothing.</strong> The iOS test flows failed on their first tap for three weeks; nothing went red, because nothing ran them. The step that was supposed to hold the SOS button reported COMPLETED and did nothing, and a single SOS “passes identically on fixed and on broken code.”</p><p><strong>The check was true of the wrong thing.</strong> Three green runs were against an APK another session had installed. My spec validator passed 182 of 182 specs while one of them described a screen gone for months. A PATCH returned 200 against a backend that hadn&#39;t received the migration and silently dropped the field.</p><h3>The rule: a green check is not evidence until it has been seen to fail</h3><p>Before trusting any check, reintroduce the exact defect it exists to catch and confirm it goes red; remove it and confirm green — in the same session you wrote it. My docs-audit script was built this way: “flipping a status, adding a dangling link and stripping a delta each go red.” Its design note is the principle in one line: <em>“a check that cannot fail is decoration.”</em> And it carries no baseline file: suppressing 292 known findings to land green “reads as coverage.”</p><h3>How to set up your first loop</h3><p>Start with the four answers, written down before any code — as a comment at the top of the flow, script, or rule. If one is missing, you’ll find out now instead of in a run that silently passes.</p><p>Then build the smallest one, the tap loop. It needs two things: labelled controls (contentDescription or testTag on Android, accessibilityLabel on iOS), and a rule the agent follows every time it touches the screen. Mine lives in the repo&#39;s instruction file — the file Claude Code reads at the start of every session — and reads, in essence:</p><pre>Driving the emulator:<br>- Before every tap: `adb shell uiautomator dump`, and find the label you intend to tap.<br>- Tap the centre of that node&#39;s bounds. Never reuse a coordinate from an earlier dump.<br>- After the tap: dump again and confirm the expected label appeared. Poll up to 10 s,<br>  then stop and report red — do not guess a second tap.<br>- If the app won&#39;t launch: `pm dump &lt;pkg&gt; | grep enabled=` before suspecting the build.</pre><p>That is a loop the agent runs, written as four sentences. The four answers: what runs (dump, tap, dump), what it reads (the tree), what ends it (the label, or 10 s), when it asks a human (never — red is the answer).</p><p>Then, before trusting whatever check ends it, break it on purpose: rename the label and confirm the loop goes red. If it stays green, it isn’t reading anything.</p><h3>Set them up in this order</h3><ol><li><strong>Tap loop</strong> — the rule above, in your agent’s instruction file. Everything else assumes the agent can act and then see.</li><li><strong>Pre-commit, fail-closed</strong> — a hook script committed in the repo, installed into .git/hooks by a short setup script so every checkout runs the committed version. No scanner, no commit.</li><li><strong>Mutation-test each gate the day you write it</strong> — defect in, red; defect out, green. Do it in the same session, or it won’t happen.</li><li><strong>A bounded retry per known flake</strong> — cold Gradle build, simulator boot, splash screen — as one line in the agent’s memory or instruction file: “retry once, then blame the change.”</li><li><strong>A verify step separate from implementation</strong>, with its own written output — a checklist against the change record, not a sentence saying “tests pass.”</li><li><strong>A one-sentence human checkpoint</strong> in the instruction file. Mine: “if reversing costs more than ~1 day of rework, ask first.”</li></ol><p>That is the whole setup, across five parts: a worktree that builds, an account that signs in, a screen the agent can read, a device that’s yours for the run, and loops that end on checks you have watched fail.</p><p><em>The app is </em><a href="https://www.yarina.ai/"><em>Yarina</em></a><em> — voice messages, handled by an agent. Android and iOS.</em></p><p><em>The series: </em><a href="https://medium.com/@purnachandra/a-fresh-claude-code-worktree-cant-build-your-mobile-app-four-sessionstart-hooks-fix-that-955569b83e0a"><em>Part 1 — the fresh worktree</em></a><em> · </em><a href="https://medium.com/@purnachandra/how-my-ai-agent-signs-in-on-the-emulator-firebase-test-phone-numbers-not-a-test-bypass-a27c9af6e19e"><em>Part 2 — sign-in without a bypass</em></a><em> · </em><a href="https://medium.com/@purnachandra/how-my-ai-agent-drives-the-app-on-an-emulator-tap-by-accessibility-label-never-by-coordinates-0d02c4e0ea2d"><em>Part 3 — tap by label</em></a><em> · </em><a href="https://medium.com/@purnachandra/two-claude-code-sessions-one-emulator-a-postgres-device-lease-registry-so-parallel-agents-dont-85b936810979"><em>Part 4 — device leases</em></a><em>. Start with part 1’s fresh-worktree audit; every loop above runs inside that worktree.</em></p><p><em>Series: Harness engineering for mobile developers — part 5 of 5.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9f3ad58a20a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Two Claude Code Sessions, One Emulator: A Postgres Device-Lease Registry So Parallel Agents Don’t…]]></title>
            <link>https://medium.com/@purnachandra/two-claude-code-sessions-one-emulator-a-postgres-device-lease-registry-so-parallel-agents-dont-85b936810979?source=rss-3caf6482dda1------2</link>
            <guid isPermaLink="false">https://medium.com/p/85b936810979</guid>
            <category><![CDATA[ai-mobile-app-development]]></category>
            <category><![CDATA[harness-engineering]]></category>
            <category><![CDATA[loop-engineering]]></category>
            <category><![CDATA[ai-engineering]]></category>
            <category><![CDATA[claude]]></category>
            <dc:creator><![CDATA[Purnachandra Patro]]></dc:creator>
            <pubDate>Sun, 13 Sep 2026 14:46:25 GMT</pubDate>
            <atom:updated>2026-09-13T14:46:25.099Z</atom:updated>
            <content:encoded><![CDATA[<h3>Two Claude Code Sessions, One Emulator: A Postgres Device-Lease Registry So Parallel Agents Don’t Fight Over Devices</h3><p><em>Harness engineering for mobile developers, part 4: </em><em>pkill -f maestro killed the emulator, because the AVD was named </em><em>maestro_e2e. Three silent collisions in one session. The fix is one Postgres table, a 243-line bash file, and three lines in each test runner.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3iPz0utWC-ALotKKnPxfxQ.png" /></figure><p>From the commit that added the registry:</p><blockquote><em>Nine worktrees exist and sessions run concurrently, but every runner assumed it was alone. Three collisions in one session, all silent:</em></blockquote><ul><li>pkill -f &quot;maestro&quot; also killed the Android emulator — the AVD is named maestro_e2e and matched the pattern.</li><li>Simulators were booted, erased and deleted with no way to know whether another session was mid-run.</li><li>Two sessions on one device fail in a way that looks like a product bug. That is the expensive part: the symptom never points at the cause.</li></ul><p>Today the repo has eleven worktrees. Each Claude Code session runs in its own; several run at once; and they share two Android emulators, a real Galaxy Z Fold over Samsung’s Remote Test Lab, and two iOS simulators. Nothing coordinated them.</p><h3>The design: one table, and the primary key is the lock</h3><p>The registry is a single Postgres table in its own database, yarina_devtools — deliberately not a schema inside the app&#39;s database, because &quot;it should never show up in app migrations, dumps or backups, and dropping it should never be frightening.&quot;</p><pre>CREATE TABLE IF NOT EXISTS device_lease (<br>  device_id   text PRIMARY KEY,<br>  platform    text NOT NULL CHECK (platform IN (&#39;ios&#39;, &#39;android&#39;)),<br>  worktree    text NOT NULL,<br>  session_id  text NOT NULL,<br>  holder_pid  integer NOT NULL,<br>  purpose     text NOT NULL DEFAULT &#39;&#39;,<br>  acquired_at timestamptz NOT NULL DEFAULT now(),<br>  expires_at  timestamptz NOT NULL<br>);</pre><p>The primary key is the whole atomicity story. Claiming a device is one statement — INSERT … ON CONFLICT (device_id) DO UPDATE … WHERE the existing row belongs to this same session or has expired, RETURNING session_id. Postgres serializes concurrent claimants on the key, so exactly one of N racers wins. A history table with an active flag would move &quot;is this device free?&quot; into a query, and that is precisely where a race between two claimants would live.</p><p>Every runner does the same three lines before touching a device:</p><pre>source &quot;$REPO_ROOT/e2e/scripts/device-lease.sh&quot;<br>trap &#39;lease_release_all&#39; EXIT INT TERM<br>lease_claim &quot;$DEVICE&quot; android &quot;android $SUITE&quot; || exit 1</pre><p>A refused claim names the holder — worktree, session, purpose, age — and prints the command to clear it. Liveness comes from kill -0 on the holder&#39;s PID: Postgres can&#39;t know whether a process is alive, but this is machine-local, so the caller can. A 4-hour TTL is the backstop for a recycled PID. The table creates itself on the first claim; bootstrapping it at session start was tried and reverted, because most sessions never touch a device.</p><h3>Three bugs the tests caught — and real use never would have</h3><p><strong>psql prints the command tag.</strong> A refused claim returns zero rows — that <em>is</em> the refusal — and without -q, psql printed INSERT 0 0 on stdout. The empty-output check saw text, so every contention test read as success. Caught by the contention test; invisible in use.</p><p><strong>Reading liveness before claiming is a race.</strong> The first version read the incumbent’s PID in one query and passed the answer into the insert. Eight racing claimants all read “no incumbent,” all decided the device was free, and all eight won. Now the claim is conservative first — never steal from a live holder — and only on refusal does it inspect the incumbent and compare-and-swap-delete on (holder_pid, acquired_at) before one retry. One of eight.</p><p><strong>A CLI claim that records its own PID is dead the instant it exits.</strong> Manual claims record holder_pid 0: no owning process, TTL governs.</p><p>And one from the runner: exec maestro … replaces the shell process, so the EXIT trap never runs and the lease outlives the run. Call maestro as an ordinary command instead. The trap matters because &quot;a lease released only on the happy path strands the device on exactly the runs that go wrong, which is when you are most likely to immediately re-run.&quot;</p><h3>Fail closed, and say what isn’t covered</h3><p>If Postgres is unreachable, the runner refuses and names the cause. “Degrading silently to a no-op is worse than having no registry at all, because the operator believes they are protected while they are not.” YARINA_DEVICES_OPTIONAL=1 is the documented way to proceed unguarded.</p><p>A bare maestro test --device X bypasses leases entirely. A wrapper shim around maestro/simctl/adb was considered and rejected — intrusive, and bypassed the moment anything calls the real binary. The runners are the boundary, and the rule is written in CLAUDE.md, the one file every session reads.</p><h3>Leases don’t make a green run true</h3><p>Two more checks the shared-device world forced:</p><p><strong>Hash the build before believing a result.</strong> Three green runs turned out to be against an APK a concurrent session had installed. The re-run that replaced them checked the on-device APK’s hash (pm path, then shasum) against the local build before and after, and that is now the written rule for any shared device. A passing flow says nothing about code that is not on the device.</p><p><strong>Check the machine’s load.</strong> Runs that passed at load ~8 failed at ~20 with retry timeouts, on unchanged code. Two simulators plus an Android emulator took the load average to 94 and crashed SpringBoard 16 times; the iOS runner now refuses above a load limit. Raising emulator RAM pushed swap to 93% and the OS killed the emulator mid-run — which reads, again, as a flaky suite.</p><h3>Do this in your repo</h3><ol><li><strong>One table, primary key = device id.</strong> Claim in one INSERT … ON CONFLICT … WHERE … RETURNING.</li><li><strong>Release from a trap on </strong><strong>EXIT INT TERM.</strong> No exec in the runner.</li><li><strong>Refuse when the store is down.</strong> Provide one explicit escape hatch.</li><li><strong>Test contention with N racers</strong> before trusting it. Check for empty output, and use psql -q.</li><li><strong>Hash the on-device APK and check </strong><strong>uptime</strong> before believing a green run on a shared machine.</li><li><strong>Write the rule where every session reads it.</strong> A registry nobody knows about is bypassed by default.</li></ol><h3>Takeaways</h3><ul><li><strong>Parallel agents need a lock on physical devices.</strong> Two sessions on one emulator produce failures that look like product bugs.</li><li><strong>Put the lock in the primary key.</strong> One atomic statement; no read-then-write.</li><li><strong>A green contention test can be lying.</strong> INSERT 0 0 read as success until a test checked.</li><li><strong>Fail closed and name the holder.</strong> Silent no-op is worse than no registry.</li><li><strong>The lease isn’t the last check.</strong> Hash the build, watch the load, then trust the run.</li></ul><p><em>The app is </em><a href="https://www.yarina.ai/"><em>Yarina</em></a><em> — voice messages, handled by an agent. Android and iOS.</em></p><p><em>Previously: </em><a href="https://medium.com/@purnachandra/a-fresh-claude-code-worktree-cant-build-your-mobile-app-four-sessionstart-hooks-fix-that-955569b83e0a"><em>Part 1</em></a><em> · </em><a href="https://medium.com/@purnachandra/how-my-ai-agent-signs-in-on-the-emulator-firebase-test-phone-numbers-not-a-test-bypass-a27c9af6e19e"><em>Part 2</em></a><em> · </em><a href="https://medium.com/@purnachandra/how-my-ai-agent-drives-the-app-on-an-emulator-tap-by-accessibility-label-never-by-coordinates-0d02c4e0ea2d"><em>Part 3</em></a><em>.</em></p><p><em>Next, and last: the pre-commit gate that never fired — how to prove a check can fail before you trust it, and the five-rung verification ladder for a mobile app.</em></p><p><em>Series: Harness engineering for mobile developers — part 4 of 5.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85b936810979" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Monday Follows Sunday: The Weekday Order Is a Fossil of the Number 24]]></title>
            <link>https://medium.com/@purnachandra/why-monday-follows-sunday-the-weekday-order-is-a-fossil-of-the-number-24-4c2f32d2d468?source=rss-3caf6482dda1------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c2f32d2d468</guid>
            <category><![CDATA[history]]></category>
            <category><![CDATA[sacred-geometry]]></category>
            <category><![CDATA[horoscopes]]></category>
            <category><![CDATA[planetary-science]]></category>
            <category><![CDATA[astrology]]></category>
            <dc:creator><![CDATA[Purnachandra Patro]]></dc:creator>
            <pubDate>Sun, 13 Sep 2026 08:03:44 GMT</pubDate>
            <atom:updated>2026-09-13T08:03:44.210Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Sun, Moon, Mars, Mercury, Jupiter, Venus, Saturn. That sequence isn’t brightness, distance, or speed — it’s the remainder left over when you divide 24 by 7.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*szFeVnYrIAvcekVDMV1ZcQ.png" /></figure><p>The days of the week are in a strange order and almost nobody notices. Sunday, Monday, Tuesday: the Sun, the Moon, Mars. Nothing about the sky puts those three in that sequence. Ask why the Moon follows the Sun and most people reach for “tradition.”</p><p>It isn’t tradition. It’s a division with a remainder of 3, and you can run the whole derivation in your head in about thirty seconds.</p><h3>Seven bodies, ranked by speed</h3><p>The classical world tracked seven moving objects in the sky: Saturn, Jupiter, Mars, the Sun, Venus, Mercury, the Moon. Rank them by apparent motion against the fixed stars, slowest first, and you get that same list. Saturn creeps round in about 29 years; the Moon laps the sky in about 27 days. This is an observational ranking, not a theoretical one — no model of the solar system required, just patience and good records.</p><p>This is the Chaldean order. Note what it is not: it looks nothing like the week — Sunday does not follow Saturday here. Nothing in this list predicts your calendar.</p><h3>The engine: one hour at a time</h3><p>Now assign each <em>hour</em> a ruling planet, cycling down that list and starting over at the bottom — the scheme the ancient sources call <em>planetary hours</em>. One detail carries everything: <strong>the cycle never resets.</strong> It runs straight through midnight, indifferent to where days begin.</p><p>A day is 24 hours. There are 7 planets. And 24 = (3 × 7) + 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EDzjebQqg18WIibzSYCD0Q.png" /></figure><p>Sunday’s first hour belongs to the Sun. Twenty-one hours later — three complete laps of seven — you are back at the Sun with three hours still to spend: Sun, Venus, Mercury. So the twenty-fifth hour, the first hour of the next day, lands on the Moon.</p><p>Monday. Somvar. Lundi. Every one of those names is making the same claim.</p><p>That is the entire mechanism. Each day’s opening ruler sits three seats further along the list, because 24 mod 7 = 3.</p><h3>Why the cycle hits all seven</h3><p>Step by 3 repeatedly around a ring of 7 and you touch all seven positions before repeating. That is not luck — it’s because 3 and 7 share no factors. Stepping by <em>s</em> around <em>n</em> positions produces a cycle of length n / gcd(s, n), and since 7 is prime, any step that isn&#39;t a multiple of 7 sweeps the whole set.</p><p>Start at the Sun and add 3 each time:</p><pre>Sun → Moon → Mars → Mercury → Jupiter → Venus → Saturn → (Sun)</pre><p>That’s the week. Derived, not decreed.</p><p>The Romance languages left the planets on the surface — <em>mardi</em>, <em>mercredi</em>, <em>jeudi</em>, <em>vendredi</em> for Mars, Mercury, Jupiter, Venus. Sanskrit did too: Mangalvar, Budhvar, Guruvar, Shukravar. English went half-Norse, dropping Tiw, Woden, Thor and Frigg into those same four slots, which is why Tuesday through Friday look unrelated to anything until you know the substitution.</p><h3>The star is the same object as the week</h3><p>“Connect every third vertex of a seven-sided polygon” is the same instruction as “add 3, mod 7.” The path closes only after visiting all seven points, so it draws in one unbroken stroke — the {7/3} star polygon at the top of this article.</p><p>The star and the week are the same fact. One is drawn, one is recited.</p><h3>The fossil</h3><p>Here is the test of whether the mechanism has actually landed: ask what a <em>different</em> day would have produced.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UqnqXvZJZAv7zoqsUUXazw.png" /></figure><p>A 21-hour day gives a remainder of 0. Every day would open on the same planet — no week at all, just one name repeating forever. A 22-hour day gives a remainder of 1, and the week would simply <em>be</em> the speed order: Saturn, Jupiter, Mars, Sun, Venus, Mercury, Moon. Only the 24-hour day produces the scrambled-looking sequence we use.</p><p>So the weekday order looks arbitrary for exactly one reason: 24 leaves a remainder of 3 when divided by 7. Change the hour count and you change the week. The order on your calendar is a fossil of the Egyptian decision to cut a day into 24 parts — a number that has nothing to do with planets, preserved by accident inside a system that does.</p><h3>Check it yourself</h3><p>There’s a nice consistency test, and it needs no tools.</p><p>Since 3 × 5 = 15 ≡ 1 (mod 7), the inverse of “step 3” is “step 5” — or equivalently, step backwards by 2. So read the weekdays backwards, taking every second one:</p><pre>Saturday → Thursday → Tuesday → Sunday → Friday → Wednesday → Monday<br> Saturn     Jupiter    Mars      Sun      Venus     Mercury     Moon</pre><p>That’s the speed ranking, recovered exactly, from nothing but the names on a calendar.</p><h3>The other claim, and what survives checking</h3><p>This math usually arrives attached to a second, louder story: that India built the system, Rome adopted it, and the two calendars then stayed in perfect step for 1,500 years until the British arrived to find Sunday already sitting on Ravivar. Two separate claims are bundled there, and they hold up very differently.</p><p><strong>The synchronization is real, but it isn’t astronomy.</strong> The week is a free-running counter, decoupled from the calendar: it ignores month lengths, leap years and solar drift, and nothing about “which day is it” requires an observation. Two societies that start in phase stay in phase indefinitely, provided neither ever skips or repeats a day. That’s bookkeeping, not genius.</p><p><strong>And it nearly broke.</strong> The Gregorian reform of 1582 deleted ten calendar dates outright — 4 October was followed by 15 October. The weekday cycle was deliberately carried straight through the gap, Thursday to Friday, unbroken. The chain survived because someone chose to preserve it.</p><p><strong>The attribution is the weak link.</strong> The planetary-hour scheme is generally traced to Hellenistic Egypt and Babylonian astronomy, with transmission into India during the early centuries CE; the surviving text of the <em>Surya Siddhanta</em> is usually dated to roughly the 4th–5th century CE, by which point the planetary week was already circulating in the Roman world — there is planetary-week graffiti at Pompeii, so it was ordinary street knowledge there before the town was buried in 79 CE. Shared inheritance, faithfully preserved at both ends, is the version that survives scrutiny — and it’s the better story, because you can check it.</p><p>One more piece of fine print: the Hindu <em>vāra</em> traditionally runs sunrise to sunrise, while the Western day runs midnight to midnight. Ravivar and Sunday are the same <em>named</em> day, offset by roughly six hours. Same label, different boundaries.</p><h3>Takeaways</h3><ul><li><strong>The weekday order is a remainder.</strong> 24 mod 7 = 3, so each day’s ruling planet sits three seats along the speed-ranked list.</li><li><strong>You get seven days because 7 is prime.</strong> Stepping by 3 visits every planet before repeating, which is what makes a full week instead of a short loop.</li><li><strong>The order is an artifact of “24.”</strong> A 22-hour day would have handed us a completely different week; a 21-hour day, no week at all.</li><li><strong>The week’s survival is bookkeeping, not astronomy.</strong> A free-running counter stays in sync as long as nobody skips a day — and in 1582, somebody deliberately didn’t.</li><li><strong>Check the arithmetic, not the vibe.</strong> The math here is verifiable in a minute. The historical attribution usually bolted onto it is not, and usually doesn’t survive the check.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c2f32d2d468" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How My AI Agent Drives the App on an Emulator: Tap by Accessibility Label, Never by Coordinates]]></title>
            <link>https://medium.com/@purnachandra/how-my-ai-agent-drives-the-app-on-an-emulator-tap-by-accessibility-label-never-by-coordinates-0d02c4e0ea2d?source=rss-3caf6482dda1------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d02c4e0ea2d</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[ai-test-automation]]></category>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[test-automation]]></category>
            <category><![CDATA[maestros]]></category>
            <dc:creator><![CDATA[Purnachandra Patro]]></dc:creator>
            <pubDate>Sat, 12 Sep 2026 06:47:55 GMT</pubDate>
            <atom:updated>2026-09-12T06:47:55.580Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Harness engineering for mobile developers, part 3: a blind tap disabled the app package and opened Gmail. A blind swipe dragged the app icon onto Uninstall. The fix is a two-command loop and one labelling rule that works on Android and iOS.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*APWGtpZq6zVT_N1L0aJW8Q.png" /></figure><p>On 2026–08–18 an agent was driving my Android emulator by remembered screen coordinates. The emulator rebooted and cold-started slower than before, so the layout it had memorized no longer matched the screen. One tap landed in Gmail. Another hit an app-info control and left my app’s package <strong>disabled</strong> — pm dump showed enabled=3 — which then surfaced as &quot;No activities found to run.&quot; Several minutes went into diagnosing an app bug that was self-inflicted.</p><p>Five days later it happened again with a swipe: an input swipe meant to scroll the notification shade closed it instead, landed on the app drawer, and dragged the app icon onto Uninstall. The next four commands reported only that the app was gone. No error named the cause. Cost: a reinstall and a full re-login.</p><h3>The rule: resolve every target from the accessibility tree</h3><p>Never reuse a coordinate from an earlier screenshot, and never chain gestures. One gesture per command, and read the screen before and after each one. On Android that’s two commands:</p><pre>adb -s &lt;serial&gt; shell uiautomator dump --compressed /sdcard/ui.xml<br>adb -s &lt;serial&gt; shell cat /sdcard/ui.xml | tr &#39;&lt;&#39; &#39;\n&#39; | grep -oE &#39;content-desc=&quot;[^&quot;]*&quot;&#39;<br># then tap the centre of that node&#39;s bounds=&quot;[x1,y1][x2,y2]&quot;</pre><p>Poll for the label you expect instead of sleep 5 and hoping. If the app suddenly won&#39;t launch, run pm dump &lt;pkg&gt; | grep enabled= before suspecting the build — enabled=3 means user-disabled, and pm enable &lt;pkg&gt; fixes it.</p><p>This is what the emerging agent-driver tools (Callstack’s agent-device, Software Mansion’s Argent) do under the hood: read a tree, act on a node. The rule transfers whatever tool sits on top.</p><h3>Labels are the API — make sure they reach the tree</h3><p>Android: Compose testTags become resource-ids for UIAutomator and Maestro only if you opt in at the root:</p><pre>// MainActivity.kt (trimmed) — expose Compose testTags as resource-ids<br>Box(Modifier.semantics { testTagsAsResourceId = true }) { NavHost(...) }</pre><p>A ModalBottomSheet composes into its own window — a separate Compose root that does not inherit that flag — so the sheet needed it again on its own modifier. Its tags were invisible until then.</p><p>iOS, measured with maestro hierarchy against the running app: accessibilityIdentifier on a SwiftUI Button never reaches the tree (the SF Symbol name shows up instead); accessibilityLabel always does. So the rule is: select by identifier where it resolves uniquely, otherwise by label. The bonus: the labels are identical to Android&#39;s contentDescriptions — &quot;Record voice drop&quot; selects the same control on both platforms.</p><p>A Maestro flow is the same loop written down. This is the whole test for playing a voice message, reformatted to one line per step:</p><pre>- runFlow: ../../helpers/open-chat.yaml<br>- tapOn: { text: &quot;Play voice message&quot; }<br>- extendedWaitUntil: { visible: { text: &quot;Stop&quot; }, timeout: 10000 }<br>- tapOn: { text: &quot;Stop&quot; }<br>- extendedWaitUntil: { visible: { text: &quot;Play voice message&quot; }, timeout: 10000 }</pre><p>Read, act, read again. Currently 69 such flows on Android and 60 on iOS.</p><h3>Five traps, each found by a failed run</h3><p><strong>Maestro takes the first match, and the first match is the oldest.</strong> Tapping “Play voice message” in a chat played the oldest clip in the conversation — two seconds long, too short to observe the playing state. index: -1 selects the newest.</p><p><strong>Text matching is case-sensitive.</strong> A settings redesign restyled the row labels — “Priority Contacts” became “Priority contacts” — and broke eleven flows. They failed as “element not found,” which reads like a navigation bug. They had been red for five days. Nobody noticed because nobody ran them.</p><p><strong>A twelfth flow was missed because it navigated by hand.</strong> Eleven flows reached Settings through a shared open-settings.yaml helper; the grep that found them was keyed on that helper. The twelfth tapped its way there directly. Route every flow through shared helpers, so a renamed screen is one fix and one search.</p><p><strong>The false pass.</strong> Running the iOS suite with an Android emulator attached, Maestro picked the emulator. The iOS guards matched nothing, every step reported SKIPPED, and the run exited 0. The runner now pins the device and refuses to run unpinned.</p><p><strong>Some controls can’t be reached from accessibility at all.</strong> The SOS button is a Compose pointerInput hold gesture. To the tree it&#39;s clickable=false, long-clickable=false. Measured at the same coordinates: maestro longPressOn → COMPLETED, no session; maestro swipe with start equal to end, 3000 ms → COMPLETED, no session; adb shell input swipe X Y X Y 3000 → session created, every time. The runner does the hold over adb, with X and Y read from the button&#39;s own bounds in the tree — still no hardcoded coordinates.</p><h3>Simulating a call and a music app</h3><p>Some inputs aren’t taps. To test audio focus without hardware: adb emu gsm call &lt;number&gt; gives a transient loss (a phone call); a tone served from the host and played in Chrome at http://10.0.2.2:&lt;port&gt; gives a permanent loss (a music app — the emulator ships none); dumpsys audio | grep -A6 &quot;Audio Focus stack&quot; shows who holds focus.</p><h3>Do this in your repo</h3><ol><li><strong>Label every interactive control.</strong> contentDescription or testTag on Android, accessibilityLabel on iOS. Keep the strings identical across platforms.</li><li><strong>Enable </strong><strong>testTagsAsResourceId at the root — and in every dialog window.</strong></li><li><strong>Give the agent the loop as a rule:</strong> dump, find the label, one gesture, dump again. Never reuse coordinates.</li><li><strong>Route flows through shared navigation helpers.</strong> A renamed screen becomes one edit.</li><li><strong>Pin the device in the runner</strong> and refuse to run without it. A run that touched no device must not exit 0.</li><li><strong>When accessibility can’t reach a control, use </strong><strong>adb input</strong> with coordinates read from the tree at that moment.</li></ol><h3>Takeaways</h3><ul><li><strong>Coordinates are stale the moment the screen changes.</strong> Two blind gestures cost a disabled package and an uninstall.</li><li><strong>The accessibility tree is the agent’s API.</strong> Label controls for it, and opt in wherever a new window starts.</li><li><strong>Same labels on both platforms, one selector for both.</strong> iOS identifiers on Buttons don’t reach Maestro; labels do.</li><li><strong>A green run must prove it touched a device.</strong> SKIPPED steps and exit 0 is a false pass.</li><li><strong>Keep an escape hatch, but keep it honest.</strong> adb input for what accessibility can&#39;t drive, with coordinates from the tree.</li></ul><p><em>The app is </em><a href="https://www.yarina.ai/"><em>Yarina</em></a><em> — voice messages, handled by an agent. Android and iOS.</em></p><p><em>Previously: </em><a href="https://medium.com/@purnachandra/a-fresh-claude-code-worktree-cant-build-your-mobile-app-four-sessionstart-hooks-fix-that-955569b83e0a"><em>Part 1</em></a><em> · </em><a href="https://medium.com/@purnachandra/how-my-ai-agent-signs-in-on-the-emulator-firebase-test-phone-numbers-not-a-test-bypass-a27c9af6e19e"><em>Part 2</em></a><em>.</em></p><p><em>Next: two Claude Code sessions, one emulator — the Postgres device-lease registry that stops parallel agents from fighting over devices.</em></p><p><em>Series: Harness engineering for mobile developers — part 3 of 5.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0d02c4e0ea2d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How My AI Agent Signs In on the Emulator: Firebase Test Phone Numbers, Not a Test Bypass]]></title>
            <link>https://medium.com/@purnachandra/how-my-ai-agent-signs-in-on-the-emulator-firebase-test-phone-numbers-not-a-test-bypass-a27c9af6e19e?source=rss-3caf6482dda1------2</link>
            <guid isPermaLink="false">https://medium.com/p/a27c9af6e19e</guid>
            <category><![CDATA[claude-code]]></category>
            <category><![CDATA[emulator]]></category>
            <category><![CDATA[e2e-testing]]></category>
            <category><![CDATA[maestros]]></category>
            <dc:creator><![CDATA[Purnachandra Patro]]></dc:creator>
            <pubDate>Fri, 11 Sep 2026 11:40:52 GMT</pubDate>
            <atom:updated>2026-09-11T11:40:52.753Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Harness engineering for mobile developers, part 2: agents kept reporting “can’t verify this on a device — there’s no test login.” The fix: a Firebase console setting, a 73-line Maestro flow, one paragraph in CLAUDE.md.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*atHOFiF4dZATKSOzW3-lnw.png" /></figure><p>The top of my repo’s CLAUDE.md now contains this: <strong>&quot;Signing in on an emulator is already solved — never conclude a change &#39;can&#39;t be verified on a device&#39;. There is deliberately no test-OTP bypass.&quot;</strong></p><p>That paragraph exists because agents kept hitting the Login screen, finding no test-login path, and reporting the change as unverifiable. (OTP: the one-time code the app sends by SMS at sign-in.) They were right about the facts. The app has no test auth path, the backend has none — every login verifies a real Firebase ID token — and there is no seed script. All three were rejected on purpose: a bypass is a second authentication path shipped in production code, and it’s the one your tests would exercise instead of the real one.</p><p>They were wrong about the conclusion. Signing in works — it just needs nothing in the app.</p><h3>The mechanism: a property of the account, not the app</h3><p>Firebase Phone Auth has a console setting for exactly this: Authentication → Sign-in method → Phone → “Phone numbers for testing.” You register a fictional number and a fixed verification code. Firebase’s own docs: “When you provide the fictional phone number and send the verification code, no actual SMS is sent. Instead, you need to provide the previously configured verification code to complete the sign in.” You can add up to 10 per project, and Firebase’s own advice is to pick ones that are hard to guess and change them often.</p><p>Everything else is real: a real user on the real backend, the production OTP screen. Only the SMS step is skipped. My iOS test README puts it in one line: <em>“a property of the account, not a bypass in the app.”</em> The iOS suite signs in the same way through its own flow; the only difference is phone format — E.164 there, ten national digits here, because the Android app pins the country code.</p><h3>The login flow</h3><p>The credentials live in a gitignored e2e/android/.env (MAESTRO_PHONE, MAESTRO_OTP, and the recipient pair), symlinked into every worktree by the SessionStart hook from part 1. This is helpers/login.yaml, trimmed:</p><pre>appId: ${MAESTRO_APP_ID}<br>---<br>- extendedWaitUntil: { visible: { text: &quot;Continue&quot; }, timeout: 30000 }<br>- tapOn: { text: &quot;98765 43210&quot; }        # phone field placeholder<br>- inputText: ${MAESTRO_PHONE}<br>- scrollUntilVisible: { element: { text: &quot;Continue&quot; }, direction: DOWN }<br>- tapOn: { text: &quot;Continue&quot; }<br># OTP screen. Gate on the field label, not the Verify button.<br>- extendedWaitUntil: { visible: { text: &quot;6-DIGIT CODE&quot; }, timeout: 45000 }<br>- inputText: ${MAESTRO_OTP}<br>- scrollUntilVisible: { element: { text: &quot;Verify&quot; }, direction: DOWN }<br>- tapOn: { text: &quot;Verify&quot; }<br>- extendedWaitUntil: { notVisible: { text: &quot;Verify&quot; }, timeout: 45000 }<br>- runFlow: assert-home.yaml</pre><p>A wrapper, ensure-logged-in.yaml, makes it safe to run at the start of any flow: launch the app, then retry up to three times — run login.yaml only if &quot;Continue&quot; is visible, then assert Home. The retry exists because right after a cold start the splash screen hides both Login and Home for about three seconds.</p><p>Three lines in that flow are each a failed run:</p><ul><li><strong>scrollUntilVisible before every tap.</strong> Both auth screens use imePadding to keep the button above the keyboard. That holds on a Pixel; on a Galaxy S25+ (One UI 7) the keyboard has an extra toolbar row and pushes &quot;Continue&quot; and &quot;Verify&quot; off-screen — &quot;Element not found.&quot; On the Pixel the scroll is a harmless no-op.</li><li><strong>Gate on “6-DIGIT CODE”, not “Verify”.</strong> The button the keyboard hides cannot be the signal that the screen arrived.</li><li><strong>No </strong><strong>hideKeyboard.</strong> Its fallback is BACK, which exits the screen if the keyboard already closed.</li></ul><h3>Secrets stay out of ps</h3><p>The runner does set -a &amp;&amp; source e2e/android/.env &amp;&amp; set +a. Maestro reads shell variables prefixed MAESTRO_, so the flow&#39;s ${MAESTRO_OTP} resolves without the code appearing on a command line — maestro test -e OTP=… would put it in shell history and ps output. One trap, measured against Maestro 2.8.0: an env: block in the workspace config.yaml is silently ignored. It looks accepted and never resolves.</p><h3>Which account is this device on?</h3><p>The two-device suite needs a sender and a recipient, because an account cannot message itself. Whether it went green or red depended on “which account each device happened to be left on by the last person to log in by hand.” Both devices had been running the sender’s login helper. Signing in only helps a device that’s signed <em>out</em>: a device on the wrong account sails through ensure-logged-in untouched, because &quot;Continue&quot; never appears.</p><p>The fix: the helper reads the phone number off the Settings profile card and, if it’s the wrong account, signs out and back in. It compares phone numbers, not display names. One more catch: that screen shows “User / No phone” when the device is offline, because the identity block only fills in on a successful fetch. “No phone” means a failed request, not an account.</p><h3>The caveat: emulator green doesn’t cover store auth</h3><p>Firebase picks its app-verification path by install source: sideloaded builds use a reCAPTCHA fallback, Play Store installs require the Play Integrity API. With Play Integrity disabled on the project, every Play Store user got ERROR_APP_NOT_AUTHORIZED while my own sideloaded handset worked. No emulator run catches that.</p><h3>Do this in your repo</h3><ol><li><strong>Register test numbers in the Firebase console.</strong> Pick ones that are hard to guess (Firebase allows 10). Sign each up once by hand so it’s a real account. Make two.</li><li><strong>Put phone and code in a gitignored </strong><strong>.env</strong>, linked into every worktree (part 1).</li><li><strong>Write one idempotent login flow.</strong> Gate on labels that survive every keyboard; scroll, don’t dismiss; never type the code by hand.</li><li><strong>Pin each device to an account by phone number</strong>, not by “Home is visible.”</li><li><strong>Write the paragraph where the agent trips.</strong> Mine is in CLAUDE.md: sign-in is solved, here&#39;s the flow.</li></ol><h3>Takeaways</h3><ul><li><strong>Don’t add a test bypass; configure a test account.</strong> Firebase test numbers keep the production auth path intact and skip only the SMS.</li><li><strong>Credentials in a gitignored env file, read as shell variables.</strong> Command-line flags leak into ps and history.</li><li><strong>Gate flows on what the keyboard can’t hide.</strong> Samsung’s taller keyboard broke a flow that passed on every Pixel.</li><li><strong>“Logged in” isn’t enough — check which account.</strong> Two devices on one account fail in a way that looks like a broken flow.</li><li><strong>Emulator sign-in proves nothing about Play Store sign-in.</strong> Verification paths differ by install source.</li></ul><p><em>The app is </em><a href="https://www.yarina.ai/"><em>Yarina</em></a><em> — voice messages, handled by an agent. Android and iOS.</em></p><p><em>Previously: </em><a href="https://medium.com/@purnachandra/a-fresh-claude-code-worktree-cant-build-your-mobile-app-four-sessionstart-hooks-fix-that-955569b83e0a"><em>Part 1 — a fresh Claude Code worktree can’t build your mobile app</em></a><em>.</em></p><p><em>Next: letting the agent drive the app — tap by accessibility label, never by coordinates, and what happened when it didn’t.</em></p><p><em>Series: Harness engineering for mobile developers — part 2 of 5.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a27c9af6e19e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Fresh Claude Code Worktree Can’t Build Your Mobile App. Four SessionStart Hooks Fix That.]]></title>
            <link>https://medium.com/@purnachandra/a-fresh-claude-code-worktree-cant-build-your-mobile-app-four-sessionstart-hooks-fix-that-955569b83e0a?source=rss-3caf6482dda1------2</link>
            <guid isPermaLink="false">https://medium.com/p/955569b83e0a</guid>
            <category><![CDATA[claude-code]]></category>
            <category><![CDATA[git-hooks]]></category>
            <category><![CDATA[ai-engineering]]></category>
            <category><![CDATA[claude-hooks]]></category>
            <category><![CDATA[harness-engineering]]></category>
            <dc:creator><![CDATA[Purnachandra Patro]]></dc:creator>
            <pubDate>Thu, 10 Sep 2026 13:01:06 GMT</pubDate>
            <atom:updated>2026-09-11T11:44:36.367Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Harness engineering for mobile developers, part 1: my iOS test suite was unrunnable for 20 days because one gitignored file was never linked into new worktrees. Here’s the setup that prevents it, with the real config.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EoVBDfJTcmIs77NJIcU6Tw.png" /></figure><p>A 15-line change to one setup script recently fixed my iOS end-to-end test suite. It had been unrunnable for twenty days, and no test had failed.</p><p>The suite wouldn’t run from any new git worktree. Its runner script looked for a credentials file, e2e/ios/.env.local, found nothing, and exited. The file existed — at the old path from before I split the suite into e2e/android and e2e/ios, which nothing read anymore. It had simply stopped being runnable everywhere except my main checkout.</p><p>When an agent hits this, it reports the natural diagnosis: <em>the test flow is broken.</em> The flow was fine; the worktree was missing one file. A comment in my setup script records what that misdiagnosis cost once before: “a full debugging detour.”</p><h3>What this series covers</h3><p>I build a voice-messaging app — Android, iOS, Python backend — mostly by directing Claude Code. This series is about the setup around the agent: the scripts, config, and test infrastructure that let it build, run, and verify a mobile app on its own. Five parts, one layer each, real config in every one.</p><p>Part 1 is the lowest layer: the git worktree the agent works in.</p><h3>Why a fresh worktree can’t build a mobile app</h3><p>I run every Claude Code session in its own git worktree — a second checkout of the same repo in a separate folder, on its own branch, so parallel sessions don’t collide. A worktree contains everything git tracks. It contains nothing that’s gitignored.</p><p>On a mobile project, the gitignored files are the ones the build needs. From a fresh worktree, mine failed four ways:</p><ul><li>./gradlew — &quot;SDK location not found,&quot; then &quot;google-services.json is missing.&quot; Both files are gitignored on purpose.</li><li>iOS — GoogleService-Info.plist is gitignored, and the Xcode project is generated by xcodegen, not committed.</li><li>Backend — crashes on import because the cloud config in backend/.env isn&#39;t there. The error says the app is broken, not that config is missing.</li><li>End-to-end tests — abort because the test-account credentials aren’t there.</li></ul><p>Keeping secrets out of git is correct. But it means a fresh checkout is not a working project, and every error above blames the code instead of the missing file. A developer hits this once per laptop and remembers. An agent hits it in every new worktree with no memory of the last time — and the error text tells it the code is wrong.</p><h3>The fix: four SessionStart hooks</h3><p>Claude Code has a <strong>SessionStart hook</strong>: a shell command that runs when a session opens, before the agent reads anything. Here’s the real config, trimmed from .claude/settings.json:</p><pre>{<br>  &quot;hooks&quot;: {<br>    &quot;SessionStart&quot;: [<br>      { &quot;hooks&quot;: [<br>        { &quot;command&quot;: &quot;bash setup/scripts/link-secrets.sh&quot; },<br>        { &quot;command&quot;: &quot;bash setup/scripts/ios-worktree-setup.sh&quot; },<br>        { &quot;command&quot;: &quot;bash setup/scripts/android-worktree-setup.sh&quot; },<br>        { &quot;command&quot;: &quot;bash setup/scripts/install-git-hooks.sh&quot; }<br>      ]}<br>    ]<br>  }<br>}</pre><p>Four scripts, run in order, every session:</p><ol><li><strong>link-secrets.sh</strong> — symlinks 7 gitignored files (test credentials, backend/.env, the push-notification key, infra secrets, the dev-server launch config) from the main checkout into the worktree.</li><li><strong>ios-worktree-setup.sh</strong> — copies GoogleService-Info.plist, <em>then</em> runs xcodegen. Order matters: the generated project only bundles the plist if it exists first.</li><li><strong>android-worktree-setup.sh</strong> — copies google-services.json and local.properties from the main checkout.</li><li><strong>install-git-hooks.sh</strong> — installs the pre-commit hook (part 5 covers what it checks).</li></ol><p>When the agent reads its first prompt, the worktree builds.</p><h3>Three rules the scripts follow</h3><p><strong>Check before acting.</strong> Every step tests whether the file already exists before copying or linking. The hook runs every session, so it must be safe to run repeatedly.</p><p><strong>One missing file can’t stop the rest.</strong> The script runs under set -e, so any failed command aborts it — right for real errors, but known-harmless cases need guarding first. .claude/ is gitignored, so a fresh worktree doesn&#39;t have that folder; without a mkdir -p before the link, ln fails, the hook aborts, and nothing after that point gets linked.</p><p><strong>Symlink shared files, copy per-machine files.</strong> Test credentials are symlinked from one canonical copy, so updating them once updates every worktree. local.properties and signing config are copied, because they&#39;re per-checkout.</p><p>The same three rules apply to Cursor, Windsurf, or a script you run by hand. A SessionStart hook is just whatever your tool runs first.</p><h3>Some environment failures look like code bugs</h3><p>The first Gradle build in a brand-new worktree once failed with a StackOverflowError inside KSP (Kotlin Symbol Processing), on cold caches. It looked like the change under test had broken the build. An identical retry passed, and it didn&#39;t recur in the next four builds.</p><p>The fix was one line in the agent’s persistent memory file: <em>first cold build in a fresh worktree can fail inside KSP — retry once before blaming the change.</em> Without it, every future session that hits the flake diagnoses a bug that doesn’t exist.</p><h3>Do this in your repo</h3><ol><li><strong>Find the gaps.</strong> Create a fresh worktree (git worktree add -b scratch ../scratch), try to build and test every platform, and record each failure&#39;s exact error text.</li><li><strong>Write one script per gap.</strong> Check first, act only if needed, and never let one missing file abort the rest.</li><li><strong>Register the scripts as SessionStart hooks</strong> in .claude/settings.json, not as a README step. A step a human has to remember is a step the agent skips.</li><li><strong>Record environment flakes</strong> in the agent’s memory file, not just your head.</li></ol><h3>Takeaways</h3><ul><li><strong>Set up the worktree before the agent starts.</strong> A session that begins in a broken checkout starts by diagnosing the wrong problem.</li><li><strong>On mobile, the files the build needs are the gitignored ones.</strong> Signing config, Firebase files, SDK paths, test credentials.</li><li><strong>Automate setup in a hook, not a README.</strong> A hook runs whether or not anyone remembers the instructions.</li><li><strong>Check first, act second, and isolate failures.</strong> One missing file should never stop the other six from linking.</li><li><strong>Write down flakes that look like bugs.</strong> A recorded flake costs one retry; an unrecorded one costs every future session.</li></ul><p><em>The app is </em><a href="https://www.yarina.ai/"><em>Yarina</em></a><em> — voice messages, handled by an agent. Android and iOS.</em></p><p><em>Background: </em><a href="https://medium.com/@purnachandra/i-wrote-85-000-lines-of-markdown-so-ai-agents-could-write-my-app-365756948264"><em>I Wrote 85,000 Lines of Markdown So AI Agents Could Write My App</em></a><em> and</em><a href="https://medium.com/@purnachandra/i-asked-claude-which-of-my-rules-it-could-break-the-answer-was-all-but-one-5fb51ce16353?sharedUserId=purnachandra"><em> I Asked Claude Which of My Rules It Could Break</em></a><em>.</em></p><p><em>Next: </em><a href="https://medium.com/@purnachandra/how-my-ai-agent-signs-in-on-the-emulator-firebase-test-phone-numbers-not-a-test-bypass-a27c9af6e19e?sharedUserId=purnachandra"><em>signing in on an emulator with no test-OTP bypass — the Firebase test-number setup and the Maestro login flow that make it work.</em></a></p><p><em>Series: Harness engineering for mobile developers — part 1 of 5.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=955569b83e0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Tried to Make My Coding Rules Impossible to Break. Most of Them Weren’t Rules.]]></title>
            <link>https://medium.com/@purnachandra/i-tried-to-make-my-coding-rules-impossible-to-break-most-of-them-werent-rules-55177ba3d0b9?source=rss-3caf6482dda1------2</link>
            <guid isPermaLink="false">https://medium.com/p/55177ba3d0b9</guid>
            <category><![CDATA[solo-devs]]></category>
            <category><![CDATA[ai-sdlc]]></category>
            <category><![CDATA[claude]]></category>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[harness-engineering]]></category>
            <dc:creator><![CDATA[Purnachandra Patro]]></dc:creator>
            <pubDate>Thu, 27 Aug 2026 14:26:25 GMT</pubDate>
            <atom:updated>2026-08-27T14:26:25.215Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Three earned a lock. The rest had no failing case — which is how I found out they were never rules, only things I liked saying.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iA9Cyog60giG13E39Ka6GA.png" /></figure><p>Last post I asked my AI agent which of its own rules it could break with nothing stopping it. The answer was: all of them but one. This is what happened when I went to build the missing locks — and found that most of what I’d called rules couldn’t be locked, because there was nothing there to lock.</p><p>In 1877 Charles Sanders Peirce wrote that a belief isn’t a feeling you hold about a proposition; it’s a habit that decides how you act — “the establishment of a habit,” carried into the next situation. William James put the blade in: the meaning of a conviction is its cash-value in conduct. A belief that changes nothing you do is not a belief.</p><p>My CLAUDE.md has swollen into a small book of rules, most written in the grammar of rules. When I went to give each one a <em>mechanism</em> — the thing that makes it a habit the environment carries, not a mood I&#39;m in — most had no conduct to attach to. I found out which rules I believed by trying to make them impossible to break.</p><h3>The test that sorts a rule from a wish</h3><p>Post 2 was about metrics that forbid no observation — Popper’s point that a claim earns standing only by ruling something out. A rule is the same animal. “No vehicles in the park” names a state the world can be caught in; “drive reasonably” needs a judge. Last post’s image was Odysseus lashed to the mast; what I learned is that the rope only reaches the rules that name their own shipwreck.</p><p>So the test, applied to every line I wanted to enforce: <strong>can I write the failing case?</strong> Can I name one arrangement of files this rule says must not exist? If yes, it can become a control. If the only violation I can describe is “this is bad,” it was never a rule — it was a direction I face.</p><h3>Three that became controls</h3><p>The easy one: a credential in a staged commit is a failing case you can state in a sentence and a machine finds in a second, and the harm — a key exposed the instant it’s pushed, unrecoverable — is total. It earns the strongest control I own: a pre-commit hook that blocks the commit and won’t even run if the scanner is missing. It <strong>fails closed</strong> — a missing scanner isn’t a pass, it’s a stop.</p><pre># the secret-scan hook, in essence — a missing scanner is a stop, not a pass<br>command -v gitleaks &gt;/dev/null || { echo &quot;no scanner&quot;; exit 1; }<br>gitleaks git --staged --redact || exit 1</pre><p>The second guards a failure the agents invented for me. Sessions run in throwaway git worktrees; a subagent reports back an absolute path into the <em>main</em> checkout, an edit lands there, and the change is on the wrong branch. The failing case is exact — a write inside the main repo but outside this worktree — so a hook denies it before it lands and returns the corrected path.</p><p>The third is three rules at once: a slice’s status must match the index that lists it, a link must resolve, a shipped slice must record which requirements it touched. Each compares two things that both exist in the repo and must agree — so a violation isn’t an opinion, it’s a contradiction, and a human can see which half is wrong.</p><pre># a slice&#39;s status must match the index that lists it<br>if frontmatter_status != index_status:<br>    flag(readme, f&quot;says {frontmatter_status}, index says {index_status}&quot;)</pre><p>My checker found <strong>291</strong> of them, most being shipped slices whose only pointer was an archive path that won’t survive the next worktree. This repo has already lost two such records that way.</p><p>At 291 findings the temptation is a baseline: forgive today’s failures, gate only new ones, land green tomorrow. I’ll quote the line I’d written into my own backlog, because it’s the whole discipline of a gate: <em>a gate that ships green over known-bad strings is worse than no gate, because it reads as coverage.</em> So there’s no baseline — and no hard block either. A stale doc isn’t a leaked key, and half of each fix is a human deciding which side was right. It can’t stop me; it just drops every contradiction into the session when I open a pull request, so I can’t proceed <em>not knowing.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UMc_mUq7On28y7WW9Y9mYA.png" /><figcaption>Where each control fires in the agent’s loop: DENY at the write, BLOCK at the commit, REPORT at the pull request. Solid boxes stop you; the outline only keeps you from proceeding unaware.</figcaption></figure><p><em>The three controls, placed at the moment each one fires — deny before an edit lands, block at commit time (fail closed), report at the pull request. Solid means it stops you; the outline only makes sure you can’t proceed unaware.</em></p><h3>Two I believe, and left unlocked</h3><p>Not everything that <em>could</em> be a control <em>should</em> be. I could refuse any commit that strips a line from an append-only journal — post 1’s rule — but the false positives would tax every honest commit to catch a violation that almost never comes; a control has a price, and the innocent pay it. And verify, my proudest loop step, I can&#39;t lock at all: nothing outside can read whether the agent that <em>reports</em> running it actually did. Belief isn&#39;t what&#39;s missing there — a reading is.</p><h3>The ones that were never rules</h3><p>The remainder is most of them. “Keep the slice READMEs thin.” “Write every task for a stranger.” “Is this document any good?” I couldn’t write the failing case for any of them. A thin <em>bad</em> README passes a line count; a long <em>good</em> one fails it. “Good” and “for a stranger” name no state the repo can be caught in. These aren’t rules I neglected to enforce — they’re values wearing the grammar of rules, and the enforcement exercise is what undressed them.</p><p>The sharpest instance is one word. Post 2 was built around making things <em>honest</em>; I noted then it appeared in 83 of my documentation files. I recounted for this one: a hundred and twenty now — the fastest-growing word in the repo, and the least enforceable thing I own. No diff will ever read as <em>dishonest.</em> The word I reach for most is the one I could never make a rule.</p><h3>What I can’t tell you</h3><p>Whether the unlocked values are working anyway. A direction with no control still points; the agents mostly keep the READMEs thin and write for the stranger, and <em>mostly</em> carries weight I can’t measure. Nor should the fix be more controls — a repo where every sentence blocks a commit is one where nothing ships, and most of governance is judgment you’d be a fool to hand to a grep. The goal was never to lock everything, but to stop mistaking the sentences I can’t lock for the ones I can.</p><h3>Takeaways</h3><ul><li><strong>A rule you can’t write a failing case for is a value, not a rule.</strong> Name the exact state the repo must never be in; if you can’t, you’re holding a direction, and directions don’t get gates.</li><li><strong>You learn what you believe by trying to enforce it.</strong> The rules that survive contact with a mechanism are the ones you actually hold; the rest were things you liked saying.</li><li><strong>Match the control to the harm.</strong> A leaked key fails the commit closed; a self-contradicting doc reports and lets you pass; a value only points.</li><li><strong>A gate with a baseline is a warning again.</strong> Forgiving today’s known-bad so the check lands green turns coverage into theatre.</li><li><strong>Some believed rules should stay unenforced.</strong> A control taxes every innocent pass to catch a rare guilty one; when the base rate is low, the warning is the right engineering, not the lazy one.</li></ul><p><em>The app is </em><a href="https://www.yarina.ai/"><em>Yarina</em></a><em> — voice messages, handled by an agent. Android and iOS.</em></p><p><em>Previously: </em><a href="https://medium.com/@purnachandra/i-wrote-85-000-lines-of-markdown-so-ai-agents-could-write-my-app-365756948264"><em>I Wrote 85,000 Lines of Markdown So AI Agents Could Write My App</em></a><em>, </em><a href="https://medium.com/@purnachandra/i-shipped-an-unfalsifiable-hypothesis-and-called-it-telemetry-39b7e1e15ccf"><em>I Shipped an Unfalsifiable Hypothesis and Called It Telemetry</em></a><em>, and </em><a href="https://medium.com/@purnachandra/i-asked-claude-which-of-my-rules-it-could-break-365756948264"><em>I Asked Claude Which of My Rules It Could Break</em></a><em>.</em></p><p><em>Next: the finale — the one job in an agent-built repo that never became a mechanism, because it’s mine.</em></p><p><em>Series: Building a voice app solo with AI agents — post 4 of 5.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55177ba3d0b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LLM Latency Isn’t One Number. It’s a Floor and a Slope.]]></title>
            <link>https://medium.com/@purnachandra/llm-latency-isnt-one-number-it-s-a-floor-and-a-slope-183fe682b1c8?source=rss-3caf6482dda1------2</link>
            <guid isPermaLink="false">https://medium.com/p/183fe682b1c8</guid>
            <category><![CDATA[gemini]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[latency]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Purnachandra Patro]]></dc:creator>
            <pubDate>Wed, 12 Aug 2026 14:59:49 GMT</pubDate>
            <atom:updated>2026-08-12T14:59:49.015Z</atom:updated>
            <content:encoded><![CDATA[<p><em>A follow-up to a 5-part series on building a production text-to-SQL agent — </em><a href="https://medium.com/@purnachandra/text-to-sql-over-133-tables-why-we-let-the-agent-discover-the-schema-371e9fbe96ca"><em>discovery-first schema design</em></a><em>, </em><a href="https://medium.com/@purnachandra/stop-making-your-llm-write-sql-it-already-knows-e67d7630f160"><em>turning prompt recipes into tools</em></a><em>, </em><a href="https://medium.com/@purnachandra/crewai-your-task-prompt-is-the-most-expensive-text-in-your-system-fb5e9ee850fd"><em>the caching economics</em></a><em>, </em><a href="https://medium.com/@purnachandra/your-llm-judge-will-fail-correct-answers-gate-on-proof-instead-9ed17e1ae5e9"><em>the eval harness</em></a><em>, and </em><a href="https://medium.com/@purnachandra/week-5-the-finale-of-a-5-part-series-on-building-a-production-text-to-sql-agent-c1ee3ac72b56"><em>the model race</em></a><em>. That last one ended on a loose thread: the most expensive model was also the slowest. This is what happened when I pulled it.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*74DidayL3dzjOeEqycAKIw.jpeg" /></figure><p>Our agent takes about 27 seconds to answer a question. I spent a day working out why, and my first two guesses were both wrong.</p><p>That’s the useful part of this post. Not the fix — the fix is boring. The useful part is that “it’s slow” is not a diagnosis, and the number everyone quotes (seconds per request) is the one number that can’t tell you what to do next.</p><h3>What we’re looking at</h3><p>The agent answers questions about restaurant inventory by writing SQL against a live database. A question comes in, the model picks tools, the tools run queries, the model writes the answer. Fifteen recent production turns looked like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E5_IQGCvVnUmf0KpvM1MIQ.png" /><figcaption><em>Figure 1 — each dot is one production turn. Half finish under 27s; the slowest takes 61.</em></figcaption></figure><p>This is a chat box. Twenty-seven seconds is long enough to switch tabs, and a minute is long enough to assume it’s broken and hit send again. Nobody had to file a bug for me to hear about it.</p><h3>Wrong guess #1: it’s the database</h3><p>This was the obvious one. We query a real inventory database over a VPN, and some of those tables are large. Surely that’s the drag.</p><p>I pulled the trace for the worst turn, the 61-second one, and added up the spans:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3eV0CqofmY199fUufc1EXw.png" /><figcaption><em>Figure 2 — the worst production turn, 61.3s total, 9 LLM calls and 7 tool calls.</em></figcaption></figure><p>The database was never the problem. The slowest SQL query in that turn was 1.2 seconds. Every tool call together came to 3.2 seconds out of 61.</p><p>It’s a strange feeling, finding out the component you blamed is a rounding error. But it narrows things: if 94% of the clock is the model, that’s where to look.</p><h3>Wrong guess #2: it’s the framework</h3><p>Second theory. We run the agent on CrewAI, and frameworks add overhead. I’d read enough complaints about that to believe it.</p><p>So I did some arithmetic: a bare API call from my laptop, minus what the server traces showed, left roughly 750 milliseconds per call unaccounted for. Across nine calls that’s nearly seven seconds. I wrote it down as a finding.</p><p>It was wrong, and embarrassingly so. I’d subtracted two measurements taken on different machines, and one of them was a cold start.</p><p>When I measured it properly, same machine and same process, three turns in a row with the framework’s own tracing switched on, the answer was this:</p><pre>turn 1    16,547ms total    16,483ms LLM    64ms everything else<br>turn 2    11,295ms total    11,233ms LLM    62ms everything else</pre><p>Sixty-two milliseconds. Not seven seconds. The framework was doing nothing wrong at all.</p><p>I’m including this because it’s the part I’d normally quietly delete, and because the mistake is an easy one to repeat: <strong>I compared two numbers that weren’t measured under the same conditions, and the gap between them felt like a discovery.</strong> It wasn’t. It was noise wearing a lab coat.</p><h3>The thing I should have measured first</h3><p>Between those two measurements, 94% of a production turn and 99% of a local one, the model is basically the whole clock. So: <em>which part of the model call?</em></p><p>Here’s the trap. A normal, non-streaming call gives you one number, total time, and that number is the sum of two unrelated things:</p><ul><li><strong>Floor</strong> — the wait before the <em>first</em> answer token. That’s the prompt being processed, plus the model’s entire “thinking” block, which happens before it writes anything you can see.</li><li><strong>Slope</strong> — how fast tokens arrive once it starts writing.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2vRM9h9Y61HrFeKDuAN5UQ.png" /></figure><p>Different causes, different fixes. If your floor is bad, shorter answers won’t help. If your slope is bad, a shorter prompt won’t help.</p><p>And you can’t see either one without streaming. That’s why this was hard to find: every dashboard we had reported the sum.</p><p>So I wrote a benchmark that streams, timestamps the moment the first real answer token lands, and reports the two separately. Three Gemini Flash models, four thinking levels each, on a 16,000-token prompt shaped like ours.</p><h3>The two numbers</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yfzhCS3hHrKFuujJcVrJPw.png" /><figcaption><em>Figure 3 — extra wait each thinking level adds versus minimal thinking (the 0 baseline). 16k-token prompt, streamed, median of three runs.</em></figcaption></figure><p>We were running 3.5 Flash at medium. Look at what that costs: <strong>11.6 seconds before the first character appears.</strong> The same model, same prompt, with thinking turned down to minimal, starts answering in 2.2 seconds.</p><p>One honest caveat before anyone quotes these at me: three runs each, one region, one prompt, one afternoon. The absolute numbers are ours, not yours. What transfers is which lever moves which number.</p><h3>Three things I didn’t expect</h3><p><strong>Thinking is a floor cost, and it’s free on slope.</strong> Minimal to medium moved our floor from 2.2s to 11.6s, more than five times. The slope went <em>up</em>, 140 to 257 tokens per second. Thinking is paid entirely up front, in silence, before the user sees a character.</p><p><strong>“medium” and “high” aren’t in order.</strong> On both Flash models, high produced <em>fewer</em> thinking tokens than medium and came back sooner. I&#39;d assumed the levels were a ladder. They&#39;re a hint. With three runs the two overlap on the older model, so call it indistinguishable rather than inverted — but it held on the newer one.</p><p><strong>Defaults are not consistent between models.</strong> Flash-Lite at low returned exactly zero thinking tokens — identical to minimal. Two models, same word, different behaviour.</p><h3>Where our seconds were actually going</h3><p>With the two numbers separated, our own traces stopped being mysterious.</p><p>Here are three short conversational questions put through the real agent. No tools, no database, nothing to look up:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3d7tMXt3wdKiNYXXDRm2RA.png" /><figcaption><em>Figure 4 — three conversational turns, no tool calls, time for the planner call.</em></figcaption></figure><p>Same class of question. A 2x swing in response time, driven entirely by how much the model decided to think. That variance <em>is</em> our p95 problem. It was never queue depth or database load.</p><p>And the single most annoying number I found: <strong>804 thinking tokens spent on the words “and what else?”</strong> Three words, no tools, nothing to look up. The model deliberated for eight hundred tokens over a follow-up question, because medium is the default and nobody had ever told it otherwise.</p><p>One companion finding stung a little. A while back we did serious work on <a href="https://medium.com/@purnachandra/crewai-your-task-prompt-is-the-most-expensive-text-in-your-system-fb5e9ee850fd">prompt caching</a> and got 98% of our input tokens served from cache, cutting cost per turn dramatically. Good work, and I’d do it again. But it barely moved latency, because caching attacks prefill, and prefill was never the expensive part of our floor. Thinking was.</p><p>Which is the lesson underneath all of this: <strong>we optimized the part we could see.</strong></p><h3>What we’ve changed so far</h3><p>Honestly? Not much yet, and deliberately.</p><p>The direction is clear. Turn the second model call down to minimal — it&#39;s a formatter reshaping an answer another model already wrote, so it has nothing to reason about — then benchmark the newer model, which had a lower floor at every level and costs less per output token. On paper that&#39;s around 13 seconds off a two-call turn, and I&#39;d treat 13 as an upper bound until it&#39;s confirmed end to end.</p><p>But none of it ships until the <a href="https://medium.com/@purnachandra/your-llm-judge-will-fail-correct-answers-gate-on-proof-instead-9ed17e1ae5e9">eval suite</a> is green. A latency change that quietly breaks an answer is worse than a slow answer.</p><h3>Takeaways</h3><ul><li><strong>“Seconds per request” is not a diagnosis.</strong> It’s the sum of two numbers with different causes and different fixes. Report it if you must, but never act on it.</li><li><strong>You need streaming to see the split.</strong> Not to ship streaming to users, necessarily — just to measure. A non-streaming call structurally cannot tell you where the time went.</li><li><strong>Thinking level is the biggest latency dial most people never touch.</strong> It moved our floor 5x. It’s one config value, and on most stacks it’s set to a default nobody chose.</li><li><strong>Measure both numbers on the same machine, in the same process, warm.</strong> My 750ms “finding” was a laptop measurement minus a server measurement, with a cold start hiding inside one of them.</li><li><strong>Optimizing what you can see is the default failure.</strong> We had beautiful cost dashboards and no latency decomposition, so we spent our effort where the graphs were.</li></ul><p><strong>The full benchmark.</strong> Floor in seconds, slope in output tokens per second, medians of three runs.</p><pre>model                     level      floor    slope    thinking<br>                                       (s)    (t/s)      tokens<br>-------------------------------------------------------------<br>Gemini 3.5 Flash          minimal      2.2      140           0<br>                          low          7.6      228         922<br>                          medium      11.6      257       1,470<br>                          high        10.1      203       1,048<br><br>Gemini 3.6 Flash          minimal      1.2      160           0<br>                          low          5.0      186         718<br>                          medium       8.0      248       1,184<br>                          high         5.8      176         804<br><br>Gemini 3.5 Flash-Lite     minimal      0.9      216           0<br>                          low          0.9      219           0<br>                          medium       4.3      485       1,097<br>                          high         5.0      504       1,216</pre><p>The benchmark that produced that table is under 300 lines of Python. We’d been having the “why is this thing so slow” conversation for a while before anyone bothered to write it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=183fe682b1c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Asked Claude Which of My Rules It Could Break. The Answer Was: All but One.]]></title>
            <link>https://medium.com/@purnachandra/i-asked-claude-which-of-my-rules-it-could-break-the-answer-was-all-but-one-5fb51ce16353?source=rss-3caf6482dda1------2</link>
            <guid isPermaLink="false">https://medium.com/p/5fb51ce16353</guid>
            <category><![CDATA[claude]]></category>
            <category><![CDATA[loop-engineering]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[ai-agent]]></category>
            <category><![CDATA[harness-engineering]]></category>
            <dc:creator><![CDATA[Purnachandra Patro]]></dc:creator>
            <pubDate>Tue, 11 Aug 2026 10:11:44 GMT</pubDate>
            <atom:updated>2026-08-11T10:11:44.930Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w3eogyH-W9cH-B-Dr1rJ6w.jpeg" /></figure><p><em>176 specs, 86 changes, one git hook — and the two skills that replaced prompt engineering.</em></p><p>Last week I asked an AI agent to audit the apparatus I had built to govern it. One question: <strong>which of these rules can you break with nothing stopping you?</strong></p><p>It answered honestly. All of them but one.</p><p>Behind it: five months building a voice app with agents. 176 specifications. 86 completed changes. 24 append-only journals. 33 memory files. A four-step workflow no agent may skip.</p><p>Jon Elster built a career on the distinction I had missed: deciding something, versus making it impossible to un-decide. Odysseus does not resolve to ignore the Sirens; he knows exactly what that resolution is worth once he can hear them. He has himself lashed to the mast and orders the crew to refuse his own future commands. Elster’s word is <strong>precommitment</strong>: not willpower, but destroying the option to change your mind.</p><p>I had written the resolution version of everything.</p><h3>Two words worth having</h3><p>There’s a ladder here. The top two rungs don’t have common names yet.</p><p><em>Prompt engineering</em> asks what you say this turn. <em>Context engineering</em> asks what’s in the window. Above those:</p><p><strong>Harness engineering</strong> is the apparatus around the model — which tools exist and how they’re described, what the environment looks like when the agent wakes up, what feedback it can obtain, and what it’s structurally prevented from doing.</p><p><strong>Loop engineering</strong> is the control flow over time — how many passes, what feeds back between them, where verification sits relative to generation, which iterations run silently and which halt for a human, and what ends the loop.</p><p>The test that separates them: harness asks <em>what can this agent see and do at any given moment</em>; loop asks <em>how many moments are there, in what order, and what ends them</em>. Harness is the instrument. Loop is how you play it.</p><p>Both outrank prompt wording the moment a task outgrows one context window.</p><h3>What mine looks like</h3><p>Harness: four setup hooks that run before the agent’s first token — credentials linked, worktree prepared, and the one gate below installed. Sixteen numbered environment gotchas, so failures aren’t rediscovered each session. Seventeen skills, twelve slash commands, and a routing rule atop CLAUDE.md naming which directory to read first.</p><p>Loop: a fixed cycle of propose, apply, <strong>verify</strong>, archive — where verification is a separate pass, not a self-check inside implementation. A design workflow whose audit phase is non-skippable and repeats until its five tests pass. An eleven-row table of what an agent decides alone versus what stops for me, indexed on reversibility. (<a href="https://medium.com/@purnachandra/i-wrote-85-000-lines-of-markdown-so-ai-agents-could-write-my-app-365756948264">Post 1</a> covers how that grew.)</p><p>It reads like a governed system. Then you count what enforces it.</p><h3>Warnings and controls</h3><p>Shigeo Shingo, formalising mistake-proofing inside the Toyota Production System, separated two grades. A <strong>warning</strong> poka-yoke tells you that you have erred. A <strong>control</strong> poka-yoke makes the error physically impossible — the part will not seat the wrong way round, the machine will not start. Warnings need an operator who’s paying attention; the defect class exists because sometimes nobody is.</p><p>My repo: 176 specs, 86 changes, 17 skills, 34 end-to-end test flows.</p><p>Zero CI workflows. One installed git hook — fourteen lines of shell.</p><p>That hook is a secret scan that blocks any commit containing a credential, and refuses to run if the scanner is missing. It’s the only control in the building. Everything else is a warning addressed to a reader with no memory and unlimited confidence.</p><p>Look what that does to my proudest step. verify is a stage an agent <strong>reports having performed</strong>; nothing compares the report to reality. An agent that runs it and one that skips it and says otherwise produce identical artifacts — same summary, same archived change. That&#39;s the failure <a href="https://medium.com/@purnachandra/i-shipped-an-unfalsifiable-hypothesis-and-called-it-telemetry-39b7e1e15ccf">post 2</a> was about, moved from telemetry into process: a state that looks correct from inside, passes every check written from inside, and is wrong only from a vantage point nobody occupies.</p><p>The escalation ladder is short:</p><pre>prose in CLAUDE.md      the agent may comply<br>a skill or command      the agent complies when it remembers<br>a SessionStart hook     already done before the agent wakes<br>a pre-commit hook       the agent cannot proceed</pre><p>Post 1 ended on: <em>longer prompts fix one session, files fix every session.</em> True, and not far enough. <strong>A file is still a request. A hook is not.</strong></p><h3>How to ask for this in your own repo</h3><p>Three asks that produce mechanisms, not more prose.</p><p><strong>Ask for evidence, not best practices.</strong> “Read my last ten sessions and every journal entry. What did you re-derive that one line in a file could have told you?” A harness built from your own repeated failures beats any template.</p><p><strong>Name the layer.</strong> Agents default to prose because prose is what they emit. “Put this in a SessionStart hook.” “Make this a pre-commit hook.” “Turn this into a skill.” Specifying the rung gets you the rung.</p><p><strong>Then run the audit that found this gap:</strong></p><blockquote><em>Which rules in CLAUDE.md can you violate with nothing stopping you? For each, tell me what would stop you.</em></blockquote><p>Follow with the sentence that converts a warning into a control: <strong>“Make this impossible, not discouraged.”</strong></p><h3>What I can’t tell you</h3><p>Whether the unenforced remainder is doing work anyway. Agents mostly follow the four-step loop; <em>mostly</em> is load-bearing, and I have no measurement of the tail. Nor should everything become a gate: a repo where every convention blocks a commit is a repo where nothing ships.</p><p>I also found this by asking, not by getting burned. That’s the only luck in this post.</p><h3>Takeaways</h3><ul><li><strong>Separate the harness from the loop.</strong> One governs what an agent can see and do; the other, how many passes there are. Conflating them hides which is broken.</li><li><strong>A rule is only as strong as its enforcement layer.</strong> Prose, then skill, then hook — know which rung each of yours stands on.</li><li><strong>Ask your agent which of your rules it can break.</strong> The list is longer than you think.</li><li><strong>“Make it impossible, not discouraged.”</strong> The one sentence that moves work from documentation into mechanism.</li><li><strong>Self-reported verification is not verification.</strong> If the compliant and the non-compliant run produce identical artifacts, you have a convention, not a check.</li></ul><p><em>The app is </em><a href="https://www.yarina.ai/"><em>Yarina</em></a><em> — voice messages, handled by an agent. Android and iOS.</em></p><p><em>Previously: </em><a href="https://medium.com/@purnachandra/i-wrote-85-000-lines-of-markdown-so-ai-agents-could-write-my-app-365756948264"><em>I Wrote 85,000 Lines of Markdown So AI Agents Could Write My App</em></a><em> and </em><a href="https://medium.com/@purnachandra/i-shipped-an-unfalsifiable-hypothesis-and-called-it-telemetry-39b7e1e15ccf"><em>I Shipped an Unfalsifiable Hypothesis and Called It Telemetry</em></a><em>.</em></p><p><em>Next: converting the memos into masts — and finding out which rules I never believed.</em></p><p><em>Series: Building a voice app solo with AI agents — post 3 of 5.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5fb51ce16353" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Good Tool Architecture Makes Model Choice Boring]]></title>
            <link>https://medium.com/@purnachandra/week-5-the-finale-of-a-5-part-series-on-building-a-production-text-to-sql-agent-c1ee3ac72b56?source=rss-3caf6482dda1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1ee3ac72b56</guid>
            <category><![CDATA[agentic-ai-systems]]></category>
            <category><![CDATA[db-agent]]></category>
            <category><![CDATA[redshift]]></category>
            <category><![CDATA[sql-agent]]></category>
            <category><![CDATA[crew-ai]]></category>
            <dc:creator><![CDATA[Purnachandra Patro]]></dc:creator>
            <pubDate>Fri, 07 Aug 2026 19:57:24 GMT</pubDate>
            <atom:updated>2026-08-12T13:15:49.045Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9lTndPjUCF5ANwagmEUpwQ.jpeg" /></figure><p><em>Week 5 — the finale — of a 5-part series on building a production text-to-SQL agent. Previously: discovery-first schema design, turning prompt recipes into tools, the caching economics, and the eval harness.</em></p><p>We swapped our production agent’s brain four times in one afternoon. Same tools, same prompts, same 22 questions against the same live database — the only variable was the model, and the whole experiment cost about 50 cents of agent spend.</p><p>That afternoon existed because of last week’s eval harness. “Should we switch models?” is usually a religious debate; with a gating eval it’s four runs and a table. This post is that table, the findings that matter more than it, and the reason the finale of an optimization series ends with the model barely mattering.</p><h3>The rules of the race</h3><p>Four Gemini models, each dropped into the identical agent — the discovery tools from week 1, the deterministic tools from week 2, the cached prompt from week 3 — and run through the full 22-case suite from week 4.</p><p>Two rules made the numbers comparable:</p><ul><li><strong>The judge is pinned.</strong> The advisory LLM judges ran on the same fixed model (EVAL_JUDGE_MODEL) for every contestant. A model must never grade itself — a lenient family member on the bench poisons the whole comparison.</li><li><strong>The verdicts that matter don’t pass through a judge at all.</strong> The gate — tool routing read from trace spans, execution accuracy checked by reference SQL run live — is deterministic. Whatever bias a judge might have, it can’t touch the pass/fail column.</li></ul><h3>The table</h3><p>All four are Gemini models; names shortened to fit.</p><pre>model                 gate fails   judge    avg s      cost       vs<br>                     (route/exec)  flags    /case     /case  current<br>--------------------------------------------------------------------<br>3.5-flash (current)     0 / 0        0       12.7   $0.0150       1x<br>3-flash-preview         0 / 2        1        8.9   $0.0028     -82%<br>2.5-flash               0 / 2        2        7.8   $0.0022     -85%<br>3.1-flash-lite          0 / 2        2        8.0   $0.0017     -89%</pre><p>The incumbent kept a perfect scorecard — and cost 5–9× more than everything else. The challengers were all faster, all dramatically cheaper, and all failed exactly two cases. What those failures <em>were</em> is the real story.</p><h3>Finding 1: routing was 100% on every model</h3><p>Look down the routing column: zero, zero, zero, zero. Including the budget model.</p><p>That column is the payoff of this entire series. In week 2 we moved settled SQL and branching logic out of the prompt and into deterministic tools; what’s left for the model is reading the question and pressing the right button. That remaining job is now small enough that <em>every</em> model does it perfectly — which means the thing we spent weeks engineering was never really the model. It was the size of the job we hand it.</p><p>When judgment lives in tools, the model stops being the architecture and becomes a swappable part.</p><h3>Finding 2: the challengers’ misses were over-caution, not wrong answers</h3><p>Both execution failures on the two mid-tier models were the <em>same two cases</em>, and both involved “Almond Milk” — a name that matches 4 products in our catalog. These questions travel the free-form SQL path, which does <em>not</em> carry week 2’s exact-name rule (that rule lives inside the stock tool). The premium model made the call on its own anyway — one product is named precisely what the user said, so that’s the product — and answered. The cheaper models stopped and asked the user which one they meant.</p><p>That’s a stricter reading of a guardrail, not a wrong number. Under our own hierarchy of sins for a data agent — asking is free, slow is annoying, wrong is disqualifying — it’s the failure mode we’d choose.</p><p>Before believing any of this, we re-ran the incumbent minutes later as a control: 22/22 again, ruling out database churn as the explanation (a lesson week 4 taught us the hard way).</p><h3>Finding 3: the cheapest model told us a wrong number</h3><p>The −89% model matched the mid-tier models’ over-cautious asks — and then, on the discovery cases, miscounted the barcodes table. Not “asked unnecessarily,” not “phrased it oddly”: produced the only genuinely wrong numbers of the day.</p><p>Wrong numbers are worse than slow ones. A user forgives “which Almond Milk did you mean?” and forgives a 13-second answer; a confidently wrong stock count ends trust in the whole system. The −89% price tag does not survive one invented number, so the lite tier is out regardless of everything else it did well.</p><h3>Finding 4: cheaper was also faster</h3><p>The surprise in the latency column: the expensive model is the <em>slowest</em>. It spends more thinking and output tokens per call — that’s where the extra care lives, and it’s also what you’re billed for. The challengers think less, type less, and arrive 30–40% sooner. Premium judgment isn’t free even when it’s right.</p><h3>What we actually did</h3><p>Nothing, yet — deliberately. The incumbent has the only perfect scorecard, so it keeps the job while the gap is closed <em>in code</em>: the exact-name rule that decided the Almond Milk cases already exists inside the current_stock_of_item tool, but the failing cases went down the free-form SQL path, which lacks it. Port that one rule into the SQL path&#39;s prompt, re-run the race, and the −82% challenger — the strongest of the three, with a single advisory flag against it — plausibly goes 22/22. The switch happens on a clean scorecard or not at all.</p><p>That’s the shape of the whole exercise: the eval turned a model migration from a leap of faith into a checklist. One honest caveat belongs next to it — this is 22 cases in one domain. It measures <em>our</em> system, not the models in general; your race, and your winner, will look different.</p><h3>Takeaways</h3><ul><li><strong>Shrink the model’s job until the model is swappable.</strong> After tools took over the settled decisions, four very different models routed 100% identically — the architecture, not the model, carries the system.</li><li><strong>Pin the judge, and gate on determinism.</strong> Contestants must share one fixed judge, and the pass/fail verdicts should come from checks no judge can bias.</li><li><strong>Classify failures before counting them.</strong> The mid-tier models’ misses were safe over-caution; the budget model’s were invented numbers — similar tallies, opposite verdicts. A raw pass rate would have hidden the only disqualifying result.</li><li><strong>Run a control before trusting a surprise.</strong> The incumbent’s repeat 22/22 minutes later is what separated “model regression” from “database churn.”</li><li><strong>Close capability gaps in code, then re-race.</strong> One rule ported from a tool into a prompt is plausibly the difference between paying 1× and 0.18× — cheaper than upgrading models in either direction.</li></ul><p><em>That’s the series: </em><a href="https://medium.com/@purnachandra/text-to-sql-over-133-tables-why-we-let-the-agent-discover-the-schema-371e9fbe96ca"><em>a schema the agent discovers instead of memorizes</em></a><em> → </em><a href="https://medium.com/@purnachandra/stop-making-your-llm-write-sql-it-already-knows-e67d7630f160"><em>settled SQL promoted into tools</em></a><em> → </em><a href="https://medium.com/@purnachandra/crewai-your-task-prompt-is-the-most-expensive-text-in-your-system-fb5e9ee850fd"><em>static text moved behind the cache boundary</em></a><em> → </em><a href="https://medium.com/@purnachandra/your-llm-judge-will-fail-correct-answers-gate-on-proof-instead-9ed17e1ae5e9"><em>an eval that gates on proof</em></a><em> → and, as the payoff, a system where the model is the least interesting part. Thanks for reading along.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1ee3ac72b56" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>