LLM hallucinates router import from @appdeploy/sdk when backend diffs fail

Resolved 💬 2 comments Opened Feb 25, 2026 by realcryptomer Closed Feb 28, 2026

Problem

When the coding agent's first deploy_app call fails due to a bad diffs[] match on backend/index.ts, it retries by sending the full file as content instead. When rewriting from scratch, it imports { router } from @appdeploy/sdk — which doesn't exist. This causes (0 , x.router) is not a function at runtime.

The router function is defined inline in the backend template (common-ts/templates/backend.ts line 205), not exported from the SDK. The LLM sees import { db, storage, ws, auth } from '@appdeploy/sdk' and assumes router comes from there too.

Root Cause

The deploy instructions reference router() multiple times without clarifying it's a local function defined in the template:

  • "frontend+backend: extend backend/index.ts template. Add routes to the router() call using diffs."
  • "confirm backend template is extended via diffs (e.g., add routes to router() in backend/index.ts)"

When the agent switches from diffs to full content, it loses the inline router definition and hallucinates the import.

Evidence

  • App 07f24c2ce11a4a99b5 (yaron stage): (0 , I.router) is not a function
  • App 6e9519868edd4fa3a1 (yaron stage): (0 , x.router) is not a function, then on retry (0 , x.json) is not a function
  • e2e test "PhotoShare" burns 3-4 deploy_app calls on this pattern

Possible Fixes

  1. Add explicit instruction: "router is defined inline in the backend template — do NOT import it from @appdeploy/sdk"
  2. Move router into the SDK so import { router } from '@appdeploy/sdk' actually works
  3. Add router to the SDK type declarations (types.d.ts) so the agent sees it as an available export

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗