Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai-harness): join and resume a run on any instance, and no insecure transport defaults #1781

Mergedjherrmerged 3 commits intofeat/harness-transport fromrefs/pull/1781/headmerged by AlemTuzlak View on GitHub

jherrcommented

A chat run on a durable host could only be joined or resumed on the instance that runs it, so useChat could not recover from a cut connection behind a serverless platform. This PR streams POST run and GET run?runId= from the shared log on any instance. It also removes three defaults that are insecure or work only in one process: an allow-all canAccess, a random mediaSecret per instance, and an OAuth login that opens a listener inside the server.

Each fix is its own commit:

CommitWhat it fixes
no insecure or single-process transport defaultscanAccess allowed every principal into every thread. Signed media URLs failed on other instances. OAuth defaulted to a loopback listener in the server process.
join and resume a run on any instance of a durable hostPOST run had no id: lines, and GET run?runId= returned 404 on any instance but the one that runs the turn.
mark the session view experimental, and say what a cursor isSessionViewState and the view events become public API on publish.

🎯 Changes

  • canAccess is required on createHarnessHandler and handleHarnessSocket. Allow-all is an explicit canAccess: () => true.
  • On a durable host (stores.log), the handler throws at creation without mediaSecret. A host without a log store keeps the random default.
  • oauthConnector requires login. A CLI passes 'loopback', a server passes 'device'.
  • On a durable host, each POST run event has its log cursor as id. A retry with Last-Event-ID finds the same turn and streams after the cursor, without running it again.
  • GET run?runId= finds a turn that another instance runs (through stores.runs), and streams it from the log. GET run?threadId= reports that turn as activeRun.
  • createSessionView, SessionViewState, and SessionViewEvents are tagged @experimental.
  • Docs: connect.md (required options, cursors, joining on any server) and auth.md (login).

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request. (See Testing: the targets that apply were run one by one. test:pr compares against main.)
  • I fully understand the code in this pull request, including any code generated with AI assistance.
  • Docs: I updated docs/ for this change, or this change is not user-facing.
  • Changeset: I added a changeset (pnpm changeset), or this PR does not change a published package.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Root cause

Issue. Behind several instances with no sticky routing, a useChat stream that is cut (Netlify Play cuts connections at random after 40 to 120 seconds) cannot resume, and a reload that joins the run gets 404 on any instance but the one that runs it. A handler with no canAccess lets every principal use every thread.

Cause. POST run streams with toServerSentEventsResponse and writes no id: lines. joinTurn uses sessionOfTurn, which only finds turns of this process. createHarnessHandler defaults canAccess to () => true and mediaSecret to a random key per handler. oauthConnector defaults login to 'loopback'.

Fix. On a durable host, POST run and the join read the operation's events from the shared log with log cursors as ids, so any instance can stream or resume them. The handler requires canAccess, requires mediaSecret on a durable host, and oauthConnector requires login.

Possible alternatives

  • Sticky routing by thread id. Most serverless platforms do not offer it, and it does not help after an instance stops.
  • Default canAccess to session-index ownership. Works only with stores.sessions, and hides the choice. A required option is clearer.
  • Default OAuth login to 'device'. It needs oauth.deviceUrl, which many OAuth apps do not have, so the failure would move to run time.

Testing

Commands run (in this branch, after a rebase on the current feat/harness-transport):

  • pnpm install, then nx run-many -t build for all packages: pass.
  • ai-harness, ai-mcp, ai-persistence: test:lib and test:types: pass (1003 tests in ai-harness).
  • oxlint: no new warnings in changed files.
  • pnpm test:kiira (1865 snippets) and pnpm test:docs: pass.
  • E2E: tsc --noEmit in testing/e2e, and playwright test harness (42 specs): pass. The whole suite passed on an integration branch of every PR in the stack plus these fixes.
  • Not run: pnpm test:pr, test:knip, test:sherif (they compare against main).

Repro before and after: tests/run-route-hosts.test.ts runs two hosts over one set of stores. On feat/harness-transport all 6 cases fail (404 on a join from host B, no cursor on POST run events). On this branch all 6 pass.

Manual test

  1. Run npx vitest run tests/run-route-hosts.test.ts in packages/ai-harness.
  2. Check the cases: live join from host B, resume of a cut join, resume of a cut POST run with one model call, activeRun on host B, 403 and 404.

How this PR makes testing easy: tests/run-route-hosts.test.ts, type tests for the required options, and a runtime test for the mediaSecret check.

Risk / rollback

  • Every caller of createHarnessHandler and handleHarnessSocket must pass canAccess. Every oauthConnector must pass login. A durable host must pass mediaSecret. Other PRs in the stack need small updates: #1768 (CLI) and #1760 (worker build) have fix PRs.
  • Rollback: revert the PR.

Public API change

Before

createHarnessHandler({ host, harness, authorize })
oauthConnector({ id: 'github', label: 'GitHub', oauth })

After

createHarnessHandler({
  host,
  harness,
  authorize,
  canAccess: (principal, threadId) => threadId.startsWith(`${principal.id}-`),
  mediaSecret: process.env.MEDIA_SECRET, // required with stores.log
})
oauthConnector({ id: 'github', label: 'GitHub', login: 'device', oauth })

🤖 Generated with Claude Code

    1. Important

      Review skipped

      Auto reviews are disabled on base/target branches other than the default branch.

      Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration
      • Configuration used: Repository: TanStack/ai/.coderabbit.yaml
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: a015461f-12c5-4f44-ab14-e566e1ac007a

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      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.
    2. 🦋 Changeset detected

      Latest commit: 0d59133e6d09a3fc43e66dd00b49ef1bdd57254c

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 4 packages
      NameType
      @tanstack/ai-harnessPatch
      @tanstack/ai-acpPatch
      @tanstack/ai-mcpPatch
      @tanstack/ai-skillsPatch

      Not sure what this means? Click here to learn what changesets are.

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

    3. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit 0d59133e6d09a3fc43e66dd00b49ef1bdd57254c

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded5m 23sView ↗
      nx run-many --targets=test:coverage --projects=...✅ Succeeded3sView ↗
      nx run-many --targets=build --exclude=examples/...✅ Succeeded38sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-10-14 20:34:27 UTC

    4. Open in StackBlitz

      @tanstack/ai

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@1781

      @tanstack/ai-acp

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-acp@1781

      @tanstack/ai-angular

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-angular@1781

      @tanstack/ai-anthropic

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@1781

      @tanstack/ai-bedrock

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-bedrock@1781

      @tanstack/ai-byteplus

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-byteplus@1781

      @tanstack/ai-claude-code

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-claude-code@1781

      @tanstack/ai-client

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@1781

      @tanstack/ai-cloudflare

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cloudflare@1781

      @tanstack/ai-code-mode

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode@1781

      @tanstack/ai-code-mode-snippets

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode-snippets@1781

      @tanstack/ai-codex

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-codex@1781

      @tanstack/ai-cohere

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cohere@1781

      @tanstack/ai-compaction

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-compaction@1781

      @tanstack/ai-devtools-core

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@1781

      @tanstack/ai-durable-stream

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-durable-stream@1781

      @tanstack/ai-elevenlabs

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-elevenlabs@1781

      @tanstack/ai-event-client

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-event-client@1781

      @tanstack/ai-fal

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-fal@1781

      @tanstack/ai-gemini

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@1781

      @tanstack/ai-grok

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@1781

      @tanstack/ai-grok-build

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok-build@1781

      @tanstack/ai-groq

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-groq@1781

      @tanstack/ai-harness

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-harness@1781

      @tanstack/ai-isolate-cloudflare

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-cloudflare@1781

      @tanstack/ai-isolate-daytona

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-daytona@1781

      @tanstack/ai-isolate-e2b

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-e2b@1781

      @tanstack/ai-isolate-node

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-node@1781

      @tanstack/ai-isolate-quickjs

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs@1781

      @tanstack/ai-isolate-quickjs-bun

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs-bun@1781

      @tanstack/ai-llmgateway

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-llmgateway@1781

      @tanstack/ai-lovable

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-lovable@1781

      @tanstack/ai-mcp

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mcp@1781

      @tanstack/ai-memory

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-memory@1781

      @tanstack/ai-mistral

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mistral@1781

      @tanstack/ai-octane

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-octane@1781

      @tanstack/ai-ollama

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@1781

      @tanstack/ai-ollaya

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollaya@1781

      @tanstack/ai-openai

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@1781

      @tanstack/ai-opencode

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-opencode@1781

      @tanstack/ai-openrouter

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@1781

      @tanstack/ai-perplexity

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-perplexity@1781

      @tanstack/ai-persistence

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-persistence@1781

      @tanstack/ai-preact

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@1781

      @tanstack/ai-react

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@1781

      @tanstack/ai-react-ui

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@1781

      @tanstack/ai-reactor

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-reactor@1781

      @tanstack/ai-remix

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-remix@1781

      @tanstack/ai-sandbox

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox@1781

      @tanstack/ai-sandbox-blaxel

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-blaxel@1781

      @tanstack/ai-sandbox-boxd

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-boxd@1781

      @tanstack/ai-sandbox-cloudflare

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-cloudflare@1781

      @tanstack/ai-sandbox-daytona

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-daytona@1781

      @tanstack/ai-sandbox-docker

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-docker@1781

      @tanstack/ai-sandbox-e2b

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-e2b@1781

      @tanstack/ai-sandbox-local-process

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-local-process@1781

      @tanstack/ai-sandbox-railway

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-railway@1781

      @tanstack/ai-sandbox-sprites

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-sprites@1781

      @tanstack/ai-sandbox-upstash-box

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-upstash-box@1781

      @tanstack/ai-sandbox-vercel

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-vercel@1781

      @tanstack/ai-skills

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-skills@1781

      @tanstack/ai-solid

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@1781

      @tanstack/ai-solid-ui

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@1781

      @tanstack/ai-svelte

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@1781

      @tanstack/ai-typesafe

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-typesafe@1781

      @tanstack/ai-utils

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-utils@1781

      @tanstack/ai-vercel-gateway

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vercel-gateway@1781

      @tanstack/ai-vertex

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vertex@1781

      @tanstack/ai-vue

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@1781

      @tanstack/ai-vue-ui

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@1781

      @tanstack/ai-worldlabs

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-worldlabs@1781

      @tanstack/openai-base

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/openai-base@1781

      @tanstack/preact-ai-devtools

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@1781

      @tanstack/react-ai-devtools

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@1781

      @tanstack/solid-ai-devtools

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@1781

      @tanstack/svelte-ai-devtools

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/svelte-ai-devtools@1781

      commit: 0d59133

    5. Coverage

      ✅ Coverage held across 21 compared package(s).

      Each package is measured twice in this job — on this PR and on its merge-base with main — and compared. A metric fails only when it is at or above 60% on the merge-base and under 60% on this PR. Other drops are listed but do not fail. Packages your PR doesn't affect are not measured and not listed.

      packagestatementsbranchesfunctionslines
      ai-acp82.32% (0.00)71.27% (0.00)77.08% (0.00)83.97% (0.00)ok
      ai-claude-code88.93% (0.00)76.88% (0.00)86.88% (0.00)90.40% (0.00)ok
      ai-codex94.55% (0.00)85.10% (0.00)89.28% (0.00)95.56% (0.00)ok
      ai-durable-stream86.70% (0.00)82.25% (0.00)92.30% (0.00)88.72% (0.00)ok
      ai-grok-build79.19% (0.00)63.56% (0.00)77.39% (0.00)81.02% (0.00)ok
      ai-harness92.47% (+0.08)87.29% (+0.07)92.36% (+0.10)94.04% (+0.04)ok
      ai-mcp96.71% (0.00)91.77% (0.00)96.86% (0.00)98.66% (0.00)ok
      ai-opencode68.77% (0.00)60.82% (0.00)64.04% (0.00)70.78% (0.00)ok
      ai-sandbox77.45% (0.00)82.80% (0.00)74.47% (0.00)77.97% (0.00)ok
      ai-sandbox-blaxel87.64% (0.00)77.18% (0.00)82.26% (0.00)89.71% (0.00)ok
      ai-sandbox-boxd95.86% (0.00)87.12% (0.00)95.31% (0.00)98.17% (0.00)ok
      ai-sandbox-cloudflare67.91% (0.00)57.47% (0.00)71.79% (0.00)69.62% (0.00)ok
      ai-sandbox-daytona82.70% (0.00)81.89% (0.00)67.14% (0.00)85.18% (0.00)ok
      ai-sandbox-docker80.15% (0.00)71.49% (0.00)77.38% (0.00)82.13% (0.00)ok
      ai-sandbox-e2b94.42% (0.00)88.97% (0.00)93.24% (0.00)98.63% (0.00)ok
      ai-sandbox-local-process68.00% (0.00)53.59% (0.00)75.86% (0.00)68.88% (0.00)ok
      ai-sandbox-railway94.75% (0.00)92.68% (0.00)90.90% (0.00)97.59% (0.00)ok
      ai-sandbox-sprites73.23% (0.00)59.70% (0.00)73.83% (0.00)76.17% (0.00)ok
      ai-sandbox-upstash-box94.82% (0.00)91.52% (0.00)91.04% (0.00)97.76% (0.00)ok
      ai-sandbox-vercel44.67% (0.00)38.18% (0.00)35.18% (0.00)45.76% (0.00)ok
      ai-skills83.39% (0.00)68.53% (0.00)87.36% (0.00)85.48% (0.00)ok
    6. github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer

    7. AlemTuzlak approved these changes

    8. AlemTuzlak merged thise5af9da

    9. AlemTuzlak closed this

Sign in to join this conversation.