feat(ai-harness, ai-persistence, ai-skills): onEvent and onMedia callbacks, object params, and review fixes #1779
feat/harness-core fromrefs/pull/1779/head·merged by AlemTuzlak View on GitHubYou 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)andsession.onEvent(type, listener). With a type,eventhas 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 }) => ...)andChatTurnResult.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.errorand 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),durableToolexecute(args, ctx),step.do(name, fn), andfn(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()(nowrejectedwithclosed), early turn failures that never settled, cancel did not reject a turn's or a command's questions, a failedopen()leaked plugins, reload during close,harnessTextabort 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,resumePendingreads 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-harness748,@tanstack/ai-persistence339,@tanstack/ai-skills79,@tanstack/ai-acp88. test:typesandtest:oxlintfor those packages: pass.buildandtest:buildfor 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.
- Open
docs/harness/overview.mdstep 3 and run the sample: text streams throughnext.onEvent('TEXT_MESSAGE_CONTENT', ...). - Run
pnpm --filter @tanstack/ai-harness test:lib -- tests/on-event.test.ts tests/session-media.test.ts. - Run
pnpm --filter @tanstack/ai-persistence test:libto 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:onMediaandresult.media.- One focused test per review fix, across the harness, persistence, and skills test files.
testing/e2e/tests/harness-continue.spec.tschecks thatsession.onEventsees 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 themediafield when they rebase. TypeScript points at each call. - Behavior changes: inputs during
close()are refused withclosed, a session keeps the last 500 settled non-agent operations, and alifetime: '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
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.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ 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_statustofalsein 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.
Comment `@coderabbitai help` to get the list of available commands.-
View your CI Pipeline Execution ↗ for commit 553a40f44f2cce46cb66ddc5102f6a6f8695052c
Command Status Duration Result nx run-many --targets=build --exclude=examples/...✅ Succeeded 44s View ↗
☁️ Nx Cloud last updated this comment at
2026-10-14 16:41:41UTC@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@1779commit:
553a40fCoverage#
✅ 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.package statements branches functions lines ai-acp 82.32% (0.00) 71.27% (0.00) 77.08% (0.00) 83.97% (0.00) ok ai-claude-code 88.93% (0.00) 76.88% (0.00) 86.88% (0.00) 90.40% (0.00) ok ai-codex 94.55% (0.00) 85.10% (0.00) 89.28% (0.00) 95.56% (0.00) ok ai-durable-stream 86.70% (0.00) 82.25% (0.00) 92.30% (0.00) 88.72% (0.00) ok ai-grok-build 79.19% (0.00) 63.56% (0.00) 77.39% (0.00) 81.02% (0.00) ok ai-harness 91.62% (+0.53) 86.57% (+0.27) 90.81% (-0.36) 93.21% (+0.57) ok ai-opencode 68.77% (0.00) 60.82% (0.00) 64.04% (0.00) 70.78% (0.00) ok ai-persistence 91.87% (+0.01) 80.88% (-0.08) 97.99% (+0.01) 95.68% (+0.03) ok ai-sandbox 77.45% (0.00) 82.80% (0.00) 74.47% (0.00) 77.97% (0.00) ok ai-sandbox-blaxel 87.64% (0.00) 77.18% (0.00) 82.26% (0.00) 89.71% (0.00) ok ai-sandbox-boxd 95.86% (0.00) 87.12% (0.00) 95.31% (0.00) 98.17% (0.00) ok ai-sandbox-cloudflare 67.91% (0.00) 57.47% (0.00) 71.79% (0.00) 69.62% (0.00) ok ai-sandbox-daytona 82.70% (0.00) 81.89% (0.00) 67.14% (0.00) 85.18% (0.00) ok ai-sandbox-docker 80.15% (0.00) 71.49% (0.00) 77.38% (0.00) 82.13% (0.00) ok ai-sandbox-e2b 94.42% (0.00) 88.97% (0.00) 93.24% (0.00) 98.63% (0.00) ok ai-sandbox-local-process 68.00% (0.00) 53.59% (0.00) 75.86% (0.00) 68.88% (0.00) ok ai-sandbox-railway 94.75% (0.00) 92.68% (0.00) 90.90% (0.00) 97.59% (0.00) ok ai-sandbox-sprites 73.23% (0.00) 59.70% (0.00) 73.83% (0.00) 76.17% (0.00) ok ai-sandbox-upstash-box 94.82% (0.00) 91.52% (0.00) 91.04% (0.00) 97.76% (0.00) ok ai-sandbox-vercel 44.67% (0.00) 38.18% (0.00) 35.18% (0.00) 45.76% (0.00) ok ai-skills 83.39% (+0.04) 68.53% (+0.83) 87.36% (+0.13) 85.48% (+0.13) ok AlemTuzlak merged this170879e
AlemTuzlak closed this
Sign in to join this conversation.
⚠️ 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