Preserve routed context for agent.run in WebSocket callbacks#1365
Preserve routed context for agent.run in WebSocket callbacks#1365parteeksingh24 wants to merge 4 commits intomainfrom
agent.run in WebSocket callbacks#1365Conversation
- restore HTTP and agent async-local context in websocket callbacks - preserve routed session/thread/auth for `agent.run` - add regression test for websocket context propagation
|
The latest Agentuity deployment details.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 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). (15)
📝 WalkthroughWalkthroughCapture agent and HTTP async-local storage contexts and re-establish them (alongside the OpenTelemetry ROOT_CONTEXT) during WebSocket handler execution; added an end-to-end Bun test validating agent context propagation across the WebSocket lifecycle. Changes
🚥 Pre-merge checks | ✅ 1✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
agent.run in WebSocket callbacks
📦 Canary Packages Publishedversion: PackagesInstallAdd to your {
"dependencies": {
"@agentuity/cli": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-cli-2.0.9-67e3698.tgz",
"@agentuity/email": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-email-2.0.9-67e3698.tgz",
"@agentuity/coder": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-coder-2.0.9-67e3698.tgz",
"@agentuity/server": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-server-2.0.9-67e3698.tgz",
"@agentuity/coder-tui": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-coder-tui-2.0.9-67e3698.tgz",
"@agentuity/task": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-task-2.0.9-67e3698.tgz",
"@agentuity/schedule": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-schedule-2.0.9-67e3698.tgz",
"@agentuity/opencode": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-opencode-2.0.9-67e3698.tgz",
"@agentuity/webhook": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-webhook-2.0.9-67e3698.tgz",
"@agentuity/core": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-core-2.0.9-67e3698.tgz",
"@agentuity/db": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-db-2.0.9-67e3698.tgz",
"@agentuity/migrate": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-migrate-2.0.9-67e3698.tgz",
"@agentuity/auth": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-auth-2.0.9-67e3698.tgz",
"@agentuity/evals": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-evals-2.0.9-67e3698.tgz",
"@agentuity/claude-code": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-claude-code-2.0.9-67e3698.tgz",
"@agentuity/postgres": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-postgres-2.0.9-67e3698.tgz",
"@agentuity/runtime": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-runtime-2.0.9-67e3698.tgz",
"@agentuity/drizzle": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-drizzle-2.0.9-67e3698.tgz",
"@agentuity/frontend": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-frontend-2.0.9-67e3698.tgz",
"@agentuity/queue": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-queue-2.0.9-67e3698.tgz",
"@agentuity/schema": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-schema-2.0.9-67e3698.tgz",
"@agentuity/vector": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-vector-2.0.9-67e3698.tgz",
"@agentuity/workbench": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-workbench-2.0.9-67e3698.tgz",
"@agentuity/react": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-react-2.0.9-67e3698.tgz",
"@agentuity/sandbox": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-sandbox-2.0.9-67e3698.tgz",
"@agentuity/keyvalue": "https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-keyvalue-2.0.9-67e3698.tgz"
}
}Or install directly: bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-cli-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-email-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-coder-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-server-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-coder-tui-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-task-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-schedule-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-opencode-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-webhook-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-core-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-db-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-migrate-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-auth-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-evals-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-claude-code-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-postgres-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-runtime-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-drizzle-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-frontend-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-queue-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-schema-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-vector-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-workbench-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-react-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-sandbox-2.0.9-67e3698.tgz
bun add https://agentuity-sdk-objects.t3.storageapi.dev/npm/2.0.9-67e3698/agentuity-keyvalue-2.0.9-67e3698.tgz |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/runtime/test/websocket-agent-context.test.ts (1)
32-46: Use the shared test mock utilities here.
createMockAuth()is local test scaffolding. Please pull this from the repo’s shared test utilities instead so auth mock shape stays aligned across tests.As per coding guidelines "Use
@agentuity/test-utilsfor mocks in tests".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/runtime/test/websocket-agent-context.test.ts` around lines 32 - 46, Replace the local test scaffolding function createMockAuth (which returns AuthInterface-shaped objects) with the shared mock from the repo test utilities: remove the local createMockAuth implementation and import/use the mock provider from `@agentuity/test-utils` (the shared auth mock used across tests); update any references in websocket-agent-context.test.ts to call the imported utility (and adjust any argument shape if needed) so the test uses the canonical shared auth mock instead of the local definition.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/runtime/test/websocket-agent-context.test.ts`:
- Around line 48-81: The waiters waitForOpen and waitForJsonMessage only reject
on 'error' and can hang if the socket emits 'close' before opening or before a
message; add 'close' event listeners in both functions that remove the paired
listeners (e.g., in waitForOpen remove 'error' and in waitForJsonMessage remove
'message') and call reject with a clear Error like 'WebSocket closed before
open' / 'WebSocket closed before message', and ensure the 'close' handlers are
registered with { once: true } and cleaned up when the other terminal event
fires.
---
Nitpick comments:
In `@packages/runtime/test/websocket-agent-context.test.ts`:
- Around line 32-46: Replace the local test scaffolding function createMockAuth
(which returns AuthInterface-shaped objects) with the shared mock from the repo
test utilities: remove the local createMockAuth implementation and import/use
the mock provider from `@agentuity/test-utils` (the shared auth mock used across
tests); update any references in websocket-agent-context.test.ts to call the
imported utility (and adjust any argument shape if needed) so the test uses the
canonical shared auth mock instead of the local definition.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d8ba4ec1-ccbd-4084-8817-17cbc935eb29
📒 Files selected for processing (2)
packages/runtime/src/handlers/websocket.tspackages/runtime/test/websocket-agent-context.test.ts
📜 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). (15)
- GitHub Check: Build
- GitHub Check: Storage CLI Tests
- GitHub Check: Playwright E2E Smoke Test
- GitHub Check: Sandbox CLI Tests
- GitHub Check: Framework Integration Tests (TanStack & Next.js)
- GitHub Check: Queue CLI Tests
- GitHub Check: Queue SDK Tests
- GitHub Check: Package Installation & Usage Test
- GitHub Check: SDK Integration Test Suite
- GitHub Check: Postgres SSL Integration Test
- GitHub Check: Standalone Agent Test
- GitHub Check: Pack & Upload
- GitHub Check: Cloud Deployment Tests
- GitHub Check: Template Integration Tests
- GitHub Check: Agentuity Deployment
🧰 Additional context used
📓 Path-based instructions (5)
packages/runtime/**/*.{ts,tsx}
📄 CodeRabbit inference engine (packages/runtime/AGENTS.md)
packages/runtime/**/*.{ts,tsx}: Every agent handler receivesAgentContextwith logger, tracer, storage (kv, vector, stream), and auth properties
Usectx.loggerinstead ofconsole.logfor observability
Files:
packages/runtime/test/websocket-agent-context.test.tspackages/runtime/src/handlers/websocket.ts
packages/runtime/**/*.test.{ts,tsx}
📄 CodeRabbit inference engine (packages/runtime/AGENTS.md)
packages/runtime/**/*.test.{ts,tsx}: Useapp.request()for route testing, nottestClient()
Mock contexts fromtest/helpers/test-context.tswhen testing
Import from../src/in tests rather than from compiled output
When running tests, prefer using a subagent (Task tool) to avoid context bloat from test output
Files:
packages/runtime/test/websocket-agent-context.test.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use Biome as code formatter with tabs (width 3), single quotes, semicolons, lineWidth 100, and trailingCommas es5
Files:
packages/runtime/test/websocket-agent-context.test.tspackages/runtime/src/handlers/websocket.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx}: Use TypeScript Strict mode with ESNext target and bundler moduleResolution
UseStructuredErrorfrom@agentuity/corefor error handling
Files:
packages/runtime/test/websocket-agent-context.test.tspackages/runtime/src/handlers/websocket.ts
**/test/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/test/**/*.{ts,tsx}: Place tests intest/folder, never insrc/or__tests__/directories
Import from../src/in test files
Use@agentuity/test-utilsfor mocks in tests
Files:
packages/runtime/test/websocket-agent-context.test.ts
🧠 Learnings (3)
📚 Learning: 2025-12-13T14:15:18.261Z
Learnt from: jhaynie
Repo: agentuity/sdk PR: 168
File: packages/runtime/src/session.ts:536-546
Timestamp: 2025-12-13T14:15:18.261Z
Learning: The agentuity/runtime package is Bun-only; during code reviews, do not replace Bun-native APIs (e.g., Bun.CryptoHasher, Bun.serve, and other Bun namespace APIs) with Node.js alternatives. Review changes with the assumption that runtime runs on Bun, and ensure any edits preserve Bun compatibility and do not introduce Node.js-specific fallbacks. Apply this guidance broadly to files under packages/runtime (e.g., packages/runtime/src/...); if there are conditional environment checks, document why Bun is required and avoid dereferencing Bun-only APIs in non-Bun contexts.
Applied to files:
packages/runtime/test/websocket-agent-context.test.tspackages/runtime/src/handlers/websocket.ts
📚 Learning: 2025-12-21T00:31:41.858Z
Learnt from: jhaynie
Repo: agentuity/sdk PR: 274
File: packages/cli/src/cmd/build/vite/server-bundler.ts:12-41
Timestamp: 2025-12-21T00:31:41.858Z
Learning: In Bun runtime, BuildMessage and ResolveMessage are global types and are not exported from the bun module. Do not import { BuildMessage } from 'bun' or similar; these types are available globally and should be used without import. This applies to all TypeScript files that target the Bun runtime within the repository.
Applied to files:
packages/runtime/test/websocket-agent-context.test.tspackages/runtime/src/handlers/websocket.ts
📚 Learning: 2026-02-21T02:05:57.982Z
Learnt from: jhaynie
Repo: agentuity/sdk PR: 1010
File: packages/drizzle/test/proxy.test.ts:594-603
Timestamp: 2026-02-21T02:05:57.982Z
Learning: Do not rely on StructuredError from agentuity/core in test files or simple error handling paths. In tests and straightforward error handling, use plain Error objects to represent failures, reserving StructuredError for more complex error scenarios in application logic.
Applied to files:
packages/runtime/test/websocket-agent-context.test.ts
🔇 Additional comments (2)
packages/runtime/src/handlers/websocket.ts (1)
104-107: Nice fix for WebSocket context re-entry.Capturing both async-local stores at upgrade time and re-entering them for the handler plus each lifecycle callback closes the routed
agent.run()gap without disturbing the existing OTEL root-context workaround.Also applies to: 145-160, 167-168, 182-182, 197-197, 208-208
packages/runtime/test/websocket-agent-context.test.ts (1)
95-209: Good regression coverage for the routed WebSocket path.This exercises the real upgrade flow and asserts session/thread/auth propagation from the routed request through
ws.onMessage, which is exactly the failure mode described in the PR.
- reject waiters when the socket closes before open/message - clean up paired event listeners in websocket test helpers
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/runtime/test/websocket-agent-context.test.ts (1)
32-46: Use shared test mock/context helpers instead of a bespokeAuthInterfacestub.Line 32 builds a custom auth mock inline. Please switch this to repository-standard test mocks/context helpers to reduce drift as auth contracts evolve.
As per coding guidelines: "Mock contexts from test/helpers/test-context.ts when testing" and "Use
@agentuity/test-utilsfor mocks in tests".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/runtime/test/websocket-agent-context.test.ts` around lines 32 - 46, The inline auth stub function createMockAuth should be replaced with the repository-standard test helpers: import and use the mock/auth helper (e.g., the test context factory or auth mock exported from test/helpers/test-context.ts or `@agentuity/test-utils`) instead of the bespoke AuthInterface implementation; update the test to call the shared helper to obtain an AuthInterface (preserving the same userId variation used now) and remove createMockAuth, ensuring any calls to getUser/getToken/getOrg/etc. come from the shared mock API (adjust imports and variable names accordingly).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/runtime/test/websocket-agent-context.test.ts`:
- Around line 32-46: The inline auth stub function createMockAuth should be
replaced with the repository-standard test helpers: import and use the mock/auth
helper (e.g., the test context factory or auth mock exported from
test/helpers/test-context.ts or `@agentuity/test-utils`) instead of the bespoke
AuthInterface implementation; update the test to call the shared helper to
obtain an AuthInterface (preserving the same userId variation used now) and
remove createMockAuth, ensuring any calls to getUser/getToken/getOrg/etc. come
from the shared mock API (adjust imports and variable names accordingly).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d7716029-b226-47a8-89dc-75523272123a
📒 Files selected for processing (1)
packages/runtime/test/websocket-agent-context.test.ts
📜 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). (15)
- GitHub Check: Template Integration Tests
- GitHub Check: Storage CLI Tests
- GitHub Check: Playwright E2E Smoke Test
- GitHub Check: Sandbox CLI Tests
- GitHub Check: Standalone Agent Test
- GitHub Check: Queue CLI Tests
- GitHub Check: Framework Integration Tests (TanStack & Next.js)
- GitHub Check: Package Installation & Usage Test
- GitHub Check: Queue SDK Tests
- GitHub Check: Build
- GitHub Check: Postgres SSL Integration Test
- GitHub Check: Cloud Deployment Tests
- GitHub Check: SDK Integration Test Suite
- GitHub Check: Pack & Upload
- GitHub Check: Agentuity Deployment
🧰 Additional context used
📓 Path-based instructions (5)
packages/runtime/**/*.{ts,tsx}
📄 CodeRabbit inference engine (packages/runtime/AGENTS.md)
packages/runtime/**/*.{ts,tsx}: Every agent handler receivesAgentContextwith logger, tracer, storage (kv, vector, stream), and auth properties
Usectx.loggerinstead ofconsole.logfor observability
Files:
packages/runtime/test/websocket-agent-context.test.ts
packages/runtime/**/*.test.{ts,tsx}
📄 CodeRabbit inference engine (packages/runtime/AGENTS.md)
packages/runtime/**/*.test.{ts,tsx}: Useapp.request()for route testing, nottestClient()
Mock contexts fromtest/helpers/test-context.tswhen testing
Import from../src/in tests rather than from compiled output
When running tests, prefer using a subagent (Task tool) to avoid context bloat from test output
Files:
packages/runtime/test/websocket-agent-context.test.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use Biome as code formatter with tabs (width 3), single quotes, semicolons, lineWidth 100, and trailingCommas es5
Files:
packages/runtime/test/websocket-agent-context.test.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/*.{ts,tsx}: Use TypeScript Strict mode with ESNext target and bundler moduleResolution
UseStructuredErrorfrom@agentuity/corefor error handling
Files:
packages/runtime/test/websocket-agent-context.test.ts
**/test/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
**/test/**/*.{ts,tsx}: Place tests intest/folder, never insrc/or__tests__/directories
Import from../src/in test files
Use@agentuity/test-utilsfor mocks in tests
Files:
packages/runtime/test/websocket-agent-context.test.ts
🧠 Learnings (3)
📚 Learning: 2025-12-13T14:15:18.261Z
Learnt from: jhaynie
Repo: agentuity/sdk PR: 168
File: packages/runtime/src/session.ts:536-546
Timestamp: 2025-12-13T14:15:18.261Z
Learning: The agentuity/runtime package is Bun-only; during code reviews, do not replace Bun-native APIs (e.g., Bun.CryptoHasher, Bun.serve, and other Bun namespace APIs) with Node.js alternatives. Review changes with the assumption that runtime runs on Bun, and ensure any edits preserve Bun compatibility and do not introduce Node.js-specific fallbacks. Apply this guidance broadly to files under packages/runtime (e.g., packages/runtime/src/...); if there are conditional environment checks, document why Bun is required and avoid dereferencing Bun-only APIs in non-Bun contexts.
Applied to files:
packages/runtime/test/websocket-agent-context.test.ts
📚 Learning: 2025-12-21T00:31:41.858Z
Learnt from: jhaynie
Repo: agentuity/sdk PR: 274
File: packages/cli/src/cmd/build/vite/server-bundler.ts:12-41
Timestamp: 2025-12-21T00:31:41.858Z
Learning: In Bun runtime, BuildMessage and ResolveMessage are global types and are not exported from the bun module. Do not import { BuildMessage } from 'bun' or similar; these types are available globally and should be used without import. This applies to all TypeScript files that target the Bun runtime within the repository.
Applied to files:
packages/runtime/test/websocket-agent-context.test.ts
📚 Learning: 2026-02-21T02:05:57.982Z
Learnt from: jhaynie
Repo: agentuity/sdk PR: 1010
File: packages/drizzle/test/proxy.test.ts:594-603
Timestamp: 2026-02-21T02:05:57.982Z
Learning: Do not rely on StructuredError from agentuity/core in test files or simple error handling paths. In tests and straightforward error handling, use plain Error objects to represent failures, reserving StructuredError for more complex error scenarios in application logic.
Applied to files:
packages/runtime/test/websocket-agent-context.test.ts
🔇 Additional comments (2)
packages/runtime/test/websocket-agent-context.test.ts (2)
48-104: Nice hardening of WebSocket waiter lifecycle handling.The symmetric cleanup +
closerejection paths prevent dangling waiters and reduce test hangs in close-before-open/message scenarios.
151-218: Regression coverage is well-targeted to the fix.This directly exercises
agent.run()insidews.onMessageand verifies propagatedsessionId,threadId, and late-bound auth, which matches the reported failure mode.
- replace createApp setup with direct Hono websocket wiring - keep real websocket routing and agent middleware coverage - avoid suite collisions from mocked app service modules
|
This PR preserves routed context for The regression test uses a real Verification:
|
Summary
agent.run()insidews.onMessageVerification
bun test packages/runtime/test/websocket-agent-context.test.tsbun run --filter='./packages/runtime' buildNotes
agent.run()insidews.onMessage, where the unfixed runtime threwAgentContextNotAvailableErrorSummary by CodeRabbit
Bug Fixes
Tests