Skip to content

In-session continuation behind token, idle, and bounds gates, accept DL-008 (+DL-013, DL-014) - #38

Closed
jimutt wants to merge 3 commits into
feat/dld-goal-ext-statefrom
feat/dld-goal-ext-loop
Closed

In-session continuation behind token, idle, and bounds gates, accept DL-008 (+DL-013, DL-014)#38
jimutt wants to merge 3 commits into
feat/dld-goal-ext-statefrom
feat/dld-goal-ext-loop

Conversation

@jimutt

@jimutt jimutt commented Aug 25, 2026

Copy link
Copy Markdown
Owner

What

In-session continuation: agent_end advances an active run when it is safe. The handler schedules a deferred dispatch (never awaits script calls inside the handler, because pi invalidates the extension runtime at session disposal), and the deferred callback re-checks gates and dispatches via pi.sendMessage with triggerTurn.

User input suspends continuation; /dld-goal resume and start clear suspension and dispatch immediately. Esc suspends the loop on abort detection (DL-014). Pause aborts the current turn via ctx.abort().

turn_end finishes the completion transaction. With review enabled the loop cannot accept; with review disabled it accepts with every write checked, aborting on the first failure.

Three facts from live testing reshaped the wiring, recorded as DL-013 and DL-014 amending DL-008.

Stacks on #37.

jimutt and others added 2 commits August 21, 2026 18:01
…ept DL-008

agent_end advances an active run when it is safe: token checked at entry
and again after the awaited script calls, idle and no pending messages,
on-disk status active, wall-clock bounds within limits, and next-item
selecting work. Empty next-item output means the run is complete, not an
error - the failure mode the first draft got wrong, spamming an error on
every turn after the last item.

turn_end finishes the completion transaction. With review enabled the
loop cannot accept - it notifies once that the review subagent must run
and the item stays verifying. With review disabled it accepts with every
write checked, aborting on the first failure so state and the event log
never contradict. Failures retry once, then block with the reason (DL-004).

Event handlers catch every error and notify rather than throw, because an
exception in an extension handler repeats on every turn for the rest of
the session. The empty start bug the user hit live - a run with no items
treated as an error forever - is the same class, fixed the same way.

The token gate is honest about what it guards: the in-flight race between
script calls and dispatch, not a queued continuation that does not exist.
The primary anti-stale guard is the on-disk status check.

Co-Authored-By: Claude Opus 5 <noreply@pi.dev>
Generated-By: pi 0.84.2
Three facts from live testing reshaped the wiring:

- isIdle() is false at agent_end in every mode (the flag clears only at
  agent_settled), so an idle gate at event time can never pass
- pi invalidates the extension runtime at session disposal and reload,
  so a handler still awaiting script calls dies with a stale-ctx error
- pi-goal-pro's production pattern is a setTimeout that returns from the
  handler immediately and re-checks gates in the deferred callback

The handler now schedules, the deferred callback dispatches via
pi.sendMessage with triggerTurn, and user input suspends continuation
until /dld-goal resume. Resume and start dispatch immediately so the
loop never waits for a turn that may not come.

DL-013 amends DL-008: the record's agent_end rationale was right about
the event, wrong about gating on idle at event time and about awaiting
in the handler. Verified end-to-end in RPC mode (resume dispatches a
second agent start).

Co-Authored-By: Claude Opus 5 <noreply@pi.dev>
Generated-By: pi 0.84.2
Co-Authored-By: Claude Opus 5 <noreply@pi.dev>
Generated-By: pi 0.84.2
@jimutt

jimutt commented Aug 25, 2026

Copy link
Copy Markdown
Owner Author

Superseded by feat/pi-harness-extension — all commits from this branch are merged there. See #41 for the findings log on top.

@jimutt jimutt closed this Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant