Skip to content

fix(adapters): resume paused runs with their own turn's tool results - #1899

Merged
elie222 merged 4 commits into
mainfrom
codex/resume-paused-turn-context
Oct 22, 2026
Merged

elie222 merged 4 commits into
mainfrom
codex/resume-paused-turn-context

Conversation

@elie222

@elie222 elie222 commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Why

When a run paused for an approval, a question, a takeover or a secret, the next attempt rebuilt its context from the thread's messages only. The tool calls and results from the paused turn were gone, so the bot repeated work, sometimes picked a different tool than the one that was approved, and could hit a second approval card.

What changed

  • When a run pauses, it saves the turn so far (its tool calls and results), encrypted like other content and tied to the run. Nothing keeps running while it waits, and nothing large goes into the events clients sync.
  • The next attempt restores that turn before its first model call. The approved call runs exactly as approved and its result goes back on the original tool call. Answers and takeover hand-backs complete the call that asked for them.
  • Restored results go through the existing context budget and screenshot pruning. The restored prefix is unchanged from what the model saw before, so the prompt cache can still be reused. Thinking from a different model is stripped.
  • Tool calls still run in parallel. If a sibling call hadn't finished when the run paused, it isn't run again; it gets the existing "outcome unknown" result so the bot checks before retrying.
  • A resumed attempt counts as having seen outside content, so approval checks are never weaker than before.
  • If a saved turn can't be used (older format or the tool is no longer available), the run falls back to the old behaviour, and the approved call still replays exactly. If it can't be decrypted, the run fails before calling the model or any tool.
  • Saved turns are cleared when the run completes, fails or is cancelled, and are deleted along with the run or space.
  • No migration: saved turns use the existing effects table under a reserved kind, which is kept out of approval queues and effect replay.

Tests

  • Offline tests with the model emulator and the real executor: a tool result carrying a marker, then a pause for approval, a question or a takeover. After resuming, the first model request contains the earlier call and its marker, the approved call ran once with its approved arguments, and no second card appeared. These failed before the fix.
  • Runtime tests cover all four pause kinds, parallel batches (finished vs unfinished siblings), a sequential tail that never started, and a later question in the same turn.
  • Unit tests cover the saved format round trip, dropping an aborted reply, stripping thinking across models, the context budget and pruning on restore, encryption and binding to the run, stale-writer rejection, cleanup on cancel, complete and fail, fallbacks, and keeping the reserved rows out of effect handling.
  • The adapters, db, adapter-kit, contracts, api and testkit suites pass locally, apart from two shell-script test files that fail the same way on main on this machine. Postgres-backed tests are left to CI.

Fixes #1884

Human waits ended the runtime, and later attempts rebuilt only thread history, discarding the paused turn's tool calls and results.

Persist an encrypted, lease-fenced transcript at each human pause and restore it before the next model request. Resolve pending approved calls through the executor while retaining tool IDs, context limits, taint checks, and terminal cleanup.

Fixes #1884
@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
rakazo-www Skipped Skipped Oct 22, 2026 7:06pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] No new blocking issue was established in the changes since the previous review.

Summary

Paused runs save and restore their turn's tool calls and results before asking the model to continue.

  • Paused runs resume with the model turn and pending tool call that led to the wait.
  • Each paused run keeps its checkpoint private and clears it when work ends.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Tool call needs human input] --> B[Save encrypted turn]
  B --> C[Release worker and wait]
  C --> D[User answers or approves]
  D --> E[Restore saved calls and results]
  E --> F[Complete pending call]
  F --> G[Apply context limits]
  G --> H[Continue model turn]
  H --> I[Clear saved turn on terminal outcome]
Loading

Reviews (3) · Last reviewed commit: "fix(adapters): only reuse saved effect k..." · Reviewed by Greptile

Comment thread packages/adapters/src/pi-runtime.ts Outdated
Comment thread packages/adapters/src/pi-runtime.ts
Comment thread packages/adapters/src/executor.ts Outdated
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Playwright screenshots

No new feature frames; gallery is suite-vs-main drift.

Open screenshot gallery · Dashboard · CI run

Updated for commit 9f45a18.

Comment thread packages/adapters/src/executor.ts Outdated
@elie222
elie222 merged commit 3f88661 into main Oct 22, 2026
27 checks passed
@elie222
elie222 deleted the codex/resume-paused-turn-context branch October 22, 2026 19:26
fgbhhnnn added a commit to fgbhhnnn/rakazo that referenced this pull request Oct 23, 2026
Keeps fork dispatcher design (hidden workers, no Stop, busy indicator, owner-managed
deployment settings); takes upstream bug fixes from elie222#1685/elie222#1891/elie222#1920/elie222#1899 and the
interactive/background worker lanes with hidden workers forced onto the background lane.

This branch was previously deployed

1 inactive deployment
Preview — 9f45a189 Deployed Oct 22, 2026 by vercel[bot]
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.

[Bug]: Resumed runs lose the paused turn's tool results (approvals, questions, takeovers, retries)

1 participant