<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Liudas Sodonis — Principal Cloud &amp; AI Architect</title>
    <subtitle>Production AI systems, sovereign cloud blueprints, and architecture notes by Liudas Sodonis (Vancouver, Canada).</subtitle>
    <link rel="self" type="application/atom+xml" href="https://liudass-macbook-pro.tail11ead.ts.net/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://liudass-macbook-pro.tail11ead.ts.net"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-12-02T00:00:00+00:00</updated>
    <id>https://liudass-macbook-pro.tail11ead.ts.net/atom.xml</id>
    <entry xml:lang="en">
        <title>Offline GCP IAM Assistant With Local Gemma 4 and SQLite: Five Benchmarks and What Actually Broke</title>
        <published>2026-12-02T00:00:00+00:00</published>
        <updated>2026-12-02T00:00:00+00:00</updated>
        
        <author>
          <name>Liudas Sodonis</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://liudass-macbook-pro.tail11ead.ts.net/writing/offline-gcp-iam-benchmark-gemma-sqlite/"/>
        <id>https://liudass-macbook-pro.tail11ead.ts.net/writing/offline-gcp-iam-benchmark-gemma-sqlite/</id>
        
        <content type="html" xml:base="https://liudass-macbook-pro.tail11ead.ts.net/writing/offline-gcp-iam-benchmark-gemma-sqlite/">&lt;p&gt;Regulated Canadian teams keep asking whether a useful AI assistant can run completely offline with zero external API calls. To test that on a domain with zero tolerance for invented strings, I benchmarked a local 4-bit &lt;strong&gt;Gemma 4 E4B&lt;/strong&gt; model (&lt;code&gt;4.8 GB&lt;/code&gt; Metal VRAM, &lt;code&gt;5.4 GB&lt;/code&gt; RAM on an Apple M5 Pro) against &lt;strong&gt;14,435 canonical GCP IAM permissions&lt;/strong&gt; and &lt;strong&gt;2,420 predefined roles&lt;/strong&gt; stored in SQLite.&lt;/p&gt;
&lt;p&gt;Across five controlled runs on a 45-question golden set, fixing retrieval (structure-aware chunking plus dual SQLite FTS5) drove overall hard fails to &lt;strong&gt;0.00%&lt;/strong&gt; and role recall to &lt;strong&gt;93.33%&lt;/strong&gt;, while base Gemma took &lt;strong&gt;13.71s&lt;/strong&gt; median latency. A behavioral LoRA that preserved a short 1 to 2 sentence thought block cut median latency &lt;strong&gt;6.8x&lt;/strong&gt; down to &lt;strong&gt;2.02s&lt;/strong&gt; and held exact permission recall at &lt;strong&gt;90.00%&lt;/strong&gt;, at the cost of a &lt;strong&gt;4.44%&lt;/strong&gt; residual hard-fail rate.&lt;/p&gt;
&lt;h2 id=&quot;the-setup-zero-tolerance-offline-eval&quot;&gt;The Setup: Zero-Tolerance Offline Eval&lt;/h2&gt;
&lt;p&gt;Everything ran locally on an Apple M5 Pro (48 GB unified memory) with zero external API calls. The source corpus is an &lt;code&gt;8.0 GiB&lt;/code&gt; local SQLite crawl (&lt;code&gt;315,051&lt;/code&gt; URLs, &lt;code&gt;296,974&lt;/code&gt; completed), filtered to &lt;code&gt;988&lt;/code&gt; IAM pages (&lt;code&gt;42.07 MB&lt;/code&gt;) and deduplicated to &lt;code&gt;901&lt;/code&gt; unique documents in the hybrid index, including &lt;code&gt;356&lt;/code&gt; &lt;code&gt;/iam/docs/roles-permissions/*&lt;/code&gt; service pages. From those tables, a deterministic extractor built the ground-truth catalog: &lt;code&gt;14,435&lt;/code&gt; canonical permissions, &lt;code&gt;2,420&lt;/code&gt; predefined roles, and &lt;code&gt;14,274&lt;/code&gt; custom-role support entries.&lt;/p&gt;
&lt;p&gt;All five runs used the exact same model (&lt;code&gt;mlx-community/gemma-4-E4B-it-4bit&lt;/code&gt;, &lt;code&gt;temp=0.0&lt;/code&gt;, &lt;code&gt;max_tokens=1536&lt;/code&gt;), the same embedding model (&lt;code&gt;BAAI/bge-small-en-v1.5&lt;/code&gt;, &lt;code&gt;384&lt;/code&gt;-dim on MPS), &lt;code&gt;top_k = 5&lt;/code&gt;, the same &lt;code&gt;SYSTEM_PROMPT&lt;/code&gt;, and the same &lt;code&gt;45&lt;/code&gt;-question golden set (&lt;code&gt;15&lt;/code&gt; exact permission lookups, &lt;code&gt;15&lt;/code&gt; least-privilege role selections, and &lt;code&gt;15&lt;/code&gt; unanswerable/fake-entity refusal checks). A programmatic scorer verified every emitted permission, &lt;code&gt;roles/*&lt;/code&gt; ID, and citation against the ground-truth catalog.&lt;/p&gt;
&lt;pre&gt;&lt;code data-lang=&quot;text&quot;&gt;[User Question]
       │
       ├──▶ [chunks_fts_exact: per-token quoted FTS5 (tokenchars &amp;#39;._/-&amp;#39;)]
       ├──▶ [chunks_fts_text: Porter BM25 + authoritative table slice]
       └──▶ [BAAI/bge-small-en-v1.5: 384-dim cosine similarity on MPS]
                                  │
                                  ▼
                [Weighted RRF Fusion (rrf_k=60, top_k=5)]
                                  │
                                  ▼
         [Local Gemma 4 E4B 4-bit via MLX (Base or LoRA Adapter)]
                                  │
                                  ▼
       [Zero-Tolerance Scorer vs. 14,435 Permissions / 2,420 Roles]
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;five-controlled-runs-the-numbers&quot;&gt;Five Controlled Runs: The Numbers&lt;/h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Metric&lt;/th&gt;&lt;th style=&quot;text-align: right&quot;&gt;Exp A: Naive Vector&lt;/th&gt;&lt;th style=&quot;text-align: right&quot;&gt;Exp B: Hybrid v1&lt;/th&gt;&lt;th style=&quot;text-align: right&quot;&gt;Exp B2: Hybrid v2&lt;/th&gt;&lt;th style=&quot;text-align: right&quot;&gt;Exp C: LoRA (iter 100 / 200)&lt;/th&gt;&lt;th style=&quot;text-align: right&quot;&gt;Exp C2: Thought LoRA (iter 80)&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Exact Permission Recall (%)&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;78.33&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;90.00&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;90.00&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;81.67&lt;/code&gt; / &lt;code&gt;71.67&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;90.00&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Exact Permission Match (%)&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;66.67&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;76.67&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;86.67&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;66.67&lt;/code&gt; / &lt;code&gt;56.67&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;80.00&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Role Recall (%)&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;70.00&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;86.67&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;93.33&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;86.67&lt;/code&gt; / &lt;code&gt;86.67&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;86.67&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Forbidden Perm Violation (%)&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;6.67&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;6.67&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;6.67&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;0.00&lt;/code&gt; / &lt;code&gt;0.00&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;3.33&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Correct Refusal Rate (%)&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;100.0&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;100.0&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;100.0&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;93.33&lt;/code&gt; / &lt;code&gt;93.33&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;93.33&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Doc Citation Accuracy (%)&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;53.33&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;76.67&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;90.00&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;76.67&lt;/code&gt; / &lt;code&gt;63.33&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;76.67&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Overall Hard Fail Rate (%)&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;2.22&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;2.22&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;0.00&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;8.89&lt;/code&gt; / &lt;code&gt;6.67&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;4.44&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Latency P50 / P95 (s)&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;11.49 / 18.87&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;11.59 / 15.94&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;13.71 / 27.42&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;1.33 / 5.73&lt;/code&gt; | &lt;code&gt;1.22 / 2.03&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;2.02 / 8.48&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Training Time (s)&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;0&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;0&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;0&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;~315s&lt;/code&gt; / &lt;code&gt;~627s&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: right&quot;&gt;&lt;code&gt;~413s&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;Two patterns stand out immediately:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Retrieval sets the hard ceiling (&lt;code&gt;Exp A -&amp;gt; B -&amp;gt; B2&lt;/code&gt;):&lt;/strong&gt; Structure-aware chunking plus stripping repetitive &lt;code&gt;Service agent roles Warning&lt;/code&gt; boilerplate cut total chunks by &lt;strong&gt;54%&lt;/strong&gt; (&lt;code&gt;42,349 -&amp;gt; 19,480&lt;/code&gt;) and cut MPS index build time &lt;strong&gt;3.6x&lt;/strong&gt; (&lt;code&gt;362.87s -&amp;gt; 99.96s&lt;/code&gt;). Upgrading retrieval scoring alone in Experiment B2 (zero index rebuild) drove Overall Hard Fail Rate to &lt;strong&gt;0.00%&lt;/strong&gt;, Role Recall to &lt;strong&gt;93.33%&lt;/strong&gt;, and Doc Citation Accuracy to &lt;strong&gt;90.00%&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fine-tuning buys latency, not missing facts (&lt;code&gt;Exp C -&amp;gt; C2&lt;/code&gt;):&lt;/strong&gt; Experiment C (&lt;code&gt;360&lt;/code&gt; zero-leakage synthetic examples, &lt;code&gt;0.047%&lt;/code&gt; trainable params, &lt;code&gt;rank=8&lt;/code&gt;, &lt;code&gt;200&lt;/code&gt; iters) suppressed Gemma 4&#39;s spontaneous thinking completely for a &lt;strong&gt;9.5x speedup&lt;/strong&gt; (&lt;code&gt;11.59s -&amp;gt; 1.22s&lt;/code&gt; P50) and &lt;code&gt;0.00%&lt;/code&gt; forbidden violations, but caused role-vs-permission conflation and template leakage (&lt;code&gt;6.67%&lt;/code&gt; to &lt;code&gt;8.89%&lt;/code&gt; hard fail). Experiment C2 (&lt;code&gt;rank=8&lt;/code&gt;, &lt;code&gt;scale=4.0&lt;/code&gt;, &lt;code&gt;16&lt;/code&gt; layers, &lt;code&gt;80&lt;/code&gt; iters, &lt;code&gt;~413s&lt;/code&gt;) preserved a 1 to 2 sentence &lt;code&gt;&amp;lt;|channel&amp;gt;thought&lt;/code&gt; (~20 to 50 tokens), recovering &lt;strong&gt;90.00%&lt;/strong&gt; Exact Permission Recall and &lt;strong&gt;80.00%&lt;/strong&gt; Exact Match at &lt;strong&gt;2.02s&lt;/strong&gt; P50 (&lt;strong&gt;6.8x faster&lt;/strong&gt; than B2), while leaving &lt;code&gt;2/45&lt;/code&gt; (&lt;code&gt;4.44%&lt;/code&gt;) residual hard fails (&lt;code&gt;perm-04&lt;/code&gt;, &lt;code&gt;trick-11&lt;/code&gt;).&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;three-real-failure-modes-what-actually-broke&quot;&gt;Three Real Failure Modes (What Actually Broke)&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Mid-row Markdown table slicing (&lt;code&gt;role-01&lt;/code&gt;):&lt;/strong&gt; In Cloud Storage IAM docs, each predefined role and its entire permission list sit on a single Markdown table row (median &lt;code&gt;2,517&lt;/code&gt; chars, max &lt;code&gt;18,936&lt;/code&gt; chars). Experiment A&#39;s 1,200-char windows sliced right through the middle of a row, severing the role header from its permissions and causing Gemma to bind &lt;code&gt;storage.objects.get&lt;/code&gt; and &lt;code&gt;storage.objects.list&lt;/code&gt; to &lt;code&gt;roles/storage.expressModeServiceOutput&lt;/code&gt; instead of &lt;code&gt;roles/storage.objectViewer&lt;/code&gt;. Experiment B2 fixed it (&lt;code&gt;100%&lt;/code&gt; recall and match).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Duplicate REST &lt;code&gt;/delete&lt;/code&gt; pages drowning canonical roles (&lt;code&gt;perm-08&lt;/code&gt;):&lt;/strong&gt; Asked for the permission to delete a GCP project, pure dense vectors ranked &lt;code&gt;docs.cloud.google.com/iam/docs/reference/rest/v1/organizations.roles/delete&lt;/code&gt; and &lt;code&gt;cloud.google.com/iam/reference/rest/v1/organizations.roles/delete&lt;/code&gt; in Top-5 slots 1 and 2, pushing &lt;code&gt;resourcemanager.projects.delete&lt;/code&gt; out of context. Experiment B2&#39;s &lt;code&gt;content_hash&lt;/code&gt; dedup and authoritative table BM25 slice fixed it.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Service-agent mega-roles hijacking multi-permission FTS5 (&lt;code&gt;role-12&lt;/code&gt;):&lt;/strong&gt; In Experiment B, joining two exact permissions with &lt;code&gt;OR&lt;/code&gt; (&lt;code&gt;&quot;bigquery.jobs.create&quot; OR &quot;bigquery.tables.getData&quot;&lt;/code&gt;) caused giant cross-service roles that happen to hold both strings (&lt;code&gt;roles/looker.serviceAgent&lt;/code&gt;, &lt;code&gt;roles/enterpriseknowledgegraph.serviceAgent&lt;/code&gt;, &lt;code&gt;roles/dlp.projectdriver&lt;/code&gt;) to outrank &lt;code&gt;roles/bigquery.jobUser&lt;/code&gt; and &lt;code&gt;roles/bigquery.dataViewer&lt;/code&gt;. Experiment B2 eliminated service-agent hijacking with per-token FTS5 fan-out and a &lt;code&gt;0.35&lt;/code&gt; downweight on &lt;code&gt;serviceAgent&lt;/code&gt; and &lt;code&gt;jobfunctions&lt;/code&gt; roles.&lt;/li&gt;
&lt;/ol&gt;
&lt;aside class=&quot;callout&quot;&gt;
&lt;div class=&quot;callout-title&quot;&gt;Speed vs. Zero-Fail Discipline&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;LoRA never fixed a single retrieval miss:&lt;/strong&gt; Every retrieval failure (&lt;code&gt;role-01&lt;/code&gt;, &lt;code&gt;perm-08&lt;/code&gt;, &lt;code&gt;role-12&lt;/code&gt;) stayed broken until retrieval itself improved. If your chunks are wrong, fine-tuning just produces wrong answers faster.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Base Hybrid v2 is safer; Concise-Thought LoRA is interactive:&lt;/strong&gt; For security-critical lookups where 13.7s latency is acceptable, base Gemma plus Hybrid v2 (&lt;code&gt;0.00%&lt;/code&gt; hard fail, &lt;code&gt;15/15&lt;/code&gt; refusals) still beats the LoRA adapter (&lt;code&gt;4.44%&lt;/code&gt; hard fail, &lt;code&gt;14/15&lt;/code&gt; refusals). Use C2 when 2-second interactive speed matters and downstream validators catch residual slips.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Even evaluator regexes lie if you do not audit transcripts:&lt;/strong&gt; Auditing Experiment A and B transcripts caught passive-voice refusals (&lt;code&gt;&quot;cannot be verified from the provided documentation context&quot;&lt;/code&gt;) that naive refusal regexes initially missed.&lt;/li&gt;
&lt;/ol&gt;
&lt;/aside&gt;
&lt;h2 id=&quot;when-to-use-each-stack&quot;&gt;When to Use Each Stack&lt;/h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Stack&lt;/th&gt;&lt;th&gt;Best For&lt;/th&gt;&lt;th&gt;Measured Accuracy / Hard Fails&lt;/th&gt;&lt;th&gt;Latency&lt;/th&gt;&lt;th&gt;Infrastructure Footprint&lt;/th&gt;&lt;th&gt;Main Risk&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Base Gemma 4 + Hybrid SQLite v2&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Air-gapped security audits and compliance checks where correctness beats speed&lt;/td&gt;&lt;td&gt;&lt;code&gt;0.00%&lt;/code&gt; hard fail, &lt;code&gt;93.33%&lt;/code&gt; role recall, &lt;code&gt;90.00%&lt;/code&gt; doc citations&lt;/td&gt;&lt;td&gt;&lt;code&gt;13.71s&lt;/code&gt; P50 / &lt;code&gt;27.42s&lt;/code&gt; P95&lt;/td&gt;&lt;td&gt;&lt;code&gt;4.8 GB&lt;/code&gt; VRAM, &lt;code&gt;5.4 GB&lt;/code&gt; RAM, &lt;code&gt;63 MiB&lt;/code&gt; index&lt;/td&gt;&lt;td&gt;Slow multi-second thinking traces on every turn&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Concise-Thought LoRA (Exp C2) + Hybrid v2&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Interactive local developer assistants with strict latency budgets&lt;/td&gt;&lt;td&gt;&lt;code&gt;4.44%&lt;/code&gt; hard fail, &lt;code&gt;90.00%&lt;/code&gt; exact perm recall, &lt;code&gt;80.00%&lt;/code&gt; exact match&lt;/td&gt;&lt;td&gt;&lt;code&gt;2.02s&lt;/code&gt; P50 / &lt;code&gt;8.48s&lt;/code&gt; P95&lt;/td&gt;&lt;td&gt;Same footprint + tiny &lt;code&gt;rank=8&lt;/code&gt; LoRA (&lt;code&gt;~6m 53s&lt;/code&gt; to train)&lt;/td&gt;&lt;td&gt;Residual &lt;code&gt;2/45&lt;/code&gt; slips on trick refusals and rare role echoes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Regional Canadian Cloud API + Hybrid RAG&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Multi-user enterprise teams needing frontier reasoning inside Canadian residency&lt;/td&gt;&lt;td&gt;Not benchmarked here; depends on host model&lt;/td&gt;&lt;td&gt;Network-bound&lt;/td&gt;&lt;td&gt;Regional VPC + private endpoints (&lt;code&gt;northamerica-northeast1&lt;/code&gt; / Canada Central)&lt;/td&gt;&lt;td&gt;Egress governance, per-token spend, and cloud ops&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;appendix-under-the-hood-mechanics&quot;&gt;Appendix: Under-the-Hood Mechanics&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Cross-host 1-byte diffs defeating &lt;code&gt;content_hash&lt;/code&gt; dedup:&lt;/strong&gt; &lt;code&gt;cloud.google.com&lt;/code&gt; and &lt;code&gt;docs.cloud.google.com&lt;/code&gt; returned &lt;code&gt;1,901&lt;/code&gt; raw &lt;code&gt;/iam/&lt;/code&gt; rows that differed by roughly 1 byte, bypassing pure hash deduplication until lowercase URL-path dedup ran first (&lt;code&gt;973&lt;/code&gt; unique &lt;code&gt;/iam/&lt;/code&gt; docs, &lt;code&gt;988&lt;/code&gt; with product IAM pages), followed by &lt;code&gt;content_hash&lt;/code&gt; dedup (&lt;code&gt;901&lt;/code&gt; unique docs) to strip REST path aliases.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SQLite FTS5 dot-quoting trap:&lt;/strong&gt; Default &lt;code&gt;unicode61&lt;/code&gt; splits &lt;code&gt;storage.objects.get&lt;/code&gt; on &lt;code&gt;.&lt;/code&gt; and &lt;code&gt;/&lt;/code&gt;, blurring it with &lt;code&gt;storage.objects.list&lt;/code&gt;. Switching to &lt;code&gt;unicode61 tokenchars &#39;._/-&#39;&lt;/code&gt; fixes tokenization, but unquoted &lt;code&gt;storage.objects.get&lt;/code&gt; then raises &lt;code&gt;fts5: syntax error near &quot;.&quot;&lt;/code&gt;, requiring double-quoted tokens across dual FTS5 tables (&lt;code&gt;exact&lt;/code&gt; + &lt;code&gt;porter&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Gemma 4&#39;s spontaneous &lt;code&gt;&amp;lt;|channel&amp;gt;thought&lt;/code&gt; channel:&lt;/strong&gt; Even with &lt;code&gt;enable_thinking=False&lt;/code&gt; and no &lt;code&gt;&amp;lt;|think|&amp;gt;&lt;/code&gt; token injected, &lt;code&gt;gemma-4-E4B-it-4bit&lt;/code&gt; entered &lt;code&gt;&amp;lt;|channel&amp;gt;thought&lt;/code&gt; on &lt;strong&gt;44 of 45&lt;/strong&gt; multi-source RAG prompts. At &lt;code&gt;max_tokens=384&lt;/code&gt;, &lt;code&gt;0/44&lt;/code&gt; finished thinking; prefilling &lt;code&gt;&amp;lt;|channel&amp;gt;thought\n&amp;lt;channel|&amp;gt;&lt;/code&gt; failed too (Gemma printed a plain-text &lt;code&gt;Thought Process:&lt;/code&gt; plus a stray &lt;code&gt;&amp;lt;channel|&amp;gt;&lt;/code&gt;). Allowing native generation up to &lt;code&gt;max_tokens=1536&lt;/code&gt; and parsing past &lt;code&gt;&amp;lt;channel|&amp;gt;&lt;/code&gt; fixed truncation (&lt;code&gt;0/45&lt;/code&gt; empty answers).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Gemma 4 &lt;code&gt;chat_template.jinja&lt;/code&gt; silently stripping training thoughts:&lt;/strong&gt; Gemma 4&#39;s Jinja template runs &lt;code&gt;strip_thinking()&lt;/code&gt; on every &lt;code&gt;role == &#39;model&#39;&lt;/code&gt; message without &lt;code&gt;tool_calls&lt;/code&gt;, so &lt;code&gt;mlx_lm.lora&lt;/code&gt;&#39;s built-in &lt;code&gt;ChatDataset&lt;/code&gt; silently deleted all &lt;code&gt;&amp;lt;|channel&amp;gt;thought...&amp;lt;channel|&amp;gt;&lt;/code&gt; tokens before training. Preserving concise thoughts in Experiment C2 required a custom &lt;code&gt;ThoughtChatDataset&lt;/code&gt; that renders the prompt prefix and directly encodes the completion with special token IDs (&lt;code&gt;&amp;lt;|channel&amp;gt;=100&lt;/code&gt;, &lt;code&gt;&amp;lt;channel|&amp;gt;=101&lt;/code&gt;, &lt;code&gt;&amp;lt;turn|&amp;gt;=106&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Checkpoint overfit past iter 100 and &lt;code&gt;scale: 20.0&lt;/code&gt; repetition loops:&lt;/strong&gt; In Experiment C, training from iter 100 to iter 200 dropped Exact Permission Recall by &lt;strong&gt;10 percentage points&lt;/strong&gt; (&lt;code&gt;81.67% -&amp;gt; 71.67%&lt;/code&gt;) even though &lt;code&gt;val_loss&lt;/code&gt; looked flat (&lt;code&gt;0.011 -&amp;gt; 0.007&lt;/code&gt;), and drove template-echo garbling (&lt;code&gt;&quot;is not present&quot;&lt;/code&gt; loops on &lt;code&gt;trick-11&lt;/code&gt;). In the first C2 attempt, repeated imperative checklist lines in thoughts plus &lt;code&gt;scale: 20.0&lt;/code&gt; across 8 layers triggered a 70x greedy repetition loop that never closed &lt;code&gt;&amp;lt;channel|&amp;gt;&lt;/code&gt;. Switching to varied 1 to 2 sentence natural thoughts and &lt;code&gt;scale: 4.0&lt;/code&gt; across 16 layers eliminated loops (&lt;code&gt;0/45&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Authoritative-table boost trade-off (&lt;code&gt;role_def&lt;/code&gt; vs &lt;code&gt;product_iam&lt;/code&gt;):&lt;/strong&gt; Boosting &lt;code&gt;role_def&lt;/code&gt; (&lt;code&gt;1.25&lt;/code&gt;) over &lt;code&gt;product_iam&lt;/code&gt; (&lt;code&gt;1.00&lt;/code&gt;) in Experiment B2 eliminated hard fails across the board, with one subtle side effect on &lt;code&gt;perm-01&lt;/code&gt; and &lt;code&gt;perm-03&lt;/code&gt;: &lt;code&gt;roles/storage.legacyBucketReader&lt;/code&gt; displaced &lt;code&gt;/storage/docs/access-control/iam-permissions&lt;/code&gt;, because role tables list permissions without explaining action-level preconditions (such as object overwrite requiring both &lt;code&gt;create&lt;/code&gt; and &lt;code&gt;delete&lt;/code&gt;).&lt;/li&gt;
&lt;/ol&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Same Model, Different Agent Harness: When RL Harness Adapters Are Actually Worth It</title>
        <published>2026-12-01T00:00:00+00:00</published>
        <updated>2026-12-01T00:00:00+00:00</updated>
        
        <author>
          <name>Liudas Sodonis</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://liudass-macbook-pro.tail11ead.ts.net/writing/agent-harnesses-and-harness-adapters/"/>
        <id>https://liudass-macbook-pro.tail11ead.ts.net/writing/agent-harnesses-and-harness-adapters/</id>
        
        <content type="html" xml:base="https://liudass-macbook-pro.tail11ead.ts.net/writing/agent-harnesses-and-harness-adapters/">&lt;p&gt;An LLM on its own is just stateless text prediction. Everything that turns it into a working agent (the control loop, tool schemas, context compaction, memory, and guardrails) lives in the harness around it.&lt;/p&gt;
&lt;p&gt;Because every serious harness makes different design choices, dropping a generic model cold into a harness wastes tokens and burns turns on avoidable mistakes. Recent research from Hugging Face shows you can keep base weights frozen and train a small LoRA harness adapter directly inside your live harness, making an open-weights model more accurate and roughly twice as token-efficient.&lt;/p&gt;
&lt;p&gt;Before you jump to RL training, though, you have to understand what production harnesses actually do and where the real cost sits.&lt;/p&gt;
&lt;h2 id=&quot;production-teams-hand-write-their-harnesses&quot;&gt;Production Teams Hand-Write Their Harnesses&lt;/h2&gt;
&lt;p&gt;A recent source-code study, &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://arxiv.org/pdf/2609.00006&quot;&gt;Harness Engineering: Anatomy, Architecture, and Evolution of Coding Agents (arXiv:2609.00006)&lt;/a&gt; by Barbaste et al., inspected roughly 4 million lines of code across 11 production coding agents: Claude Code, Codex CLI, Gemini CLI, OpenHands, Aider, Pi, OpenCode, Hermes, OpenClaw, Mistral Vibe, and Mini-SWE-Agent.&lt;/p&gt;
&lt;p&gt;Two findings stand out right away:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;0 of 11&lt;/strong&gt; import general-purpose agent frameworks like LangChain, LangGraph, or AutoGen. Every team wrote its own execution loop and control layer.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;0 of 11&lt;/strong&gt; rely on vector databases for code search. They use deterministic file traversal, grep, and explicit context controls instead.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Across those 11 codebases, the authors found seven recurring subsystems: the execution loop, the LLM provider layer, tool definitions, memory and context management, safety and permissions, sub-agent orchestration, and extension surfaces. Standards like &lt;code&gt;SKILL.md&lt;/code&gt; (in 9 of 11 systems) and MCP (in 8 of 11) are converging at the edges, while the core execution loops stay strongly opinionated.&lt;/p&gt;
&lt;p&gt;That matches what I have seen on smaller production builds. In our &lt;a href=&quot;/work/agentic-3d-proposal-engine/&quot;&gt;3D construction proposal engine&lt;/a&gt;, asking the model to write Blender Python code directly failed on consistency, so I moved the team to a small bounded loop (JSON floor plans, a Python math validator, and a 10-iteration cap). And in my &lt;a href=&quot;/work/offline-gcp-iam-rag/&quot;&gt;offline GCP IAM RAG lab&lt;/a&gt;, pure vector search blurred exact permission strings like &lt;code&gt;storage.objects.get&lt;/code&gt; and &lt;code&gt;storage.objects.list&lt;/code&gt;, so exact-match search (SQLite FTS5) had to run first. Production coding agents hit the exact same walls.&lt;/p&gt;
&lt;h2 id=&quot;same-model-weights-four-different-harnesses&quot;&gt;Same Model Weights, Four Different Harnesses&lt;/h2&gt;
&lt;p&gt;Maarten Grootendorst&#39;s &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://newsletter.maartengrootendorst.com/p/a-visual-guide-to-agent-harnesses&quot;&gt;A Visual Guide to Agent Harnesses&lt;/a&gt; starts from a ~600-line minimal loop (&lt;code&gt;TinyAgent&lt;/code&gt;) and compares four open-source harnesses running on the same underlying model weights.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Harness&lt;/th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Tool Surface &amp;amp; Execution&lt;/th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Context &amp;amp; Memory Strategy&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Pi&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Minimalist (~4 default tools); the agent can edit its own harness and skills; JSONL branching sessions.&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Compacts history at 184k tokens while keeping the most recent 20k tokens verbatim.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;OpenCode&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Shared server backed by SQLite sessions for multiple clients; &quot;Code Mode&quot; chains tool calls in one script; blocks file-edit tools until a &lt;code&gt;plan.md&lt;/code&gt; exists.&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Enforces planning before edits and manages multi-client state cleanly in SQLite.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Hermes&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Exposes rich tool schemas upfront (20+ default tools); runs a review agent after heavy tool runs to save working patterns into markdown skills.&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Compacts context early to keep per-turn token overhead and tool bloat in check.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;OpenClaw&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Multi-channel gateway (30+ messaging channels) with leaner default tools paired with workspace markdown files (&lt;code&gt;SOUL.md&lt;/code&gt;, &lt;code&gt;MEMORY.md&lt;/code&gt;).&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Runs a 30-minute heartbeat plus overnight multi-pass &quot;Scheduled Dreaming&quot; to promote daily logs into long-term memory.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;These differences show up before the user types a single word. One harness spends opening context tokens on 20+ tool schemas, while another spends them on workspace identity and memory files. One expects one tool call per turn, while another expects batched scripts or a &lt;code&gt;plan.md&lt;/code&gt; file first. Even file-edit formats differ down to whitespace parsing and fuzzy matching (see the &lt;a href=&quot;https://liudass-macbook-pro.tail11ead.ts.net/writing/agent-harnesses-and-harness-adapters/#appendix-under-the-hood-mechanics-that-separate-harnesses&quot;&gt;appendix&lt;/a&gt; for the small mechanics). When a generic model ignores those conventions, it burns extra turns recovering from tool errors and re-reading files it already saw.&lt;/p&gt;
&lt;h2 id=&quot;training-models-to-fit-the-harness-harness-adapters&quot;&gt;Training Models to Fit the Harness: Harness Adapters&lt;/h2&gt;
&lt;p&gt;Hugging Face&#39;s &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://huggingface.co/blog/harness-adapters-at-scale&quot;&gt;Introducing Harness Adapters&lt;/a&gt; turns that observation into a training recipe. Instead of changing the agent loop or fine-tuning all base weights, they froze &lt;code&gt;Qwen3.8-27B&lt;/code&gt;, attached a lightweight &lt;strong&gt;rank-32 LoRA adapter&lt;/strong&gt; to linear projections, and trained it with reinforcement learning (&lt;code&gt;AsyncGRPOTrainer&lt;/code&gt; in TRL, running inside &lt;code&gt;OpenEnv&lt;/code&gt; and &lt;code&gt;Harbor&lt;/code&gt; sandboxes) directly inside unmodified live harnesses (Pi, OpenCode, and Hermes) on verifiable tasks from Terminal-Bench 2.1 and SWE-bench Pro.&lt;/p&gt;
&lt;pre&gt;&lt;code data-lang=&quot;text&quot;&gt;                [Frozen Base Model: Qwen3.8-27B]
                                │
        ┌───────────────────────┼───────────────────────┐
        ▼                       ▼                       ▼
 [Rank-32 LoRA: Pi]     [Rank-32 LoRA: OpenCode] [Rank-32 LoRA: Hermes]
        │                       │                       │
        ▼                       ▼                       ▼
 [Live Pi Harness]      [Live OpenCode Harness]  [Live Hermes Harness]
  (RL Sandbox)           (RL Sandbox)             (RL Sandbox)
        └───────────────────────┴───────────────────────┘
                                │
                                ▼
             [Verifiable Pass/Fail Reward Signal]
                                │
        (Cosine Similarity: 0.01–0.02 → Near-Orthogonal Updates)
                                │
                                ▼
             [Optional Merge Without Retraining]
             [Single Rank-96 &amp;quot;Super-Adapter&amp;quot;]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Under &lt;strong&gt;Pi&lt;/strong&gt;, Terminal-Bench 2.1 &lt;code&gt;pass@1&lt;/code&gt; jumped from &lt;strong&gt;39% to 55%&lt;/strong&gt;, and scores on the hardest 51 SWE-bench Pro tasks rose from &lt;strong&gt;39.2% to 64.7%&lt;/strong&gt;. Average token usage dropped roughly in half, from ~2.9K down to ~1.5K tokens per task, because the adapted model stopped wasting turns on redundant file reads and dead-end loops.&lt;/p&gt;
&lt;p&gt;What showed up in the weights is just as telling. Layer-by-layer cosine similarity between the Pi, OpenCode, and Hermes adapters was only &lt;strong&gt;0.01 to 0.02&lt;/strong&gt;. Each harness pushed the model in a nearly orthogonal direction, which is a direct measurement of how differently these runtimes behave. Because the updates barely collided, Hugging Face concatenated and scaled them without retraining into a single rank-96 &lt;strong&gt;super-adapter&lt;/strong&gt;. With thinking mode on, that merged adapter lifted cross-harness mean &lt;code&gt;pass@1&lt;/code&gt; from &lt;strong&gt;55.5% to 63.5%&lt;/strong&gt; while cutting tool calls by &lt;strong&gt;19% to 48%&lt;/strong&gt; (and by &lt;strong&gt;53% to 73%&lt;/strong&gt; with thinking off).&lt;/p&gt;
&lt;p&gt;This reinforces the boundary from my &lt;a href=&quot;/work/offline-gcp-iam-rag/&quot;&gt;offline IAM lab&lt;/a&gt;: &lt;strong&gt;fine-tune for behavior, retrieve facts.&lt;/strong&gt; A harness adapter never memorizes your repository or policy manuals. It teaches the model the reflexes of a specific runtime.&lt;/p&gt;
&lt;h2 id=&quot;what-this-means-for-enterprise-and-sovereign-ai-costs&quot;&gt;What This Means for Enterprise and Sovereign AI Costs&lt;/h2&gt;
&lt;p&gt;Multi-turn agent loops multiply token costs fast. A 20-step coding or triage run calling a hosted frontier API pays for your system prompt and accumulated tool output on every single turn. For regulated Canadian or mid-market workloads, sending internal schemas and logs to external APIs is often off the table anyway due to &lt;code&gt;PIPEDA&lt;/code&gt;, &lt;code&gt;Quebec Law 25&lt;/code&gt;, or &lt;code&gt;CLOUD Act&lt;/code&gt; constraints.&lt;/p&gt;
&lt;p&gt;Hosting one frozen open-weights model on regional cloud GPUs or local hardware and swapping small LoRA harness adapters attacks both accuracy and unit economics at the same time. Each adapter is tens of megabytes rather than a full checkpoint, so one shared base model can serve multiple internal workflows. Cutting token consumption roughly in half per task translates directly into lower latency and roughly half the GPU burn per run.&lt;/p&gt;
&lt;aside class=&quot;callout&quot;&gt;
&lt;div class=&quot;callout-title&quot;&gt;Fix Your Harness Before You Spend a Dollar on RL&lt;/div&gt;
&lt;p&gt;I will not approve GPU or RL pipeline budget for harness adapters until three things are already true:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Verifiable rewards already exist.&lt;/strong&gt; Coding and terminal benchmarks have cheap deterministic graders like exit codes and unit tests. Enterprise workflows like proposal generation, ticket triage, or compliance review rarely have crisp pass/fail signals. Without trustworthy evals, RL optimizes for a broken proxy.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The harness contract is stable.&lt;/strong&gt; Changing your system prompt, tool schemas, or compaction threshold can silently break a harness-tuned LoRA. You now own adapter versioning, regression eval suites, and scheduled retraining in CI/CD.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Token burn actually hurts your monthly bill.&lt;/strong&gt; If your loop is unbounded, your tools dump 50KB of raw JSON into context, and you lack basic validators, fix the harness first. You will get bigger savings for a fraction of the maintenance cost.&lt;/li&gt;
&lt;/ol&gt;
&lt;/aside&gt;
&lt;h2 id=&quot;when-to-use-what&quot;&gt;When to Use What&lt;/h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Approach&lt;/th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Best For&lt;/th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Token &amp;amp; Hosting Economics&lt;/th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Operational Overhead&lt;/th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Where It Breaks&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Frontier API + Off-the-Shelf Harness&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Fast pilots, general coding, low-volume internal tools&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;High per-token cost; zero GPU ops&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Minimal&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Data residency limits and compounding multi-turn API spend&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Lean Custom Harness + Deterministic Validators&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Domain workflows with strict rules and fixed schemas&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Moderate API or self-hosted cost&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Code, CI/CD, and validator maintenance&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Models still waste turns fighting harness-specific quirks&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Custom Harness + RL LoRA Harness Adapter&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;High-volume or sovereign open-weights deployments with stable tool contracts&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Best unit economics (~50% fewer tokens on one shared base model)&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Requires RL pipeline, verifiable evals, and adapter versioning&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Prompt/schema drift or weak reward signals&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;Start with a small, explicit harness and plain validators you can debug. What changes my mind and justifies RL harness adapters is high-volume or sovereign open-weights traffic where the tool contract has settled, your evals are solid, and cutting multi-turn token burn in half materially moves your monthly GPU bill.&lt;/p&gt;
&lt;h2 id=&quot;appendix-under-the-hood-mechanics-that-separate-harnesses&quot;&gt;Appendix: Under-the-Hood Mechanics That Separate Harnesses&lt;/h2&gt;
&lt;p&gt;You do not strictly need to know how an edit tool counts leading spaces to make a platform decision, but I love reading these small mechanics—they are a great exercise for the brain, and they show exactly why two harnesses running the same model weights behave so differently in practice. Across the three sources, five small details stand out:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Relative indentation with &lt;code&gt;←&lt;/code&gt; arrows (Aider&#39;s &lt;code&gt;RelativeIndenter&lt;/code&gt;):&lt;/strong&gt; LLMs frequently miscount leading spaces in deeply nested files. Instead of matching raw absolute whitespace, Aider strips leading whitespace shared with the preceding line and inserts a Unicode left-arrow (&lt;code&gt;←&lt;/code&gt;) whenever indentation steps back relative to the line above. That lets search-and-replace blocks match even when the model gets the outer nesting depth wrong.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Unicode and smart-quote cleanup with byte-preserving overlay (Pi):&lt;/strong&gt; Models regularly slip curly quotes, non-ASCII Unicode variants, or trailing spaces into code edits. Pi applies NFKC Unicode normalization, strips trailing whitespace, and converts smart quotes to plain ASCII while computing the match, then overlays only the changed lines back onto the original raw file bytes so untouched lines keep their exact original spaces, tabs, and line endings.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A 9-stage cascading fuzzy matcher (OpenCode):&lt;/strong&gt; Rather than failing immediately on a whitespace mismatch and burning another LLM turn, OpenCode&#39;s &lt;code&gt;edit&lt;/code&gt; tool runs up to nine sequential replacer passes from strictest to loosest (&lt;code&gt;Simple&lt;/code&gt; exact match, &lt;code&gt;LineTrimmed&lt;/code&gt;, &lt;code&gt;BlockAnchor&lt;/code&gt; using first and last line anchors with Levenshtein similarity on the interior, &lt;code&gt;WhitespaceNormalized&lt;/code&gt;, &lt;code&gt;IndentationFlexible&lt;/code&gt;, &lt;code&gt;EscapeNormalized&lt;/code&gt;, &lt;code&gt;TrimmedBoundary&lt;/code&gt;, &lt;code&gt;ContextAware&lt;/code&gt;, and &lt;code&gt;MultiOccurrence&lt;/code&gt;). The first pass that finds a clean match applies the edit and exits.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Why harnesses avoid line-number edits and enforce read-before-edit (&lt;code&gt;arXiv:2609.00006&lt;/code&gt;):&lt;/strong&gt; The 11-system study explicitly warns against line-number-based edit contracts because models drift on line counts far more often than on contextual text matches. To stop hallucinated patches, harnesses like Claude Code and Mistral Vibe enforce a read-before-edit rule (refusing to edit a file until the model has explicitly read it in the session), while Codex CLI relies on a custom &lt;code&gt;*** Begin Patch&lt;/code&gt; grammar that its models are trained to emit.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Disk-backed log truncation, mid-flight steering, and overnight &quot;Dreaming&quot; (Pi and OpenClaw):&lt;/strong&gt; When a command like &lt;code&gt;pytest&lt;/code&gt; produces 15,000 lines of output, Pi writes all 15,000 lines to disk and returns only the last 2,000 lines plus the file path, giving the model the failure trace without blowing the context window. Pi also runs independent tool calls in parallel, lets users inject a steering prompt right before tool outputs return to the model, and stores turns in an append-only &lt;code&gt;session.jsonl&lt;/code&gt; with &lt;code&gt;id&lt;/code&gt; and &lt;code&gt;parent&lt;/code&gt; pointers so conversations can branch like Git commits. OpenClaw takes a long-horizon approach with a 30-minute &lt;code&gt;HEARTBEAT.md&lt;/code&gt; check and overnight Light, Deep, and REM &quot;Scheduled Dreaming&quot; passes that promote durable facts from daily logs into &lt;code&gt;MEMORY.md&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Maarten Grootendorst, &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://newsletter.maartengrootendorst.com/p/a-visual-guide-to-agent-harnesses&quot;&gt;A Visual Guide to Agent Harnesses&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Hugging Face, &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://huggingface.co/blog/harness-adapters-at-scale&quot;&gt;Introducing Harness Adapters&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Paul Barbaste, Tristan Darrigol, Germain Vu, Tom Wiltberger, &lt;a rel=&quot;noopener noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://arxiv.org/pdf/2609.00006&quot;&gt;Harness Engineering: Anatomy, Architecture, and Evolution of Coding Agents (arXiv:2609.00006)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>How We Replaced a $10k/mo Managed ETL Pipeline With Under $1k/mo in Native GCP Primitives</title>
        <published>2026-11-27T00:00:00+00:00</published>
        <updated>2026-11-27T00:00:00+00:00</updated>
        
        <author>
          <name>Liudas Sodonis</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://liudass-macbook-pro.tail11ead.ts.net/writing/cloud-primitives-vs-managed-etl/"/>
        <id>https://liudass-macbook-pro.tail11ead.ts.net/writing/cloud-primitives-vs-managed-etl/</id>
        
        <content type="html" xml:base="https://liudass-macbook-pro.tail11ead.ts.net/writing/cloud-primitives-vs-managed-etl/">&lt;p&gt;My worst managed-tool call was choosing GCP Cloud Data Fusion for a legacy SQL Server to BigQuery migration. It was well-marketed and looked like the fastest path, so I signed off on it.&lt;/p&gt;
&lt;p&gt;Over the next three months, while the team was still building downstream data models and dashboards, the managed service billed around &lt;strong&gt;$10,000 a month&lt;/strong&gt; without proper monitoring or automated checks against the source databases. When we finally audited the numbers, they were not matching production. I got on daily calls with the client CTO, escalated with Google engineering to confirm whether Data Fusion could hit our cost and accuracy targets, and owned the rebuild.&lt;/p&gt;
&lt;p&gt;We replaced it with a &lt;strong&gt;Debezium server feeding native GCP primitives&lt;/strong&gt; (Pub/Sub, Cloud Storage staging, and BigQuery). Monthly ingestion spend dropped from &lt;strong&gt;$10,000 to under $1,000&lt;/strong&gt;, and the permanent rule I installed afterward is simple: no managed data tool gets past week two without a hard billing cap and automated row-count parity checks against source tables.&lt;/p&gt;
&lt;h2 id=&quot;why-the-native-primitives-worked-better&quot;&gt;Why the Native Primitives Worked Better&lt;/h2&gt;
&lt;p&gt;For a multi-year pipeline, managed visual ETL platforms stop acting like a shortcut and start acting like a tax. You pay for always-on cluster capacity and instance licensing even when your daily data delta is fairly modest.&lt;/p&gt;
&lt;p&gt;Debugging inside a black-box UI is also miserable. When a legacy SQL Server schema changes silently or a retry loop locks a table, you spend hours digging through proprietary abstractions instead of reading a normal stack trace. Moving to Debezium and plain GCP primitives cut the cloud bill by roughly 10x and gave us normal code, normal logs, and normal tests.&lt;/p&gt;
&lt;h2 id=&quot;building-is-cheap-now-maintaining-for-five-years-is-not&quot;&gt;Building Is Cheap Now. Maintaining for Five Years Is Not.&lt;/h2&gt;
&lt;p&gt;This is where build-vs-buy conversations usually go wrong, especially now that LLMs let people spin up working tools left and right.&lt;/p&gt;
&lt;p&gt;The biggest cost of an internal tool is never building version one. It is owning it for three to five years: updating libraries, applying security patches, handling schema drift, and adding new features when business needs change.&lt;/p&gt;
&lt;p&gt;In too many companies, one strong engineer (&quot;Bob&quot;) builds a clever internal service and becomes its only owner. Six months later, Bob switches teams, runs out of time, or leaves the company, and nobody else wants to touch the code.&lt;/p&gt;
&lt;aside class=&quot;callout&quot;&gt;
&lt;div class=&quot;callout-title&quot;&gt;Cloud Bills Are Half the Cost. Maintenance Is the Other Half.&lt;/div&gt;
&lt;p&gt;Cutting $9k/month off a cloud invoice is only a win if you do not spend $12k/month of senior engineering time babysitting fragile scripts. I will not approve a custom internal tool built by one lone engineer. Either a real team owns it with a roadmap and on-call coverage, or we buy it so another vendor owns the patching and security team.&lt;/p&gt;
&lt;/aside&gt;
&lt;p&gt;Buying also has an underrated people benefit: users accept boundaries. Nobody expects Excel to rewrite itself around one department&#39;s whim, whereas an internal tool attracts endless custom feature requests the day it ships.&lt;/p&gt;
&lt;h2 id=&quot;when-to-buy-vs-when-to-build-on-primitives&quot;&gt;When to Buy vs. When to Build on Primitives&lt;/h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Dimension&lt;/th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Heavy Managed ETL&lt;/th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Debezium + Native Cloud Primitives&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Time to first demo&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Days&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;1–2 weeks&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Monthly cloud bill&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;High (~$8k–$15k/mo)&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Low (under $1k/mo)&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Engineering overhead&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Low at first; painful on weird edge cases&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Requires CI/CD, alerting, and schema-drift ownership&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Debugging&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Vendor UI and opaque logs&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Normal code, unit tests, and cloud logging&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;When to pick it&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Short pilots or teams without dedicated platform engineers&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;Multi-year pipelines backed by a team that owns operations&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;Use managed tools when you need to prove business value quickly or when you have no dedicated platform team to own security and upgrades—paying $8k–$10k/month to a vendor is still cheaper than hiring a senior engineer from scratch. What flips the call is longevity and ownership: once a high-frequency workload is staying for three to five years and you have a team to maintain it, plain cloud primitives win on both cost and control.&lt;/p&gt;
</content>
        
    </entry>
</feed>
