-
Notifications
You must be signed in to change notification settings - Fork 33
Fix auth adapter runtime parity #311
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| "kitcn": patch | ||
| --- | ||
|
|
||
| ## Patches | ||
|
|
||
| - Fix unbounded auth queries hanging after 200 rows. | ||
| - Prevent action contexts from exposing mutation-only transaction options. | ||
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
...ns/integration-issues/convex-auth-pagination-needs-forward-progress-20260730.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| --- | ||
| title: Convex auth pagination needs an unbounded budget and forward progress | ||
| date: 2026-07-30 | ||
| category: integration-issues | ||
| module: auth-adapter | ||
| problem_type: integration_issue | ||
| component: authentication | ||
| symptoms: | ||
| - unbounded auth count and findMany calls can loop after 200 rows | ||
| - shared runMutation contexts expose options unavailable from actions | ||
| root_cause: wrong_api | ||
| resolution_type: code_fix | ||
| severity: high | ||
| tags: [auth, convex, better-auth, pagination, action] | ||
| --- | ||
|
|
||
| # Convex auth pagination needs an unbounded budget and forward progress | ||
|
|
||
| ## Problem | ||
|
|
||
| The shared auth pagination helper treated a missing caller limit as a 200-row | ||
| total limit. After collecting the first page, it requested zero rows while | ||
| retaining the cursor and could loop forever. | ||
|
|
||
| The shared mutation runner type also used the mutation-context signature even | ||
| though its runtime union includes action contexts. Newer Convex versions allow | ||
| transaction-limit options only for nested calls inside mutations. | ||
|
|
||
| ## Symptoms | ||
|
|
||
| - `count()` and unbounded `findMany()` do not terminate above 200 matching rows. | ||
| - A stalled backend page can repeat forever when it is not done, returns | ||
| nothing, and leaves the cursor unchanged. | ||
| - TypeScript permits a transaction-options argument on a context that may be an | ||
| action, even though action runners accept only the function reference and | ||
| arguments. | ||
|
|
||
| ## Solution | ||
|
|
||
| Keep pagination unbounded only when the caller omits `limit`, while preserving | ||
| the 200-row per-page cap. Abort when a non-final page neither advances the | ||
| cursor nor produces rows or a count. | ||
|
|
||
| Type the shared `runMutation` property from `GenericActionCtx`. Mutation | ||
| contexts remain assignable because their runner supports the action-safe call | ||
| shape plus mutation-only options. | ||
|
|
||
| ## Why This Works | ||
|
|
||
| The page cap and total result limit are different constraints. An unbounded | ||
| query still fetches at most 200 rows per request, but every subsequent request | ||
| retains a positive budget until Convex reports completion. | ||
|
|
||
| The action signature is the common callable surface across both runtime | ||
| contexts. Consumers can call mutations safely without receiving options that | ||
| only one branch of the union can honor. | ||
|
|
||
| ## Prevention | ||
|
|
||
| 1. Test unbounded pagination with more rows than the per-page cap. | ||
| 2. Require every non-final pagination step to advance its cursor or produce | ||
| output. | ||
| 3. Type union-context methods from the narrowest runtime that must support the | ||
| call. | ||
| 4. Run the type regression against a pinned Convex version that exposes | ||
| mutation-only transaction options, while keeping the package baseline at its | ||
| minimum supported version. | ||
| 5. Re-audit copied Convex Better Auth helpers whenever upstream changes their | ||
| termination or context contracts. | ||
|
|
||
| ## Related | ||
|
|
||
| - `docs/solutions/integration-issues/convex-better-auth-upstream-sync-runtime-fixes-20260416.md` | ||
| - `docs/solutions/integration-issues/better-auth-1-6-support-needs-structural-convex-auth-wrappers-20260416.md` |
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import type { | ||
| FunctionReference, | ||
| GenericDataModel, | ||
| GenericMutationCtx, | ||
| } from 'convex/server'; | ||
| import { expectTypeOf, test } from 'vitest'; | ||
| import type { RunMutationCtx } from './context-utils'; | ||
|
|
||
| type TestMutation = FunctionReference< | ||
| 'mutation', | ||
| 'internal', | ||
| { value: string }, | ||
| null | ||
| >; | ||
|
|
||
| const checkCommonRunMutationCalls = ( | ||
| ctx: RunMutationCtx<GenericDataModel>, | ||
| mutation: TestMutation | ||
| ) => { | ||
| void ctx.runMutation(mutation, { value: 'accepted' }); | ||
|
|
||
| void ctx.runMutation( | ||
| mutation, | ||
| { value: 'rejected' }, | ||
| // @ts-expect-error transaction limits are unavailable from action contexts | ||
| { transactionLimits: { documentsRead: 1 } } | ||
| ); | ||
| }; | ||
|
|
||
| const checkMutationRunMutationOptions = ( | ||
| ctx: GenericMutationCtx<GenericDataModel>, | ||
| mutation: TestMutation | ||
| ) => { | ||
| void ctx.runMutation( | ||
| mutation, | ||
| { value: 'accepted' }, | ||
| { transactionLimits: { documentsRead: 1 } } | ||
| ); | ||
| }; | ||
|
|
||
| test('runMutation uses the call shape shared by mutation and action contexts', () => { | ||
| expectTypeOf< | ||
| RunMutationCtx<GenericDataModel>['runMutation'] | ||
| >().toBeFunction(); | ||
| expectTypeOf(checkCommonRunMutationCalls).toBeFunction(); | ||
| expectTypeOf(checkMutationRunMutationOptions).toBeFunction(); | ||
| }); |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "baseUrl": "../..", | ||
| "noEmit": true, | ||
| "paths": { | ||
| "convex/server": [ | ||
| "node_modules/convex-type-test/dist/esm-types/server/index.d.ts" | ||
| ] | ||
| } | ||
| }, | ||
| "exclude": [], | ||
| "include": ["src/**/*.test-d.ts", "../../tooling/global.d.ts"] | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RunMutationCtxis publicly exported fromkitcn/server, and this commit deliberately makes its thirdtransactionLimitsargument a type error, so existing consumers using that signature stop compiling. Classify this as a minor breaking change rather than a patch. .agents/rules/changeset.mdcL15-L19Useful? React with πΒ / π.