Skip to content

fix(ai-chat): wrap onRequest in constructor to guarantee /get-messages works#953

Merged
threepointone merged 7 commits into
mainfrom
fix/ai-chat-get-messages-wrapper
Feb 23, 2026
Merged

fix(ai-chat): wrap onRequest in constructor to guarantee /get-messages works#953
threepointone merged 7 commits into
mainfrom
fix/ai-chat-get-messages-wrapper

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Move /get-messages handling from the prototype override to a constructor wrapper. This ensures the endpoint works even if users override onRequest without calling super.onRequest().

Why this is needed

When users override onRequest in their AIChatAgent subclass without calling super.onRequest(), the /get-messages endpoint doesn't work, causing messages to not persist on page reload.

Changes

  • Add constructor wrapper for onRequest that handles /get-messages before delegating to user code
  • Remove the now-redundant override onRequest() method

Note to reviewer

Pretty sure this isnt a breaking change.

  • Users calling super.onRequest(): Same behavior
  • Users NOT calling super.onRequest(): Was broken (404), now fixed
  • Users not overriding: Same behavior

Test plan

  • All 195 existing ai-chat tests pass

…s works

Move /get-messages handling from the prototype override to a constructor
wrapper. This ensures the endpoint works even if users override onRequest
without calling super.onRequest().

Not a breaking change - fixes broken code without affecting working code.
@changeset-bot

changeset-bot Bot commented Feb 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2c66c3b

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

This PR includes changesets to release 1 package
Name Type
@cloudflare/ai-chat 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 Feb 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/agents@953
npm i https://pkg.pr.new/cloudflare/agents/@cloudflare/ai-chat@953
npm i https://pkg.pr.new/cloudflare/agents/@cloudflare/codemode@953
npm i https://pkg.pr.new/cloudflare/agents/hono-agents@953

commit: 2c66c3b

Detect the /get-messages endpoint by comparing the last path segment (url.pathname.split('/').pop()) instead of using endsWith. Add a new AgentWithoutSuperCall Durable Object and register it in Env and the wrangler test config. Include tests to ensure /get-messages works when onRequest is overridden without calling super, and that non-get-messages routes are still delegated to the user's onRequest override.
@threepointone
threepointone merged commit bd22d60 into main Feb 23, 2026
4 checks passed
@threepointone
threepointone deleted the fix/ai-chat-get-messages-wrapper branch February 23, 2026 10:30
@github-actions github-actions Bot mentioned this pull request Feb 23, 2026
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.

2 participants