fix(ai-harness, ai-persistence): pass inputs to the instance that owns a thread, and other pre-release fixes #1780
feat/harness-core fromrefs/pull/1780/head·merged by AlemTuzlak View on GitHubOn a durable host that runs on more than one instance (Netlify, Vercel, Lambda), an input that reaches a second instance takes the session log from the instance that runs the turn, and that turn fails. This PR passes the input to the owner of the thread instead. It also fixes four smaller things that are breaking to change after release: approvals answered on another instance, log records from a newer version during a deploy, two store shapes, and definePlugin keys that are silently ignored.
Each fix is its own commit. Review them one at a time.
| Commit | What it fixes |
|---|---|
definePlugin refuses a setup() contribution at the top level | definePlugin({ name, adapter }) type-checked, and the adapter was never used. |
refuse to write a log that has a record type from a newer harness | During a rolling deploy, an old host skipped newer records and wrote on top of the wrong state. |
store shapes that third-party backends can implement | InboxStore needs a thread id on get/markApplied/markRejected. WorkClaimStore.get tells a host who owns a thread. Content-hash revisions (S3, Netlify Blobs ETags) are allowed. |
pass an input to the host that owns the thread | The multi-instance bug above, and ctx.session.ask answers that reach another instance. |
a host that opens a thread leaves a live owner's inputs alone | A request that opened the thread on another instance ran the owner's input before its run lease existed. |
a forwarded turn runs under the run id of the host that took it | A POST run on a non-owner instance streamed nothing. |
a host that passed an input on runs it if the owner stops | A forwarded input waited for a sweep after the owner crashed. |
run a forwarded input safely when the owner stops | Review fixes. A host that passed a POST run on refused it as conflict when it ran it itself. A failed log write lost a forwarded prompt, because the entry was marked applied first. A host that took a thread through the inbox never recovered the stopped owner's inputs. |
a forwarded resume runs as its run id, and two lint errors | Review fixes. A POST run with resume on a non-owner host got HTTP 409, and the owner ran it under another id. test:oxlint failed in CI. |
keep a forwarded secret answer out of the inbox | Review fix. A secret answer that reached another host stayed in stores.inbox as typed. New InboxStore.delete: the owner deletes a forwarded answer after it applies it. |
a forwarded input runs once, keeps its wake mark, and ids stay bounded | Review fixes. The owner applied a forwarded command again on each inbox read after a failed markApplied. A forwarded wake lost its mark. The forwarded id set grew forever. |
refuse a revert on a host that does not own the thread | Review fix. revert and unrevert on a non-owner host wrote to the log during the owner's turn, and that turn failed with a log conflict. They now refuse with busy. |
🎯 Changes#
- With
stores.workClaims,accept()checks who owns the thread. Withstores.inbox(now allowed in durable mode), an input for a thread that another host owns waits in the inbox, and the receipt isqueued. The owner reads the inbox every second while it holds the claim. Without an inbox, the input is refused withowned_elsewhere. - A question from
ctx.session.askclaims its thread, and a thread with a pending question is not idle. So an answer that reaches another host goes to the host that asked. - The owner deletes a forwarded answer from the inbox after it applies it (
InboxStore.delete). The other host cannot tell if a question is a secret, and the log keeps a secret answer as[secret]. - A log fold that sees an unknown
harness.*record type refuses to write (LogVersionError). Checkpoints list the record types their writer knew. definePluginrefusessetup()keys (adapter,tools,prompts, and so on) at the top level, in the type and at runtime. Other extra keys stay the plugin's own API, such assnapshots().diff.- Docs:
durable-sessions.md(inputs on another instance, rolling deploys, questions and claims),plugins.md, andstore-reference.md.
This came out of hosting the harness on Netlify Play: the full analysis and test results are in the PR stack discussion.
✅ 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:prcompares againstmain, which this stacked PR is not based on.) - 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. On a durable host with more than one instance, an input (prompt, steer, follow-up, answer) that reaches an instance that does not run the thread makes the running turn fail with LogConflictError. Two instances on one cold start is common on serverless platforms. Approvals from ctx.session.ask are lost when the answer reaches another instance.
Cause. markBusy() in session/base.ts claims the thread, but a claim that another host holds is ignored, and accept() appends the input to the log anyway. The log's compare-and-append fences the second writer, and stopOnLogFailure aborts every operation of the loser, which can be the owner. ask() keeps the question in an in-memory map, so answer() on another host returns unknown_question.
Fix. accept() reads the work claim. When another live host holds it, the input goes to stores.inbox (or is refused without one), and the owner applies it through the normal session methods. A pending question keeps its thread claimed, so its answer is forwarded the same way.
Possible alternatives#
- Reject only (
owned_elsewhere) and no inbox. Smaller, and it is what happens withoutstores.inbox. Alone, it makes about half of the inputs fail on a platform with no sticky routing, so the inbox path is included. - Store questions and answers in the log. Would also make questions visible to every instance. It changes the client API of questions (they would become interrupts), which this PR avoids. Forwarding the answer to the owner keeps the API.
- Version every log record (
vfield). The skip-and-refuse check on record types covers the deploy case with no new field, as long as a changed record meaning gets a new type name. The docs ofLogVersionErrorsay so.
Testing#
Commands run (after a merge of the current feat/harness-core, with #1757 and #1759):
ai-harness:vitest run1155/1155,test:types,test:oxlint: pass.ai-persistence:vitest run339/339,test:types,test:oxlint: pass.pnpm test:kiira(1870 snippets) andpnpm test:docs: pass.- Before the review fixes: E2E
playwright test harness(4 specs, includingharness-forwarding.spec.ts) passed. Not run again locally after the review fixes: CI runs it. - Not run:
pnpm test:pr,test:knip,test:sherif(they compare againstmain).
Repro before and after (agent-written tests, run against feat/harness-core and this branch):
- Second host input: on
feat/harness-core, the owner's turn fails withAnother host wrote to this log, so this session stopped.On this branch it completes, and the input is refused (no inbox) or runs after the turn (inbox). - Answer on another host: on
feat/harness-corethe receipt isrejected: unknown_questionand the owner's session closes. On this branch the command resolves with the answer. tests/forwarding.test.ts,tests/define-plugin.test.ts, and the new cases intests/log.test.ts: 9 fail onfeat/harness-core, all pass here.- Review fixes: 9 new cases in
tests/forwarding.test.ts(revert refused, POST run taken back, failed store keeps the entry, recovery on takeover, forwarded resume, secret answer, command runs once, wake mark, bounded ids). Each fails without its fix and passes with it.
Manual test
- Run
npx vitest run tests/forwarding.test.tsinpackages/ai-harness. It starts two hosts on one set of memory stores. - Check the cases: an input queued for the owner, refused without an inbox, run after the owner stops, a
POST runstreamed under its run id, and an answer that reaches the host that asked.
Also tested on Netlify Play. A Netlify Server app built on this stack (with Blobs stores) sent 16 follow-ups during a running turn. All 16 reached a non-owner instance, went through the inbox, and ran on the owner. A 4-agent research test with self-scheduled wake-ups passed.
How this PR makes testing easy: tests/forwarding.test.ts (two hosts in one process) and testing/e2e/tests/harness-forwarding.spec.ts.
Risk / rollback#
- A durable host with
workClaimsand noinboxnow refuses inputs for a thread that another live host owns (owned_elsewhere), where it ran them before. That is the intended change, and the docs say to addinbox. definePluginthrows for asetup()key at the top level. A plugin that did this had a key that never worked.- Store authors must update
InboxStoremethods, addInboxStore.delete, and addWorkClaimStore.get. None of these interfaces is released yet. - Rollback: revert the PR.
Public API change#
Before
await inbox.markApplied({ inputId, operationId })
const entry = await inbox.get(inputId)
// no way to read a claim
const host = createHarnessHost({
persistence: { stores: { log, runs, workClaims } }, // inbox refused with log
})
After
await inbox.markApplied({ threadId, inputId, operationId })
const entry = await inbox.get({ threadId, inputId })
const claim = await workClaims.get(threadId) // { ownerId, until } | null
await inbox.delete({ threadId, inputId }) // the owner removes a forwarded answer
const host = createHarnessHost({
persistence: { stores: { log, runs, workClaims, inbox } },
})
const receipt = await session.followUp('And then?') // 'queued' when another host owns the thread
🤖 Generated with Claude Code
- 1
🦋 Changeset detected#
Latest commit: c99760c4354f1ea181d191f13b2116077f7bc241
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 5 packages
Name Type @tanstack/ai-harness Patch @tanstack/ai-persistence Patch @tanstack/ai-acp Patch @tanstack/ai-mcp Patch @tanstack/ai-skills Patch 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
These six PRs come from running the harness stack on Netlify Play (several instances, no sticky routing). Each one targets the PR it fixes:
Fix PR Into What #1780 #1755 core Inputs go to the instance that owns the thread, answers reach the instance that asked, log records from a newer version, store shapes, definePluginkeys#1781 #1757 transport Join and resume a run on any instance; canAccess,mediaSecret, and OAuthloginare required#1782 #1768 CLI Passes canAccessandmediaSecret(needs #1781)#1783 #1760 worker build Two tests pass canAccess(needs #1781)#1784 #1765 provider keys One test uses the new inbox.get(needs #1780 first)#1785 #1769 code mode Tells the model what execute_typescriptreturnsMerge order: #1780 and #1781 first, then the others. All six together, merged with every PR of the stack, pass build, types, unit tests, and the full E2E suite.
Not in these PRs: #1764 conflicts with
mainin 26 files (it carries unsquashed copies of #1750), and #1768 carries an older copy of the session view that #1761 replaced infeat/harness-transport. Both need a rebase.View your CI Pipeline Execution ↗ for commit c99760c4354f1ea181d191f13b2116077f7bc241
Command Status Duration Result nx run-many --targets=build --exclude=examples/...✅ Succeeded 42s View ↗
☁️ Nx Cloud last updated this comment at
2026-10-15 11:47:24UTC@tanstack/ai
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@1780@tanstack/ai-acp
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-acp@1780@tanstack/ai-angular
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-angular@1780@tanstack/ai-anthropic
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@1780@tanstack/ai-bedrock
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-bedrock@1780@tanstack/ai-byteplus
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-byteplus@1780@tanstack/ai-claude-code
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-claude-code@1780@tanstack/ai-client
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@1780@tanstack/ai-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cloudflare@1780@tanstack/ai-code-mode
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode@1780@tanstack/ai-code-mode-snippets
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode-snippets@1780@tanstack/ai-codex
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-codex@1780@tanstack/ai-cohere
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cohere@1780@tanstack/ai-compaction
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-compaction@1780@tanstack/ai-devtools-core
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@1780@tanstack/ai-durable-stream
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-durable-stream@1780@tanstack/ai-elevenlabs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-elevenlabs@1780@tanstack/ai-event-client
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-event-client@1780@tanstack/ai-fal
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-fal@1780@tanstack/ai-gemini
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@1780@tanstack/ai-grok
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@1780@tanstack/ai-grok-build
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok-build@1780@tanstack/ai-groq
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-groq@1780@tanstack/ai-harness
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-harness@1780@tanstack/ai-isolate-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-cloudflare@1780@tanstack/ai-isolate-daytona
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-daytona@1780@tanstack/ai-isolate-e2b
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-e2b@1780@tanstack/ai-isolate-node
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-node@1780@tanstack/ai-isolate-quickjs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs@1780@tanstack/ai-isolate-quickjs-bun
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs-bun@1780@tanstack/ai-llmgateway
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-llmgateway@1780@tanstack/ai-lovable
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-lovable@1780@tanstack/ai-mcp
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mcp@1780@tanstack/ai-memory
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-memory@1780@tanstack/ai-mistral
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mistral@1780@tanstack/ai-octane
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-octane@1780@tanstack/ai-ollama
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@1780@tanstack/ai-ollaya
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollaya@1780@tanstack/ai-openai
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@1780@tanstack/ai-opencode
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-opencode@1780@tanstack/ai-openrouter
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@1780@tanstack/ai-perplexity
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-perplexity@1780@tanstack/ai-persistence
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-persistence@1780@tanstack/ai-preact
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@1780@tanstack/ai-react
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@1780@tanstack/ai-react-ui
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@1780@tanstack/ai-reactor
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-reactor@1780@tanstack/ai-remix
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-remix@1780@tanstack/ai-sandbox
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox@1780@tanstack/ai-sandbox-blaxel
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-blaxel@1780@tanstack/ai-sandbox-boxd
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-boxd@1780@tanstack/ai-sandbox-cloudflare
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-cloudflare@1780@tanstack/ai-sandbox-daytona
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-daytona@1780@tanstack/ai-sandbox-docker
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-docker@1780@tanstack/ai-sandbox-e2b
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-e2b@1780@tanstack/ai-sandbox-local-process
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-local-process@1780@tanstack/ai-sandbox-railway
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-railway@1780@tanstack/ai-sandbox-sprites
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-sprites@1780@tanstack/ai-sandbox-upstash-box
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-upstash-box@1780@tanstack/ai-sandbox-vercel
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-vercel@1780@tanstack/ai-skills
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-skills@1780@tanstack/ai-solid
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@1780@tanstack/ai-solid-ui
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@1780@tanstack/ai-svelte
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@1780@tanstack/ai-typesafe
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-typesafe@1780@tanstack/ai-utils
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-utils@1780@tanstack/ai-vercel-gateway
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vercel-gateway@1780@tanstack/ai-vertex
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vertex@1780@tanstack/ai-vue
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@1780@tanstack/ai-vue-ui
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@1780@tanstack/ai-worldlabs
npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-worldlabs@1780@tanstack/openai-base
npm i https://pkg.pr.new/TanStack/ai/@tanstack/openai-base@1780@tanstack/preact-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@1780@tanstack/react-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@1780@tanstack/solid-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@1780@tanstack/svelte-ai-devtools
npm i https://pkg.pr.new/TanStack/ai/@tanstack/svelte-ai-devtools@1780commit:
c99760cCoverage#
✅ Coverage held across 22 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 92.86% (-0.02) 87.40% (-0.02) 93.30% (+0.09) 94.42% (-0.03) ok ai-mcp 96.71% (0.00) 91.77% (0.00) 96.86% (0.00) 98.66% (0.00) ok ai-opencode 68.77% (0.00) 60.82% (0.00) 64.04% (0.00) 70.78% (0.00) ok ai-persistence 91.92% (+0.05) 80.94% (+0.06) 98.00% (+0.01) 95.71% (+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.00) 68.53% (0.00) 87.36% (0.00) 85.48% (0.00) ok github-actions[bot](GitHub profile, opens in a new tab) assignedAlemTuzlak
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: author
AlemTuzlak approved these changes
AlemTuzlak merged this634ac2f
AlemTuzlak closed this
Sign in to join this conversation.
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
48f62658-406b-4ecc-bc72-4aa3fc1936f0You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
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