Skip to content

Declared tools a client answers: hold, then park, with gates - #248

Merged
lydakis merged 3 commits into
mainfrom
claude/project-thread-qzgtqy
Oct 28, 2026
Merged

lydakis merged 3 commits into
mainfrom
claude/project-thread-qzgtqy

Conversation

@lydakis

@lydakis lydakis commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

This is step 2 of the tool-or-command rule (design page; George picked "Hold, then park"). Today a declared tool only records a fixed result. This change lets a client answer the call itself, so the next PR can turn Sonny's agent-only commands into tools: task start and rm, show, run, the lookout subscriptions, and project add.

What changes

  • answered_by: TAG on a declared tool (with expire_ms, 1 ms to 1 h, default 60 s) takes the place of result. A call that fits the tool's parameters starts and then waits. Its tool_started names answered_by and expires_ms.
  • tool_result {bot, turn, call_id, output | error{code,detail}} answers a call.
    • Only the first answer counts.
    • The other cases get typed errors: call_already_answered, no_pending_call (the call ended or ran out of time), stale_turn, invalid_tool_result and tool_output_limit.
    • output and detail are each capped at 64 KiB and redacted the same way command output is.
  • tool_calls {tag, after?, limit?} lists the calls still waiting, oldest first and paged. A client that starts late or restarts uses it to catch up.
  • Hold, then park. The turn holds live for min(approval_hold_ms, 250 ms).
    • An answer that arrives during the hold is written with the call's result.
    • After the hold, the turn parks the way wait does: turn_waiting {call_id, answer, deadline_ms}, also shown in the view as waiting_on.
    • A parked turn holds no task and no slot, and survives a restart.
  • Expiry. A call with no answer by expires_ms ends with {"error":"tool_unserved"} and the turn goes on. If a later call's gate lapses first, the wait ends the same way and the turn ends as a turn waiting on a verdict does.
  • Gates can name declared tools on create, fork, set_gate and configure. On configure, the gate is checked against the declarations sent in the same request. A gate's tool limit is now the registered tools plus MAX_DECLARED.
  • inherit: false (Sonny: group the lead's tasks by state in /status, and let the lead resolve them #244) works with answered tools unchanged.
  • Versions: protocol 21 (Sonny: group the lead's tasks by state in /status, and let the lead resolve them #244 took 20) and schema 55 (new answers table, no data to move).

Where this differs from the design page

  • No serve_tools lease and no tool_requested push. A client follows * or calls tool_calls, so nothing that isn't durable can be lost. A tag is the client's to serve.
  • No expired: true flag on tool_completed. The expiry is the typed tool_unserved output.
  • The live hold is capped at 250 ms.

Measurements

Main is cf8cf65. Full tables are in docs/DAEMON_MEASUREMENTS.md, under "Answered declared tools". All figures are per turn.

p50 p99 CPU fsync
main, fixed declared 10.20 ms 15.29 ms 7.55 ms 6.26
this, fixed declared 9.83 ms 16.15 ms 7.60 ms 6.26
this, answered in the hold 10.43 ms 19.71 ms 8.10 ms 6.27
this, answered after parking 12.95 ms 19.04 ms 9.85 ms 9.33

An answer within the hold adds no fsync. The 32-bot completion burst and the 32-bot echo lifecycle are within noise of main.

Tests

  • tests/test_answered.py (9 tests):
    • validation
    • an answer within the hold
    • a parked answer, and an error as the answer
    • a call nobody serves, both live and parked
    • restart and interrupt while parked
    • a gate before the answer
    • a later gate lapsing
    • configure declaring and gating at once
    • a call that doesn't fit
  • A store contract test for paging past held answers and refusing an answer that arrives too late.
  • cargo test --workspace --no-fail-fast passes except two SandFS tests in sonny/tests/task.rs, which also fail on main in this container without fusermount3. CI installs fusermount3. The full runtime suite passed before the merge with main.

No visible change, so no screenshots.

🤖 Generated with Claude Code

A tool declared with `answered_by: TAG` takes no fixed result. A call that
fits its parameters waits for the answer of whichever client serves that
tag. The client finds it by following the bot (`tool_started` carries
`answered_by` and `expires_ms`) or with `tool_calls {tag}`, and answers with
`tool_result {output | error{code,detail}}`. The turn holds live for up to
250 ms, then parks like `wait` and survives restart. A call nobody answers by
`expire_ms` (default 60 s) ends as a typed `tool_unserved` result, and the
turn goes on.

Gates may now name declared tools, so a client's tool can need approval
before it is asked. Protocol 20, schema 55 (`answers` table).

The approval_overhead bench gains declared, answered and answered_parked
arms. Measurements are in DAEMON_MEASUREMENTS.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGErsjQZRay4MEvYNpr
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 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-28T01:24:24.542537Z 5da71f2 Manual request
🔒 Security Review ✅ Completed 2026-10-28T01:26:03.307439Z 5da71f2 Manual request
ℹ️ 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.

@lydakis lydakis self-assigned this Oct 28, 2026

@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: fe46346eb0

ℹ️ 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/store/db.rs Resolved
Comment thread src/store/db.rs Resolved
Comment thread src/store/db.rs Resolved
Comment thread src/store/db.rs Resolved
# Conflicts:
#	docs/RUST_PROTOTYPE.md
#	src/tools.rs
#	tests/store_contract.rs

lydakis commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

@codex review


Generated by Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 5da71f2d98

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 5da71f2d98

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@lydakis
lydakis merged commit cd2dbcf into main Oct 28, 2026
3 checks passed
lydakis pushed a commit that referenced this pull request Oct 28, 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.

2 participants