Skip to content

Update chat client handling#1381

Merged
Kitenite merged 6 commits into
mainfrom
kitenite/test-prod-chat
Feb 10, 2026
Merged

Update chat client handling#1381
Kitenite merged 6 commits into
mainfrom
kitenite/test-prod-chat

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Feb 10, 2026

Description

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other (please describe):

Testing

Screenshots (if applicable)

Additional Notes

Summary by CodeRabbit

  • Chores

    • Updated environment defaults and examples for simpler local setup.
    • Removed outdated migration documentation.
  • New Features

    • Added user-friendly stream error messages and standardized error handling.
    • Introduced a configurable streams URL placeholder for desktop builds.
  • Refactor

    • Made session stop operations asynchronous with improved error propagation.
  • Bug Fixes

    • Improved error display in the chat UI for clearer, copyable messages.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 10, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR defaults/optionalizes several Streams env vars, removes STREAMS_SECRET from examples and a migration doc, starts a durable streams server using a computed internal URL fallback, and standardizes durable-session error handling while making stop() async and proxy-based.

Changes

Cohort / File(s) Summary
Streams env & startup
/.env.example, apps/streams/src/env.ts, apps/streams/src/index.ts
Removed STREAMS_SECRET from example; made STREAMS_PORT and STREAMS_INTERNAL_PORT defaulted, STREAMS_INTERNAL_URL optional, and STREAMS_DATA_DIR default to ./data; index.ts starts DurableStreamTestServer and computes internalUrl fallback (removed freePort logic).
Durable-session client & errors
packages/durable-session/src/client.ts, packages/durable-session/src/errors.ts, packages/durable-session/src/index.ts
Added StreamError class and re-export; normalized proxy URL; replaced ad-hoc response parsing with StreamError.fromResponse; converted stop() to async and POSTs to proxy /v1/sessions/{id}/stop.
React hook updates
packages/durable-session/src/react/use-durable-chat.ts
Made stop() async, awaiting client.stop() and capturing errors into hook state.
Desktop renderer & build helpers
apps/desktop/src/renderer/index.html, apps/desktop/vite/helpers.ts, apps/desktop/src/renderer/.../ChatInterface/ChatInterface.tsx
Replaced hardcoded localhost connect-src with %STREAMS_URL% placeholder; inject %STREAMS_URL% in HTML build transform; chat UI now uses StreamError.friendly for error rendering and styling changes.
Docs removal
docs/replace-streams-secret-with-session-auth.md
Deleted migration guide describing replacement of STREAMS_SECRET with session-based auth.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant DurableClient as Durable Chat Client
  participant Proxy
  participant Streams as Streams Server
  Client->>DurableClient: stop() (await client.stop())
  DurableClient->>Proxy: POST /v1/sessions/{sessionId}/stop { messageId: null }
  Proxy-->>Streams: Forward stop request
  Streams-->>Proxy: 200 OK
  Proxy-->>DurableClient: 200 OK
  DurableClient-->>Client: resolve
Loading
sequenceDiagram
  participant Desktop
  participant DurableClient as Durable Chat Client
  participant Proxy
  participant AuthDB as Auth DB
  participant Streams as Streams Server
  Desktop->>DurableClient: connect/create session (token)
  DurableClient->>Proxy: POST /v1/sessions (with token)
  Proxy->>AuthDB: validate session token
  AuthDB-->>Proxy: valid
  Proxy->>Streams: create/validate session
  Streams-->>Proxy: 201/200
  Proxy-->>DurableClient: 201/200
  DurableClient-->>Desktop: session info / ws url
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hopped through envs to tidy the lair,

Secrets hidden, defaults placed with care.
Async stops now cross the proxy brook,
Friendly errors show the useful look,
A little patchwork, cleaner paths to share. 🥕

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is completely empty except for template placeholders. It lacks any substantive content describing the changes, related issues, type of change, testing performed, or additional context. Fill in all required sections with actual content: describe the changes made (async stop method, environment configuration updates), specify the type of change, document testing performed, and explain the rationale for these modifications.
Title check ❓ Inconclusive The title 'Update chat client handling' is vague and overly broad. While it relates to changes in chat client code (DurableChatClient and useDurableChat), it fails to convey the main change: making the stop() method asynchronous and adding error handling. Use a more specific title that captures the key change, such as 'Make chat client stop method asynchronous with error handling' or 'Convert stop method from sync to async in DurableChat'.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kitenite/test-prod-chat

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/durable-session/src/client.ts`:
- Around line 384-388: The stop() method currently calls postToProxy directly
and lacks the connection guard and error-state handling used by other mutation
methods; update stop() to first check this._isConnected and then perform the
POST via this.executeAction so any failures set this._error and invoke
this.options.onError (i.e., wrap the call to
this.postToProxy(`/v1/sessions/${this.sessionId}/stop`, { messageId: null })
inside this.executeAction and ensure the method short-circuits when
!this._isConnected).

Comment on lines +384 to 388
async stop(): Promise<void> {
await this.postToProxy(`/v1/sessions/${this.sessionId}/stop`, {
messageId: null,
});
}
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.

⚠️ Potential issue | 🟡 Minor

stop() lacks the connection guard and error-state handling present in other mutation methods.

Every other public mutation (sendMessage, addToolResult, addToolApprovalResponse, addToolAnswerResponse) checks this._isConnected before proceeding and routes errors through executeAction (which sets this._error and calls this.options.onError). stop() skips both.

If stop() is called on a disconnected client, the fetch will likely fail with an unhelpful network error. And on failure, this._error won't be set at the client level (though the React hook does catch it separately).

Proposed fix
 async stop(): Promise<void> {
+  if (!this._isConnected) {
+    throw new Error("Client not connected. Call connect() first.");
+  }
-  await this.postToProxy(`/v1/sessions/${this.sessionId}/stop`, {
-    messageId: null,
-  });
+  try {
+    await this.postToProxy(`/v1/sessions/${this.sessionId}/stop`, {
+      messageId: null,
+    });
+  } catch (error) {
+    this._error = error instanceof Error ? error : new Error(String(error));
+    this.options.onError?.(this._error);
+    throw error;
+  }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async stop(): Promise<void> {
await this.postToProxy(`/v1/sessions/${this.sessionId}/stop`, {
messageId: null,
});
}
async stop(): Promise<void> {
if (!this._isConnected) {
throw new Error("Client not connected. Call connect() first.");
}
try {
await this.postToProxy(`/v1/sessions/${this.sessionId}/stop`, {
messageId: null,
});
} catch (error) {
this._error = error instanceof Error ? error : new Error(String(error));
this.options.onError?.(this._error);
throw error;
}
}
🤖 Prompt for AI Agents
In `@packages/durable-session/src/client.ts` around lines 384 - 388, The stop()
method currently calls postToProxy directly and lacks the connection guard and
error-state handling used by other mutation methods; update stop() to first
check this._isConnected and then perform the POST via this.executeAction so any
failures set this._error and invoke this.options.onError (i.e., wrap the call to
this.postToProxy(`/v1/sessions/${this.sessionId}/stop`, { messageId: null })
inside this.executeAction and ensure the method short-circuits when
!this._isConnected).

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 10, 2026

🚀 Preview Deployment

🔗 Preview Links

Service Status Link
Neon Database (Neon) View Branch
Fly.io Electric (Fly.io) View App
Fly.io Streams (Fly.io) View App
Vercel API (Vercel) Failed to deploy
Vercel Web (Vercel) Failed to deploy
Vercel Marketing (Vercel) Failed to deploy
Vercel Admin (Vercel) Failed to deploy
Vercel Docs (Vercel) Failed to deploy

Preview updates automatically with new commits

@Kitenite Kitenite merged commit d00d704 into main Feb 10, 2026
5 checks passed
@Kitenite Kitenite deleted the kitenite/test-prod-chat branch February 10, 2026 23:57
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.

1 participant