Skip to content

refactor(workbench): fail the Agent Document and host discovery atoms with their typed client errors - #515

Merged
ScriptedAlchemy merged 2 commits into
mainfrom
refactor/effect-workbench-atom-errors
Sep 4, 2026
Merged

refactor(workbench): fail the Agent Document and host discovery atoms with their typed client errors#515
ScriptedAlchemy merged 2 commits into
mainfrom
refactor/effect-workbench-atom-errors

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Summary

Effect-conformance cleanup 4 of the prior audit (Workbench runtime/agent-document-atoms.ts + discovery/discovery-atoms.ts): the two Atom Effect channels that failed with a bare string / global Error now fail with the existing typed client errors, setting the Atom error pattern for the Workbench. Behavior-preserving: every rendered message is unchanged; the discovery page shows the same code (AB8234 fallback) and text.

What changed

  • packages/workbench/src/runtime/agent-document-atoms.ts (audit row :15–18, fail channel was a string): agentDocumentEventsAtom is typed Effect<readonly AgentRenderEvent[], AgentDocumentClientError>. The "loading is not available in this Workbench session" state fails with new AgentDocumentClientError('AB8206', …); tryPromise's catch passes an AgentDocumentClientError through unchanged; any other coded Error — the production loader RuntimeClient.readRunDocument rethrows RuntimeClientError, and the foreground authority raises ForegroundRouteClientError — keeps its own code, message, and numeric status; an uncoded rejection becomes AgentDocumentClientError('AB8206', error.message | 'Agent Document request could not be completed.'). AB8206 is the documented "Workbench runtime client failure" code (docs/diagnostics.md), already used by runtime-client.ts; no new diagnostic code.
  • packages/workbench/src/runtime-inspector.tsx: onError renders error.message instead of the former string — same text.
  • packages/workbench/src/discovery/discovery-atoms.ts (audit row :41, Effect.fail(new Error(…))): discoveryReportAtom is typed Effect<HostDiscoveryReport, DiscoveryClientError>. The unavailable state and uncoded rejections fail with DiscoveryClientError('AB8234', …) — the documented host-discovery decoder code and the exact fallback errorDetails in discovery-page.tsx already applied to an uncoded Error. A coded Error (e.g. ForegroundRouteClientError AB8019 when foreground authentication was invalidated) keeps its own code/message/status, so the rendered <code> <message> pair is identical to what the page derived before. DiscoveryClientErrors pass through untouched.
  • No Atom/AsyncResult types leak into DTOs or exports; components still only use @effect/atom-react hooks; no Effect.run* outside the registry (docs/effect-conventions.md § Workbench browser state).

Idioms and citations

Idiom Doc repos/effect/LLMS.md / repo section
Typed class errors on the fail channel instead of string / global Error Error Management → Expected Errors ("The type makes the possible failure visible to callers") LLMS.md § Error handling; agent-patterns/effect-errors.md "What to avoid: unknown or global Error in the fail channel (globalErrorInEffectFailure)"; docs/effect-conventions.md § Error mapping — existing classes, no Schema.TaggedError
Effect.tryPromise({ try, catch }) mapping rejections onto the typed error Resource Management → Scope → acquireRelease example (same tryPromise catch shape) LLMS.md § Creating effects from common sources

Tests

  • New packages/workbench/tests/atom-error-channels.test.ts (unit, AtomRegistry.make() + subscribe): for each atom family — loader unavailable → typed error with the exact code/message/name; a client error from the loader passes through by identity; a coded foreign error (RuntimeClientError AB8208, ForegroundRouteClientError AB8019 + status: 401) keeps its code/message/status; an uncoded TypeError is wrapped with its message; a non-Error rejection gets the generic message; a resolving loader yields AsyncResult success.
  • pnpm typecheck (includes packages/workbench/tsconfig.json), pnpm lint green; pnpm test:unit green (3173 passed, incl. all packages/workbench/tests).

Changeset

skip-changeset: packages/workbench is private and ignored by changesets (.changeset/README.md); no publishable package changed.

Review status

No PR comments are posted by the author; every review thread is answered in this section.

Head Review Threads
55c8a51 Codex completed (2 P2) discovery-atoms.ts:56 "Preserve foreground discovery diagnostic codes" and agent-document-atoms.ts:27 "Preserve runtime document diagnostic codes" — both valid: the wrappers relabelled ForegroundRouteClientError / RuntimeClientError codes. Fixed in 4beb5f1: coded Errors keep code, message, and numeric status; tests added for AB8019 (status 401) and AB8208.
4beb5f1 pending

… with their typed client errors

The two Atom Effect channels that failed with a bare string or a global
Error now fail with AgentDocumentClientError (AB8206) and
DiscoveryClientError (AB8234): client errors from the loader pass through
unchanged and any other rejection is wrapped with its message, so every
rendered message and the discovery page's code/message pair are unchanged.
@ScriptedAlchemy ScriptedAlchemy added the skip-changeset PR changes a publishable package but ships no observable change; changeset not required label Sep 4, 2026
@changeset-bot

changeset-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4beb5f1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 4, 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-09-04T03:09:04.633105Z 55c8a51 PR opened
ℹ️ 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: 55c8a51693

ℹ️ 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 on lines +53 to +56
if (error instanceof DiscoveryClientError) return error;
return new DiscoveryClientError(
discoveryClientErrorCode,
error instanceof Error ? error.message : 'Host discovery request could not be completed.',

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 foreground discovery diagnostic codes

When discovery fails before receiving a response, such as when ForegroundRouteClient.protectedRequest rejects with AB8019 because foreground authentication was invalidated, the error is a ForegroundRouteClientError, not a DiscoveryClientError. Previously the atom passed that Error through and DiscoveryPage.errorDetails displayed its code; this wrapper instead relabels it as AB8234, incorrectly presenting an authentication/session failure as a host-discovery decoder failure. Preserve coded foreground errors when converting them, or normalize them inside DiscoveryClient without discarding their diagnostic code.

Useful? React with 👍 / 👎.

Comment on lines +24 to +27
if (error instanceof AgentDocumentClientError) return error;
return new AgentDocumentClientError(
runtimeClientErrorCode,
error instanceof Error ? error.message : 'Agent Document request could not be completed.',

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 runtime document diagnostic codes

In the production Workbench path, RuntimePlayground supplies RuntimeClient.readRunDocument, which catches every AgentDocumentClientError and rethrows a RuntimeClientError while preserving codes such as AB8208 and AB8209. Consequently this instanceof AgentDocumentClientError branch does not match actual route failures, and the new typed atom channel overwrites their diagnostic code with AB8206; the added test misses this by injecting an AgentDocumentClientError directly. Convert the production RuntimeClientError while preserving its code, or let the production loader propagate the original client error.

Useful? React with 👍 / 👎.

@pkg-pr-new

pkg-pr-new Bot commented Sep 4, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle@515
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle/create-agent-bundle@515
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle/@agent-bundle/runtime@515

commit: 4beb5f1

…ed client errors

RuntimeClientError (the production Agent Document loader) and
ForegroundRouteClientError (invalidated foreground authentication) carry
their own AB codes; the atom wrappers now preserve code, message, and
numeric status instead of relabelling them as AB8206 / AB8234.
@ScriptedAlchemy
ScriptedAlchemy merged commit 0400764 into main Sep 4, 2026
13 checks passed
@ScriptedAlchemy
ScriptedAlchemy deleted the refactor/effect-workbench-atom-errors branch September 4, 2026 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changeset PR changes a publishable package but ships no observable change; changeset not required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant