Skip to content

Conversation

@NathanFlurry
Copy link
Member

No description provided.

Copy link
Member Author

NathanFlurry commented Jan 26, 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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 26, 2026

More templates

@rivetkit/virtual-websocket

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

@rivetkit/cloudflare-workers

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

@rivetkit/db

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

@rivetkit/framework-base

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

@rivetkit/next-js

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

@rivetkit/react

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

rivetkit

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

@rivetkit/sql-loader

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

@rivetkit/traces

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

@rivetkit/workflow-engine

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

@rivetkit/engine-runner

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

@rivetkit/engine-runner-protocol

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

commit: b18c3ae

Comment on lines +1 to +55
import { AsyncLocalStorage } from "node:async_hooks";
import { Buffer } from "node:buffer";
import { randomBytes } from "node:crypto";
import { performance } from "node:perf_hooks";
import { decode as decodeCbor, encode as encodeCbor } from "cbor-x";
import { pack, unpack } from "fdb-tuple";
import {
CHUNK_VERSIONED,
CURRENT_VERSION,
READ_RANGE_VERSIONED,
encodeRecord,
type ActiveSpanRef,
type Attributes,
type Chunk,
type KeyValue,
type ReadRangeWire,
type Record as TraceRecord,
type RecordBody,
type SpanEnd,
type SpanEvent,
type SpanId,
type SpanLink,
type SpanRecordKey,
type SpanSnapshot,
type SpanStart,
type SpanStatus,
SpanStatusCode,
type SpanUpdate,
type StringId,
type TraceId,
} from "../schemas/versioned.js";
import {
anyValueFromJs,
hexFromBytes,
type OtlpExportTraceServiceRequestJson,
type OtlpKeyValue,
type OtlpResource,
type OtlpSpan,
type OtlpSpanEvent,
type OtlpSpanLink,
type OtlpSpanStatus,
} from "./otlp.js";
import type {
EndSpanOptions,
EventOptions,
ReadRangeOptions,
ReadRangeResult,
SpanHandle,
SpanStatusInput,
StartSpanOptions,
Traces,
TracesDriver,
TracesOptions,
UpdateSpanOptions,
} from "./types.js";
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 need to be sorted alphabetically. Biome linter expects imports to be sorted in a specific order. Run 'biome check --write .' to automatically fix this issue.

Spotted by Graphite Agent (based on CI logs)

Fix in Graphite


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

@NathanFlurry NathanFlurry force-pushed the 01-21-feat_rivetkit_integrate_workflows_in_to_actors branch from 2bdce1c to 9524546 Compare January 28, 2026 01:12
@jog1t jog1t force-pushed the 01-21-feat_rivetkit_integrate_workflows_in_to_actors branch from 9524546 to e9cb986 Compare January 28, 2026 19:55
@claude
Copy link

claude bot commented Jan 28, 2026

PR Review: feat(rivetkit): traces

This is an impressive implementation of a compact, high-performance tracing system for RivetKit. The design is well-thought-out with excellent documentation and a clear spec.


✅ Strengths

Architecture & Design

  • Excellent spec documentation: TRACES_SPEC.md and TRACES_DESIGN_NOTES.md provide comprehensive design rationale
  • Well-designed storage model: Chunked append-only records with snapshots for long-running spans
  • Smart time handling: Using a single anchor with monotonic clock prevents drift between chunks
  • Proper OTLP v1 JSON compliance: Good alignment with OpenTelemetry standards
  • Memory management: Active span cap with depth-based eviction prevents unbounded growth

Implementation Quality

  • Clean abstraction: TracesDriver interface provides good separation of concerns
  • Comprehensive test coverage: 750+ lines of tests covering encoding, write path, read path, and OTLP export
  • Type safety: Strong TypeScript types throughout
  • Error handling: Proper validation and error handling throughout

🔍 Critical Issues

1. Potential Memory Leak in Write Chain

Location: traces.ts:559-567

The writeChain promise chain keeps growing indefinitely without cleanup. If errors occur, they're not handled and could cause unhandled rejections.

Recommendation: Add error handling to the promise chain

2. Race Condition in Flush

Location: traces.ts:777-784

resetChunkState is called before writeChain completes. If new records are appended during the write, they could be lost.

Recommendation: Wait for writes before resetting state


🐛 Bugs to Fix

3. Integer Overflow in Chunk ID

Location: traces.ts:240-244

No validation that chunkId doesn't exceed MAX_CHUNK_ID. This could cause data corruption.

4. Unbounded Attribute Values

Location: traces.ts:293-320

No size limit on attribute values. A buggy actor could store arbitrarily large objects.


⚡ Performance Improvements

5. Inefficient Array Search

Location: traces.ts:1139-1144

Linear search through pendingChunks array could become slow. Consider using a Map for O(1) lookups.

6. Repeated String Interning

Location: traces.ts:259-268

Consider a global string cache for common attribute keys.


🧪 Testing Gaps

7. Missing Edge Case Tests

  • No test for chunk ID overflow
  • No test for concurrent flush + append
  • No test for malformed CBOR
  • No test for attribute size limits
  • No test for invalid ID lengths

8. No Integration Test with ActorDriver

Tests use InMemoryTracesDriver, but ActorTracesDriver isn't tested.


📋 Summary

Category Count
Critical Issues 2
Bugs 2
Performance 2
Testing 2

Before Merge:

  1. Fix write chain error handling - Critical
  2. Fix flush race condition - Critical
  3. Add chunk ID overflow check
  4. Add attribute value size limits
  5. Add missing edge case tests

Post-Merge:

  • Optimize pending chunk lookups
  • Add compression support
  • Add metrics exposure

Overall, this is high-quality work with excellent design. The identified issues are mostly edge cases and hardening opportunities. Great job! 🎉

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