Skip to content

refactor(rivetkit): make traces server only lib#4051

Closed
jog1t wants to merge 1 commit intographite-base/4051from
01-27-refactor_rivetkit_make_traces_server_only_lib
Closed

refactor(rivetkit): make traces server only lib#4051
jog1t wants to merge 1 commit intographite-base/4051from
01-27-refactor_rivetkit_make_traces_server_only_lib

Conversation

@jog1t
Copy link
Contributor

@jog1t jog1t commented Jan 27, 2026

No description provided.

@jog1t jog1t marked this pull request as ready for review January 27, 2026 20:10
@jog1t jog1t mentioned this pull request Jan 27, 2026
Copy link
Contributor Author

jog1t commented Jan 27, 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.

@jog1t jog1t mentioned this pull request Jan 27, 2026
@claude
Copy link

claude bot commented Jan 27, 2026

PR Review: refactor(rivetkit): make traces server only lib

Summary

This PR refactors the @rivetkit/traces package to be server-only by adding a browser stub that throws helpful errors when used in browser environments. It also replaces the fdb-tuple dependency with a forked version @rivetkit/fdb-tuple and includes formatting/linting improvements.


✅ Code Quality & Best Practices

Strong Points:

  • Clear browser compatibility strategy: The new browser.ts stub provides clear, helpful error messages when users try to use server-only functionality in the browser
  • Type-only exports for browsers: Correctly exports types from the browser entry point, allowing type checking without bundling Node.js code
  • Package.json exports configuration: Proper use of conditional exports with the browser field taking precedence over default imports
  • Dependency migration: Clean migration from fdb-tuple to @rivetkit/fdb-tuple across both traces and workflow-engine packages

Code Style Issues:
The PR includes extensive formatting changes (reformatting function parameters, line breaks, etc.) that make the diff harder to review. According to CLAUDE.md:

Do not run ./scripts/cargo/fix.sh. Do not format the code yourself.

While this is a TypeScript PR (not Rust), the same principle applies - formatting changes should ideally be separated or avoided unless necessary.


🐛 Potential Issues

1. Dependency Management Concern ⚠️

The PR uses a pkg.pr.new URL for the dependency:

"@rivetkit/fdb-tuple": "https://pkg.pr.new/rivet-dev/fdb-tuple/@rivetkit/fdb-tuple@32f95e2"

Issues:

  • This appears to be a preview/temporary deployment URL for testing PRs
  • The hash 32f95e2 references a specific commit, which is fragile for production
  • If this is meant to be permanent, it should use a proper npm registry version or Git URL

Recommendation:

  • If the fork is ready for use, publish it to npm with proper versioning
  • If this is temporary, add a TODO comment and issue reference
  • Consider using a Git URL format: "@rivetkit/fdb-tuple": "git+https://github.com/rivet-dev/fdb-tuple.git#commit-or-tag"

2. Removed Code Without Context

In workflow-engine/src/keys.ts, the PR removes helper functions:

-function bufferToUint8Array(buf: Buffer): Uint8Array {
-  return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
-}
-
-function uint8ArrayToBuffer(arr: Uint8Array): Buffer {
-  return Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
-}

These were removed because the new @rivetkit/fdb-tuple likely returns Uint8Array directly instead of Buffer. This is good, but:

  • Ensure the forked library truly returns Uint8Array consistently
  • Verify no other code depends on Buffer-specific behavior

3. Build Configuration

The package.json build script now includes:

tsup src/index.ts src/reader.ts src/browser.ts

But tsup.config.ts doesn't specify any special handling for the browser entry. Verify that:

  • tsup correctly generates separate bundles for each entry point
  • The browser bundle doesn't include Node.js APIs (crypto, async_hooks, etc.)
  • Consider adding platform: 'browser' to tsup config for the browser entry

🔒 Security Concerns

No significant security issues, but:

  • The use of a preview deployment URL (pkg.pr.new) in production dependencies is concerning from a supply chain security perspective
  • The URL is mutable (could point to different code if the preview is regenerated)

⚡ Performance Considerations

Positive:

  • Removed unnecessary Buffer conversions in workflow-engine/src/keys.ts, directly using Uint8Array
  • Browser bundles won't include unused Node.js polyfills

Neutral:

  • Formatting changes don't impact runtime performance

🧪 Test Coverage

Good:

  • Tests were updated to use @rivetkit/fdb-tuple instead of fdb-tuple
  • Test logic remains unchanged, indicating the API is compatible
  • Import order was corrected (Node.js imports before external packages)

Could Be Better:

  • No tests verify the browser stub behavior
  • Consider adding a test that imports from the browser entry point and expects errors

📝 Documentation & Comments

Issue:
According to CLAUDE.md:

Write comments as normal, complete sentences. Avoid fragmented structures with parentheticals and dashes

The comment in browser.ts:2 is fine, but could be more complete:

// Browser stub for @rivetkit/traces
// This file is used as the browser entry point to prevent Node.js-specific code from being bundled

Better:

// Browser stub for @rivetkit/traces.
// This file serves as the browser entry point to prevent Node.js-specific code 
// from being bundled in client applications. All functions throw helpful errors.

🎯 Recommendations

  1. High Priority:

    • Replace the pkg.pr.new URL with a stable dependency source (published npm package or Git URL)
    • Verify the forked @rivetkit/fdb-tuple returns Uint8Array consistently
  2. Medium Priority:

    • Add browser stub tests to verify error messages
    • Consider splitting formatting changes into a separate commit
    • Add platform-specific tsup config for browser builds
  3. Low Priority:

    • Improve comment formatting per CLAUDE.md guidelines
    • Document why the fork of fdb-tuple was necessary (in a comment or PR description)

✨ Overall Assessment

Verdict: Approved with Minor Concerns ⚠️

The refactoring is well-executed and the browser stub pattern is a clean solution. The main concern is the temporary dependency URL which should be addressed before merging to production. The code changes are sound, tests pass, and the architectural decision makes sense.

Key Blocker:

  • Resolve the pkg.pr.new dependency URL before merging

Nice to Have:

  • Browser stub tests
  • Cleaner git history (separate formatting commits)

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 27, 2026

More templates

@rivetkit/cloudflare-workers

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

@rivetkit/db

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

@rivetkit/framework-base

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

@rivetkit/next-js

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

@rivetkit/react

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

rivetkit

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

@rivetkit/sql-loader

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

@rivetkit/traces

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

@rivetkit/workflow-engine

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/workflow-engine@4051

@rivetkit/virtual-websocket

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

@rivetkit/engine-runner

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

@rivetkit/engine-runner-protocol

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

commit: 471f2e8

@graphite-app
Copy link
Contributor

graphite-app bot commented Jan 27, 2026

Graphite Automations

"Test" took an action on this PR • (01/27/26)

1 assignee was added to this PR based on Kacper Wojciechowski's automation.

Comment on lines +34 to +36
async list(
prefix: Uint8Array,
): Promise<Array<{ key: Uint8Array; value: Uint8Array }>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

The function parameter formatting should be consistent with the project's style guide. Run Biome linter with --apply to automatically format this function declaration.

Spotted by Graphite Agent (based on CI logs)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

"@rivetkit/bare-ts": "^0.6.2",
"cbor-x": "^1.6.0",
"fdb-tuple": "^1.0.0",
"@rivetkit/fdb-tuple": "https://pkg.pr.new/rivet-dev/fdb-tuple/@rivetkit/fdb-tuple@32f95e2",
Copy link
Contributor

Choose a reason for hiding this comment

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

The custom URL dependency '@rivetkit/fdb-tuple': 'https://pkg.pr.new/rivet-dev/fdb-tuple/@rivetkit/fdb-tuple@32f95e2' is causing TypeScript compilation errors during CI. Consider using a standard npm package, a GitHub URL (github:rivet-dev/fdb-tuple#commit-hash), or adding a resolution in the root package.json to help resolve this URL correctly.

Spotted by Graphite Agent (based on CI logs)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

"@rivetkit/bare-ts": "^0.6.2",
"cbor-x": "^1.6.0",
"fdb-tuple": "^1.0.0",
"@rivetkit/fdb-tuple": "https://pkg.pr.new/rivet-dev/fdb-tuple/@rivetkit/fdb-tuple@32f95e2",
Copy link
Contributor

Choose a reason for hiding this comment

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

The custom URL dependency '@rivetkit/fdb-tuple': 'https://pkg.pr.new/rivet-dev/fdb-tuple/@rivetkit/fdb-tuple@32f95e2' is causing TypeScript compilation errors during CI. Consider using a standard npm package, a GitHub URL (github:rivet-dev/fdb-tuple#commit-hash), or adding a resolution in the root package.json to help resolve this URL correctly.

Spotted by Graphite Agent (based on CI logs)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@NathanFlurry NathanFlurry changed the base branch from 01-24-feat_frontend_traces_ui to graphite-base/4051 January 28, 2026 01:11
@jog1t jog1t force-pushed the graphite-base/4051 branch from 4189086 to 3c7fabc Compare January 28, 2026 19:55
@jog1t jog1t force-pushed the 01-27-refactor_rivetkit_make_traces_server_only_lib branch from 471f2e8 to 63d40ba Compare January 28, 2026 19:55
@jog1t jog1t changed the base branch from graphite-base/4051 to 01-24-feat_frontend_traces_ui January 28, 2026 19:56
@NathanFlurry NathanFlurry changed the base branch from 01-24-feat_frontend_traces_ui to graphite-base/4051 January 30, 2026 08:19
@jog1t jog1t force-pushed the 01-27-refactor_rivetkit_make_traces_server_only_lib branch from 63d40ba to d77a4fc Compare January 30, 2026 21:29
@jog1t jog1t force-pushed the graphite-base/4051 branch from 3c7fabc to 0232d12 Compare January 30, 2026 21:29
@jog1t jog1t changed the base branch from graphite-base/4051 to 01-24-feat_frontend_traces_ui January 30, 2026 21:29
@NathanFlurry NathanFlurry changed the base branch from 01-24-feat_frontend_traces_ui to graphite-base/4051 February 3, 2026 20:02
Comment on lines 7 to 28
@@ -26,6 +25,7 @@ import {
type SpanUpdate,
type StringId,
type TraceId,
type Record as TraceRecord,
Copy link
Contributor

Choose a reason for hiding this comment

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

The imports from schemas/versioned.js are not properly grouped and ordered. Constants like CHUNK_VERSIONED and CURRENT_VERSION should be grouped together, not interspersed with type imports. This violates Biome's import organization rules.

Spotted by Graphite Agent (based on CI logs)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +1 to +84
// Browser stub for @rivetkit/traces
// This file is used as the browser entry point to prevent Node.js-specific code from being bundled

import type {
OtlpAnyValue,
OtlpExportTraceServiceRequestJson,
OtlpInstrumentationScope,
OtlpKeyValue,
OtlpResource,
OtlpResourceSpans,
OtlpScopeSpans,
OtlpSpan,
OtlpSpanEvent,
OtlpSpanLink,
OtlpSpanStatus,
} from "./otlp.js";
import type {
EndSpanOptions,
EventOptions,
ReadRangeOptions,
ReadRangeResult,
ReadRangeWire,
SpanHandle,
SpanStatusInput,
StartSpanOptions,
Traces,
TracesDriver,
TracesOptions,
UpdateSpanOptions,
} from "./types.js";

function notSupported(name: string): never {
throw new Error(
`@rivetkit/traces: ${name} is not supported in the browser. Traces are only available on the server.`,
);
}

export function createTraces(
_options: TracesOptions<OtlpResource>,
): Traces<OtlpExportTraceServiceRequestJson> {
notSupported("createTraces");
}

export function encodeReadRangeWire(_wire: ReadRangeWire): Uint8Array {
notSupported("encodeReadRangeWire");
}

export function decodeReadRangeWire(_bytes: Uint8Array): ReadRangeWire {
notSupported("decodeReadRangeWire");
}

export function readRangeWireToOtlp(
_wire: ReadRangeWire,
_resource?: OtlpResource,
): { otlp: OtlpExportTraceServiceRequestJson; clamped: boolean } {
notSupported("readRangeWireToOtlp");
}

// Re-export types (these are safe for browsers)
export type {
EndSpanOptions,
EventOptions,
ReadRangeOptions,
ReadRangeResult,
ReadRangeWire,
SpanHandle,
SpanStatusInput,
StartSpanOptions,
Traces,
TracesDriver,
TracesOptions,
UpdateSpanOptions,
OtlpAnyValue,
OtlpExportTraceServiceRequestJson,
OtlpInstrumentationScope,
OtlpKeyValue,
OtlpResource,
OtlpResourceSpans,
OtlpScopeSpans,
OtlpSpan,
OtlpSpanEvent,
OtlpSpanLink,
OtlpSpanStatus,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

This new file likely has formatting issues throughout. Since it's a completely new file, it should be formatted according to Biome's rules. Run 'biome format --write' on this file to ensure proper formatting.

Spotted by Graphite Agent (based on CI logs)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@jog1t jog1t closed this Feb 4, 2026
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