DEV Community

Gautam K
Gautam K

Posted on Fully Autonomous

How do you hand a half-finished task from one AI agent session to the next?

Long tasks rarely finish in one agent session. Context fills up, the session ends, or you stop for the night, and the next session starts cold.

What I keep losing in that handoff is not the code. It is the why: which approach was tried and dropped, what is half done, and what the agent was about to check next.

So I'm curious how other people do it:

  • Do you have the agent write a handoff note before it stops, or do you write it yourself?
  • Where does it live: a file in the repo, the PR description, an issue, or just the chat history?
  • How do you catch a note that is out of date because work kept going after it was written?

Would love to hear what actually works for you, and what you tried that didn't.

Top comments (5)

Collapse
 
gimalay profile image
Dmytro Halichenko •

For the 'why' I stopped putting it in the handoff note at all. Each rejected approach or standing rule is its own small markdown file with a status line, and a decision that reverses an older one names it, so the old one flips to superseded. The next session loads only the active ones. That covers the case @jacksonxly describes: a stop rule that was lifted is no longer in what the agent reads. The SHA stamp from @parlup is what I'd use for the code state. (I work on iwe, an open-source CLI; the session reads iwe find --filter '{status: active}', though a grep on the status line works too.)

Collapse
 
gautamtalksdev profile image
Gautam K •

One small file per decision with a status line, and a reversal that names what it supersedes, is a clean fix for the stale stop rule. Loading only the active ones means the old rule simply disappears from what the agent reads.

Collapse
 
parlup profile image
parlupme •

The pattern that has held up best for us is treating the handoff note as a SHA-stamped sidecar, not prose written at the very end:

  1. Write incrementally, not at shutdown: Sessions rarely die gracefully—context limits, rate limits, or manual stops cut them short. Appending structured entries at milestone boundaries (e.g. a pre-compact hook or after each failed/passing test run) beats asking for a summary when the context window is already full.
  2. Separate code state from rejected hypotheses: Put current_head, dirty_files, and last_verified_cmd (exact command + exit code) at the top, followed by ruled_out (approach -> exact failure). Keeping rejected paths explicit stops the next session from re-trying the same dead end.
  3. Catching stale notes: Stamp the handoff with git rev-parse HEAD plus a hash of git diff (stored in .git/agent-handoff.md or a draft PR comment so it doesn't pollute commits). On resume, the first step checks whether HEAD or the working-tree hash moved since the stamp; if it did, the agent reads git diff <stamped_sha>..HEAD before trusting any claim in the note.
Collapse
 
jacksonxly profile image
Jackson Ly •

The handoff that went stale on me carried a stop rule, which a check on the code wouldn't flag. One run ended with a checkpoint that forbade new work, and in the next session I changed the goal and asked for a slower pace. The lead agent messaged some areas individually and forgot the rest, so several agents spent the morning declining to run anything, correctly, under an instruction that had expired. It only surfaced when one of them reported it was idle under a rule it hadn't been told was lifted.

Collapse
 
alexcodebytes profile image
Oleksandr •

I think the most valuable part of a handoff is making the next session understand not just the current state, but the reasoning that led there.

I'd want the agent to leave three things behind:

  1. Current state: what has been completed, what is partially done, and what remains.
  2. Decisions and rejected approaches: what was tried, why it didn't work, and which assumptions are still unverified.
  3. Next action: the exact thing to investigate or do first, including any relevant files or tests.

I'd keep that in a handoff file inside the repository rather than relying on chat history. The repo is where the actual work lives, and the note should travel with it.

One extra safeguard I'd use is to update the handoff at the end of the session, not just when the agent first announces it's running out of context. Otherwise, the note can describe a project that no longer exists in that state.

The interesting challenge is that an AI agent can summarize what it did, but it doesn't always recognize which decisions will matter to the next session.

What's your most reliable way of preserving that missing context — especially the reasoning behind decisions that aren't obvious from the code?