Duncan Leung

Ai

01

Does Haiku Fan-Out Replace Sonnet? Two Experiments in Code Review and Solution Discovery

aiclaude-codeopenrig

I swapped the five Sonnet hunters in my code review pipeline for Haiku across 14 PRs with known bugs. Haiku found 20 of 26 defects to Sonnet's 21, produced 61% more raw findings, and used 28% more tokens. In a second test, 8 Haiku advocates plus an Opus adjudicator reached the same design family as 3 Sonnet advocates on all 3 decisions. The result: near-parity on recall, but no cost advantage in a validation-heavy pipeline.

02

Why I Built a Compaction System Instead of Handing Off to New Agents

aiclaude-codeopenrigmulti-agent

When a long-running orchestrator hits context limits, the obvious move is to hand off to a fresh agent. I tried that. The startup overhead, lost momentum, and broken continuity made it worse than the problem it solved. So I built a daemon-managed compaction system instead: one that monitors context usage, writes ground truth to disk, runs a four-stage idle-gated restore protocol, and distills session knowledge into a wiki page. The daemon is the sole compaction authority; seats never self-compact. Recent research shows neither approach is categorically better, but for same-model orchestrators that accumulate judgment over time, daemon-managed compaction with external ground truth wins.

03

Surviving the Dumb Zone: A Checkpoint System for Claude Code's /compact

aiclaude-codeopenrig

Claude Code's /compact command compresses your conversation to free context, but it silently drops external state mutations, abandoned approaches, and behavioral constraints. I built a precompact/postcompact checkpoint system that writes ground truth to disk before compaction and cross-checks it afterward — including live reconciliation against git, CI, and external systems. Here's the design, the research behind it, the failure modes it prevents, and how OpenRig's native compaction system eventually superseded these custom skills.

04

Building an Observer That Turns Claude Code Sessions into a Knowledge Base

aiclaude-codeknowledge-management

Every Claude Code session produces decisions, patterns, and context that vanish when the terminal closes. I built a daemon that watches for session endings, extracts the knowledge, distills it with Haiku, and compiles it into an Obsidian wiki with Sonnet — turning every coding session into searchable institutional memory for about $20/month.

05

Claude Code Research Tools: A Decision Guide

aiclaude-code

Claude Code has a dozen ways to research a question — from a single MCP call to a 98-agent adversarial pipeline. This guide maps every research tool by cost, agent count, and use case so you pick the right one the first time. Includes the full source of a custom deep-research-plus workflow that adds a Perplexity search lane to Claude Code's built-in deep-research pipeline.

06

The Attention Mechanism: Context Rot and the Lost-in-the-Middle Problem

ai

LLM context rot isn't a bug. It's a mathematical property of how the attention mechanism works. Three interacting failure modes (softmax's sum-to-one constraint, RoPE's distance decay, and causal masking's primacy bias) combine to produce the U-shaped attention curve where models attend well to the beginning and end of context but lose the middle. Understanding the mechanism changes how you structure prompts and manage context.

07

The LLM Dumb Zone: Performance Degradation Before the Context Limit

aiclaude-code

LLM context windows have a marketed size and a useful size, and they're not the same number. Research shows quality degrades gradually based on absolute token count, not fill percentage, and a 1M-token model at 40% full is far more degraded than a 200K model at 40%. Here's the research behind the Smart Zone, the Warn Zone, and the Dumb Zone, plus a Claude Code statusline that tracks which zone you're in and how deep.

08

Benchmarks vs Vibes: Opus 4.6 vs Opus 5 for Daily Coding

aiclaude-code

Opus 5 scores 96.0% on SWE-bench Verified vs Opus 4.6's 80.8%, a 15-point gap. But on blind user-preference coding leaderboards, Opus 4.6 ranks 4th (ELO 1547) while Opus 5 ranks 11th (ELO 1530). Synthetic benchmarks and human preference are telling opposite stories. I ran a two-round adversarial research workflow to figure out which signal to trust and landed on a mixed-model strategy.

09

Near-Miss Retrieval in RAG: Semantic vs Hierarchical Chunking

airagretrieval

The retrieval pipeline returned chunks that mentioned vaccination schedules but didn't contain the actual schedule data. The model saw evidence that was on-topic but empty of the answer - and correctly refused. The root cause wasn't the model, the reranker, or the query. It was the chunking strategy splitting tables and structured data away from the prose that named them.

10

Stochastic Refusal in RAG: Same Evidence, Different Answer

airagretrieval

Same question, same branch, same retrieval, same 10 evidence chunks with identical rerank scores - and one deployment refused while another answered with full clinical detail. The root cause wasn't retrieval. It was the LLM making a borderline judgment call on evidence that covered half the question well and the other half barely at all.

11

Reranking in RAG: Cross-Encoder Scoring for Recall and Precision

airagretrieval

Vector search finds the right chunk but ranks it badly and waves through near-garbage that's vaguely on-topic. Reranking fixes that with a second model - a cross-encoder that reads the query and each chunk together instead of comparing two frozen vectors. The whole trick is affording an expensive judge by only running it on the cheap stage's survivors.

12

Agentic Engineering at Airvet: Research, Plan, Implement

aiproductivity

A talk I gave to the Airvet engineering org on working with AI coding agents - the mental model, context engineering, and the Research → Plan → Implement loop that ties them together.

13

AI "Overview": GPT, RAG, and How They Actually Work

ai

A talk I gave to the Airvet engineering org as a primer on AI - what GPT and RAG actually are, how neural networks, tokens, and embeddings fit together, and why the difference matters.