Skip to content

docs(ai-chat): correct chat.agent reference drift#3892

Open
ericallam wants to merge 2 commits into
mainfrom
docs/chat-agent-accuracy
Open

docs(ai-chat): correct chat.agent reference drift#3892
ericallam wants to merge 2 commits into
mainfrom
docs/chat-agent-accuracy

Conversation

@ericallam

Copy link
Copy Markdown
Member

Summary

Accuracy fixes across the AI chat docs: drop the non-existent per-call option from transport.preload, clarify that onValidateMessages only fires on turns carrying incoming messages, soften the turn-complete token-refresh wording (the header is optional), document the new onTurnComplete error field and finishReason, and correct the idle-timeout default to 30 seconds.

Fix transport.preload signature (no per-call idle option), clarify that
onValidateMessages only fires on turns carrying incoming messages, soften
the turn-complete token-refresh wording since the header is optional,
document the onTurnComplete error field and finishReason, and correct the
idle-timeout default to 30 seconds.
@changeset-bot

changeset-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 22c64cd

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

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: eee80cee-25df-4ad0-b57c-f4df956cc2c8

📥 Commits

Reviewing files that changed from the base of the PR and between 5d114d0 and 22c64cd.

📒 Files selected for processing (1)
  • docs/ai-chat/client-protocol.mdx
✅ Files skipped from review due to trivial changes (1)
  • docs/ai-chat/client-protocol.mdx
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Analyze (actions)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Mintlify Deployment

Walkthrough

This PR updates documentation across five AI chat API guides to reflect current implementation behavior. Changes clarify that turn completion events include an error field for errored turns (with potentially undefined or partial response messages), the optional nature of token refresh headers, idempotency header generation per logical send with retry reuse, default idle timeout as 30 seconds, preload transport signature accepting only chatId without per-call timeout options, and hook execution conditions that skip validation on turns without incoming messages.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides a clear summary of all changes made, but does not follow the repository's required template structure with checklist, testing, and changelog sections. Add the required template sections including checklist confirmation, testing steps, and structured changelog entry to match the repository's pull request template.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main objective: correcting documentation accuracy issues across the AI chat module regarding the chat.agent reference implementation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/chat-agent-accuracy

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mintlify

mintlify Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
trigger 🟢 Ready View Preview Jun 10, 2026, 2:50 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

coderabbitai[bot]

This comment was marked as resolved.

The built-in clients generate a high-entropy id per send (UUID in the
browser, full-length nanoid server-side), not a short id.
@ericallam ericallam marked this pull request as ready for review June 11, 2026 07:39

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 3 potential issues.

View 2 additional findings in Devin Review.

Open in Devin Review

| `usage` | `LanguageModelUsage \| undefined` | Token usage for this turn |
| `totalUsage` | `LanguageModelUsage` | Cumulative token usage across all turns |
| `finishReason` | `FinishReason \| undefined` | Why the LLM stopped (`"stop"`, `"tool-calls"`, `"error"`, …) |
| `error` | `unknown` | Set when the turn threw; `responseMessage` is then undefined or partial |

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.

🟡 Documentation references non-existent error field on TurnCompleteEvent

The reference docs add error: unknown as a field of TurnCompleteEvent, but this field does not exist in the actual TypeScript type definition at packages/trigger-sdk/src/v3/ai.ts:4175-4243. The type ends with finishReason?: FinishReason and has no error property. Additionally, when a turn throws (the catch block at packages/trigger-sdk/src/v3/ai.ts:7527), onTurnComplete is not invoked at all — the error handler writes an error chunk to the stream and waits for the next message, skipping the turn-complete hooks entirely. Users following this documentation will destructure a field that is always undefined.

Prompt for agents
The TurnCompleteEvent type in packages/trigger-sdk/src/v3/ai.ts:4175-4243 does not have an `error` field. Either (a) remove the `error` row from the reference table and the corresponding documentation in error-handling.mdx, or (b) if this is intended new behavior, add the `error` field to the TurnCompleteEvent type and update the turn error handler (ai.ts:7527-7597) to invoke onTurnComplete with the error before waiting for the next message. The same issue appears in docs/ai-chat/error-handling.mdx lines 134, 137, and 143-144.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +137 to +144
onTurnComplete: async ({ chatId, uiMessages, responseMessage, stopped, error }) => {
// Persist the messages regardless of error state
await db.chat.update({
where: { id: chatId },
data: {
messages: uiMessages,
// Mark the chat as errored if no response message
lastTurnStatus: responseMessage ? "ok" : stopped ? "stopped" : "errored",
// `error` is set when the turn threw
lastTurnStatus: error ? "errored" : stopped ? "stopped" : "ok",

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.

🟡 Error-handling doc example destructures non-existent error field from onTurnComplete event

The updated code example destructures error from the onTurnComplete callback and uses it to determine lastTurnStatus. However, TurnCompleteEvent (defined at packages/trigger-sdk/src/v3/ai.ts:4175-4243) has no error field — the destructured value will always be undefined, so lastTurnStatus will never be "errored". The previous code (responseMessage ? "ok" : stopped ? "stopped" : "errored") was at least a heuristic that worked; the new code is strictly broken for detecting errors. The accompanying prose at line 134 ("error carries the thrown value") is also incorrect per the current codebase — onTurnComplete is not called on errored turns at all (packages/trigger-sdk/src/v3/ai.ts:7527-7597).

Prompt for agents
The onTurnComplete code example destructures `error` from the event and uses `error ? "errored" : ...` to set lastTurnStatus. But TurnCompleteEvent (packages/trigger-sdk/src/v3/ai.ts:4175-4243) has no `error` field, and onTurnComplete is not called on errored turns (see the catch block at ai.ts:7527). Either revert to the previous heuristic (`responseMessage ? "ok" : stopped ? "stopped" : "errored"`), or first add the `error` field to TurnCompleteEvent in the SDK and update the turn error handler to call onTurnComplete with the error. Also fix the prose at line 134 which claims `error` carries the thrown value.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +134 to +144
`onTurnComplete` fires after every turn — successful **or** errored. On an errored turn `responseMessage` is undefined or partial and `error` carries the thrown value (with `finishReason` set to `"error"`). Use this to mark the turn as failed:

```ts
onTurnComplete: async ({ chatId, uiMessages, responseMessage, stopped }) => {
onTurnComplete: async ({ chatId, uiMessages, responseMessage, stopped, error }) => {
// Persist the messages regardless of error state
await db.chat.update({
where: { id: chatId },
data: {
messages: uiMessages,
// Mark the chat as errored if no response message
lastTurnStatus: responseMessage ? "ok" : stopped ? "stopped" : "errored",
// `error` is set when the turn threw
lastTurnStatus: error ? "errored" : stopped ? "stopped" : "ok",

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.

🚩 Documentation may be pre-documenting a planned error field on TurnCompleteEvent

The error field additions across reference.mdx and error-handling.mdx could be intentional documentation written ahead of the corresponding SDK code changes (a common pattern when docs and code PRs are split). If so, this PR should either be merged after the SDK PR that adds the error field, or the two should be coordinated. Currently, the SDK at packages/trigger-sdk/src/v3/ai.ts:4175-4243 does not have this field, and the turn error handler at line 7527 does not invoke onTurnComplete on errors.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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