8 min read
The eight missing tokens that weren’t
A coding agent flagged eight design tokens as absent from the new package. They all existed; the paths were simply wrong. How that early report shaped the briefs we used to migrate 49 token factories safely across 13 waves.
Two weeks before the first migration wave, a coding agent handed me a gap report. It claimed eight design tokens were missing from the new token package. All eight existed. The agent had simply used the wrong paths.
That report changed how I wrote every brief that followed.
Over four weeks and 13 waves, the agent produced 49 token factories for the next generation of our component library's design system. Each wave landed as a single-commit PR, adding roughly 11,100 lines in total. Five of the 13 PRs merged with exactly the code that was first opened for review. Here's what went into the briefs that made this possible, what still broke, and how I measured whether something was right the first time.
The dump technique behind the byte-identical checks has its own article: How to prove your refactor changed nothing.
What we were building
Each component family has token factories that turn the design token tree into the values its styles read. The legacy output had to remain byte-identical. The new factories map values from the token package, which we pin in the repo using frozen JSON snapshots. Any family without a new factory silently keeps the legacy values.
Three layers of guidance
We worked with three levels of documentation.
The first was a plan document that applied to every wave. Everything in it followed one central rule: the old factories define exactly what a component receives. Same keys, nothing added, nothing dropped. The token package only supplies values. If a key has no counterpart in the new package, we keep the old hard-coded value and record it in the spec as a finding rather than a defect.
Its definition of done added ten extra gates on top of tests, type checking, and linting. These included matching the legacy key set exactly, writing a unit spec for each factory, updating visual snapshots, and landing each change in a single commit.
The second was a reusable command that encoded the full process: read the token tree, write a spec, get it reviewed, create a plan, review that, implement, run all the gates, make one commit, review the diff, and answer six standard questions in the PR description. The spec mattered most. It captured every token finding exactly as reported, noted what the tree didn't contain, and provided a clear mapping from each output key to its source in the new tree, or to a literal value plus the reason for keeping it. The spec then received two separate reviews from fresh subagents. This approach forced reviewers to engage with the document itself rather than the reasoning that produced it.
The third was a short kickoff note for each wave, usually drafted at the end of the previous wave's session. It listed which components were next, restated the PR rules (one PR, one commit, off main, no stacking), and offered any useful hints. One kickoff suggested the modal's backdrop could reuse the overlay factory migrated a wave earlier.
That hint was incorrect. The overlay factory has no scrim. The agent implementing the wave pointed this out. It served as a reminder that briefs written by agents can be just as fallible as the ones I write. Later briefs added two sections that proved especially useful: "why this exists (don't re-derive)" for decisions that were already settled, and "escalate instead of guessing" for clear stop conditions.
How we verified each PR
Before a PR existed, the output had to pass multiple checks.
Five fresh reviewer subagents reviewed the work: two on the spec (correctness and over-engineering), one on the plan, and two on the commit. Transcripts from waves 2 to 11 show this process, though one wave skipped the plan review.
All the gates had to pass: tests, type checking, linting, a dependency-version check, and a cross-theme contract test.
For the four waves that moved legacy factory code we also required a before/after dump. One additional wave moved some legacy code without producing a dump.
After that came a review bot, a human reviewer, and a triage command that validated every review comment against the code and snapshots before suggesting fixes. I reviewed the visual snapshots myself.
In the ten wave sessions with transcripts, the only things I typed before a PR existed were the kickoff and either "create PR" or "don't create a PR yet." Time from kickoff to open PR ranged from 35 to 90 minutes.
The false missing-token reports
Let's go back to that initial gap report.
Before the waves began, I used the agent's help to move 51 files from a product app onto the new token package. The agent then produced a list of what it believed the package lacked. The draft listed eight tokens as missing that were really just wrong paths.
I can't show you the original eight. The draft was never committed and the transcript is gone. What survived includes:
- The committed report names the exact package version it was checked against and lists four tokens that truly are missing.
- One remaining note on the border-radius scale correcting an earlier claim and confirming the scale is complete.
- Documentation of the underlying problem. The token tree has five different leaf shapes and no consistent rule for which one you receive. Some intents are plain strings, some nest by state (
.default), some by step (['100']). One level off in any direction and you getundefined, which looks exactly like a missing token.
Three days later we added a new first step to the handoff brief: phase 0. Every token name and value in the brief counted as unverified until we re-derived it from the installed package. No code was written until we had one unambiguous mapping. Phase 1 waited on that mapping: a table with a column per theme where every cell was either resolved or explicitly marked as a gap.
The rule only partially carried over to the waves. Spec reviewers verified that every key cited in a spec existed in the tree. That catches wrong paths. It does not catch a mistaken claim that something is absent. In wave 11 the spec took a slider's thumb size from a legacy literal. There are three relevant slider paths (rail color, thumb width, and thumb height), but the spec only used one. This command finds all three:
jq -r 'paths(type != "object" and type != "array") | map(tostring) | join(".")' tokens.json | grep -i slider
A reviewer blocked the PR. The next brief added a clear rule: before claiming the tree doesn't ship X, search every path for X.
A check you can run
This script lists the installed package's vocabulary, or validates claimed paths and tells you whether a miss stopped short or went too deep:
// Usage: node token-paths.mjs <package> <json file in the package> [claimed.path ...]
// No claims: print every leaf of the INSTALLED package. With claims: check each one.
import { createRequire } from 'node:module';
import { readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
const [pkg, file, ...claims] = process.argv.slice(2);
// Resolves "<pkg>/package.json" from the current directory. If the package's
// "exports" map hides package.json, pass its folder as ./path instead of the name.
const root = dirname(createRequire(join(process.cwd(), 'x.js')).resolve(`${pkg}/package.json`));
const { version } = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
const tree = JSON.parse(readFileSync(join(root, file), 'utf8'));
const leaves = (node, path = []) =>
node && typeof node === 'object'
? Object.entries(node).flatMap(([k, v]) => leaves(v, [...path, k]))
: [[path.join('.'), node]];
const all = new Map(leaves(tree));
const show = (v) => JSON.stringify(v);
if (claims.length === 0) {
for (const [path, value] of all) console.log(`${path}\t${show(value)}`);
console.error(`${pkg}@${version} ${file}: ${all.size} leaves`);
process.exit(0);
}
let bad = 0;
for (const claim of claims) {
if (all.has(claim)) { console.log(`ok ${claim} = ${show(all.get(claim))}`); continue; }
bad++;
const kids = [...all.keys()].filter((p) => p.startsWith(`${claim}.`));
if (kids.length) { console.log(`BRANCH ${claim} has ${kids.map((p) => p.slice(claim.length + 1)).join(', ')}`); continue; }
const parts = claim.split('.');
const leafAbove = parts.map((_, i) => parts.slice(0, i).join('.')).find((p) => all.has(p));
console.log(leafAbove
? `TOO DEEP ${claim}: ${leafAbove} is already a leaf = ${show(all.get(leafAbove))}`
: `MISSING ${claim} (not in ${pkg}@${version})`);
}
process.exit(bad ? 1 : 0);
Running it against a toy package looks like this:
$ node token-paths.mjs @acme/tokens dist/tokens.json color.icon.strong color.text.body \
color.icon.strong.default radius.m z-index.modal
ok color.icon.strong = "#3c3c3c"
BRANCH color.text.body has default, inverse
TOO DEEP color.icon.strong.default: color.icon.strong is already a leaf = "#3c3c3c"
ok radius.m = "4px"
MISSING z-index.modal (not in @acme/tokens@4.2.0)
It exits with code 1 on any failed claim, so it can gate a spec. MISSING is a candidate gap. You should search the full listing before claiming one. BRANCH and TOO DEEP are the signatures of a wrong path.
What else went wrong
A few other issues surfaced during the migration.
Wrong premises in briefs that the implementing agent caught: the plan's suggested overlay source, a status-color branch the new tree doesn't have, and the backdrop hint mentioned earlier.
One error made it through: a brief described a set of snapshots as "unread" when they were in fact read. The review bot caught it.
An exact-paste instruction copied its own bug. A brief shared by three parallel waves told the agent to insert a type directly above an interface. This detached the interface's documentation comment. All three branches needed amending.
Wave 0 added a key that the legacy shape lacked, violating the plan's central rule. The reviewer caught it.
Wave 2 passed narrow subtrees to factories where neighbors received the whole tree. I caught it in review.
The key-set gate was mostly asserted rather than tested. One wave turned it into an actual test. An audit after the last wave found that legacy and new key sets had drifted in 17 families. The final guard we added freezes that drift per family and only allows it to shrink. It is the ratchet described in Making migrations stick.
Tooling caused problems too. Stale agent worktrees were not lint-ignored, producing 8,009 errors from 16 worktrees while the real tree had zero. Piping lint output into tail also hid the exit code twice.
How often did we get it right first try?
Here "unit" refers to the wave PR. There were 13 in total. For each force-push I compared commits before and after with git patch-id, inspected changes file by file, and read the review threads.
| After the PR was opened | Waves |
|---|---|
| No code change, only rebases | 1.5, 5, 6, 7, 8 (5 of 13) |
| Rendered defect fixed | 11 (slider thumb) |
| Fixed, no rendered change | 0 (extra key), 2 (narrow subtrees), 3 (a hardcoded width now derived), 9 and 10 (type placement from the shared brief) |
| Cleanup, or cause not on record | 1 (two legacy bodies restructured, reason not recorded; reviewer cleanups moved to a later PR), 4 (one shared font constant I chose to take) |
No wave needed a later bug fix on main for its own output. The 17-family key-set drift is what this table misses.
A few limits worth noting. The first three waves predate the transcripts I kept. "First attempt" means after the agent's own reviews, not its raw initial draft. Approval of visual snapshots is not counted. And patch-id changes when a rebase resolves conflicts or shifts surrounding lines, so I checked every flagged push manually.
The brief template we settled on
# <Wave N>: <components> (<ticket>)
Repo agent rules and the plan's governing rule beat this brief.
## Context
What the code does, what must stay byte-identical, what's out of scope.
Settled (don't re-derive): <decision>: <reason>.
## Verify (don't trust)
Token paths here are hints. Print the installed version and list the real
tree first. Before writing "X is missing", search all paths for X and paste
the command and output into the spec.
## Steps
1. Spec: findings verbatim, mapping (key -> source, or literal and why).
2. Fresh reviewers: correctness (cited paths exist AND absence claims were
searched), over-engineering. Then a reviewed plan. Implement.
3. Dump protected outputs before and after; report N/N identical.
## Done
Tests, types, lint (never piped into tail), dependency check. One commit.
## Escalate instead of guessing
Stop and record a blocker if a protected output would change, no source
exists, or a gate fails outside your diff.
## Output
Spec at <path>; status on each state change; no PR until I say so.
Every failure we saw came from a confident claim that no one had checked. Every useful line in these briefs turned that kind of claim into a specific command whose output then lived in the document.