Skip to content

errors: Add AI Transport (AIT) error codes 104000-104011 - #353

Open
lmars wants to merge 1 commit into
mainfrom
ait-error-codes
Open

errors: Add AI Transport (AIT) error codes 104000-104011#353
lmars wants to merge 1 commit into
mainfrom
ait-error-codes

Conversation

@lmars

@lmars lmars commented Jul 25, 2026

Copy link
Copy Markdown
Member

Add the AI Transport SDK's own error codes to the registry, from the AIT errors docs page plus the two codes defined in ably-ai-transport-js that the page omits (104010, 104011).

  • 104000 streamed_message_finalize_failed
  • 104001 session_subscription_failed
  • 104002 run_cancel_handler_failed
  • 104003 run_lifecycle_publish_failed
  • 104004 session_closed
  • 104005 session_send_failed
  • 104006 session_continuity_not_guaranteed
  • 104007 session_channel_not_ready
  • 104008 run_response_stream_failed
  • 104010 adopted_run_start_not_observed
  • 104011 session_history_fetch_failed

Each entry has a title, summary, and body verified against the throw sites in ably-ai-transport-js (message strings, status codes, cause preservation, and surfacing). protocol/errors.json regenerated via npm run generate:errors.

Add the AI Transport SDK's own error codes to the registry, from the
AIT errors docs page plus the two codes defined in ably-ai-transport-js
that the page omits (104010, 104011).

- 104000 streamed_message_finalize_failed
- 104001 session_subscription_failed
- 104002 run_cancel_handler_failed
- 104003 run_lifecycle_publish_failed
- 104004 session_closed
- 104005 session_send_failed
- 104006 session_continuity_not_guaranteed
- 104007 session_channel_not_ready
- 104008 run_response_stream_failed
- 104010 adopted_run_start_not_observed
- 104011 session_history_fetch_failed

Each entry has a title, summary, and body verified against the throw
sites in ably-ai-transport-js (message strings, status codes, cause
preservation, and surfacing). protocol/errors.json regenerated via
npm run generate:errors.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lmars
lmars requested a review from mschristensen July 25, 2026 10:31

@mschristensen mschristensen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for this! One small comment for you to address, otherwise LGTM

I think the handling of some of these errors could be improved and surfaced differently in the SDK, so I've left some tickets for that work separately (marked TODO)

Comment thread errors/codes/104002.md

You will not catch this from a call you made. Because it arises while the SDK is handling an inbound message, it is delivered to the run's `onError` handler if you supplied one, and otherwise emitted on the session's `error` event; handle it in whichever you use.

If it was `onCancel` that threw, the SDK stopped before cancelling the run, so the run keeps running as if the cancel had not arrived. Cancel it again, once the handler is fixed, if it still needs to stop.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cancel it again, once the handler is fixed, if it still needs to stop.

That doesn't really make sense, because cancel is validate for the duration of an agent run, I don't think it makes sense to talk about patching code while an agent is running. I would just remove this paragraph.

Comment thread errors/codes/104002.md

## Why it happens

When a cancel message arrives for a run, the SDK calls your `onCancel` hook; when a steering message folds into a run, it calls your `onSteer` hook. This error is raised when one of them throws, with the thrown value preserved as the `cause`. It also covers an unexpected failure while routing a cancel message to its run.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TODO: we should not overload this error code with the cancel-routing failure. We should have a distinct error code for both cancel and steer message routing.

Comment thread errors/codes/104001.md

## Why it happens

Two situations raise it. During `connect()`, attaching the channel was rejected; common reasons are the Ably client not being connected, the token lacking the channel's [capabilities](https://ably.com/docs/auth/capabilities), or the channel being in a failed state. The other is a handler throwing at runtime: an inbound message arrived, but processing it (the codec folding it into session state, or a session-level subscription callback) threw. Either way the originating error is preserved as the `cause`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TODO: we should have a separate error code for each case, to allow the developer to handle each accordingly.

Comment thread errors/codes/104003.md
@@ -0,0 +1,18 @@
---
code: 104003
identifier: run_lifecycle_publish_failed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TODO: we should use the same code for steps, and make this just lifecycle_event_publish_failed

@mschristensen

mschristensen commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Raised AIT-1259 to cover the three TODOs I left here — splitting the overloaded 104001, 104002 and 104003 codes in ably-ai-transport-js so each distinct failure gets its own code (and folding step-lifecycle publishes into a renamed lifecycle_event_publish_failed). The registry entries for those three codes will need amending here once the SDK change lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants