Skip to content
Source
Sign inSign up
TanStack/ai

feat(ai-harness, ai-persistence, ai-skills): onEvent and onMedia callbacks, object params, and review fixes #1779

MergedAlemTuzlakmerged 26 commits intofeat/harness-core fromrefs/pull/1779/headmerged by AlemTuzlak View on GitHub

AlemTuzlakcommented

You can now react to harness events without a for await loop: session.onEvent(...) and turn.onEvent(...) call your function as each event goes out, and turn.onMedia(...) gives you each file a turn saves. Multi-argument store and session methods now take one object, so new fields will not break callers later. This PR also fixes the High and Medium findings from a review of #1755.

🎯 Changes

New callbacks (@tanstack/ai-harness)

  • session.onEvent(listener) and session.onEvent(type, listener). With a type, event has that event's type. Each call returns a stop function.
  • operation.onEvent(...): the same, for the events of one operation. Its listeners go away when the operation settles.
  • operation.onMedia(({ media }) => ...) and ChatTurnResult.media: the media records of a turn or an agent run.
  • A listener that throws, or an async listener that rejects, is reported with console.error and does not stop the turn.

One object instead of positional arguments. These were positional with two or more plain-data arguments:

  • Stores (@tanstack/ai-persistence): InboxStore.markApplied/markRejected, CredentialStore.get/set/delete, LogStore.append/subscribe, WorkClaimStore.release, SessionIndexStore.upsertIf.
  • Harness: host.sessions.rename/update/fork, session.setConfig/answer/setDelivery/sendToAgent, ctx.session.setConfig, credentials.set.
  • Payload-plus-context shapes that copy core stay as they are: command run(input, ctx), durableTool execute(args, ctx), step.do(name, fn), and fn(id, options?).

Review fixes. Each fix has a unit test that fails without it.

  • Session engine: operations that never settled when a store write threw, unhandled rejections, input ids that a failed write blocked, inputs that came during close() (now rejected with closed), early turn failures that never settled, cancel did not reject a turn's or a command's questions, a failed open() leaked plugins, reload during close, harnessText abort and outcome, per-session maps that grew without end (now the last 500 settled operations; agent runs stay), and claim renewal.
  • Durability: a durable tool's records now land with its result, lease renewal and log subscriber rejections are caught, a reopen no longer counts usage twice, close() waits for the last append, a throwing projection is skipped with a warning, resumePending reads past other harnesses' claims, log reads page until an empty page, landed() ignores key order, the fold forgets finished calls, and repaired tool results sit next to their calls.
  • Plugins, media, skills: credentials that a session hands out are scrubbed from errors it publishes, the skills watcher re-arms after a folder is removed and works without recursive watch, upload keys encode the thread id, MIME types are strict, part types match the stored kind, base64 is chunked, plugin state uses own keys, async plugin event handlers are caught, and a lifetime: 'turn' plugin that adds commands or config fails the turn with a clear error.

Docs. overview, usage, and media use the new callbacks (the usage sample no longer loops forever). sessions has a "React to events" section. The changed call shapes are updated in sessions, fork-and-reset, plugins, subagents, and store-reference. Factual fixes from the review are in store-reference, subagents, turn-control, durable-sessions, and media.

Changeset. None added. @tanstack/ai-harness, the new @tanstack/ai-persistence stores, and the @tanstack/ai-skills harness plugin are not released yet. Their changesets on feat/harness-core cover them.

✅ 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.
  • 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).

The changed packages ship with feat/harness-core, which already has their changesets.

Testing

Commands run.

  • Unit tests pass: @tanstack/ai-harness 748, @tanstack/ai-persistence 339, @tanstack/ai-skills 79, @tanstack/ai-acp 88.
  • test:types and test:oxlint for those packages: pass.
  • build and test:build for harness, persistence, and skills; pnpm test:knip, pnpm test:sherif, pnpm test:docs, kiira check docs/harness docs/persistence, pnpm test:dts: pass.
  • E2E: the harness specs passed once after the API change (4 passed, 2 gated skips). I did not run them again after the review fixes. CI runs them.
  • Not run: the full pnpm test:pr.

Manual test.

  1. Open docs/harness/overview.md step 3 and run the sample: text streams through next.onEvent('TEXT_MESSAGE_CONTENT', ...).
  2. Run pnpm --filter @tanstack/ai-harness test:lib -- tests/on-event.test.ts tests/session-media.test.ts.
  3. Run pnpm --filter @tanstack/ai-persistence test:lib to check the store conformance kit with the new shapes.

How this PR makes testing easy.

  • packages/ai-harness/tests/on-event.test.ts: the event listener behavior.
  • session-media.test.ts: onMedia and result.media.
  • One focused test per review fix, across the harness, persistence, and skills test files.
  • testing/e2e/tests/harness-continue.spec.ts checks that session.onEvent sees the streamed text.

Risk / rollback

  • Feature branches based on feat/harness-core (transport, view, plugins, coding tools, CLI, and more) must switch to the object call shapes and the media field when they rebase. TypeScript points at each call.
  • Behavior changes: inputs during close() are refused with closed, a session keeps the last 500 settled non-agent operations, and a lifetime: 'turn' plugin cannot add commands or config.
  • To undo, revert this PR. Nothing is released yet.

Public API change

Before

const turn = session.prompt('Draw a lighthouse.')
for await (const { event } of turn.events()) {
  if (event.type === 'TEXT_MESSAGE_CONTENT') process.stdout.write(event.delta)
  if (event.type === 'CUSTOM' && event.name === HARNESS_EVENTS.media && isMediaRecord(event.value)) {
    show(event.value)
  }
}
await host.sessions.rename(threadId, 'Porto trip')
await session.setConfig('tone', 'warm')
await logStore.append(threadId, seq, records)

After

const turn = session.prompt('Draw a lighthouse.')
turn.onEvent('TEXT_MESSAGE_CONTENT', ({ event }) => process.stdout.write(event.delta))
turn.onMedia(({ media }) => show(media))
const { media } = await turn

await host.sessions.rename({ threadId, title: 'Porto trip' })
await session.setConfig({ key: 'tone', value: 'warm' })
await logStore.append({ threadId, seq, records })

🤖 Generated with Claude Code

    1. ⚠️ No Changeset found

      Latest commit: 553a40f44f2cce46cb66ddc5102f6a6f8695052c

      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

    2. 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: ce2ac7da-ef29-40c0-b346-5a95bc643b91

      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.
    3. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit 553a40f44f2cce46cb66ddc5102f6a6f8695052c

      CommandStatusDurationResult
      nx run-many --targets=build --exclude=examples/...✅ Succeeded44sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-10-14 16:41:41 UTC

    4. Open in StackBlitz

      @tanstack/ai

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

      @tanstack/ai-acp

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

      @tanstack/ai-angular

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

      @tanstack/ai-anthropic

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

      @tanstack/ai-bedrock

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

      @tanstack/ai-byteplus

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

      @tanstack/ai-claude-code

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

      @tanstack/ai-client

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

      @tanstack/ai-cloudflare

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

      @tanstack/ai-code-mode

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

      @tanstack/ai-code-mode-snippets

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

      @tanstack/ai-codex

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

      @tanstack/ai-cohere

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

      @tanstack/ai-compaction

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

      @tanstack/ai-devtools-core

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

      @tanstack/ai-durable-stream

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

      @tanstack/ai-elevenlabs

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

      @tanstack/ai-event-client

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

      @tanstack/ai-fal

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

      @tanstack/ai-gemini

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

      @tanstack/ai-grok

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

      @tanstack/ai-grok-build

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

      @tanstack/ai-groq

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

      @tanstack/ai-harness

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

      @tanstack/ai-isolate-cloudflare

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

      @tanstack/ai-isolate-daytona

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

      @tanstack/ai-isolate-e2b

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

      @tanstack/ai-isolate-node

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

      @tanstack/ai-isolate-quickjs

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

      @tanstack/ai-isolate-quickjs-bun

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

      @tanstack/ai-llmgateway

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

      @tanstack/ai-lovable

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

      @tanstack/ai-mcp

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

      @tanstack/ai-memory

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

      @tanstack/ai-mistral

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

      @tanstack/ai-octane

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

      @tanstack/ai-ollama

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

      @tanstack/ai-ollaya

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

      @tanstack/ai-openai

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

      @tanstack/ai-opencode

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

      @tanstack/ai-openrouter

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

      @tanstack/ai-perplexity

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

      @tanstack/ai-persistence

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

      @tanstack/ai-preact

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

      @tanstack/ai-react

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

      @tanstack/ai-react-ui

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

      @tanstack/ai-reactor

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

      @tanstack/ai-remix

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

      @tanstack/ai-sandbox

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

      @tanstack/ai-sandbox-blaxel

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

      @tanstack/ai-sandbox-boxd

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

      @tanstack/ai-sandbox-cloudflare

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

      @tanstack/ai-sandbox-daytona

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

      @tanstack/ai-sandbox-docker

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

      @tanstack/ai-sandbox-e2b

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

      @tanstack/ai-sandbox-local-process

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

      @tanstack/ai-sandbox-railway

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

      @tanstack/ai-sandbox-sprites

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

      @tanstack/ai-sandbox-upstash-box

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

      @tanstack/ai-sandbox-vercel

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

      @tanstack/ai-skills

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

      @tanstack/ai-solid

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

      @tanstack/ai-solid-ui

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

      @tanstack/ai-svelte

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

      @tanstack/ai-typesafe

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

      @tanstack/ai-utils

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

      @tanstack/ai-vercel-gateway

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

      @tanstack/ai-vertex

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

      @tanstack/ai-vue

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

      @tanstack/ai-vue-ui

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

      @tanstack/ai-worldlabs

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

      @tanstack/openai-base

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

      @tanstack/preact-ai-devtools

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

      @tanstack/react-ai-devtools

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

      @tanstack/solid-ai-devtools

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

      @tanstack/svelte-ai-devtools

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

      commit: 553a40f

    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-harness91.62% (+0.53)86.57% (+0.27)90.81% (-0.36)93.21% (+0.57)ok
      ai-opencode68.77% (0.00)60.82% (0.00)64.04% (0.00)70.78% (0.00)ok
      ai-persistence91.87% (+0.01)80.88% (-0.08)97.99% (+0.01)95.68% (+0.03)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.04)68.53% (+0.83)87.36% (+0.13)85.48% (+0.13)ok
    6. AlemTuzlak merged this170879e

    7. AlemTuzlak closed this

Sign in to join this conversation.