Repository navigation
feat(agents)!: start a Pi session from an existing history - #2926
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: e34ae06 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
Contributor
🟡 agents import sizes: 1 entry point grew
Changed exports (1)
How this worksEach 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 |
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
A host that starts a session from an existing history needs Pi's `init`
on the commit that creates the conversation. PiHarness created the root
when Pi opened, in onStart, before any request could seed it.
- Opening Pi no longer creates the root. The first use of the root session
(`conversation()`) creates it with `defaults`, through `pi.root()`, which
returns an existing root as is.
- `harness.root({ agent, init })` creates the root with `agent` over
`defaults` and `init` in one commit, and reports `created`: whether its
`init` ran in the commit that created the root. Pi runs a commit's
callback once and resolves only once it is stored, so this is exact.
- `sessions.create()` and `sessions.fork()` take the same options
(`PiSessionCreateOptions`).
- The contract type test pins the options to Pi's `ConversationCreateOptions`
and `Harness.root()`.
- Test fixtures that read the root through `pi.root()` create it through
the harness first, so it still gets `defaults`.
root() and sessions.create() spread agent over the defaults, so a field that was explicitly undefined replaced the default, and pi then ignored it: the session was created without its default model, thinking level or turn limit. The merge now follows pi's rule for an AgentChange: undefined leaves the default, null clears it.
ben-reitz
force-pushed
the
feat/pi-root-init
branch
from
November 20, 2026 15:09
78f05d5 to
e34ae06
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A host couldn't start a Pi session from a chat history it already has.
PiHarnesscreated the root session as soon as Pi opened, before any request arrived, so there was no point at which Pi'sinitcould be passed. Now the root is created on its first use, and everywherePiHarnesscreates a session it takes Pi'sinit.Summary
agentandinitare Pi's ownAgentChangeandConversationInit, passed through.agentis applied overdefaultsfor the root andcreate(), and over the parent's configuration for a fork.initruns in the commit that creates the session. If the root already exists, nothing is written andinitdoesn't run;createdsays which happened. Aninitthat throws creates nothing, so a laterroot()can try again.pi.mdhas a copyable example, one entry per message.Evidence
PiHarness's root sessionfail.After:
vitest run --project harness-pipasses, 115 tests (102 existing, unchanged, and 13 new).created: false; a seed racing a prompt creates the root once; a failinginitcreates nothing; a session created before the root doesn't take id"1"; an object restarted before its root exists can still be seeded;create()andfork()seed too.agentfollows Pi's rule when it is applied overdefaults: anundefinedfield keeps the default andnullclears it. Without that merge, the twoundefinedtests fail.PiSessionCreateOptionsto Pi'sConversationCreateOptionswithoutownership.Merge Danger
Door: two-way
Objects that already have a root behave as before. Seeded entries are ordinary Pi entries.
Blast Radius: new objects
On an object whose root has not been used yet:
sessions.list()doesn't include the root.harness.pi(),pi.conversation(ROOT_CONVERSATION_ID)returnsundefined, and Pi's ownpi.root()creates the root withoutdefaults. Code that does either should callharness.root()first.