Skip to content

Conversation

@NathanFlurry
Copy link
Member

No description provided.

@vercel
Copy link

vercel bot commented Nov 3, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
rivetkit-serverless Ready Ready Preview Comment Nov 4, 2025 8:26pm
3 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
rivet-cloud Ignored Ignored Nov 4, 2025 8:26pm
rivet-inspector Ignored Ignored Preview Nov 4, 2025 8:26pm
rivet-site Ignored Ignored Preview Nov 4, 2025 8:26pm

@vercel vercel bot temporarily deployed to Preview – rivetkit-serverless November 3, 2025 22:20 Inactive
Copy link
Member Author

NathanFlurry commented Nov 3, 2025

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

claude bot commented Nov 3, 2025

Code Review

Thanks for adding the HTTP test behavior to the smoke test! Here's my feedback:

Critical Issues

1. Undefined variable in spawnActorSleepCycle (spawn-actor.ts:55)

succeeded = true;

The variable succeeded is referenced but never declared in spawnActorSleepCycle. This will cause a runtime error. Unlike spawnActorHttp which declares let succeeded = false; at line 72, this function is missing that declaration.

Fix: Add let succeeded = false; at the start of the try block or remove this line entirely since it's not used anywhere in the function.


Medium Issues

2. Unsafe type assertion (index.ts:22-23)

export const BEHAVIOR: ActorBehavior = (process.env.BEHAVIOR ??
	"sleep-cycle") as ActorBehavior;

Using as ActorBehavior bypasses type safety. If someone sets BEHAVIOR=invalid, it will pass validation but fail at runtime with "Unknown behavior".

Fix: Add validation:

const behaviorValue = process.env.BEHAVIOR ?? "sleep-cycle";
if (behaviorValue !== "sleep-cycle" && behaviorValue !== "http") {
	throw new Error(`Invalid BEHAVIOR: ${behaviorValue}. Must be 'sleep-cycle' or 'http'`);
}
export const BEHAVIOR: ActorBehavior = behaviorValue;

3. Poor error handling in switch statement (spawn-actor.ts:32)

default:
	throw "Unknown behavior";

Throwing a string instead of an Error object is an anti-pattern. It doesn't provide stack traces and makes debugging harder.

Fix:

default:
	throw new Error(`Unknown behavior: ${BEHAVIOR}`);

Minor Issues

4. Dead code in spawnActorHttp (spawn-actor.ts:101-102)

if (succeeded) {
}

This empty if statement serves no purpose and should be removed.

5. Inconsistent error handling patterns

  • spawnActorSleepCycle catches errors and pushes them to the errors array
  • spawnActorHttp does the same
  • However, neither function uses the succeeded variable meaningfully (in spawnActorSleepCycle, it's set but never checked)

Consider removing the unused succeeded variable from spawnActorSleepCycle for consistency.


Code Quality Observations

Good:

  • Clear separation of concerns with behavior-based dispatch
  • Proper TypeScript typing with ActorBehavior type
  • Good documentation comment for the ActorBehavior type

Could improve:

  • The removal of the sleep logic (lines removed from old code) eliminates the "cycle" aspect of "sleep-cycle". Consider renaming to just "counter-increment" or similar to better reflect what it does
  • Consider adding JSDoc comments to the new spawnActorSleepCycle and spawnActorHttp functions to document their behavior

Test Coverage

No automated tests were added for the new behavior switching logic. Consider adding tests to verify:

  • Both behavior types execute correctly
  • Invalid behavior values are handled gracefully
  • The dispatch logic in spawnActor works as expected

Summary

Must fix before merge:

  • Undefined succeeded variable in spawnActorSleepCycle

Should fix:

  • Type assertion safety for BEHAVIOR
  • Error throwing pattern (use Error objects)
  • Remove dead code

Nice to have:

  • Better naming for "sleep-cycle" behavior
  • Test coverage

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 3, 2025

More templates

@rivetkit/actor

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

@rivetkit/cloudflare-workers

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

@rivetkit/core

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

@rivetkit/db

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

@rivetkit/framework-base

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

@rivetkit/next-js

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

@rivetkit/react

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

rivetkit

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

@rivetkit/sql-loader

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

@rivetkit/engine-runner

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

@rivetkit/engine-runner-protocol

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

commit: 74873cd

@claude
Copy link

claude bot commented Nov 4, 2025

Code Review

I've reviewed PR #3315 and have several findings to report:

Critical Issues

1. Undefined Variable in spawnActorSleepCycle (spawn-actor.ts:55)

succeeded = true;

The variable succeeded is used but never declared in the spawnActorSleepCycle function. This will cause a runtime error. Compare this to spawnActorHttp where it's properly declared on line 72:

let succeeded = false;

Fix: Add let succeeded = false; at the beginning of spawnActorSleepCycle.

2. Unsafe Type Assertion (index.ts:22-23)

export const BEHAVIOR: ActorBehavior = (process.env.BEHAVIOR ??
	"sleep-cycle") as ActorBehavior;

This uses a type assertion (as ActorBehavior) without runtime validation. If someone sets BEHAVIOR=invalid-value, it will pass TypeScript checks but fail at runtime with the error "Unknown behavior" on spawn-actor.ts:32.

Fix: Add validation before the assertion to ensure the value is valid.

3. Poor Error Handling (spawn-actor.ts:32)

default:
  throw "Unknown behavior";

Throwing a string instead of an Error object is an anti-pattern. It won't include a stack trace and makes debugging harder.

Fix: Use throw new Error() instead of throwing a string.

Code Quality Issues

4. Dead Code (spawn-actor.ts:101-102)

if (succeeded) {
}

Empty if-statement that serves no purpose. This should be removed.

5. Inconsistent Variable Declaration

In spawnActorHttp, succeeded is declared but never used meaningfully since it's always set to true before the only place it's checked. The variable could be removed entirely from spawnActorHttp along with the empty if-statement.

Best Practice Concerns

6. Missing Finally Block

Both spawnActorSleepCycle and spawnActorHttp don't guarantee that either onSuccess or onFailure will be called. If an exception occurs after the try-catch (which currently isn't possible, but could be with future changes), neither callback would be invoked, leading to incorrect counts.

7. Inconsistent Testing Behavior

  • spawnActorSleepCycle: Does 1 operation
  • spawnActorHttp: Does 20 operations

This makes performance comparison between the two behaviors inconsistent. Consider making the iteration count configurable or consistent.

8. Random Connection Method Selection

const connMethod = Math.random() > 0.5 ? "http" : "websocket";

Using Math.random() for test behavior makes tests non-deterministic and harder to reproduce. Consider using a deterministic strategy or making it configurable.

Documentation

9. Missing Documentation

The new spawnActorSleepCycle and spawnActorHttp functions lack JSDoc comments explaining:

  • What each behavior tests
  • Why you'd choose one over the other
  • What the expected outcomes are

Test Coverage

10. No Tests

This PR adds new functionality but doesn't include any tests. Consider adding tests for:

  • Both behavior modes
  • Error handling paths
  • Edge cases (invalid behavior values)

Summary

Must Fix Before Merge:

  • Undefined succeeded variable (critical runtime error)
  • Unsafe type assertion for BEHAVIOR
  • String throw instead of Error object

Should Fix:

  • Remove dead code
  • Add input validation
  • Add documentation
  • Consider test coverage

The refactoring to separate behaviors is a good architectural decision, but the implementation has a critical bug that will prevent the "sleep-cycle" behavior from working at all.

@claude
Copy link

claude bot commented Nov 4, 2025

Code Review for PR #3315: chore(smoke-test): add simple http test

Summary

This PR refactors the smoke test to support different actor behaviors via an environment variable. Overall, the changes are reasonable but there are several bugs and improvements needed.


Critical Issues

1. Bug: Undefined variable in spawnActorSleepCycle (spawn-actor.ts:55)

succeeded = true;
onSuccess();

The variable succeeded is used but never declared in spawnActorSleepCycle. This will cause a runtime error. Unlike spawnActorHttp which declares let succeeded = false; at the top, this function is missing that declaration.

Fix: Add let succeeded = false; at the beginning of the function, or simply remove the unused variable since it's set right before calling onSuccess().

2. Bug: Type casting allows invalid values (index.ts:22-23)

export const BEHAVIOR: ActorBehavior = (process.env.BEHAVIOR ??
	"sleep-cycle") as ActorBehavior;

Using as ActorBehavior bypasses type checking. If someone sets BEHAVIOR=invalid, it will compile but fail at runtime with "Unknown behavior".

Fix: Add runtime validation to check the value before casting.

3. Bug: Incorrect error throwing (spawn-actor.ts:32)

throw "Unknown behavior";

Throwing a string instead of an Error object is bad practice and makes error handling harder.

Fix: throw new Error("Unknown behavior");


Code Quality Issues

4. Dead code (spawn-actor.ts:101-102)

if (succeeded) {
}

Empty if block serves no purpose and should be removed.

5. Inconsistent variable initialization

  • spawnActorHttp declares let succeeded = false; at the top (line 72)
  • spawnActorSleepCycle uses succeeded without declaring it (line 55)

This inconsistency suggests the sleep-cycle implementation was copied from the original code but the variable declaration was lost.


Performance & Design Considerations

6. Hard-coded iteration count (spawn-actor.ts:75)

for (let i = 0; i < 20; i++) {

The HTTP test always does 20 iterations. Consider making this configurable via environment variable for more flexible testing.

7. Removed sleep behavior

The original code had random sleep times (100-900ms) that were removed. If the purpose was to test long-running connections, this removal may impact test coverage. Consider documenting why this was removed or making it optional.


Documentation

8. Missing documentation

The README doesn't mention the new BEHAVIOR environment variable. Users won't know about the new http test mode.

Suggestion: Update README.md to document:

Set `BEHAVIOR` environment variable to control actor behavior:
- `sleep-cycle` (default): Simple counter increment test
- `http`: HTTP/WebSocket connection test with 20 iterations

Minor Issues

9. Type safety improvement

The switch statement doesn't have exhaustive checking. Consider using TypeScript's exhaustive checking pattern with a never type in the default case.


Test Coverage

No automated tests were added for the new behavior switching logic. While this is a smoke test example, consider adding basic unit tests to verify:

  • Both behavior modes execute without errors
  • Invalid behavior values are rejected
  • The switch statement correctly routes to the right function

Summary of Required Fixes

  1. Fix undefined succeeded variable in spawnActorSleepCycle
  2. Add runtime validation for BEHAVIOR environment variable
  3. Throw Error object instead of string
  4. Remove dead code (empty if block)

Optional Improvements

  • Update README with BEHAVIOR documentation
  • Make iteration count configurable
  • Add exhaustive switch checking
  • Consider adding unit tests

Overall Assessment: The refactoring approach is sound, but there are critical bugs that need to be fixed before merging. The code needs better validation and error handling to prevent runtime failures.

@claude
Copy link

claude bot commented Nov 4, 2025

Code Review for PR #3315

Summary

This PR adds a simple HTTP test behavior option to the smoke test suite, allowing the test to switch between "sleep-cycle" and "http" behaviors via an environment variable.

Positive Aspects

✅ Good separation of concerns by extracting behavior logic into separate functions
✅ Environment variable-based configuration is appropriate for smoke tests
✅ Maintains existing functionality while adding new test behavior
✅ Removes debugging console.log and sleep logic that was cluttering the test

Issues Found

🔴 Critical: Undefined Variable (Bug)

Location: spawn-actor.ts:55

succeeded = true;

The succeeded variable is not declared in spawnActorSleepCycle. This will cause a runtime error. The variable is declared in spawnActorHttp (line 72) but is missing in the new function.

Fix: Declare the variable at the start of the function:

export async function spawnActorSleepCycle({...}: SpawnActorOptions): Promise<void> {
	let succeeded = false;
	try {
		// ... rest of the code

🟡 Moderate: Dead Code

Location: spawn-actor.ts:101-102

if (succeeded) {
}

Empty conditional block with no purpose. Should be removed.

🟡 Moderate: Error Handling - Throwing String Literal

Location: spawn-actor.ts:32

default:
	throw "Unknown behavior";

Throwing a string literal instead of an Error object is not best practice. It makes error handling more difficult and loses stack trace information.

Fix:

default:
	throw new Error(`Unknown behavior: ${BEHAVIOR}`);

🟡 Moderate: Type Safety Issue

Location: index.ts:22-23

export const BEHAVIOR: ActorBehavior = (process.env.BEHAVIOR ??
	"sleep-cycle") as ActorBehavior;

Using as ActorBehavior bypasses type checking. If someone sets an invalid BEHAVIOR environment variable, it will pass this check but fail at runtime in the switch statement.

Fix: Add runtime validation:

const behaviorValue = process.env.BEHAVIOR ?? "sleep-cycle";
if (behaviorValue !== "sleep-cycle" && behaviorValue !== "http") {
	throw new Error(`Invalid BEHAVIOR value: ${behaviorValue}. Must be "sleep-cycle" or "http"`);
}
export const BEHAVIOR: ActorBehavior = behaviorValue;

🔵 Minor: Inconsistent Variable Usage

Location: spawn-actor.ts:55 vs 72

In spawnActorHttp, the succeeded variable is used and checked at the end, but in spawnActorSleepCycle it's set but never used (besides the bug mentioned above). Consider either:

  1. Removing it entirely from spawnActorSleepCycle if not needed
  2. Using it consistently if there's a future purpose

Test Coverage

⚠️ No automated tests found for this smoke test suite. Consider adding tests to verify:

  • Both behavior modes work correctly
  • Error handling for invalid behaviors
  • Counter increment logic

Performance Considerations

✅ No performance concerns. The removal of the sleep logic in spawnActorHttp should actually improve test execution speed.

Security Concerns

✅ No security issues identified. Environment variable usage is appropriate for test configuration.

Recommendations

  1. Fix the undefined variable bug - This is a blocker that will cause runtime failures
  2. Remove the dead code block
  3. Improve error handling with proper Error objects
  4. Add runtime validation for the BEHAVIOR environment variable
  5. Consider adding unit tests for the spawn actor functions

Overall Assessment

The architectural direction is good - separating behaviors into dedicated functions improves maintainability. However, the undefined variable bug needs to be fixed before merging as it will cause the "sleep-cycle" behavior to fail at runtime.

@graphite-app
Copy link
Contributor

graphite-app bot commented Nov 4, 2025

Merge activity

  • Nov 4, 8:09 PM UTC: NathanFlurry added this pull request to the Graphite merge queue.
  • Nov 4, 8:11 PM UTC: CI is running for this pull request on a draft pull request (#3349) due to your merge queue CI optimization settings.
  • Nov 4, 8:41 PM UTC: The Graphite merge queue removed this pull request due to removal of a downstack PR #3342.
  • Nov 4, 8:49 PM UTC: NathanFlurry added this pull request to the Graphite merge queue.
  • Nov 4, 8:50 PM UTC: CI is running for this pull request on a draft pull request (#3352) due to your merge queue CI optimization settings.
  • Nov 4, 8:52 PM UTC: Merged by the Graphite merge queue via draft PR: #3352.

graphite-app bot pushed a commit that referenced this pull request Nov 4, 2025
@claude
Copy link

claude bot commented Nov 4, 2025

Code Review

Thank you for adding the HTTP test behavior to the smoke test! This is a useful addition for testing different actor interaction patterns. Here's my feedback:

🐛 Critical Bug

Undefined variable in spawnActorSleepCycle (spawn-actor.ts:55)

succeeded = true;  // ❌ 'succeeded' is not defined

This will cause a runtime error. The succeeded variable is declared in spawnActorHttp but not in spawnActorSleepCycle. This variable appears to be unused anyway since onSuccess() is called unconditionally in the try block, so you can simply remove this line.

⚠️ Issues

  1. Unsafe type assertion (index.ts:22-23)

    export const BEHAVIOR: ActorBehavior = (process.env.BEHAVIOR ?? "sleep-cycle") as ActorBehavior;

    The as ActorBehavior cast is unsafe. If someone sets BEHAVIOR=invalid, it will pass validation here but throw at runtime with the generic "Unknown behavior" message. Consider validating the value:

    const behaviorValue = process.env.BEHAVIOR ?? "sleep-cycle";
    if (behaviorValue !== "sleep-cycle" && behaviorValue !== "http") {
      throw new Error(`Invalid BEHAVIOR: ${behaviorValue}. Must be 'sleep-cycle' or 'http'`);
    }
    export const BEHAVIOR: ActorBehavior = behaviorValue;
  2. Poor error handling (spawn-actor.ts:32)

    throw "Unknown behavior";  // ❌ Throwing string instead of Error

    Should throw a proper Error object:

    throw new Error(`Unknown behavior: ${BEHAVIOR}`);
  3. Dead code (spawn-actor.ts:101-102)

    if (succeeded) {
    }

    Empty if block should be removed.

📝 Code Quality

  1. Missing documentation: The new spawnActorSleepCycle and spawnActorHttp functions could benefit from JSDoc comments explaining their behavior and use cases.

  2. Behavior naming: The name "sleep-cycle" is a bit misleading now that the sleep logic has been removed. The old behavior included random sleep intervals (removed in this PR), but the name still references sleeping. Consider renaming to something like "counter-only" or updating the documentation.

  3. Magic numbers: The hard-coded 20 iterations in spawnActorHttp (line 75) could be extracted to a constant or configuration variable for easier tuning.

✅ What's Good

  • Clean separation of behaviors through the switch statement
  • Good use of TypeScript union types for ActorBehavior
  • Proper async/await usage throughout
  • The HTTP test covers both websocket and HTTP connection methods

🧪 Testing

No automated tests found for this smoke test code. While this is a test utility itself, consider whether integration tests would be valuable for verifying the behavior switching logic works correctly.

Summary

Please fix the critical succeeded undefined variable bug before merging. The other issues are important but not blocking.

@claude
Copy link

claude bot commented Nov 4, 2025

Code Review

Thank you for adding the HTTP test behavior to the smoke test! This is a useful addition for testing different actor interaction patterns. Here's my review:

🐛 Critical Bug

spawn-actor.ts:55 - Undefined variable succeeded

succeeded = true;  // ❌ 'succeeded' is not declared
onSuccess();

The spawnActorSleepCycle function references succeeded without declaring it. This will cause a runtime error. The variable should either be:

  • Declared as let succeeded = false; at the start of the function (matching the pattern in spawnActorHttp), or
  • Removed entirely since it's not actually used in this function

⚠️ Code Quality Issues

  1. spawn-actor.ts:32 - Improper error throwing

    default:
        throw "Unknown behavior";  // ❌ Throwing a string literal

    Should throw a proper Error object:

    default:
        throw new Error(`Unknown behavior: ${BEHAVIOR}`);
  2. spawn-actor.ts:101-102 - Dead code

    if (succeeded) {
    }

    This empty conditional block serves no purpose and should be removed.

  3. index.ts:22-23 - Unsafe type assertion

    export const BEHAVIOR: ActorBehavior = (process.env.BEHAVIOR ??
        "sleep-cycle") as ActorBehavior;

    The as ActorBehavior cast is unsafe. If someone sets BEHAVIOR=invalid, it will bypass type checking and fail at runtime with the "Unknown behavior" error. Consider validating the input:

    const behaviorInput = process.env.BEHAVIOR ?? "sleep-cycle";
    if (behaviorInput !== "sleep-cycle" && behaviorInput !== "http") {
        throw new Error(`Invalid BEHAVIOR: ${behaviorInput}. Must be 'sleep-cycle' or 'http'`);
    }
    export const BEHAVIOR: ActorBehavior = behaviorInput;

📝 Minor Observations

  1. Inconsistent succeeded usage: The spawnActorHttp function declares and uses succeeded, but the final check at lines 101-102 doesn't do anything with it. This variable appears to be leftover from refactoring and could be removed from both functions since the callbacks (onSuccess/onFailure) are already being called.

  2. No documentation for new behavior: Consider adding a comment explaining what the "http" behavior tests (appears to test both HTTP and WebSocket connections with 20 iterations).

Positives

  • Good separation of concerns by splitting the actor spawning logic by behavior type
  • Clear naming with ActorBehavior type
  • Consistent error handling pattern across both behavior functions

🧪 Test Coverage

No automated tests were found for this smoke test. While this is a testing utility itself, consider adding:

  • Unit tests for the behavior selection logic
  • Validation tests for environment variable parsing

Recommendation

Please fix the critical bug in spawnActorSleepCycle before merging. The other issues are important for code quality but not blocking.

graphite-app bot pushed a commit that referenced this pull request Nov 4, 2025
@graphite-app graphite-app bot closed this Nov 4, 2025
@graphite-app graphite-app bot deleted the 11-02-chore_smoke-test_add_simple_http_test branch November 4, 2025 20:52
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.

3 participants