Skip to content

fix(channels example): pi adapter rejects unsupported attachments, keeps message ids across forks - #2491

Draft
cjol wants to merge 4 commits into
mainfrom
fix/pi-adapter-inputs-forks
Draft

cjol wants to merge 4 commits into
mainfrom
fix/pi-adapter-inputs-forks

Conversation

@cjol

@cjol cjol commented Oct 5, 2026

Copy link
Copy Markdown
Member

This PR fixes two gaps in the pi harness adapter of the Channels example (piChannelsHarness in examples/next/channels/src/pi/channels-harness.ts): dropped attachments and lost message ids after a fork. It also adds the example's first test setup.

Why

  • toUserInput silently dropped any part that was not an inline base64 image, so pi answered a prompt missing the PDF or remote image the user sent, with no sign anything was lost.
  • After a fork, inherited user messages showed under pi entry ids instead of the caller's message ids. resolve only looked at the fork's own submissions and cache namespace, but the inherited entries were placed by the parent session.
  • For the fork fix, two options: copy the entry-to-message mappings at fork time, or resolve each entry against the session that placed it. pi keeps the original conversationId on inherited entries, so resolving by that needs no fork hook, covers forks of forks, and falls back to pi's own submission records after eviction. Copying would need a scan at fork time and would miss mappings not yet cached.

Code Changes

  • toUserInput now throws for parts pi cannot take (non-image, non-text files, or files by URL), naming the media type. The submit fails before anything is recorded, so Channels rejects the event.
  • Inline text/* files are decoded into text parts, since pi takes text. Images use the part's mediaType and accept data URLs with extra parameters.
  • transcript() groups user entries by entry.conversationId and resolves each group against that session's operation records.
  • src/tests/: a Workers-pool vitest with a Durable Object running PiHarness on pi-ai's faux provider, modelled on examples/next/harnesses/pi/src/tests. Adds test and typecheck scripts, and the vitest pool types to the example's tsconfig.json.

@changeset-bot

changeset-bot Bot commented Oct 5, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 16a09f2

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

@agent-think

agent-think Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

✅ agents import sizes: no significant changes (1e97e117 → 16a09f27, workflow run)

@pkg-pr-new

pkg-pr-new Bot commented Oct 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 16a09f2

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