Skip to content

Match Convex 1.50 scheduling and support future references and services - #203

Merged
ianmacartney merged 6 commits into
mainfrom
ian/convex-150-parity
Nov 17, 2026
Merged

ianmacartney merged 6 commits into
mainfrom
ian/convex-150-parity

Conversation

@ianmacartney

@ianmacartney ianmacartney commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Scheduled mutation self-cancellation currently commits writes, marks the job canceled, and then hits a scheduler invariant. Match the installed Convex version: 1.50+ throws ScheduledFunctionCancelingItself, with rollback and a failed job when uncaught; older versions warn and ignore cancellation. A simple major/minor comparison includes future major versions. Direct cancellation from actions remains allowed; mutations use the inherited scheduled request ID, including mutations called by scheduled actions.

Accept FunctionReference_future in t.query, t.mutation, and t.action, using Convex's exported types, OptionalRestArgs, and FunctionReturnType. Raise the Convex peer floor from ^1.43.0 to ^1.46.0, where these exports are available. The development dependency is 1.50.0.

Add 1.0/createServiceToken and 1.0/getServiceUrl for actions and HTTP actions. The AI gateway receives an unsigned five-minute test JWT and https://ai-gateway.convex.test; unsupported services and query/mutation calls fail. Adapt the JWT test fixture to 1.50's required claims property.

v.function() remains with #182. Includes a patch changeset documenting the new peer floor.

Remaining action-cancellation parity gaps are documented with a TODO and deferred: new tasks scheduled after cancellation should start canceled (including through nested calls), canceled actions should stay canceled if they later throw, and canceling terminal jobs should preserve their state.

Validation:

  • Published Convex 1.50: full build, lint, typecheck, and all 549 tests pass.
  • Minimum supported Convex 1.46: built declarations compile with exactOptionalPropertyTypes, including future-reference argument/return inference; 33 focused runtime tests pass.
  • Covers the 1.50 threshold and future major versions, uncaught rollback, caught errors, nested/component cancellation, action descendants, direct action cancellation, future-reference typing, service claims, and HTTP actions.
  • git diff --check passes.

@pkg-pr-new

pkg-pr-new Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/convex-test@203

commit: 30f446e

Comment thread index.ts Resolved
@ianmacartney
ianmacartney marked this pull request as ready for review November 13, 2026 22:03

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 8 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="index.ts">

<violation number="1" location="index.ts:2228">
P2: Cancellation does not propagate to tasks scheduled afterward, so a canceled action can still enqueue work that runs. Track the canceled request through nested scheduling and create those descendant jobs as canceled.</violation>

<violation number="2" location="index.ts:2228">
P2: An action that cancels its own scheduled job and then throws is recorded as `failed`, overwriting `canceled`. Preserve the canceled state when handling a post-cancellation action error.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread index.ts
await getSyscalls().asyncSyscall("1.0/cancel_job", jsonArgs);
// Actions may cancel their own job; only mutation cancellation
// checks the scheduled request ID.
db.patch("_scheduled_functions", args.id, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Cancellation does not propagate to tasks scheduled afterward, so a canceled action can still enqueue work that runs. Track the canceled request through nested scheduling and create those descendant jobs as canceled.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At index.ts, line 2228:

<comment>Cancellation does not propagate to tasks scheduled afterward, so a canceled action can still enqueue work that runs. Track the canceled request through nested scheduling and create those descendant jobs as canceled.</comment>

<file context>
@@ -2213,8 +2218,16 @@ function asyncSyscallImpl() {
-          await getSyscalls().asyncSyscall("1.0/cancel_job", jsonArgs);
+          // Actions may cancel their own job; only mutation cancellation
+          // checks the scheduled request ID.
+          db.patch("_scheduled_functions", args.id, {
+            state: { kind: "canceled" },
+          });
</file context>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the cloud behavior is that canceling an action retroactively cancels any of its scheduled work. but i think it does prevent future scheduling. we can just comment that here for now and fix in a follow-up PR though. that might be more involved

Comment thread index.ts
await getSyscalls().asyncSyscall("1.0/cancel_job", jsonArgs);
// Actions may cancel their own job; only mutation cancellation
// checks the scheduled request ID.
db.patch("_scheduled_functions", args.id, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: An action that cancels its own scheduled job and then throws is recorded as failed, overwriting canceled. Preserve the canceled state when handling a post-cancellation action error.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At index.ts, line 2228:

<comment>An action that cancels its own scheduled job and then throws is recorded as `failed`, overwriting `canceled`. Preserve the canceled state when handling a post-cancellation action error.</comment>

<file context>
@@ -2213,8 +2218,16 @@ function asyncSyscallImpl() {
-          await getSyscalls().asyncSyscall("1.0/cancel_job", jsonArgs);
+          // Actions may cancel their own job; only mutation cancellation
+          // checks the scheduled request ID.
+          db.patch("_scheduled_functions", args.id, {
+            state: { kind: "canceled" },
+          });
</file context>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an action that cancels itself I don't think throws in the cloud version, so it'll just go to a canceled state?

@dowski dowski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems good!

@ianmacartney
ianmacartney merged commit cd60c87 into main Nov 17, 2026
3 checks passed
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.

3 participants