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 (2)

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
 
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?