Repository navigation
Make create and fork safe to resend, and delete safe to repeat - #88
Conversation
`create` and `fork` take an optional `request_id`, stored with the bot (schema 44, a one-way column add). A resend with the same key and fields gets the bot it made with `duplicate: true` and writes nothing; the same key with another field is `idempotency_conflict` naming the field; any other request for a taken name is still `bot_exists`. `delete` takes `bot_id`: once that identity is gone a resend succeeds as a duplicate and never reaches a later bot of the same name. The CLI keys `run --new`'s creation with the run's request ID, so the exact command resent gets its bot and turn; `fork --request-id` and `rm --bot-id` expose the rest. Protocol 7. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01L9TT37y1798majTjQbUtZW
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 81c0e14cb3
ℹ️ 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".
| if let Some(key) = &request_id { | ||
| name(key)?; |
There was a problem hiding this comment.
Reconcile keyed creates before mutable prerequisites
When a keyed create is retried after the environment changes—for example, its workspace was removed or the daemon restarted without the original provider—the handler canonicalizes the workspace and requires that provider before db.create can perform its resend check. The exact retry therefore returns invalid_workspace or provider_unavailable instead of the stored bot with duplicate: true; look up and compare the durable request before validating prerequisites needed only for a fresh creation.
AGENTS.md reference: AGENTS.md:L31-L36
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving this as is. Here is the path I traced. A keyed create succeeds and its reply is lost. Before the resend, either the workspace is removed or the daemon restarts without that provider. The resend then gets invalid_workspace or provider_unavailable.
That error is true, and the caller can act on it. Nothing the bot would do next can run in that environment either: a run --new resend would fail at its submit for the same reason. Answering it as a duplicate would mean comparing the request before validating it, which needs a second path through create for a case where the caller is blocked anyway. Once the workspace or provider is back, the same resend gets duplicate: true.
Generated by Claude Code
| // One key for the creation and the submission, so resending the same | ||
| // command gets the bot and the turn it made the first time. | ||
| let request_id = options.request_id.clone().unwrap_or_else(|| unique("run")); |
There was a problem hiding this comment.
Bind the whole new-run command before submitting
If run --new --request-id K commits the creation but loses its connection before sending submit, retrying with the same key but a changed prompt is accepted: the creation record does not include the prompt, and no turn row exists yet to report idempotency_conflict, so the changed work runs on the previously created bot. This breaks the CLI-level guarantee that changing any field under the same key conflicts after ambiguous dispatch; persist the submission fingerprint with the creation or combine creation and submission atomically.
AGENTS.md reference: AGENTS.md:L31-L32
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving this as is. Here is the path I traced. run --new --request-id K commits the creation, and the connection drops before submit is sent. The caller then resends with the same key and a different prompt.
At that point the key has done no work, because no turn exists. The bot it made is checked field by field, so a changed bot is still idempotency_conflict, and the prompt runs once. The rule exists so that one key never stands for two different pieces of work, and here it stands for only one. Storing a submission fingerprint on the bot, or making create and submit one atomic operation, would tie the bot record to its first message for this one case.
Generated by Claude Code
… finish A delete resent with --bot-id now succeeds only for the name that held the identity (kept in deleted_bots), and one resent while the first still runs finishes beside it. A keyed fork resent after its source is gone is answered from the fork. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01L9TT37y1798majTjQbUtZW
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01L9TT37y1798majTjQbUtZW
…forks and deletes Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01L9TT37y1798majTjQbUtZW
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 820467b328
ℹ️ 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".
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01L9TT37y1798majTjQbUtZW
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 642fe932ce
ℹ️ 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".
…p; document protocol 7 retries Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01L9TT37y1798majTjQbUtZW
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e1b631d524
ℹ️ 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".
| tx.execute( | ||
| "INSERT INTO deleted_bots | ||
| SELECT id,name,json_extract(creation,'$.request_id') FROM bots WHERE name=?", | ||
| [name], |
There was a problem hiding this comment.
Preserve request fingerprints in deletion tombstones
After a keyed bot is deleted, this tombstone retains only its key, so resent() cannot compare the original request fields. For example, creating Bob with key K and model A, deleting it, then reusing K with model B returns bot_deleted rather than the documented idempotency_conflict; the same applies when changing a fork request. Fresh evidence in the final tree is the deleted_bots insertion extracting only $.request_id, despite the live bot retaining the complete creation request. Store a compact fingerprint or the request fields needed for conflict detection.
AGENTS.md reference: AGENTS.md:L31-L32
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Leaving the code as is and making the contract say what it does (0e45e70). Here is the path I traced. Create Bob with key K and model A, delete Bob, then send K with model B. That request is refused either way. bot_deleted with the deleted bot_id is the more useful answer, because the bot that key made no longer exists, which is what the caller needs to know before choosing a new key. Keeping the whole request on every tombstone would grow deleted_bots by a request per deleted bot just to pick between two refusals. The docs now say that once the bot is deleted, any request with that name and key is bot_deleted.
Generated by Claude Code
… sent Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01L9TT37y1798majTjQbUtZW
|
The findings declined here are listed in #96 with a reason each. Generated by Claude Code |
Before: if
agent run --new --bot NAME --request-id IDlost its reply, resending the exact same command gotbot_exists. To recover, the caller had to drop--newand pin a--bot-idit might never have received.forkhad the same problem. A delete resent after the name had been reused could delete the newer bot.After: resending the same command gets back what the first one made, marked
duplicate: true, and writes nothing. Reusing the same key with any field changed getsidempotency_conflict, and the error names that field indetailandfield. A name taken by any other request is stillbot_exists.rm --bot NAME --bot-id Nresent while the first delete is running, or after it finishes, succeeds as a duplicate and leaves a newer bot of the same name alone. A keyed fork resent after its source is deleted still gets the fork.This is C1 of the CLI/API fixes from the agent CLI feedback, following the "safe retries" rule of the API design note. None of the open design questions were answered one by one, so I used the recommended defaults: the design note sets the direction,
--reasoningbecomes--effort, and time flags take durations. The last two land in C4, not here.How
Protocol:
createandforktake an optionalrequest_id.creationcolumn. Unkeyed creations store nothing.deleted_botstable.deletetakesbot_id. Protocol 7.Cost: no extra round trip. The key is compared during the name lookup
createalready did. Measured on 64 creations sent at once (Linux container,68b4c84againstb7bdfe4, 20 rounds):All three creating cases fall within each other's interquartile range. Recorded in docs/DAEMON_MEASUREMENTS.md under "Keyed creation cost" and in docs/EVIDENCE.md.
CLI:
runkeys both the creation and the submission with its request ID.forkgains--request-id, andrmgains--bot-id. docs/CLI.md and docs/DESIGN.md are updated.Tests:
duplicate: trueand writes nothing;run --newtwice, a changed prompt, another key, a fork twice, a fork resent after its source is deleted, and rm by id after the name is reused.Checks run:
cargo fmtandcargo clippy --all-targets -D warnings;cargo test -p agent-runtime -p agent-client;AGENT_TEST_RUNTIME=1(403 pass, 39 skipped);The Tauri crate wasn't built here because the container has no GTK; the app's code doesn't change.
Review: two Codex findings are answered rather than changed, each with the traced path: a resend after the workspace or provider is gone, and a changed prompt after a lost submit.
🤖 Generated with Claude Code