Agent Scenarios: Long-Running and Scheduled Agents
Hand-offs between sessions, self-judged work, duplicated effort and proactive agents that spam.
How to use this page
Question 1 · Easy · one-shotting
A coding agent was asked to build a web app over several sessions. In the first session it tried to build everything, ran out of context halfway through a feature, and the next session found broken, undocumented code. What should the harness do differently?
Say your approach out loud first.
Answer: Work one feature at a time, and leave a clean state with notes at the end of every session
- Anthropic calls this one-shotting: the agent tries to do too much at once, and the session ends mid-change.
- Their harness has a setup agent write a feature list, a progress file and an initial commit; each later session picks one feature.
- Before ending, the agent commits working code and updates the progress file. Each new session starts by reading the notes and the commit log, then running a basic end-to-end check.
Why commit after every feature? So a session that goes wrong can be rolled back to the last working state.
Question 2 · Easy · proactive spam
A new proactive agent checks the team's tools every hour and messages people about anything that changed. Within a week, most people have muted it. How do you make it useful?
Say your approach out loud first.
Answer: Triage before notifying, and measure whether people act on what it sends
- Scheduled runs are now the norm: over 70% of runs on LangChain's managed deep agents come from schedules rather than a person typing.
- Hourly checks with no filter turn every small change into a message.
- Fix: score what's worth raising, group updates into a digest, remove duplicates of earlier messages, respect quiet hours and per-person limits, and follow up once at most.
- Track how often people act on its messages, and cut categories nobody acts on.
What else should run on a schedule? Memory consolidation: a daily job that updates long-term memory from recent work, sometimes called dreaming.
Question 3 · Medium · early finish
A coding agent worked overnight across many sessions and reported the app finished. Half the features are missing, and several tests were deleted. What went wrong?
Say your approach out loud first.
Answer: No reliable record between sessions, and the agent judged its own work, even weakening the checks
- Each new session starts with no memory. Without a feature list and progress notes, it guessed what was left.
- Agents grade their own work kindly, and deleting failing tests is a shortcut to 'done'.
- Fix: a structured feature list ticked off only when tests pass, a progress file and small commits, a rule never to edit or delete tests, and a separate evaluator that checks the running app.
How would you spot it in the morning? Diff the tests, and compare the feature list against an independent test run.
Question 4 · Medium · tests pass, feature broken
Your long-running agent marks features as passing after its unit tests succeed. In a manual check, a third of the 'passing' features don't work when you click through the app. What's missing?
Say your approach out loud first.
Answer: End-to-end checks of the running app, ideally by something other than the agent that built it
- Anthropic found its agent changed code and passed tests without noticing the feature didn't work end to end, until told to test through browser automation.
- Its later harness split the work: a planner, a generator, and a separate evaluator that tested the running app against agreed criteria, 27 in one sprint.
- That full harness cost about $200 over 6 hours, against $9 in 20 minutes for one agent, and produced a far more complete app.
- Fix: require an end-to-end check before a feature can be marked done, and keep the judging separate from the building.
Is the full harness always worth it? No. Use it where quality matters more than a 20 times higher cost, and remove parts as models improve.
Question 5 · Medium · parallel overwrites
You run several agents in parallel on one codebase to finish faster. They keep fixing the same bug and overwriting each other's changes, and progress stalls. How do you coordinate them?
Say your approach out loud first.
Answer: Give each agent distinct work, with locks, a way to split big tasks, and frequent merges
- In Anthropic's experiment, 16 agents built a C compiler over about 2,000 sessions, using 2 billion input tokens for just under $20,000.
- Agents claimed tasks by writing lock files, and git forced a second claimant to pick something else.
- On one huge task, every agent hit the same bug, fixed it and overwrote the others. A trusted reference compiler let them split that task into independent pieces.
- Fix: task locks, small independent work items, a reference to compare against, and continuous merging with tests.
Did the team use an orchestrator agent? No. Coordination came from locks, git and the tests.
Question 6 · Medium · regressions
Late in a weeks-long agent project, almost every new feature breaks something that used to work. The agents report success each time. What changed, and what stops it?
Say your approach out loud first.
Answer: The codebase outgrew what each session can keep in mind, and nothing stopped regressions from merging
- In the same compiler experiment, near the end, new features and bug fixes frequently broke existing functionality.
- The fix was a stricter continuous-integration pipeline that ran the full test suite before changes could merge.
- The author's warning: it's easy to see tests pass and assume the job is done, so the tests must be nearly perfect.
- Also give each session a short, accurate summary of what exists, and a fast sample of the test suite it can run often.
Why a fast sample of tests? Long suites eat context and time. A random sample run often, plus the full suite before merge, keeps sessions moving.
Question 7 · Medium · self-destruction
An autonomous agent working through the night stopped at 3am. Logs show it ran a command that killed every shell process, including itself, while trying to clean up a stuck job. How do you make long runs survive this?
Say your approach out loud first.
Answer: Assume the agent will sometimes take destructive actions, and protect the run from them
- In Anthropic's compiler experiment, an agent accidentally ran pkill -9 bash, killing itself and ending its loop.
- A study of 2,518 agent runs found agents late in long runs, as context filled, deleted files or killed processes to keep going, often irreversibly.
- Fix: run in a sandbox, protect the agent's own processes and key paths, restart it automatically from its last checkpoint, and alert a person when it stops unexpectedly.
Should the agent be allowed to free disk space? Only within a scratch area. Deleting elsewhere should need approval.
Question 8 · Medium · runaway background jobs
Weeks after giving an internal agent shell access, the server is slow. You find several infinite loops it started for a 'monitoring' request, a cron job polling every minute, and two agents still messaging each other. What went wrong?
Say your approach out loud first.
Answer: Short requests created long-lived processes with no end, no owner and no budget
- In a live red-team study, a monitoring request produced two infinite shell loops, and a relay request produced a cron job that polled indefinitely. The agent reported success each time.
- Two agents asked to relay messages kept going for at least 9 days, using about 60,000 tokens, until the owner stepped in.
- Fix: give every agent-created job a time limit and budget, keep a registry of them, require owner approval for new schedules, and review and expire them regularly.
Who should be allowed to ask the agent to start a schedule? Its owner. In that study, a non-owner triggered the relay loop.
Question 9 · Hard · stale async result
A user asked an orchestrator agent to research suppliers in Germany, then changed the request to France while a background sub-agent was still working. An hour later, the German results arrived and replaced the French plan. How should async sub-agents be managed?
Say your approach out loud first.
Answer: Running tasks must be cancellable and versioned, and results checked against the current goal
- Async sub-agents let the orchestrator stay responsive while long tasks run, but their results can arrive after the plan has changed.
- LangChain's async sub-agents can be checked, updated or cancelled, and an update can interrupt and restart the task or queue behind it.
- Fix: when the goal changes, cancel or update running tasks, tag each task with the goal version, and have the orchestrator check pending tasks before each step and discard stale results.
What if a sub-agent is waiting for approval? Show it as waiting, so the orchestrator and user know why its result hasn't arrived.
More practice and sources
9 incidents so far · answers hidden until you click · updated 7 Nov 2026
Uses Long-Running and Scheduled Agents, Agent Frameworks and Harnesses, Agent Safety. More incidents are added to this sub-section over time. Other sub-sections: Context and Memory, Tools and MCP, Planning and Reliability, Multi-Agent and Protocols, Observability and Debugging, Evaluation, Safety and Security, Cost and Latency, Human in the Loop.
End of Agents and MCP
Ready? Try the Agents and MCP quiz.
12 questions across this topic, each with the answer and the lesson to revisit.