Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ai/rsc and middleware header size failing #1495

Open
mrjasonroy opened this issue May 6, 2024 · 0 comments
Open

ai/rsc and middleware header size failing #1495

mrjasonroy opened this issue May 6, 2024 · 0 comments
Labels

Comments

@mrjasonroy
Copy link

Description

With ai/rsc the post requests go to the same route and the AIState is send as part of the server action form header. As a conversation grows long and there is a lot of metadata, this can make the headers quite large.

Since many apps like ours use middleware for critical functions like authentication, this causes errors. I believe as of next 14.1, server actions go through middleware by default and this is causing this to happen often:

[POST] [middleware: "src/middleware"] /plugin/chat reason=REQUEST_HEADER_TOO_LARGE, status=431, user_error=true

While I realize this error isn't specific to ai/rsc, the way the library works to wrap server actions with the AIState in each request causes this in our case. I assume many people will run into this problem.

I believe the fix is to add next-action to the missing header.

      missing: [
        { type: 'header', key: 'next-router-prefetch' },
        { type: 'header', key: 'purpose', value: 'prefetch' },
        { type: 'header', key: 'next-action' },
      ],

We moved our implementation to the rsc library, which was a good amount of work but pushed a lot of logic to the server. But this caused us to have to revert before moving to production.

Should this directly be addressed in the docs or a code change?

Code example

No response

Additional context

We also use fairly large URLs to represent state and because next includes the router history in headers, the 2 add up to cause problems. Even when removing this we still ran into problems with large message history and metadata.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants