Sub topic 14
Troubleshooting and known limits
This chapter assumes you have used agent mode in VS Code, know the agent loop, and can read a Git diff and run build or test commands in a terminal. It covers the failures you will meet most often and how to fix them.
Why agents fail
Most agent failures come from three sources: the agent lacks the right context, it lacks a way to check its own work, or the model reaches a limit. The agent loop is plan, call a tool, read the result, then repeat. A problem in any step carries into the next ones.
Lost context
Long sessions fill the model's context window. The agent then drops or summarizes older messages, so it may forget a constraint you set early on, or repeat work it already did.
Signs of lost context:
- It edits a file you told it not to touch.
- It asks for information you already gave.
- It reintroduces a bug it fixed earlier.
Fixes:
- Move lasting rules into an instructions file, so they are loaded on every request.
- Reattach the key files or selections instead of assuming the agent still has them.
- Start a new chat for a new task. Carry over only a short summary of what matters.
Runaway edits
A vague prompt such as "clean up this module" invites changes in many files. If the agent starts editing far beyond your intent, stop the request and review before you accept anything.
- Stop the running request, then look at the list of changed files.
- Undo the edits, or use
git restoreorgit checkouton paths you did not want changed. - Rewrite the prompt with a clear goal, named files, and a constraint such as "Do not change the public function signature."
Commit or stash before a large task. A clean working tree lets you discard the whole attempt with one command.
Failing tool calls
When a tool call fails, the agent usually reads the error and tries again. Look at the actual error message instead of guessing.
| Symptom | Likely cause | What to try |
|---|---|---|
| Terminal command never finishes | A watch mode, prompt, or pager is waiting for input | Stop it, then ask for a non-interactive command such as `npm test -- --run` |
| Command not found | The agent's shell lacks your PATH or environment | Check the terminal profile and run the command by hand |
| MCP tools missing | The server failed to start or was not enabled | Check the server status in your `.vscode/mcp.json` setup and the output log, then restart it |
| Repeated denied calls | You denied approval, or policy blocks the tool | Approve deliberately, or change the prompt so the call is not needed |
| Edit does not apply | The file changed since the agent read it | Ask it to re-read the file and try again |
Known limits
- Context window size. Every model has a maximum amount of text it can consider. Large repositories cannot fit, so the agent searches for pieces and may miss related code.
- Non-determinism. The same prompt can give different results. Verify with tests rather than trusting a result because it looked right once.
- Confident errors. The agent can call a function that does not exist or claim tests passed without running them. Check the terminal output yourself.
- Rate limits and quotas. Your plan or provider may limit requests. Long agent runs make many calls, so you may hit a limit mid-task.
- Availability differs by editor and plan. Features, model lists, and settings vary across VS Code, JetBrains IDEs, Cursor, and other editors.
A practical recovery routine
- Stop the run.
- Read the last tool output.
- Check
git diff. - Revert what you do not want.
- Narrow the prompt and add a verification step, then try again.
Exercise
The agent stops following your rule "use named exports only" about an hour into a long session. Name two ways to fix this and say why each works.
Show answer
Put the rule in a custom instructions file, because those are loaded on every request and do not depend on older chat history. Alternatively, start a new chat for the next task, because a fresh session has an empty context window. You can also reattach the relevant file so the rule is visible again.
Exercise
A task stalls because npm test never returns. What is the most likely cause, and what do you change?
Show answer
The test runner is in watch mode and is waiting for input. Stop the command and ask the agent to run a single-pass form, such as npm test -- --run, depending on your test runner.