Context Management — Primitive #3 of Harness Engineering
Your agent didn't get dumber. Its window got messy.
In this deep dive I trace one real bug — an agent debugging a live-streaming app (StreamIt) that "lost the thread" around turn 40 — all the way through to the fix. Same model, same weights, same settings. What changed was what was in front of it.
We break context management down into the four moves that actually matter on a long task — Select, Compress, Write, Isolate — and watch two very different agent harnesses, Codex (OpenAI's CLI) and Hermes (Nous Research), make opposite bets at every step. Along the way: the four ways long context goes bad, the "lost in the middle" effect, the prompt-cache cost almost every talk skips, and the one habit that pays off whether you're building a harness or just using Claude Code or Codex — look at what actually reaches the model.
What you'll take away
A precise vocabulary for why agents degrade on long tasks (poisoning, distraction, confusion, clash)
The four moves, in the order they tend to bite, applied to one concrete bug
How Codex's "discipline at the door" differs from Hermes's "flexible window with reach-back"
Why reshuffling your context every turn can be correct and slow and expensive
-A research → plan → implement workflow that keeps the window clean by default
This is part of the Primitives of Harness Engineering series. If you haven't seen the earlier deep dives on context delivery, RAG, and memory, start there for the full stack.
👉 Subscribe for the rest of the 10 primitives.
---
Chapters
00:00 Intro — the context management primitive
00:41 The StreamIt bug: an agent that "got dumb" at turn 40
02:34 Why it broke — and four ways long context goes bad
04:14 Where it sits in the stack (and what it's NOT: RAG vs memory)
05:34 The naive approach: just put everything in
06:46 The four moves (Lance Martin / LangChain)
07:14 Move 1 — Select: pull the slice this turn needs
08:06 Tool selection breaks down as the tool set grows
09:16 Selection across time: Codex vs Hermes
11:46 Position matters: "lost in the middle"
12:55 Move 2 — Compress: what a good compaction keeps
14:36 Codex vs Hermes on compaction
16:32 The two hidden costs of compression
19:14 Move 3 — Write it to disk
19:51 Dex Horthy's research → plan → implement workflow
21:14 Move 4 — Isolate with subagents
22:51 The prompt-cache cost everyone skips
25:45 Codex vs Hermes, side by side
27:09 You can't fix what you can't see (observability)
28:34 How I actually run a long task
30:34 Back to the StreamIt bug — the fix
32:14 Why a whole deep dive: invisible when it works
33:42 The takeaway for everyone: look at what reaches the model
35:33 Wrap-up