Skip to content

Add onSuccess, onFailure, and onCancel handlers#175

Open
reeceyang wants to merge 2 commits intomainfrom
reece/onSuccess
Open

Add onSuccess, onFailure, and onCancel handlers#175
reeceyang wants to merge 2 commits intomainfrom
reece/onSuccess

Conversation

@reeceyang
Copy link
Contributor

@reeceyang reeceyang commented Mar 6, 2026

Add onSuccess, onFailure, and onCancel handlers. The onSuccess handler runs in the same mutation or action as the work, while onFailure and onCancel are scheduled to run after (like onComplete). The new handlers cannot be used with onComplete. Users must choose between using onSuccess/onFailure/onCancel and using onComplete.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Summary by CodeRabbit

  • New Features

    • Added outcome-specific callbacks: onSuccess, onFailure, onCancel (mutually exclusive with onComplete)
    • onSuccess runs inline in the same transaction; onFailure/onCancel run in a separate transaction
    • Public run-result types exported to distinguish success/failed/canceled outcomes
  • Tests

    • Expanded coverage for by-outcome callbacks and large-context storage behavior
  • Documentation

    • Updated README and examples showing outcome-specific usage and context handling

@coderabbitai
Copy link

coderabbitai bot commented Mar 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7c4503af-48cf-4026-807b-3582e213704f

📥 Commits

Reviewing files that changed from the base of the PR and between 82f152d and 4a5e30a.

⛔ Files ignored due to path filters (1)
  • src/component/_generated/component.ts is excluded by !**/_generated/**
📒 Files selected for processing (12)
  • README.md
  • example/convex/example.ts
  • src/client/index.ts
  • src/component/complete.test.ts
  • src/component/complete.ts
  • src/component/lib.test.ts
  • src/component/lib.ts
  • src/component/loop.test.ts
  • src/component/loop.ts
  • src/component/recovery.test.ts
  • src/component/shared.ts
  • src/component/worker.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/component/loop.test.ts
  • src/component/recovery.test.ts
  • src/component/worker.ts
  • example/convex/example.ts
  • src/component/lib.ts
  • src/component/loop.ts

📝 Walkthrough

Walkthrough

Adds outcome-specific callbacks (onSuccess, onFailure, onCancel) alongside the existing onComplete, enforces mutual-exclusivity in enqueue options, splits RunResult schemas, resolves and executes per-outcome handlers (onSuccess inline when possible), and updates context/payload handling and tests accordingly.

Changes

Cohort / File(s) Summary
Client API & types
src/client/index.ts, src/component/shared.ts
Added vOnSuccessArgs, vOnFailureArgs, vOnCancelArgs + public OnSuccessArgs/OnFailureArgs/OnCancelArgs; split vResult into vSuccessResult/vFailureResult/vCancelResult; updated vOnCompleteFnContext to support byOutcome variant and adjusted EnqueueOptions union.
Completion resolution
src/component/complete.ts, src/component/complete.test.ts
Added getOnCompleteHandle to resolve handler (byOutcome or legacy), updated completeHandler to use resolved handle; tests extended with parameterized byOutcome cases for success/failure/cancel.
Worker & execution flow
src/component/worker.ts, src/component/loop.ts, src/component/loop.test.ts, src/component/recovery.test.ts
Propagated hasOnSuccess flag into wrappers and scheduler calls; when true, run onSuccess inline within mutation (worker wrappers) else schedule completion as before; added flag propagation to relevant tests.
Context / payload management
src/component/lib.ts, src/component/lib.test.ts
Refined context size calculation and single MAX_DOC_SIZE check; use Doc<"payload"> typing for payloads; guard deletion of onComplete.context; added tests for large-context payload storage for both onComplete and byOutcome.
Docs & examples
README.md, example/convex/example.ts
Documented onSuccess/onFailure/onCancel usage and transaction boundaries; added success and singleLatencyOnSuccess example mutations showing outcome-specific wiring.

Sequence Diagram(s)

sequenceDiagram
  participant Client as Client (enqueue)
  participant Scheduler as Scheduler
  participant Worker as Worker
  participant DB as Database
  participant Complete as completeHandler

  Client->>Scheduler: enqueue(work with onComplete OR byOutcome handlers)
  Scheduler->>DB: persist work item (payloadId if large context)
  Scheduler->>Worker: schedule work execution

  Worker->>DB: run function, produce RunResult
  alt onSuccess inline allowed (hasOnSuccess = true)
    Worker->>Complete: invoke completeHandler inline with runResult
    Complete->>DB: load/remove payload if needed, run onSuccess mutation
  else schedule completion
    Worker->>Scheduler: schedule completion job
    Scheduler->>Complete: completion job -> load work, resolve handler
    Complete->>DB: run onFailure/onCancel or byOutcome handler in separate txn
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • Nicolapps

Poem

🐰 I hopped through code to split the way,
Success springs forth without delay,
Fail and Cancel take a slower track,
Each outcome finds its tidy stack —
Hooray for handlers on their way! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding three new handler types (onSuccess, onFailure, onCancel) to the workpool system. It directly matches the primary objective of the PR and is specific enough for teammates to understand the core addition.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch reece/onSuccess
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 6, 2026

Open in StackBlitz

npm i https://pkg.pr.new/get-convex/workpool/@convex-dev/workpool@175

commit: 4a5e30a

@reeceyang reeceyang force-pushed the reece/onSuccess branch 5 times, most recently from ba787de to 0e15e01 Compare March 9, 2026 22:53
@reeceyang reeceyang changed the title Reece/on success Add onSuccess, onFailure, and onCancel handlers Mar 9, 2026
@reeceyang reeceyang force-pushed the reece/onSuccess branch 2 times, most recently from b89443a to 5754bc6 Compare March 9, 2026 23:38
@reeceyang reeceyang requested a review from ianmacartney March 9, 2026 23:41
@reeceyang reeceyang marked this pull request as ready for review March 9, 2026 23:42
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/component/lib.ts (1)

95-103: ⚠️ Potential issue | 🟠 Major

Store the shared outcome context once.

src/client/index.ts now copies one options.context value into every active onSuccess/onFailure/onCancel handler, and this code sizes/persists each copy independently. That means attaching all three hooks can turn a single ~350 KB context into a >1 MB enqueue here, even though only one outcome handler will ever run. Please keep that shared context in one field/payload entry instead of duplicating it per handler.

Also applies to: 125-137, 291-295

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/component/lib.ts` around lines 95 - 103, The current logic in
getContext/workArgs handling computes and persists each handler's copy of the
same options.context separately, inflating contextSize and storage; change the
code that builds the context payload so the shared options.context is stored
once and referenced by all outcome handlers (i.e., collapse duplicated
per-handler context entries into a single shared context field), compute
getConvexSize only once for that shared entry (use the same check against
MAX_DOC_SIZE), and update the packing logic used around getContext, the
onSuccess/onFailure/onCancel payload construction, and the similar blocks at the
other locations (lines around 125-137 and 291-295) so they all reference a
single context payload instead of duplicating it per handler while still
enforcing the size limit using MAX_DOC_SIZE and including workArgs.fnName in the
error message.
🧹 Nitpick comments (2)
src/component/schema.ts (1)

71-74: Schema extension looks good.

The new optional fields for onSuccess, onFailure, and onCancel are well-structured and correctly typed. The backwards compatibility comment is helpful.

Minor typo: "compatability" → "compatibility" on line 71.

📝 Typo fix
-    // onComplete should be undefined when any of onSuccess, onFailure, or onCancel are defined. This is enforced at the client level, but not in the schema for backwards compatability.
+    // onComplete should be undefined when any of onSuccess, onFailure, or onCancel are defined. This is enforced at the client level, but not in the schema for backwards compatibility.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/component/schema.ts` around lines 71 - 74, Fix the minor typo in the
comment above the schema fields: change "compatability" to "compatibility" in
the comment that precedes the onSuccess/onFailure/onCancel definitions (the
comment referencing onComplete and backwards compatibility) so the wording is
correct.
src/component/worker.ts (1)

110-120: Silent error suppression may hide issues.

The empty catch block on lines 117-119 silently swallows any errors from the runMutation call. While falling back to the scheduler is reasonable, consider logging a debug/warn message to aid troubleshooting when the inline path fails.

📝 Add logging for fallback path
       if (args.hasOnSuccess) {
         try {
           // Attempt to run the onSuccess handler now
           await ctx.runMutation(internal.complete.complete, {
             jobs: [{ workId, runResult, attempt }],
           });
           return;
-        } catch {
+        } catch (e) {
+          console.debug("Inline onSuccess failed, falling back to scheduler", e);
           // Fall through and schedule complete instead
         }
       }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/component/worker.ts` around lines 110 - 120, The empty catch on the
inline onSuccess path (the block around args.hasOnSuccess and the
ctx.runMutation(internal.complete.complete, { jobs: [{ workId, runResult,
attempt }] })) should not silently swallow errors; update the catch to log the
caught error and context before falling back to scheduling (e.g., log a
debug/warn with the error and identifiers workId, attempt, maybe runResult
summary) using the existing logger (e.g., ctx.logger or processLogger) so
failures of ctx.runMutation are visible while preserving the fallback behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/client/index.ts`:
- Around line 445-466: The defineOnCancel declaration uses the wrong types:
update its return type from RegisteredMutation<"internal", OnFailureArgs, null>
to RegisteredMutation<"internal", OnCancelArgs, null>, and change the handler's
result parameter type from FailureResult to the cancel-specific type (RunResult
& { kind: "canceled" }) so it matches the args produced by
vOnCancelArgs(context); ensure you only adjust the generic signature and the
handler args in defineOnCancel (preserving GenericDataModel, V, context,
vOnCancelArgs, and internalMutationGeneric usage) so callers and onCancel
handlers type-check correctly.

---

Outside diff comments:
In `@src/component/lib.ts`:
- Around line 95-103: The current logic in getContext/workArgs handling computes
and persists each handler's copy of the same options.context separately,
inflating contextSize and storage; change the code that builds the context
payload so the shared options.context is stored once and referenced by all
outcome handlers (i.e., collapse duplicated per-handler context entries into a
single shared context field), compute getConvexSize only once for that shared
entry (use the same check against MAX_DOC_SIZE), and update the packing logic
used around getContext, the onSuccess/onFailure/onCancel payload construction,
and the similar blocks at the other locations (lines around 125-137 and 291-295)
so they all reference a single context payload instead of duplicating it per
handler while still enforcing the size limit using MAX_DOC_SIZE and including
workArgs.fnName in the error message.

---

Nitpick comments:
In `@src/component/schema.ts`:
- Around line 71-74: Fix the minor typo in the comment above the schema fields:
change "compatability" to "compatibility" in the comment that precedes the
onSuccess/onFailure/onCancel definitions (the comment referencing onComplete and
backwards compatibility) so the wording is correct.

In `@src/component/worker.ts`:
- Around line 110-120: The empty catch on the inline onSuccess path (the block
around args.hasOnSuccess and the ctx.runMutation(internal.complete.complete, {
jobs: [{ workId, runResult, attempt }] })) should not silently swallow errors;
update the catch to log the caught error and context before falling back to
scheduling (e.g., log a debug/warn with the error and identifiers workId,
attempt, maybe runResult summary) using the existing logger (e.g., ctx.logger or
processLogger) so failures of ctx.runMutation are visible while preserving the
fallback behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4d4a1e5d-4696-4618-beb7-4adf53babfac

📥 Commits

Reviewing files that changed from the base of the PR and between d494518 and 31aac46.

⛔ Files ignored due to path filters (1)
  • src/component/_generated/component.ts is excluded by !**/_generated/**
📒 Files selected for processing (10)
  • src/client/index.ts
  • src/component/complete.test.ts
  • src/component/complete.ts
  • src/component/lib.ts
  • src/component/loop.test.ts
  • src/component/loop.ts
  • src/component/recovery.test.ts
  • src/component/schema.ts
  • src/component/shared.ts
  • src/component/worker.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/client/index.ts (1)

445-461: ⚠️ Potential issue | 🟠 Major

defineOnCancel still exposes the failure result type.

vOnCancelArgs() and OnCancelArgs both describe a canceled result, but the handler signature here still says FailureResult. That makes cancel handlers type-check against the wrong payload shape.

🐛 Proposed fix
     handler: (
       ctx: GenericMutationCtx<DataModel>,
       args: {
         workId: WorkId;
         context: Infer<V>;
-        result: FailureResult;
+        result: RunResult & { kind: "canceled" };
       },
     ) => Promise<void>;
#!/bin/bash
# Verify that defineOnCancel's handler type matches vOnCancelArgs/OnCancelArgs.
rg -n -A12 -B4 'defineOnCancel<|vOnCancelArgs|type OnCancelArgs|result:\s*FailureResult' src/client/index.ts
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/client/index.ts` around lines 445 - 461, The handler signature for
defineOnCancel incorrectly types the payload as FailureResult; update it to use
the cancel-args type so it matches vOnCancelArgs/OnCancelArgs. Concretely, in
defineOnCancel (the handler arg shaped { workId, context, result }), replace
FailureResult with the cancel args result type (e.g. OnCancelArgs['result'] or
the project's CanceledResult alias) so the handler's result matches
vOnCancelArgs/OnCancelArgs and type-checks correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/component/lib.ts`:
- Around line 95-99: getContext() flattens per-handler contexts into a single
array and deleteContext() removes inline copies so completeHandler() ends up
only seeing payload.context (breaking handler-specific large-context paths); fix
by changing how context is stored in the payload: instead of a plain array use a
map keyed by handler name (or a dedicated shared field that preserves a single
handler's context), update the code paths that compute contextSize (uses
getContext and context.map/getConvexSize), the code that calls deleteContext,
and the completion code in completeHandler to read the selected handler's entry
from payload.contextByHandler (or the dedicated field) so the chosen handler
receives its original context value.

---

Duplicate comments:
In `@src/client/index.ts`:
- Around line 445-461: The handler signature for defineOnCancel incorrectly
types the payload as FailureResult; update it to use the cancel-args type so it
matches vOnCancelArgs/OnCancelArgs. Concretely, in defineOnCancel (the handler
arg shaped { workId, context, result }), replace FailureResult with the cancel
args result type (e.g. OnCancelArgs['result'] or the project's CanceledResult
alias) so the handler's result matches vOnCancelArgs/OnCancelArgs and
type-checks correctly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c3b65e9a-20bb-436b-b429-04ed015cc777

📥 Commits

Reviewing files that changed from the base of the PR and between 31aac46 and f7e495d.

⛔ Files ignored due to path filters (1)
  • src/component/_generated/component.ts is excluded by !**/_generated/**
📒 Files selected for processing (10)
  • src/client/index.ts
  • src/component/complete.test.ts
  • src/component/complete.ts
  • src/component/lib.ts
  • src/component/loop.test.ts
  • src/component/loop.ts
  • src/component/recovery.test.ts
  • src/component/schema.ts
  • src/component/shared.ts
  • src/component/worker.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/component/loop.test.ts
  • src/component/recovery.test.ts
  • src/component/complete.test.ts
  • src/component/worker.ts
  • src/component/loop.ts

@reeceyang reeceyang marked this pull request as draft March 10, 2026 00:35
@reeceyang reeceyang removed the request for review from ianmacartney March 10, 2026 00:36
Copy link
Member

@ianmacartney ianmacartney left a comment

Choose a reason for hiding this comment

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

it'd be nice to have some examples that highlight patterns, such as passing the same onComplete handler to all of onSuccess / onError / onCancel - the types should allow it, in case they want to centralize handling of statuses, but want transactional callbacks on success

@reeceyang reeceyang force-pushed the reece/onSuccess branch 4 times, most recently from 8a162ea to 82f152d Compare March 12, 2026 19:12
@reeceyang reeceyang marked this pull request as ready for review March 12, 2026 21:20
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/component/lib.ts (1)

91-104: ⚠️ Potential issue | 🟠 Major

Validate the combined payload document size before insert.

When both fnArgs and context cross the inline threshold, this branch stores both in one payload doc. They’re checked individually, but the combined size is never bounded, so medium-large args plus medium-large context will fail later inside ctx.db.insert("payload", ...) with a generic document-size error.

💡 Suggested fix
   if (fnArgsSize >= INLINE_METADATA_THRESHOLD) {
     // Args are large, store separately
     const payloadDoc: WithoutSystemFields<Doc<"payload">> = {
       args: workArgs.fnArgs,
     };
-    workItem.payloadSize = fnArgsSize + PAYLOAD_DOC_OVERHEAD;
     delete workItem.fnArgs;
     if (contextSize >= INLINE_METADATA_THRESHOLD) {
       // Context is also too big to inline
       payloadDoc.context = context;
-      workItem.payloadSize += contextSize;
       if (workItem.onComplete) {
         delete workItem.onComplete.context;
       }
     }
+    const payloadDocSize = getConvexSize(payloadDoc);
+    if (payloadDocSize > MAX_DOC_SIZE) {
+      throw new Error(
+        `Function arguments and callback context for function ${workArgs.fnName} too large: ${payloadDocSize} bytes (max: ${MAX_DOC_SIZE} bytes)`,
+      );
+    }
+    workItem.payloadSize = payloadDocSize;
     workItem.payloadId = await ctx.db.insert("payload", payloadDoc);
   } else if (fnArgsSize + contextSize >= INLINE_METADATA_THRESHOLD) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/component/lib.ts` around lines 91 - 104, The code currently adds both
fnArgs and context into payloadDoc without checking their combined serialized
size before calling ctx.db.insert; update the logic around payloadDoc,
workItem.payloadSize and PAYLOAD_DOC_OVERHEAD to compute the total
serialized/encoded size (fnArgs + context + PAYLOAD_DOC_OVERHEAD) and compare it
against a safe DB max document size (or introduce a constant like
MAX_PAYLOAD_DOC_SIZE) before inserting; if the combined size would exceed that
limit, avoid inlining both (e.g., omit context from payloadDoc and persist it
separately or create a separate payload record) and adjust workItem.payloadSize
and any onComplete/context deletions accordingly, ensuring
ctx.db.insert("payload", payloadDoc) is only called with a validated-size
document.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/client/index.ts`:
- Around line 674-693: In enqueueArgs, add a runtime validation that rejects
mixed callback styles: if opts.onComplete is provided and any of opts.onSuccess,
opts.onFailure, or opts.onCancel are also provided, throw a clear Error instead
of silently preferring onComplete; implement this check before creating function
handles (before the existing createFunctionHandle calls for
onComplete/onSuccess/onFailure/onCancel) so the code never continues to build a
mixed onComplete object, and include a message referencing the exclusive usage
(e.g., "Provide either onComplete OR onSuccess/onFailure/onCancel, not both") to
help callers correct the call site.

In `@src/component/worker.ts`:
- Around line 47-58: When args.hasOnSuccess is true the code calls
completeHandler(...) but swallows or converts any exception into a success path;
instead, ensure exceptions from completeHandler are not downgraded: let errors
thrown by completeHandler bubble up (or rethrow them) so the work is not
finalized as success and normal failure/retry/onFailure logic runs. Locate the
block that calls completeHandler when args.hasOnSuccess and remove or change the
catch that converts errors into a success fallback; if you must catch, rethrow
the caught error immediately so onFailure and retry semantics are preserved.

---

Outside diff comments:
In `@src/component/lib.ts`:
- Around line 91-104: The code currently adds both fnArgs and context into
payloadDoc without checking their combined serialized size before calling
ctx.db.insert; update the logic around payloadDoc, workItem.payloadSize and
PAYLOAD_DOC_OVERHEAD to compute the total serialized/encoded size (fnArgs +
context + PAYLOAD_DOC_OVERHEAD) and compare it against a safe DB max document
size (or introduce a constant like MAX_PAYLOAD_DOC_SIZE) before inserting; if
the combined size would exceed that limit, avoid inlining both (e.g., omit
context from payloadDoc and persist it separately or create a separate payload
record) and adjust workItem.payloadSize and any onComplete/context deletions
accordingly, ensuring ctx.db.insert("payload", payloadDoc) is only called with a
validated-size document.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 33620a62-617e-45ee-90a7-d9b467f815b9

📥 Commits

Reviewing files that changed from the base of the PR and between f7e495d and 82f152d.

⛔ Files ignored due to path filters (1)
  • src/component/_generated/component.ts is excluded by !**/_generated/**
📒 Files selected for processing (12)
  • README.md
  • example/convex/example.ts
  • src/client/index.ts
  • src/component/complete.test.ts
  • src/component/complete.ts
  • src/component/lib.test.ts
  • src/component/lib.ts
  • src/component/loop.test.ts
  • src/component/loop.ts
  • src/component/recovery.test.ts
  • src/component/shared.ts
  • src/component/worker.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/component/loop.ts
  • src/component/recovery.test.ts
  • src/component/loop.test.ts
  • src/component/complete.test.ts

onFailure and onCancel (new)
Copy link
Member

@ianmacartney ianmacartney left a comment

Choose a reason for hiding this comment

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

Overall LGTM! Excited to see what impact this has when we change Workflow to only use onFailure / onCancel for the workflow handler, and to use onSuccess for step completion.
Let's put this in an alpha for now.
If the latter doesn't improve performance much, we might keep using onComplete for steps... wouldn't want a step OCC'ing just b/c it was fighting to start the workpool (until the debouncing works well)

Comment on lines +692 to +698
? await createFunctionHandle(opts.onSuccess)
: undefined,
onFailureHandle: opts.onFailure
? await createFunctionHandle(opts.onFailure)
: undefined,
onCancelHandle: opts.onCancel
? await createFunctionHandle(opts.onCancel)
Copy link
Member

Choose a reason for hiding this comment

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

if these are all the same, we should try to reduce these calls - each function handle creation from an action is a request to conductor.
Ideally we'd cache this at the isolate level - maybe we do that already.

payloadDoc.context = context;
workItem.payloadSize += contextSize;
delete workItem.onComplete!.context;
if (workItem.onComplete) {
Copy link
Member

Choose a reason for hiding this comment

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

if this isn't set then there's likely a bug - assert might be more idiomatic, but this is fine too

jobs: [{ workId, runResult, attempt }],
});
return;
} catch {
Copy link
Member

Choose a reason for hiding this comment

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

can we catch OCC's or other retry-able things explicitly here somehow? If it failed b/c it read/wrote too much data, scheduling it will just have it happen again. Maybe not that common / not the worst thing.

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