Skip to content

One turn view for wait, interrupt and turns - #95

Merged
lydakis merged 5 commits into
mainfrom
claude/project-thread-7oycm8
Oct 10, 2026
Merged

lydakis merged 5 commits into
mainfrom
claude/project-thread-7oycm8

Conversation

@lydakis

@lydakis lydakis commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Before: each reply described a turn its own way. wait showed a running turn as only {"pending": true}. interrupt answered {turn, interrupt_requested}. A second interrupt that crossed the turn's own end failed with no_active_turn. A client that wanted the turn's status, tokens or what it was parked on had to make another call.

After: wait, interrupt and turns all answer with one turn view, read from the turn's row: bot, bot_id, turn, handle, request_id, status, waiting_on, tokens, rounds, retries and timing. interrupt is idempotent. A turn that already ended answers with how it ended and interrupt_requested: false.

This is C3 of the CLI feedback plan (agent-notes/shipping-plan/PLAN.md) and follows the "one turn view" rule in API_DESIGN.md. It sets no defaults of its own; --effort and duration flags come in C4. Protocol goes to 8.

What a client sees

Captured with the synthetic model on a scratch store. One held turn: wait with timeout_ms: 0, then interrupt, then interrupt again after it ended.

# before (main)
wait       {"pending":["turn:Bob/1"],"results":{"turn:Bob/1":{"pending":true}}}
interrupt  {"result":{"interrupt_requested":true,"turn":1}}
again      {"error":"no_active_turn","detail":"Bob is running no turn","running_turn":null,"status":"interrupted"}

# after
wait       {"pending":["turn:Bob/1"],"results":{"turn:Bob/1":{"bot":"Bob","bot_id":1,"turn":1,"handle":"turn:Bob/1","request_id":"1","status":"running","waiting_on":null,"pending":true,"input_tokens":0,...,"started_ms":...,"finished_ms":null}}}
interrupt  {"result":{"bot":"Bob","bot_id":1,"turn":1,"status":"running","interrupt_requested":true,...}}
again      {"result":{"bot":"Bob","bot_id":1,"turn":1,"status":"interrupted","interrupt_requested":false,"finished_ms":...,...}}

How

  • db.rs has one TURN_VIEW column list and one row reader, turn_view. waiting_on is null, {call_id, approval, deadline_ms}, {call_id, handles, any, deadline_ms}, or {resume_at_ms} for a paced turn. A finished turn's wait outcome and each turns item extend the view.
  • Database::turn_answer is how a client's wait reports a turn: a finished turn gives its outcome, a live one its view with pending: true, and one whose outcome retention pruned gives its view plus error: turn_result_pruned.
  • A client's wait reads the views of all its still-pending turns in one job on the reader connection, off the registry lock. The registry owns those reads, so shutdown ends them before stdout closes. A model's wait tool gets the turn's status and what its end recorded, error facts included, without the view's usage, timing and identity fields.
  • The wait waiter holds only a new store::Reader, not the writer Store. Holding the writer kept the publication stream open at shutdown.
  • interrupt answers with the view plus interrupt_requested. A queued, ready or parked turn ends in place, so its view already says interrupted. A turn the bot never had is turn_not_found. A turn that is starting, or is not the running one, is stale_turn. no_active_turn is gone from the protocol; the CLI keeps it for "this bot is running nothing".
  • agent interrupt [--pretty] prints the view. The app's swarm code drops its no_active_turn case.
  • bench/query_plans.py knows TURN_VIEW, so the view's queries are in the plan audit.
  • docs/RUST_PROTOTYPE.md and docs/CLI.md describe the view.

Performance

Daemon CPU, median of 15 runs (IQR), synthetic model on Linux. Before is main at #94, after is this branch. The script is in the ignored local directory.

Workload Before After
Finish 64 one-round turns 89.5 ms (86.1-101.5) 94.3 ms (84.0-99.0)
wait on 32 finished turns 3.1 ms (2.9-4.3) 4.0 ms (3.5-4.1)
wait on 32 pending turns 2.1 ms (2.0-2.5) 3.6 ms (3.2-4.2)

Finishing turns costs the same, within noise. A pending wait now reads each turn's row, about 45 µs per turn, in one reader job. Before, it read nothing and answered only pending: true. The finished-turn wait adds the view's columns to the outcome read it already made.

Checks

  • cargo fmt --check.
  • cargo clippy -p agent-runtime -p agent-client --all-targets -- -D warnings.
  • cargo test -p agent-runtime -p agent-client: all pass.
  • AGENT_TEST_RUNTIME=1 python3 -m unittest discover -s tests: 403 tests, OK (39 skipped).
  • node --test app/tests/state.test.cjs: 140 pass.
  • The plan audit (tests/test_query_plans.py) plans every TURN_VIEW query.

The app crate doesn't build on Linux. Its one change is a removed match arm in swarm.rs.

Declined review findings for this series are listed in #96.

🤖 Generated with Claude Code

wait, interrupt and turns answer with the same view of a turn, read from
its row: identity, status, what a parked turn waits on, tokens, rounds
and timing. A pending turn in a client's wait shows its view, read for
all pending turns in one job on the reader. interrupt answers with the
view and interrupt_requested, and succeeds on a turn that already
ended. Protocol 8.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01L9TT37y1798majTjQbUtZW
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T03:44:40.633615Z 12d47ad New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eac2622474

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/server/handles.rs Resolved
Comment thread src/store/db.rs Resolved
turn_answer gives a turn's outcome once finished, its view marked pending
while it runs, and its view with turn_result_pruned once retention removed
how it ended. The pending read after a deadline uses it too, so a turn
that finished meanwhile answers with its outcome, not as pending.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01L9TT37y1798majTjQbUtZW
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 753a9fa66f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/client.rs Resolved
Comment thread src/server/handles.rs Resolved
Comment thread src/server/handles.rs Resolved
The read of a wait's pending turns runs in the registry's JoinSet;
shutdown lets it finish within the drain deadline, then ends it before
stdout is joined, so it cannot hold an output open. A failed read gives
each turn the error, and only a vanished turn stays pending. interrupt
takes --pretty.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01L9TT37y1798majTjQbUtZW
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3540f4e533

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/server/mod.rs Resolved
Comment thread src/server/turn.rs Resolved
A model's wait dropped every outcome field outside a fixed list, so facts
like budget_tokens never reached it. It now removes only the turn view's
accounting fields, for pending and ended turns alike.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01L9TT37y1798majTjQbUtZW
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f88993cf9d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/server/handles.rs Resolved
Comment thread src/server/mod.rs Resolved
…-7oycm8

# Conflicts:
#	src/server/turn.rs
#	src/store/db.rs
@lydakis
lydakis merged commit f035751 into main Oct 10, 2026
1 check passed
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 12d47ad990

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/server/handles.rs
.into_iter()
.filter_map(|(text, bot, turn)| match db.turn_answer(&bot, turn) {
Ok(answer) => Some((text, answer)),
Err(error) if error.code == "turn_not_found" => None,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Read turn answers from one SQLite snapshot

When a timed-out or --any wait reads a turn while explicit or automatic retention is pruning it, this reader job can assemble an incoherent outcome: turn_answer separately queries the turn view, terminal event, last message, and node on an autocommit connection, so pruning may commit after the terminal-event query but before the message query. The response then reports a terminal turn with empty text instead of either its complete pre-prune outcome or turn_result_pruned; wrap the whole batch in one read transaction or fetch each answer from a single snapshot.

AGENTS.md reference: AGENTS.md:L32-L32

Useful? React with 👍 / 👎.

lydakis pushed a commit that referenced this pull request Oct 10, 2026
main's one turn view (#95) already moved the protocol to 8, so this
branch's required `workspaces` field moves it to 9.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01L7djWGZLxGzzTF3RkEShDN
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.

2 participants