agent hit context limit reading a 4000-line monorepo wrangler config, dropped the bindings
Fixes agents that truncate huge monorepo wrangler configs and lose the bindings sections. Use when the agent edits wrangler.toml and bindings silently disappear. Not for small config edits, binding value errors, or context limits in code files.
TL;DR
A 4000-line monorepo wrangler config does not fit in the agent's working memory, so the agent read part of it, edited blind, and dropped the bindings sections. Never let the agent rewrite a config it cannot fully read. Split the config per worker, or give the agent surgical edit tools that preserve what they do not touch.
The query
agent hit context limit reading a 4000-line monorepo wrangler config, dropped the bindingsUse this when
- Bindings vanish from wrangler.toml after an agent edit.
- The config is very large (monorepo, many envs).
- The agent admits (or the log shows) it did not read the whole file.
Not for
- Small configs with binding errors (different problem).
- Binding values that are wrong but present (value problem).
- Context limits hit on code files (different workflow).
Steps
Step 1: Restore the config from version control
git checkout -- wrangler.toml
git diff HEAD -- wrangler.tomlExpected result: the known-good config is back. Assess what the agent actually changed before restoring, so the intended edit is not lost.
Step 2: Reapply the intended edit surgically
Use a targeted edit (a script that modifies only the intended section) rather than a full-file rewrite.
Expected result: the intended change lands and every other section, including bindings, is byte-identical.
Step 3: Verify bindings survived
Diff the bindings sections before and after. Count binding entries.
Expected result: zero unintended changes. The diff shows only the intended edit.
Step 4: Split the monorepo config
Give each worker its own wrangler.toml in its own directory instead of one giant root config. Shared settings go in a documented template.
Expected result: each config fits comfortably in working memory. The structural cause of the truncation is gone.
Step 5: Ban full-file rewrites of large configs in the runbook
Expected result: agents use surgical edits (or config-splitting) for large files. The 'read part, rewrite all' pattern is prohibited.
Why it happens
Language models have finite working memory, and file rewrite is all-or-nothing: what the model did not read, it cannot reproduce. Large generated configs (monorepo env matrices) exceed that memory silently; the model does not always report the truncation. Bindings are just the most visible casualty.
Edge cases
- The agent may not realize it truncated. Always diff agent-edited configs, even when the agent reports success.
- wrangler.jsonc supports comments; a rewrite can also strip comments carrying important context. Diffs catch that too.
- If splitting is infeasible, generate the big config from smaller sources with a checked-in generator script.
- Validate with wrangler deploy --dry-run after every config edit. It catches missing bindings before they reach production.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_kzUajAlQ7qW0xGAZ5jTzGQ