Link copied
Blog › The Wall at 8,186 Characters
AI Workflow

The Wall at 8,186 Characters

KG
Teh Kim GuanACMA · CGMA
2026-10-09 · 5 min read
The Wall at 8,186 Characters

For two days this week, every shell command in my long working sessions died with the same message: an unexpected end of file while looking for a matching quote. The first fix removed the symptom on disk and changed nothing on screen. The second fix worked.

A fix that makes the evidence look clean is not a fix until the failing process agrees. The state you can inspect is not always the state that runs, and a clean file on disk proves nothing about a process that loaded the dirty one an hour ago.

The symptom

My setup runs an AI coding agent on a Windows laptop, with Git Bash as the shell. Long build sessions run for hours, compact their context many times, and launch helper agents that each start their own small session.

On the night of 7 October, every command in one of those sessions started failing at line 92 of a script I had never written. The next day it happened again at line 94. Short sessions were fine. Long ones broke, and once broken they stayed broken.

The obvious reading was corruption. Something was writing garbage into a file the shell sourced at startup.

The first diagnosis, and why it was half right

The first pass found a real fault. Two plugins append environment exports to a per-session file every time a session starts. Neither checks whether the line is already there. A session that compacts 26 times collects 26 copies. The file examined held 104 lines where four would do.

So the files were deduplicated. They went back to a few hundred bytes. The broken session stayed broken.

That should have been the moment to ask a different question. Instead the working theory became "the dedupe did not take", and a handoff rule appeared: start a fresh session after 20 compactions. A rule like that treats the symptom as weather. It means the mechanism is still unknown.

The mechanism

Per-session environment files inlined into one bash argument, with a silent cut at 8,186 characters inside a quoted value

The second pass, on the morning of 9 October, measured instead of guessing. Three facts came out.

  1. The agent inlines every environment file into one shell argument. It does not source the files from disk at run time. It reads them once and pastes their contents into a single bash -c string.
  2. Git for Windows cuts long quoted arguments silently. The runtime underneath Git Bash truncates any quoted argument at 8,186 characters. No warning, no error, just a shorter string.
  3. The arithmetic fit exactly. Each session start added about 340 bytes. After roughly 25 starts the combined string crossed 8,186 characters, and the cut landed inside a quoted value. The 7 October failure had an 8,840 character environment cut on line 92. The numbers matched to the line.

A probe script now measures the cap directly, so the figure is a measurement rather than a folk number.

There was a second, smaller defect. One plugin writes its line in two pieces. A reader that arrives between the two writes sees half a line. It reproduces with the real binary: two torn reads in 150 attempts.

Why the dedupe did not help

The agent process reads the environment files when it builds a command and holds the result. The broken session had already built its string. Cleaning the files changed what a new process would read. It did not change what the running one held. Even a manual context compaction did not clear it. Only a restart did.

When a fix appears to fail, the useful question is not "did the fix apply?" It is "which copy of the state is the failing process reading?"

The fix

The repair has four parts, each small:

  • A guard around both plugin hooks. It writes to a private temp file, appends once with a single write, and deduplicates on the way. Fifty real session starts held the file flat at 328 bytes, with zero torn reads across 144,991 snapshots. The unguarded originals grew to 16,400 bytes and failed.
  • A patcher for the installed hook files, with the originals kept so the change can be reversed.
  • A start hook that applies the patch again after a plugin update and reports the environment size against the cut.
  • A daily monitor, which runs until seven consecutive clean days and then gets switched off.

The second writer

The same afternoon, copies grew again in a few sessions. The guard was working. Something else was writing.

The desktop app runs its own copy of one plugin from a separate folder in application data. The patcher only read the main plugin registry, so it never saw that copy, and its check reported "already patched" with confidence. A second process had also started before the patch and kept the old hook definition in memory through every later compaction.

That afternoon taught two things. A check that reads the wrong inventory will report success, because the patcher's "already" was true for every copy it knew about. And the stale process pattern repeated: a process loaded old state at start and kept it, the same shape as the first failure.

The fix extended the patcher to find the second copy, added a folder-wide compaction that keeps the last complete export per variable, and wired it into every session start. Five live session folders went from bloated to 340 bytes each.

What I would tell another operator

1. Measure the limit before you write the rule. "Start a new session after 20 compactions" was a guess that happened to sit near the real threshold. The real threshold is 8,186 characters, and it also bites any single long command, compaction or not. A guess hides the second case.

2. Ask which process holds the state. Inspect the running process's inputs, not the file you just cleaned. Most "the fix did not take" moments are this. The same discipline sits behind the verification loop: check the thing that runs, not the thing you edited.

3. Reproduce with the real binary. The torn-line defect only showed up under the real plugin, at real timing. A synthetic test would have passed. Reading the source, not the README is the same instinct applied to a different tool.

4. Inventory every copy. Plugins, caches and app bundles keep their own copies. A patcher that reads one registry has a blind spot shaped like every other copy.

5. Retire the workaround in writing. The 20-compaction handoff rule is now retired. Leaving it in place would have trained future sessions to treat a solved problem as weather.

Epistemic status

The 8,186 character cut, the 340 byte growth per start, the 328 byte guarded steady state and the test counts are facts, measured this week with scripts kept in the repository. That the agent holds the built command for the life of the process is an inference. It is consistent with every observation, including the compaction that did not help, but I have not read it from the agent's source.

My recommendation is to treat any silent truncation limit in a toolchain as a design constraint and write it down with the number.

Part of the Operating Principles series from KG Consultancy.

About the Author
KG
Teh Kim Guan
Product Consultant · General Manager, PEPS Ventures

Strategy and technology are the same decision. Over 15 years in fintech (CTOS, D&B), prop-tech (PropertyGuru DataSense), and digital startups, I have built frameworks that help founders and executives make both moves at once. Based in Kuala Lumpur.

More from the blog
AI Workflow
Reverse-Engineering Malaysian Government Portals: A Reusable Crawl Pattern
Malaysian government portals hide public data behind painful interfaces. One crawl session against the LPPEH negotiator registry surfaced three reusable traps, and a starter template that cuts build time from 12 hours to 2.
2026-05-08 · 6 min read
AI Workflow
The 95% Margin Workflow: How One Consulting Engagement Compressed RM 30,000 of SEO Work into RM 800
A traditional Malaysian SEO agency quotes RM 30,000 to RM 50,000 for a topical content cluster. I just delivered the same scope in two days at RM 800. Here is exactly what changed.
2026-05-06 · 9 min read
Product Strategy
Computer Vision in Property Valuation: Precision at Scale
AVMs see the skeleton of a property. Computer vision sees condition, renovation recency, and owner investment level, closing the 15-25% gap that structural data alone cannot explain.
2026-03-23 · 8 min read
Work with KG

Working on a 0→1 product?

I help founders and operators go from idea to validated product. Let's talk about yours.

Get in touch →