Skip to content

fix(ups): upgrade nats, fix chunking, add chunking tests#4315

Merged
NathanFlurry merged 8 commits intomainfrom
02-25-fix_ups_upgrade_nats_fix_chunking_add_chunking_tests
Feb 27, 2026
Merged

fix(ups): upgrade nats, fix chunking, add chunking tests#4315
NathanFlurry merged 8 commits intomainfrom
02-25-fix_ups_upgrade_nats_fix_chunking_add_chunking_tests

Conversation

@MasterPtato
Copy link
Contributor

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

railway-app bot commented Feb 26, 2026

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

Service Status Web Updated (UTC)
website 😴 Sleeping (View Logs) Web Feb 26, 2026 at 1:24 am
frontend-inspector ❌ Build Failed (View Logs) Web Feb 26, 2026 at 1:14 am
mcp-hub ✅ Success (View Logs) Web Feb 26, 2026 at 1:13 am
frontend-cloud ❌ Build Failed (View Logs) Web Feb 26, 2026 at 1:13 am
ladle ❌ Build Failed (View Logs) Web Feb 26, 2026 at 1:13 am

Copy link
Contributor Author

MasterPtato commented Feb 26, 2026

@MasterPtato MasterPtato mentioned this pull request Feb 26, 2026
11 tasks
@claude
Copy link

claude bot commented Feb 26, 2026

PR Review: fix(ups): upgrade nats, fix chunking, add chunking tests

This is a solid PR that bundles three distinct fixes. The changes are well-reasoned and the test coverage for the chunking fix is thorough.


NATS Upgrade (0.33 → 0.46)

The upgrade is clean and the TLS consolidation (removing rustls 0.21, sct, tokio-retry, etc.) is a welcome side effect. The new event variants (Draining, Closed) are handled correctly.

One minor note: downgrading Disconnected from error to warn is appropriate since the client may reconnect, but consider whether downstream alerting rules depend on the old error level — worth a heads-up if so.


Chunking Bug Fix (chunking.rs)

The fix is mathematically correct. The key insight — that the LEB128 length prefix for the payload field grows beyond 1 byte once the payload exceeds 127 bytes — is well-explained in the comment.

Correctness verification of bare_uint_len:

  • n = 0: returns 1 ✓ (LEB128(0) = 0x00)
  • n = 127: returns 1 ✓ (LEB128(127) = 0x7F)
  • n = 128: returns 2 ✓ (LEB128(128) = 0x80 0x01)

Correctness verification of the max-payload formula:

Given raw = max_message_size - overhead (where overhead already includes 1 byte for the empty LEB128 length prefix), and max_payload = raw - (bare_uint_len(raw) - 1), the encoded chunk size satisfies:

overhead + bare_uint_len(max_payload) + max_payload
  ≤ overhead + bare_uint_len(raw) + (raw - bare_uint_len(raw) + 1)
  = overhead + raw + 1
  = max_message_size + 1 - 1
  = max_message_size ✓

The formula is sound. The saturating_sub calls also handle the degenerate case where overhead ≥ max_message_size gracefully (returns max_payload = 0, caught by the existing guard below).

Minor suggestion: The name bare_uint_len is a bit opaque without context. Something like leb128_len would be more immediately recognizable to readers unfamiliar with the BARE encoding spec, though this is purely cosmetic.


Test Coverage

The test suite is comprehensive. The regression test test_encoded_chunks_fit_within_limit directly validates the fix.

One inconsistency to check: The roundtrip helper passes reply_subject to encode_chunk for every chunk, but test_encoded_chunks_with_reply_fit_within_limit only passes it for chunk i == 0. If the production code path only includes the reply subject on the first chunk (which appears to be the intent based on the latter test), then roundtrip doesn't match production semantics. In that case, it may over-count overhead for subsequent chunks in tests, which would make the size-bound tests in roundtrip-based scenarios more conservative than necessary — not a correctness bug, but it means the tests don't catch a scenario where non-first chunks are too large when reply is passed for all of them.

Could be worth either:

  1. Clarifying whether reply should appear in all chunks or only the first, and aligning roundtrip accordingly, or
  2. Adding a comment to roundtrip noting this deviation from production behavior.

Kubernetes NATS Config

The static name: rivet-engine addition is a critical reliability fix. The comment explains the reasoning clearly. No issues here.


Test Infrastructure Refactor

The extraction of wait_for_postgres_ready into a free function and the new wait_for_ready dispatch method on TestDatabase is clean and makes future database backends easy to support. The FileSystem variant returning Ok(()) immediately is the right behavior.


Summary

Area Assessment
NATS upgrade ✅ Clean migration
Event handling ✅ All new variants handled
Chunking fix ✅ Mathematically correct
Tests ✅ Good coverage, one minor inconsistency to clarify
K8s config ✅ Important reliability fix
Test infra ✅ Clean refactor

The main thing worth double-checking before merge is the roundtrip vs test_encoded_chunks_with_reply_fit_within_limit inconsistency regarding whether reply subject is included in all chunks or only the first.

@MasterPtato MasterPtato marked this pull request as ready for review February 26, 2026 01:41
@MasterPtato MasterPtato force-pushed the 02-25-fix_ups_upgrade_nats_fix_chunking_add_chunking_tests branch from dfd219c to e0b072a Compare February 26, 2026 02:14
@MasterPtato MasterPtato force-pushed the 02-25-chore_fix_tests branch from 51558a0 to 165fa47 Compare February 26, 2026 02:14
@MasterPtato MasterPtato force-pushed the 02-25-fix_ups_upgrade_nats_fix_chunking_add_chunking_tests branch from e0b072a to e39972b Compare February 26, 2026 19:42
@MasterPtato MasterPtato force-pushed the 02-25-chore_fix_tests branch from 165fa47 to d33b11b Compare February 26, 2026 19:42
@MasterPtato MasterPtato force-pushed the 02-25-chore_fix_tests branch from d33b11b to a1e9af4 Compare February 27, 2026 00:12
@MasterPtato MasterPtato force-pushed the 02-25-fix_ups_upgrade_nats_fix_chunking_add_chunking_tests branch from e39972b to 409fdf2 Compare February 27, 2026 00:12
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 27, 2026

More templates

@rivetkit/cloudflare-workers

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

@rivetkit/framework-base

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

@rivetkit/next-js

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

@rivetkit/react

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

rivetkit

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

@rivetkit/sql-loader

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

@rivetkit/sqlite-vfs

pnpm add https://pkg.pr.new/rivet-dev/rivet/@rivetkit/sqlite-vfs@4315

@rivetkit/traces

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

@rivetkit/workflow-engine

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

@rivetkit/virtual-websocket

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

@rivetkit/engine-runner

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

@rivetkit/engine-runner-protocol

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

commit: 409fdf2

cluster {
# Static cluster name. Must be identical across all pods; without it NATS
# generates a random name on every startup and pods reject each other.
name: rivet-engine
Copy link
Member

Choose a reason for hiding this comment

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

let's update this to include the region. unlikely but good to make sure it never tries to cluster to other dcs.

Copy link
Member

@NathanFlurry NathanFlurry left a comment

Choose a reason for hiding this comment

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

x

Base automatically changed from 02-25-chore_fix_tests to main February 27, 2026 00:30
@NathanFlurry NathanFlurry merged commit 9784f8b into main Feb 27, 2026
19 of 29 checks passed
@NathanFlurry NathanFlurry deleted the 02-25-fix_ups_upgrade_nats_fix_chunking_add_chunking_tests branch February 27, 2026 00:30
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