feat(coding-agent): let an extension run the turn - #3
Open
moedash wants to merge 3 commits into
Open
Conversation
3 tasks
pi runs a turn the moment a prompt is accepted, so nothing outside it can decide when the turn happens, and an extension has no handle on the session to do it itself. registerTurnExecutor hands the turn over instead. run() is the same turn pi would have run, so the transcript, the events and the streaming do not change.
A crash during a tool call leaves a call with no result, and nothing finishes it. An executor that asks for resumeOnStart gets that turn when the session is opened again, which is the half of durable execution that only shows up after something has already gone wrong.
`_drive` asks the runner whether an extension took the turn over, and a double built before that call has no method to answer with.
moedash
force-pushed
the
moe/step-and-resume
branch
from
September 7, 2026 23:39
989c52f to
5032328
Compare
moedash
force-pushed
the
moe/turn-executor
branch
from
September 7, 2026 23:39
c45555a to
c6190dc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed?
pi.registerTurnExecutor(executor, options?). Pi hands the turn to the executor instead of running it, and the executor decides when to callturn.run().run()is the same turn pi would have run, so the transcript, the events and the streaming do not change. An executor that returns without calling it holds the turn.With
resumeOnStart, opening a session also hands the executor a turn an earlier run left unfinished, which routes throughresumeInterruptedTurn()and so through the executor like any other turn.One executor wins, the first registration. None registered leaves pi running turns itself, which is every existing session.
Stacked on #2, which added
prepareStep()andresumeInterruptedTurn().Why?
Nothing outside pi can decide when a turn happens.
prompt()runs the turn the moment it accepts the text, and an extension has no handle on theAgentSessionto drive it instead:ExtensionContextgives a read-only session manager. So an extension that wants turns to go through a scheduler, or a durable executor, has to interceptinputand run the work in a session of its own, which leaves the transcript you are looking at empty.This is the seam that avoids that. The executor runs in this process against the live session, so what the user sees is pi's own turn.
resumeOnStartis the other half. A crash during a tool call leaves a call with no result and pi does not finish it, so the durability only shows up if something picks that turn up when the session opens again.How did you test it?
npm run checkpasses. New tests cover the default (no executor registered), first-registration-wins, a wrapped turn producing the same transcript as an unwrapped one, a held turn staying unrun, resume-on-start finishing an interrupted turn without re-prompting, and a finished session being left alone.