Skip to content

CLI errors as one JSON object that states the rule and the current state - #94

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

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

Conversation

@lydakis

@lydakis lydakis commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Before: a refused command printed one agent: CODE: text line to stderr. A program had to pattern-match prose, and many refusals had no text at all (agent: bot_exists, agent: store_not_found).

After: stderr carries one JSON object, {error, detail, ...facts, hint}. detail states the rule. The facts carry the state a client needs to act on, such as the running turn, the holder's bot_id or the allowed values. hint gives flags to copy. --pretty still prints a readable line.

This is C2 of the CLI feedback plan (agent-notes/shipping-plan/PLAN.md) and follows API_DESIGN.md. It sets no defaults of its own; --effort and duration flags come in C4.

What a client sees

Captured with a synthetic provider on a scratch store:

# before (main)
agent: bot_busy: turn 2 is running; resend with --delivery steer --turn 2 to add this to it, or --delivery queue to run it afterwards; to ask without interrupting, fork --source Bob --bot NEW and send it to NEW
agent: bot_exists
agent: store_not_found

# after
{"detail":"turn 2 is running","error":"bot_busy","fork_point":3,"hint":"resend with --delivery steer --turn 2 to add this to it, or --delivery queue to run it afterwards; to ask without interrupting, fork --source=Bob --bot NEW and send it to NEW","running_turn":2}
{"bot_id":1,"detail":"Bob is taken","error":"bot_exists"}
{"detail":"no store at s.sqlite; this command never creates one","error":"store_not_found"}

# after, --pretty
agent: bot_busy: turn 2 is running; resend with --delivery steer --turn 2 to add this to it, ...
agent: store_not_found: no store at s.sqlite; this command never creates one

How

  • main.rs renders an Error as JSON: its code and detail, its facts flattened in, plus the CLI's hint. --pretty gives agent: CODE: DETAIL; HINT. The flag counts only once the parser has accepted it.
  • Error::reported builds an error from any reply or turn outcome and keeps every fact. Daemon replies, pruned-retry reconciles, the approver, and a daemon that fails to start all use it. A failed auto-start now fails with the daemon's own error, such as invalid_provider_url.
  • Daemon refusals got a detail that states the rule, plus facts:
    • bot_busy: running_turn, fork_point;
    • active_agent_limit: a --delivery queue hint;
    • bot_exists: bot_id, including a name still being deleted;
    • invalid_reasoning_level: levels;
    • invalid_delivery: deliveries;
    • gate entries outside the bot's tools: approve;
    • a duplicate approval serve: lease;
    • a budget stop: budget_tokens and tokens_used, also in turn_finished.
  • A detail can echo input, up to a whole request line. Past 4 KiB its middle is elided, in daemon responses and in the CLI's own errors, so a refusal always fits in one response.
  • The app's cli_reason reads the JSON error, and the remote launcher shares it.
  • docs/CLI.md and docs/RUST_PROTOTYPE.md describe the shape.

One Codex finding is declined and left for the owner: two launchers auto-starting the same store at once, both with invalid flags, can read each other's startup error from the shared log.

Performance

Only refusal paths change. The facts come from rows each refusal already read, so accepted requests make no new store reads and do no new work. I took no new measurements because no hot path changed.

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). The last commit touched only report(), so for it I reran test_cli and test_runtime.
  • node --test app/tests/state.test.cjs: 140 pass.

The app crate doesn't build on Linux, so I checked its cli_reason change separately.

🤖 Generated with Claude Code

The CLI writes a refusal to stderr as one JSON object, `{error, detail,
...facts, hint}`, instead of an `agent: CODE` line; `--pretty` keeps a
readable line. Daemon refusals name the rule they enforce in `detail` and
carry the state a client needs to act as facts: the running turn for
`bot_busy`, the holder's `bot_id` for `bot_exists`, the recorded decision
for an approval already answered. `invalid_request` echoes the request id.
The app reads the JSON error.

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 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-10T01:18:56.983779Z 2656ad7 New commits
🔒 Security Review ✅ Completed 2026-10-10T01:20:40.206929Z 2656ad7 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: ecad68035e

ℹ️ 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 src/main.rs Resolved
Comment thread app/src-tauri/src/daemon.rs Resolved
- `bot_exists` names the holder's `bot_id` while that bot is being deleted,
  instead of null, and says the name is taken until the deletion finishes.
- A submit's `invalid_reasoning_level` names the allowed `levels`, as a
  creation's does: one refusal, `Family::check_reasoning`, for both.
- A failure is printed for `--pretty` only when the parser accepted that
  flag, so `run --bot --pretty` still reports JSON.
- The app reads remote hosts' CLI errors with the same JSON parser as the
  local daemon's.

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: a6fb718ff4

ℹ️ 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/main.rs Resolved
Comment thread src/store/db.rs Resolved
Comment thread src/server/hub.rs Resolved
Comment thread src/store/db.rs Resolved
Comment thread src/server/turn.rs Resolved
- `active_agent_limit` gets the CLI hint `--delivery queue`, as
  `bot_busy` does.
- `--pretty` counts as asked for once `prepare` accepts it, so a later
  flag's failure still prints the readable line.
- `approve_not_in_tools` names the refused entries as `approve`, the field
  they came from.
- A turn's end carries its error's facts in `turn_finished`, so a budget
  stop says `budget_tokens` and `tokens_used`.
- A session serving a tag already is told to renew its lease, with it.

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: 31e083b0b6

ℹ️ 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/client.rs Resolved
Comment thread src/server/hub.rs Resolved
Comment thread src/store/db.rs Resolved
- `Error::reported` reads an error from a reply or an outcome with its
  facts, and `From<agent_client::Error>` keeps them: the socket client,
  the pruned-retry reconcile, `agent approver` and `models` all use them,
  so no CLI path drops what the daemon sent.
- `history_read` and `artifact_page` say an offset is past its bound
  instead of blaming a valid page limit.

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: aab4c7387b

ℹ️ 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/session.rs Resolved
Comment thread docs/CLI.md Resolved
A bot named like a flag, such as `--worker`, still parses as the source
when the hint is copied.

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: 7e8c95e38f

ℹ️ 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/codec.rs Resolved
Comment thread src/main.rs Resolved
… daemon's error

A refusal's detail is elided in its middle past 4 KiB at the response
boundary, so a detail that echoes a whole request line still fits.
invalid_delivery states the rule and lists deliveries. A daemon that
fails to start reports its error, and the CLI fails with that error.

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: c11487aac0

ℹ️ 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/main.rs Resolved
Comment thread src/client.rs Resolved
report() prints CLI-side errors without passing a daemon response, so it
applies the same bound to a detail that echoes an argument.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01L9TT37y1798majTjQbUtZW
@lydakis
lydakis merged commit ed75d78 into main Oct 10, 2026
1 check passed

lydakis commented Oct 10, 2026

Copy link
Copy Markdown
Owner Author

The finding deferred here, the shared daemon log race, is listed in #96 and is being fixed in its own small PR.


Generated by Claude Code

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