Designing Plans for Weak Coding Models
Don't give a weak model a big prompt — give it a small decision space. The strong model does all architecture, file localization, interface design, and edge-case enumeration. The weak model only executes one atomic, fully-specified, machine-verifiable change. Compilers, linters, and tests are the referees, not the weak model's judgment.
Maximize decision-removal, not prompt length.
Instead of this (bad — delegates decisions to the weak model):
Add login feature with JWT authentication.
Do this (good — zero architectural decisions left open):
YAMLtask_id: AUTH-03 objective: "Add password verification to existing auth service." allowed_files: - src/auth/service.ts - src/auth/service.test.ts read_context: - src/users/repository.ts#UserRepository.findByEmail - src/auth/errors.ts#InvalidCredentialsError - src/auth/token.ts#TokenService.issue do_not: - "Add new dependency" - "Change public method signatures" - "Refactor other files" implementation: - "Call findByEmail inside authenticateUser(email, password)." - "If user not found, throw InvalidCredentialsError." - "Compare passwordHash with bcrypt.compare." - "On success call TokenService.issue(user.id) and return { token }." acceptance_criteria: - "Valid user receives token." - "Unknown user throws InvalidCredentialsError." - "Wrong password throws InvalidCredentialsError." tests: - npm run typecheck - npm test -- src/auth/service.test.ts repair_policy: max_attempts: 2 escalate_if: - "public API must change" - "new dependency needed" - "test failure contradicts plan assumptions"
Progress:
- Step 1: Strong model explores repo, locates relevant files/symbols/contracts
- Step 2: Strong model decomposes feature into a dependency DAG of atomic tasks
- Step 3: For each task, fill the 11-field plan template (see below)
- Step 4: Weak model implements ONE task using only its given context
- Step 5: Run format → typecheck → unit test → integration test
- Step 6: On failure, feed back only the test output + task context, repair up to 2-3 times
- Step 7: On repeated failure / scope creep / missing requirement → escalate to strong model
- Step 8: Strong model does final cross-task review (interface consistency, security, regressions, full suite)
The 11 Required Fields Per Atomic Task
- Objective — one sentence
- Preconditions — which prior tasks must be done
- Read context — only the files/functions/types actually needed
- Targets to change — file path + class/function name
- Exact contract — signature, input/output, exception behavior, data model
- Do-not list — no new deps, no public API changes, no unrelated refactors
- Implementation steps — small, ordered
- Acceptance criteria — observable outcomes
- Test commands — exact commands to run
- Repair protocol — how many retries, in what scope
- Output format — changed files + test results + unresolved issues
Dependency DAG, Not a Flat Task List
T1: Update User type
↓
T2: Repository function
↓
T3: Auth service
↓
T4: API route
↓
T5: Integration test
Each task sees only the final contracts produced by its dependencies — never the full chat history of how those contracts were derived. This cuts tokens and prevents earlier confusion/errors from propagating forward.
Verification Loop (per task)
PLAN → IMPLEMENT → FORMAT/TYPECHECK → UNIT TEST → INTEGRATION TEST (if needed)
PASS → commit/checkpoint
FAIL → feed back only test output + task context → limited patch → retest
Escalation Rules (return to strong model when)
- Same test fails twice for the same reason
- Task requires touching a file not in
allowed_files - Public interface needs to change
- A new dependency becomes necessary
- Plan assumptions contradict repository reality
- Fix scope spreads across 3+ modules
- Model can't articulate why the acceptance criteria pass/fail
These are operational heuristics; the general principle backed by research is: only re-run the failed subtask, never the whole pipeline.
Example 1 — Feature decomposition
Input: "Add profile picture upload for users."
Output (task chain):
T0 [STRONG] — Repo discovery: locate User model, route layer, storage abstraction, test setup
T1 [WEAK] — Add avatarUrl field to User type + migration; typecheck
T2 [WEAK] — Implement uploadAvatar in existing StorageService interface; unit test
T3 [WEAK] — Implement uploadUserAvatar(userId, file) using T1/T2 contracts, reuse NotFoundError; unit test
T4 [WEAK] — Add POST /users/:id/avatar route, reuse existing auth middleware and validation rules; route test
T5 [WEAK] — Add integration test: success + invalid mime type
T6 [STRONG] — Full diff review, run entire test suite, check interface consistency/security/regressions
Example 2 — Bad vs good task granularity
Input: "Fix the bug where total price is wrong."
Bad output: "Find and fix the pricing bug." (no file target, no contract, no acceptance test — forces weak model to investigate and decide)
Good output:
YAMLobjective: "Fix tax calculation in calculateTotal() to apply tax after discount, not before." allowed_files: [src/pricing/calculator.ts, src/pricing/calculator.test.ts] implementation: - "Reorder: apply discount first, then multiply by (1 + taxRate)." acceptance_criteria: - "calculateTotal(100, 0.1 discount, 0.08 tax) returns 97.2, not 97.92" tests: ["npm test -- src/pricing/calculator.test.ts"]
- Minimum sufficient context, not maximum context. Send only the function body, its direct callers/callees, relevant types, and 1-2 nearby examples — not the whole repo.
- Let the model ask for context explicitly. If it needs more, it should emit a structured signal like
NEED_CONTEXT: <file/symbol>rather than wandering the repo freely. - Make tasks atomic: one logical purpose, ideally ≤2-3 files, clear inputs/outputs, machine-verifiable completion.
- Use schema-validated plan output (e.g. JSON Schema / Structured Outputs) to catch missing required fields before the weak model ever sees the task — but still validate business logic separately.
- Track metrics, not vibes: first-pass test rate, retries per task, tokens per task, escalation rate, regression rate.
- Cap repair attempts (2-3 max) then escalate. Repeated identical failures usually mean a wrong architectural assumption, not a typo — more retries won't fix it.
- Keep a strong final-review pass across the full diff; small models executing isolated tasks can still produce globally inconsistent results.
- Giving the weak model open-ended feature requests. It will make silent architectural decisions you didn't intend.
- Over-decomposing without branch/retry logic. Splitting into many tiny tasks doesn't save cost by itself — the savings come from re-running only the failed subtask, not from decomposition alone.
- Dumping the entire repository as context "to be safe." This increases cost and makes it harder for the model to identify what's relevant.
- Allowing unlimited local debug loops. Repeated failure on the same test is usually a planning/localization error, not something more retries will fix.
- Over-specifying unnecessary detail. Excess constraints increase token cost and can lock the model harder into a wrong path if the plan itself is slightly wrong.
- Carrying full task history forward. Downstream tasks should see finalized contracts from upstream tasks, not the reasoning/mistakes that produced them.