Skip to content

fix(rivetkit): handle undefined options with scheduling#4000

Closed
NathanFlurry wants to merge 1 commit into
01-21-chore_engine_add_force_shutdown_timeoutfrom
01-21-fix_rivetkit_handle_undefined_options_with_scheduling
Closed

fix(rivetkit): handle undefined options with scheduling#4000
NathanFlurry wants to merge 1 commit into
01-21-chore_engine_add_force_shutdown_timeoutfrom
01-21-fix_rivetkit_handle_undefined_options_with_scheduling

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown
Member Author

NathanFlurry commented Jan 22, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Jan 22, 2026

Code Review

Summary

This PR adds a defensive null check for this.#config.actions in the schedule manager. The fix handles cases where actions might be undefined during scheduled event execution.

Analysis

The Good:
Defensive programming: The nullish coalescing operator (??) correctly handles undefined/null cases
Consistent with schema: While the Zod schema at config.ts:62 defines actions: z.record(z.string(), zFunction()).default(() => ({})), the TypeScript type at config.ts:468 declares actions?: TActions as optional, making this defensive check appropriate
Minimal change: The fix is surgical and doesn't introduce unnecessary complexity

Potential Concerns:

⚠️ Root cause unclear: The schema should guarantee actions is always an empty object {} via the default, yet this fix suggests it can be undefined at runtime. This points to one of two issues:

  1. The config is being created/passed without going through schema validation
  2. There's a type/runtime mismatch where the Zod schema isn't being enforced

⚠️ Silent failure path: When actions is undefined, all scheduled events will fail with "Missing action for scheduled event" errors. This might be expected behavior, but it could indicate a configuration error that should be caught earlier (e.g., during actor initialization).

⚠️ No test coverage: There are no tests for ScheduleManager in the codebase. This fix would benefit from:

  • A test verifying scheduled events work when actions is undefined/empty
  • A test ensuring the error message is helpful when an action is missing

Recommendations

  1. Investigate the root cause: Check how configs are created without schema validation. Consider adding validation at the point where ScheduleManager is instantiated.

  2. Consider earlier validation: If actors shouldn't schedule events without actions defined, validate this during actor creation rather than at event execution time.

  3. Add test coverage: Create tests for ScheduleManager, especially edge cases like:

    test('handles undefined actions gracefully', async () => {
      // Test that scheduling events with undefined actions throws appropriate error
    });
  4. Optional: Add logging: Consider logging a warning if someone tries to schedule an event when no actions are configured, as this might indicate a developer mistake.

Code Quality

  • ✅ Follows TypeScript best practices
  • ✅ Uses appropriate nullish coalescing
  • ✅ No security concerns
  • ✅ No performance impact
  • ⚠️ Missing test coverage

Verdict

Approve with suggestions - The fix is correct and safe, but investigating why actions can be undefined at runtime would prevent similar issues. The mismatch between the Zod schema's default and the need for this null check suggests a gap in the config validation pipeline.


Reviewed with guidance from CLAUDE.md

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 22, 2026

More templates

@rivetkit/virtual-websocket

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/virtual-websocket@4000

@rivetkit/cloudflare-workers

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/cloudflare-workers@4000

@rivetkit/db

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/db@4000

@rivetkit/framework-base

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/framework-base@4000

@rivetkit/next-js

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/next-js@4000

@rivetkit/react

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/react@4000

rivetkit

pnpm add https://pkg.pr.new/rivet-dev/rivet/rivetkit@4000

@rivetkit/sql-loader

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/sql-loader@4000

@rivetkit/engine-runner

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/engine-runner@4000

@rivetkit/engine-runner-protocol

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/engine-runner-protocol@4000

commit: 0e340d5

@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app Bot commented Jan 22, 2026

Merge activity

  • Jan 22, 6:58 AM UTC: NathanFlurry added this pull request to the Graphite merge queue.
  • Jan 22, 6:59 AM UTC: CI is running for this pull request on a draft pull request (#4007) due to your merge queue CI optimization settings.
  • Jan 22, 7:00 AM UTC: Merged by the Graphite merge queue via draft PR: #4007.

@graphite-app graphite-app Bot closed this Jan 22, 2026
@graphite-app graphite-app Bot deleted the 01-21-fix_rivetkit_handle_undefined_options_with_scheduling branch January 22, 2026 07:00
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.

1 participant