Skip to content

Make create and fork safe to resend, and delete safe to repeat - #88

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

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

Conversation

@lydakis

@lydakis lydakis commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Before: if agent run --new --bot NAME --request-id ID lost its reply, resending the exact same command got bot_exists. To recover, the caller had to drop --new and pin a --bot-id it might never have received. fork had 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 gets idempotency_conflict, and the error names that field in detail and field. A name taken by any other request is still bot_exists. rm --bot NAME --bot-id N resent 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, --reasoning becomes --effort, and time flags take durations. The last two land in C4, not here.

How

  • Protocol: create and fork take an optional request_id.

    • The bot stores the key and the request as it was sent, in a new creation column. Unkeyed creations store nothing.
    • A finished deletion records its identity's name in a new deleted_bots table.
    • Both are schema 44, added one way; bots made before it have no key.
    • Instructions are compared against the bot's own columns rather than copied.
    • delete takes bot_id. Protocol 7.
  • Cost: no extra round trip. The key is compared during the name lookup create already did. Measured on 64 creations sent at once (Linux container, 68b4c84 against b7bdfe4, 20 rounds):

    Case Median daemon CPU
    main 11.73 ms
    unkeyed 10.88 ms
    keyed 11.86 ms
    resending all 64 5.88 ms

    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: run keys both the creation and the submission with its request ID. fork gains --request-id, and rm gains --bot-id. docs/CLI.md and docs/DESIGN.md are updated.

  • Tests:

    • store tests for create and fork resends, the conflicting field, unkeyed names, deleted identities bound to their names, and the schema 43 migration;
    • a server test that a resent create answers duplicate: true and writes nothing;
    • two keyed deletes running at once;
    • a CLI test of the whole flow: the same run --new twice, 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 fmt and cargo clippy --all-targets -D warnings;
    • cargo test -p agent-runtime -p agent-client;
    • the Python suite with AGENT_TEST_RUNTIME=1 (403 pass, 39 skipped);
    • the app's node tests (140 pass).

    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

`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
@lydakis lydakis self-assigned this Oct 9, 2026
@lydakis
lydakis marked this pull request as ready for review October 9, 2026 21:44
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 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-09T23:14:03.711223Z 0e45e70 New commits
🔒 Security Review ✅ Completed 2026-10-09T23:14:13.258466Z 0e45e70 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: 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".

Comment thread src/server/mod.rs
Comment on lines +1829 to +1830
if let Some(key) = &request_id {
name(key)?;

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 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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

Comment thread src/client.rs Resolved
Comment thread src/store/db.rs Resolved
Comment thread src/client.rs
Comment on lines +1238 to +1240
// 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"));

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 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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

Comment thread src/server/mod.rs Resolved
Comment thread docs/DAEMON_MEASUREMENTS.md Resolved
claude added 4 commits October 9, 2026 22:21
… 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

@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: 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".

Comment thread src/client.rs Resolved

@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: 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".

Comment thread src/server/mod.rs Resolved
Comment thread src/store/db.rs Resolved
Comment thread client/src/lib.rs Resolved

@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: 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".

Comment thread src/store/db.rs
Comment on lines +6091 to +6094
tx.execute(
"INSERT INTO deleted_bots
SELECT id,name,json_extract(creation,'$.request_id') FROM bots WHERE name=?",
[name],

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 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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

Comment thread docs/RUST_PROTOTYPE.md Resolved
Comment thread docs/DAEMON_MEASUREMENTS.md Resolved
@lydakis
lydakis merged commit 4122858 into main Oct 9, 2026
1 check passed
@lydakis
lydakis deleted the claude/project-thread-7oycm8 branch October 9, 2026 23:20

lydakis commented Oct 10, 2026

Copy link
Copy Markdown
Owner Author

The findings declined here are listed in #96 with a reason each.


Generated by Claude Code

@lydakis lydakis mentioned this pull request Oct 11, 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