Skip to content

fix(rivetkit): fix BigInt serialization in inspector workflow history and state deserialization#5058

Open
abcxff wants to merge 1 commit into
mainfrom
05-14-fix_rivetkit_fix_bigint_serialization_in_inspector_workflow_history_and_state_deserialization
Open

fix(rivetkit): fix BigInt serialization in inspector workflow history and state deserialization#5058
abcxff wants to merge 1 commit into
mainfrom
05-14-fix_rivetkit_fix_bigint_serialization_in_inspector_workflow_history_and_state_deserialization

Conversation

@abcxff
Copy link
Copy Markdown
Contributor

@abcxff abcxff commented May 14, 2026

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@railway-app
Copy link
Copy Markdown

railway-app Bot commented May 14, 2026

🚅 Deployed to the rivet-pr-5058 environment in rivet-frontend

Service Status Web Updated (UTC)
website 😴 Sleeping (View Logs) Web May 19, 2026 at 8:28 pm
frontend-cloud 😴 Sleeping (View Logs) Web May 19, 2026 at 8:27 pm
frontend-inspector ❌ Build Failed (View Logs) Web May 19, 2026 at 8:20 pm
kitchen-sink ❌ Build Failed (View Logs) Web May 19, 2026 at 8:19 pm
ladle ✅ Success (View Logs) Web May 19, 2026 at 8:19 pm
mcp-hub ✅ Success (View Logs) Web May 14, 2026 at 6:10 pm

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 14, 2026

Code Review — fix(rivetkit): fix BigInt serialization in inspector workflow history and state deserialization

Overview

This PR fixes two distinct BigInt-related bugs in the RivetKit TypeScript runtime:

  1. State deserialization (decodeValue): was calling decodeCborJsonCompat, which silently coerces safe-integer BigInts to Numbers, corrupting stored BigInt actor state.
  2. Inspector workflow history (serializeWorkflowHistoryForJson): was returning raw BigInt values that caused JSON.stringify to throw TypeError: Do not know how to serialize a BigInt.

Correctness

decodeValue change — correct.
Switching from decodeCborJsonCompat to decodeCborCompat is the right fix. encodeCborCompat wraps BigInts as bigint-tagged tuples, and decodeCborCompat faithfully revives them. The old decodeCborJsonCompat path was silently losing type information for any user state that stored BigInt values.

serializeWorkflowHistoryForJson change — correct with a known caveat.
Wrapping with jsonSafe() prevents the JSON serialization crash. However, toHttpJsonCompatible (called by jsonSafe) converts BigInts to Number, which is lossy for values outside the safe integer range. For epoch-ms timestamps this is fine in practice, but large integer IDs or counters stored as BigInt would silently lose precision. The TODO comment acknowledges this and CBOR encoding is the correct long-term fix.


Issues

1. Accidental ext/test workspace inclusion — should be reverted

pnpm-workspace.yaml adds ext/* and pnpm-lock.yaml gains an ext/test entry referencing @hono/node-server, @rivetkit/engine-cli, @rivetkit/rivetkit-napi, and rivetkit. The ext/ directory does not exist in the repository — this appears to be a local test harness used during development that was accidentally committed. This will cause pnpm install to warn or fail for other contributors and should be reverted before merge.

2. No regression tests added

Both bugs are straightforward to reproduce and guard against:

  • A driver test that stores a BigInt actor state value, hard-crashes the actor, and asserts the revived state preserves the BigInt type (not a Number).
  • A unit test that calls serializeWorkflowHistoryForJson with a history containing BigInt fields and confirms no serialization error is thrown.

Without these, the bugs could silently regress.


Minor Notes

  • The TODO comment (// TODO: Switch inspector routes to CBOR encoding) is good to have; make sure it lands in a tracked issue or .agent/todo/ entry so it does not get lost.
  • Removing the now-unused decodeCborJsonCompat import is clean.

@abcxff abcxff marked this pull request as ready for review May 16, 2026 01:49
@abcxff abcxff force-pushed the 05-14-fix_rivetkit_fix_bigint_serialization_in_inspector_workflow_history_and_state_deserialization branch from f4236b0 to d9123c0 Compare May 18, 2026 16:58
@abcxff abcxff force-pushed the 05-12-do_not_merge_queue_diagnose branch from 73774f1 to cc6561e Compare May 18, 2026 16:58
@abcxff abcxff changed the base branch from 05-12-do_not_merge_queue_diagnose to graphite-base/5058 May 18, 2026 17:10
@abcxff abcxff force-pushed the 05-14-fix_rivetkit_fix_bigint_serialization_in_inspector_workflow_history_and_state_deserialization branch from d9123c0 to 50b18ec Compare May 18, 2026 17:10
@abcxff abcxff changed the base branch from graphite-base/5058 to 05-09-fix_workflow-engine_only_commit_step_state_after_success May 18, 2026 17:10
@abcxff abcxff force-pushed the 05-14-fix_rivetkit_fix_bigint_serialization_in_inspector_workflow_history_and_state_deserialization branch from 50b18ec to e7602e1 Compare May 18, 2026 19:23
@abcxff abcxff force-pushed the 05-09-fix_workflow-engine_only_commit_step_state_after_success branch from 4480579 to 5c16781 Compare May 18, 2026 19:23
Copy link
Copy Markdown
Contributor Author

abcxff commented May 19, 2026

Merge activity

  • May 19, 8:06 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 19, 8:08 PM UTC: The Graphite merge of this pull request was cancelled.

@abcxff abcxff changed the base branch from 05-09-fix_workflow-engine_only_commit_step_state_after_success to graphite-base/5058 May 19, 2026 20:11
@abcxff abcxff force-pushed the 05-14-fix_rivetkit_fix_bigint_serialization_in_inspector_workflow_history_and_state_deserialization branch from e7602e1 to e64e5c1 Compare May 19, 2026 20:14
@abcxff abcxff force-pushed the graphite-base/5058 branch from 5c16781 to c999f19 Compare May 19, 2026 20:14
@graphite-app graphite-app Bot changed the base branch from graphite-base/5058 to main May 19, 2026 20:14
@abcxff abcxff force-pushed the 05-14-fix_rivetkit_fix_bigint_serialization_in_inspector_workflow_history_and_state_deserialization branch from e64e5c1 to 2be6cad Compare May 19, 2026 20:14
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