Skip to content

ThinkHarness: operations are runs on its own Tasks instance - #3147

Merged
mattzcarey merged 6 commits into
mainfrom
slim/harness-h1
Nov 25, 2026
Merged

mattzcarey merged 6 commits into
mainfrom
slim/harness-h1

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

ThinkHarness runs each operation as a run on a Tasks instance it composes (tasks/@think-harness), one lane per session. submit is tasks.run, wait is tasks.wait, abort is tasks.cancel, a turn's progress is the run's checkpoint, and each server tool call is a run.do step that runs the tool and writes its result to the transcript. The harness's own wake job, 30 s heartbeat, backoff formula, waiter map, drive map and onMemoryLimit are gone, and records.ts keeps only sessions and client tools.

Operations were the last thing the harness scheduled itself (THINK-HARNESS.md, H1):

  • A reset mid tool call shows up as the step's second attempt, so the tool's recovery policy decides as before: reported as interrupted, or rerun when marked recovery: "rerun". A tool that finished is never run again: its step completes after its result is in the transcript.
  • A reset mid model call: the next attempt finds the stream id in the checkpoint and continues the same message. A second interruption in a row sleeps the run for backoffDelay(...) (now with jitter), which keeps the lane.
  • A run that ends outside its handler (an abort, the memory-limit breaker) is finished by its terminal report: partial kept, open tool calls failed, stream discarded. abort() holds the session's lane across the cancel, so the next queued operation starts after that partial is in the transcript.
  • The Think shell (think/src/harness/think.ts) gives the harness the Agent's default this.tasks (internal tasks option).
  • Open operations a released version left in the harness store (and, through the existing import, in the 0.27 tables) become runs at start, 50 at a time, in submission order; a running one is interrupted and resumes from its stored progress and started tool calls, and one the memory-limit breaker had sealed is finished with its partial kept. Settled ones are deleted in SQL without being read: their answers are in the transcript.
  • A cancelled attempt that is still unwinding (a hook it awaits, a tool that ignores its signal) writes nothing more to the transcript, and reset() cancels every open operation, however many.
  • design/think-harness.md describes the result. The user docs change waits for the release in docs(think harness): operations run on the harness's own Tasks #3152.
  • Tasks gains one option, peekList({ lane }), for pending(session) and reset(session).

Cost, per prompt() on the test fixture, main → this PR: plain reply rows written 24 → 21, rows read 121 → 115, statements 77 → 74, setAlarm 4 → 2; one tool call 38 → 35 written, 188 → 176 read, 118 → 108 statements, setAlarm 4 → 2; two parallel tool calls 42 → 39, 199 → 186, 130 → 117, 4 → 2. storage.sync() 0 → 0. A cold start reads the store for open operations and deletes settled ones: 2 statements and 0 rows once the store is empty (main: 1). A settled run keeps its checkpoint (keepCheckpoint, about 150 bytes) until reset(), as the store kept the same fields in meta.

Harness compat score (pnpm test:harness): 131 → 133 of the 1,246 tests that construct Think, nothing that passed before fails. harness-think (80, including a reset during afterToolCall, a clear past 100 queued operations, a carry-forward of 60 open operations behind 300 settled ones, a sealed turn carried forward, a reset between a tool and the model call after it, the abort order, the harness's runs apart from the host's own Tasks, and recovery inside a sub-agent woken through the root), tasks and channels tests ran, plus pnpm run check.

How to probe: deploy main and this head with a ThinkHarness host at the root and inside a sub-agent; ctx.abort() mid model stream, mid server tool call (a tool that counts its runs in KV), and between the tool's result and the next model call; check the tool count stays 1 (unless recovery: "rerun"), the reply is one message, and an upgrade from main over a queued and a running operation finishes both.

@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 61d8038

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

This PR includes changesets to release 2 packages
Name Type
agents Patch
@cloudflare/agent-think 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

@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@3147

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@3147

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@3147

hono-agents

npm i https://pkg.pr.new/hono-agents@3147

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@3147

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@3147

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@3147

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@3147

commit: 61d8038

@agent-think

agent-think Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🔴 agents import sizes: 3 entry points over threshold

Entry point Exports Largest gzip change Size now
🔴 agents/harness/think 1 resized +14 KiB (+7.13%) 209.8 KiB
🔴 agents/experimental/channels 2 resized up to +2.4 KiB (+350.07%) 3 KiB
🔴 agents/experimental/channels/web/client 1 resized +2.2 KiB (+81.35%) 5 KiB
🟡 agents/chat 190 resized up to +341 B (+3.65%) 9.5 KiB
🟡 agents/react 1 resized +209 B (+3.45%) 6.1 KiB
🟡 agents/streams 1 resized +137 B (+2.09%) 6.5 KiB
Changed exports (196)
Import Gzip change Size now
🔴 agents/harness/think#ThinkHarness +14 KiB (+7.13%) 209.8 KiB
🔴 agents/experimental/channels#applyChunks +2.4 KiB (+350.07%) 3 KiB
🔴 agents/experimental/channels/web/client#WebChannelClient +2.2 KiB (+81.35%) 5 KiB
🟡 agents/chat#createChatStreams +341 B (+3.65%) 9.5 KiB
🟡 agents/chat#AgentToolRuns +287 B (+3.91%) 7.5 KiB
🟡 agents/chat#StreamAccumulator +221 B (+5.83%) 3.9 KiB
🟡 agents/chat#AgentToolProgressEmitter +219 B (+6.27%) 3.6 KiB
🟡 agents/chat#enforceRowSizeLimit +219 B (+5.02%) 4.5 KiB
🟡 agents/chat#recentChatTerminal +217 B (+6.77%) 3.3 KiB
🟡 agents/chat#isDurableObjectResetError +217 B (+6.52%) 3.5 KiB
🟡 agents/chat#resolveChatRecoveryConfig +217 B (+6.35%) 3.5 KiB
🟡 agents/chat#persistReconstructedOrphan +217 B (+5.37%) 4.2 KiB
🟡 agents/chat#truncateOlderMessages +217 B (+5.37%) 4.2 KiB
🟡 agents/chat#TextSegmentJoiner +216 B (+6.41%) 3.5 KiB
🟡 agents/chat#mergeQueuedUserMessages +216 B (+6.35%) 3.5 KiB
🟡 agents/chat#isPlatformFailure +216 B (+6.27%) 3.6 KiB
🟡 agents/chat#ChatRequestContext +216 B (+5.98%) 3.7 KiB
🟡 agents/chat#runServerTurn +216 B (+5.81%) 3.8 KiB
🟡 agents/chat#ResumeHandshake +216 B (+4.74%) 4.7 KiB
🟡 agents/chat#CHAT_RECOVERY_INCIDENT_TTL_MS +215 B (+6.89%) 3.3 KiB
🟡 agents/chat#LiveReply +215 B (+6.76%) 3.3 KiB
🟡 agents/chat#replyIsEmpty +215 B (+6.75%) 3.3 KiB
🟡 agents/chat#isPositionlessAgentToolChunk +215 B (+6.73%) 3.3 KiB
🟡 agents/chat#setChatRecovering +215 B (+6.59%) 3.4 KiB
🟡 agents/chat#chatRecoveryStorageAdapter +215 B (+6.3%) 3.5 KiB
🟡 agents/chat#replyToContinueIsEmpty +215 B (+6.29%) 3.5 KiB
🟡 agents/chat#retryAfterSeconds +215 B (+6.17%) 3.6 KiB
🟡 agents/chat#interceptAgentToolBroadcast +215 B (+6.17%) 3.6 KiB
🟡 agents/chat#ChatAdmissions +215 B (+5.51%) 4 KiB
🟡 agents/chat#dispatchChatRecoveryToHandoff +215 B (+5.41%) 4.1 KiB
🟡 agents/chat#dispatchChatProtocol +215 B (+5.4%) 4.1 KiB
🟡 agents/chat#broadcastTransition +215 B (+5.1%) 4.3 KiB
🟡 agents/chat#truncateOlderToolResults +215 B (+4.84%) 4.6 KiB
🟡 agents/chat#pumpReply +215 B (+3.11%) 7 KiB
🟡 agents/chat#aiSdkRecoveryCodec +214 B (+6.85%) 3.3 KiB
🟡 agents/chat#chunkMustBeStoredNow +214 B (+6.82%) 3.3 KiB
🟡 agents/chat#CHAT_LAST_TERMINAL_KEY +214 B (+6.82%) 3.3 KiB
🟡 agents/chat#CHAT_RECOVERY_INCIDENT_KEY_PREFIX +214 B (+6.81%) 3.3 KiB
🟡 agents/chat#CONTEXT_OVERFLOW_PATTERN +214 B (+6.62%) 3.4 KiB
🟡 agents/chat#settleContinuationTurn +214 B (+6.56%) 3.4 KiB
🟡 agents/chat#chatRecoveryBackoffSeconds +214 B (+6.49%) 3.4 KiB
🟡 agents/chat#truncateProviderToolPayloads +214 B (+6.33%) 3.5 KiB
🟡 agents/chat#classifyProviderError +214 B (+6.12%) 3.6 KiB
🟡 agents/chat#responseSource +214 B (+6.03%) 3.7 KiB
🟡 agents/chat#chatRecoveryNames +214 B (+6.02%) 3.7 KiB
🟡 agents/chat#clearRecentChatTerminals +213 B (+6.75%) 3.3 KiB
🟡 agents/chat#withOriginMessageIds +213 B (+6.75%) 3.3 KiB
🟡 agents/chat#ChatStreamStalledError +213 B (+6.72%) 3.3 KiB
🟡 agents/chat#TransientChatStreamError +213 B (+6.72%) 3.3 KiB
🟡 agents/chat#bumpChatRecoveryProgress +213 B (+6.72%) 3.3 KiB

…and 146 more exports in the workflow artifact.

How this works

Each runtime export is bundled on its own, minified, and gzipped. Changes smaller than 100 B, or smaller than 1% and 1 KiB, are ignored. Growth over 10% or 5 KiB is marked 🔴. This report is informational and does not fail CI. The workflow artifact contains every measurement.

Compared cfa7a52f → 61d8038b · workflow run · reported by agent-think[bot]

@mattzcarey
mattzcarey marked this pull request as ready for review November 25, 2026 11:46
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

…settled operations; docs wait for the release (#3152)
devin-ai-integration[bot]

This comment was marked as resolved.

@mattzcarey
mattzcarey merged commit 8eeab0d into main Nov 25, 2026
26 checks passed
@mattzcarey
mattzcarey deleted the slim/harness-h1 branch November 25, 2026 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant