Repository navigation
feat(cognition): typed ToolError on the ToolExecutor trait (#1207, ToolError half) - #1217
Merged
Merged
Conversation
…olError half)
Replace `Result<T, String>` on every `ToolExecutor` trait method with
`Result<T, ToolError>`. TS callers can now `switch (err.error)` on a
discriminated wire format instead of substring-matching on opaque
strings.
Per Joel's typed-error rule (feedback_two_ironclad_rules_tests_and_fallbacks.md):
"fallbacks have ruined this project … they are ILLEGAL." String-shaped
error returns at the IPC boundary are a fallback by another name —
they discard the discriminant and force callers to invent ad-hoc
substring matchers, which silently rot as error messages drift.
## Variant catalog
`ToolError` covers the funnel from registry lookup through execution
to outcome storage:
- `ToolNotFound { name }` — registry doesn't know the tool. Carries
the requested name so retry/correction logic can suggest alternatives.
- `InvalidArgs { tool, reason }` — schema validation rejected the
params (missing required, wrong type, out-of-range).
- `ExecutionFailed { tool, underlying }` — tool ran and threw. The
`underlying` is a free-form string by upstream constraint (shell
exit, HTTP body, DB driver) — but the variant + tool name preserve
enough structure for retry / correction logic.
- `Forbidden { tool, reason }` — policy / auth rejected the call.
- `ParseFailed { raw_preview, reason }` — XML-fallback parser found
no tool block in the model output. Distinct from `Ok` with empty
tool_calls (which is normal silence).
- `StoreFailed { tool, underlying }` — outcome persistence failed.
Recorded for observability; caller should NOT propagate as a turn
failure (the cognition turn already succeeded by the time storage
runs).
Wire format: `{ "error": "ToolNotFound", "data": { name: "..." } }`
(serde tag = "error", content = "data") — same shape pattern as
`AdmissionDecision`, `AdmissionError`, and the `NoLocalModelLoadable`
/ `NoMultimodalBase` typed errors.
## Why ToolError half ships separately
continuum#1207 originally bundled `AnalysisError` + `ToolError`.
claude-tab-2 was rewriting the same call sites for #1204 (#1215 PR
in flight on `analyze()` signature + IN_FLIGHT slot type). Splitting
the card avoids a forced rebase: claude-tab-2 takes AnalysisError
folded into #1215; this commit ships the ToolError half independently
since the trait has no implementations today (purely additive).
Coordinated on airc 18:01–18:02; recorded in #1207.
## Validation
- `cargo test --lib --features metal,accelerate cognition::tool_executor`
— 14 passed, 0 failed (3 new ToolError tests:
serde-discriminant round-trip, every-variant-constructs guard,
Display rendering).
- `cargo check --features metal,accelerate` clean.
- ts-rs auto-generated `shared/generated/cognition/ToolError.ts`.
- Pre-push hook ran without --no-verify.
Refs #1207 (ToolError half).
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
joelteply
pushed a commit
that referenced
this pull request
May 14, 2026
…ring> at shared_analysis boundaries Closes the AnalysisError half of #1207 (sibling has the ToolError half in PR #1217). New module cognition/shared_analysis/error.rs defines AnalysisError with 4 typed variants and ts-rs auto-export so TS callers can pattern-match on the discriminant instead of substring-matching error text: - MissingEnvelope { raw_excerpt } — model emitted prose, not JSON - MissingField { field } — JSON shape OK, key missing - EmptyField { field } — required key present but empty - InferenceFailed { reason } — provider-side failure (timeout/API/etc) Same shape pattern as cognition::host_capability_probe::ProbeError (serde tag=kind, rename_all=camelCase, thiserror::Error for Display). Joel rule: feedback_two_ironclad_rules_tests_and_fallbacks.md ('typed errors at boundary; fallbacks have ruined this project'). Sites converted: - cognition::shared_analysis::analyze public signature - cognition::shared_analysis::run_analysis internal signature - cognition::shared_analysis::prompt::parse_model_output internal - IN_FLIGHT slot type (Shared<BoxFuture<'_, Result<_, AnalysisError>>>) - generate_text mapping via AnalysisError::from_inference helper - persona::response::respond callsite maps back to String at the boundary (response.rs public surface still String for now; pushing the typed error further up is a follow-up that touches IPC handler + recorder traces) Tests: - 4 new error::tests (Display, serde round-trip, from_inference helper, auto-generated ts-rs binding) - parse_fails_loud_on_missing_summary renamed to ..._missing_summary_key (the test was actually exercising the envelope-detection path, not a missing-field path; corrected variant assertion) - parse_fails_loud_on_summary_wrong_type added — the only realistic path that surfaces MissingField (summary key present but non-string) - parse_fails_loud_on_empty_summary added — exercises EmptyField - All 21 cognition::shared_analysis tests pass (was 15 +6 new) - Clippy stays at baseline 162 Refs umbrella #1201 (codex) / #1203 (lane) — RTOS-for-AI throughput. Coordination: this commit folds the AnalysisError half of #1207 into the already-open PR #1215 (perf #1204), since both touch analyze() return type — single coherent PR avoids a rebase trap. Sibling #1217 covers the ToolError half independently in tool_executor.
This was referenced May 14, 2026
joelteply
added a commit
that referenced
this pull request
Sep 5, 2026
#3716 added an `operator.peer.room` probe so the operator self-peer's landing room is stated at boot instead of reconstructed from where cards ended up. It called `Airc::current_room_landing_in`, which is NOT a passive read. `airc.rs:2208`: that function returns early only when a default subscription already exists. Otherwise it subscribes, `set_default`s, saves, publishes presence, and emits an identity card. WHY THAT IS WORSE THAN A STYLE BUG. The probe runs AFTER the lobby subscribe and the commons join. If those SUCCEEDED, a default exists and the call returns early — harmless, which is exactly why it looked correct in verification and honestly reported `room=academy`. But on the path where the joins FAILED there is no default, so the probe would perform the very subscribe that just failed and then report a healthy academy landing. A probe that MANUFACTURES the state it claims to observe, on precisely the failure path it exists to expose — in the one line whose whole job is being trustworthy about where cards go. airc had already built the door: `peek_default_room` sits five lines below the function I reached for, documented as the read-only variant and added as the #1217 regression fix after `airc network` was caught silently subscribing to `#general` via `current_room` while claiming to be an inspection command. Same trap, same module, one caller later — I did not look for an existing read-only accessor, I took the first function that returned a `Room`. Three outcomes, kept DISTINCT rather than collapsed: - `Ok(Some(room))` → the room, as before. - `Ok(None)` → no default AFTER both joins ran, so both failed: the human has no room and operator cards have no predictable board. Its own probe class, never silently the same row as a successful landing. - `Err(_)` → the subscription set could not be READ. UNKNOWN, which is a different fact from unset. Found in review by IntelMac on the already-merged #3716; the mutation was mine. Verified against the airc source rather than taken from the report. Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc Co-authored-by: Claude Fable 5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace
Result<T, String>on everyToolExecutortrait method withResult<T, ToolError>. TS callers can nowswitch (err.error)on a discriminated wire format instead of substring-matching on opaque strings.Per Joel's typed-error rule (memory: feedback_two_ironclad_rules_tests_and_fallbacks): "fallbacks have ruined this project … they are ILLEGAL." String-shaped error returns at the IPC boundary are a fallback by another name — they discard the discriminant and force callers to invent ad-hoc substring matchers, which silently rot as error messages drift.
Variant catalog (typed)
ToolErrorcovers the funnel from registry lookup through execution to outcome storage. Same wire pattern asAdmissionDecision/AdmissionError({ \"error\": \"...\", \"data\": { ... } }):ToolNotFound { name }— registry doesn't know the tool. Carries the requested name so retry/correction logic can suggest alternatives.InvalidArgs { tool, reason }— schema validation rejected the params.ExecutionFailed { tool, underlying }— tool ran and threw. Theunderlyingis a free-form string by upstream constraint (shell exit, HTTP body, DB driver) — but the variant + tool name preserve enough structure for retry / correction logic.Forbidden { tool, reason }— policy / auth rejected the call.ParseFailed { raw_preview, reason }— XML-fallback parser found no tool block in the model output. Distinct fromOkwith empty tool_calls (= normal silence).StoreFailed { tool, underlying }— outcome persistence failed. Recorded for observability; caller should NOT propagate as a turn failure.ToolErrorderivesDisplay+std::error::Errorfor log scrapes / panic messages.Why ToolError half ships separately
continuum#1207 originally bundled
AnalysisError+ToolError. claude-tab-2 was rewriting the same call sites for #1204 (#1215 PR in flight onanalyze()signature + IN_FLIGHT slot type). Splitting the card avoids a forced rebase: claude-tab-2 takes AnalysisError folded into #1215; this PR ships the ToolError half independently since the trait has no implementations today (purely additive).Coordinated on airc 18:01–18:02.
Test plan
cargo test --lib --features metal,accelerate cognition::tool_executor— 14 passed, 0 failed (3 new ToolError tests: serde-discriminant round-trip, every-variant-constructs guard, Display rendering)cargo check --features metal,acceleratecleanshared/generated/cognition/ToolError.ts— TS callers get the discriminator at the IPC boundary--no-verifyRefs #1207 (ToolError half). claude-tab-2 ships AnalysisError half via #1215 amendment.
🤖 Generated with Claude Code