Skip to content

Conversation

@jog1t
Copy link
Contributor

@jog1t jog1t commented Oct 30, 2025

TL;DR

Refactored actor worker context to support inspector mode and standardized HTTP header usage.

What changed?

  • Added a new useConnectionDetails() hook in actor-worker-context.tsx that returns different connection details based on the application type
  • Updated ActorWorkerContextProvider to use the new hook instead of directly accessing the data provider
  • Replaced hardcoded header strings in rivetkit with imported constants from driver-helpers/mod
  • Added HEADER_ACTOR_QUERY to the list of allowed CORS headers

How to test?

  1. Run the application in both normal and inspector modes
  2. Verify that actor workers connect properly in both modes
  3. Confirm that cross-origin requests with the Rivet headers are properly handled

Why make this change?

This change improves the codebase by:

  1. Adding proper support for inspector mode in the actor worker context
  2. Reducing duplication by using constants for header names
  3. Ensuring consistent header handling across the application
  4. Preventing potential bugs from mismatched header names

@vercel
Copy link

vercel bot commented Oct 30, 2025

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

Project Deployment Preview Comments Updated (UTC)
rivet-inspector Ready Ready Preview Comment Oct 30, 2025 1:27am
rivetkit-serverless Ready Ready Preview Comment Oct 30, 2025 1:27am
2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
rivet-cloud Ignored Ignored Oct 30, 2025 1:27am
rivet-site Ignored Ignored Preview Oct 30, 2025 1:27am

@jog1t jog1t requested a review from NathanFlurry October 30, 2025 01:25
@jog1t jog1t marked this pull request as ready for review October 30, 2025 01:25
Copy link
Contributor Author

jog1t commented Oct 30, 2025


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 Oct 30, 2025

PR Review

Summary

This PR refactors actor worker context to support inspector mode and standardizes HTTP header usage by replacing hardcoded strings with constants. Overall, the changes are solid and improve maintainability.

✅ Strengths

  1. Good use of constants: Replacing hardcoded header strings ("x-rivet-actor", "x-rivet-target") with imported constants (HEADER_RIVET_ACTOR, HEADER_RIVET_TARGET) reduces duplication and prevents typos.

  2. Proper separation of concerns: The new useConnectionDetails() hook cleanly separates inspector mode from normal mode logic.

  3. Consistent pattern matching: Using ts-pattern's match API consistently with the existing useInspectorToken hook.

  4. CORS security improvement: Adding HEADER_ACTOR_QUERY to the allowed headers list ensures proper CORS handling for this header.

🔍 Issues & Suggestions

1. Code Style: Missing semicolon (Minor)

Location: frontend/src/components/actors/worker/actor-worker-context.tsx:55

The useConnectionDetails function is missing a semicolon at the end:

const useConnectionDetails = () => {
	return match(__APP_TYPE__)
		.with("inspector", () => {
			return {namespace: "", engineToken: ""};
		})
		.otherwise(() => {
			const provider = useEngineCompatDataProvider();
			return {namespace: provider.engineNamespace, engineToken: provider.engineToken};
		});
}  // Missing semicolon here

Recommendation: Add semicolon for consistency with the rest of the codebase.

2. Code Style: Inconsistent spacing (Minor)

Location: frontend/src/components/actors/worker/actor-worker-context.tsx:67

There's a trailing whitespace after the destructuring assignment:

const {engineToken, namespace} = useConnectionDetails();
	  // Extra blank line here
const {

Recommendation: Remove the trailing whitespace for consistency.

3. Code Style: Object property spacing (Minor)

Location: frontend/src/components/actors/worker/actor-worker-context.tsx:49,53

Missing spaces after colons in object literals:

return {namespace: "", engineToken: ""};  // Should be { namespace: "", engineToken: "" }
return {namespace: provider.engineNamespace, engineToken: provider.engineToken};

Recommendation: Add spaces after colons to match TypeScript/JavaScript conventions.

4. Potential Runtime Issue: Hook call order (Medium)

Location: frontend/src/components/actors/worker/actor-worker-context.tsx:52

The useConnectionDetails hook conditionally calls useEngineCompatDataProvider() only in the otherwise branch. This violates React's Rules of Hooks (hooks must be called in the same order on every render).

In inspector mode, useEngineCompatDataProvider() won't be called, but in normal mode it will. If __APP_TYPE__ could ever change at runtime, this would cause issues. While __APP_TYPE__ is likely a build-time constant, this pattern is still fragile.

Recommendation: Consider restructuring to call hooks unconditionally:

const useConnectionDetails = () => {
	const provider = match(__APP_TYPE__)
		.with("inspector", () => null)
		.otherwise(() => useEngineCompatDataProvider());
	
	return match(__APP_TYPE__)
		.with("inspector", () => ({ namespace: "", engineToken: "" }))
		.otherwise(() => ({
			namespace: provider?.engineNamespace ?? "",
			engineToken: provider?.engineToken ?? ""
		}));
}

However, this still has issues. A better approach might be:

const useConnectionDetails = () => {
	if (__APP_TYPE__ === "inspector") {
		return { namespace: "", engineToken: "" };
	}
	
	const provider = useEngineCompatDataProvider();
	return {
		namespace: provider.engineNamespace,
		engineToken: provider.engineToken
	};
}

Since __APP_TYPE__ is a compile-time constant, the dead code should be eliminated during bundling, avoiding the hook order issue.

5. Missing Test Coverage (Medium)

No test files were found for these components. Given that this PR changes critical connection logic for both normal and inspector modes, tests would be valuable.

Recommendation: Consider adding tests to verify:

  • Inspector mode returns empty strings for namespace and engineToken
  • Normal mode correctly retrieves values from the data provider
  • The connection details are properly passed to the ActorWorkerContainer

📊 Performance Considerations

No performance concerns. The refactoring maintains the same runtime behavior with minimal overhead.

🔒 Security Considerations

No security issues identified. The changes improve security by:

  • Properly declaring HEADER_ACTOR_QUERY in CORS allowed headers
  • Using constants reduces the risk of header name mismatches

📝 Best Practices

The PR follows repository conventions well:

  • ✅ Uses existing patterns (ts-pattern, hooks)
  • ✅ Proper import organization
  • ✅ Consistent with existing code style (mostly)

Final Verdict

Approve with minor suggestions. The core logic is sound and achieves the stated goals. The main concern is the conditional hook call, but if __APP_TYPE__ is truly a build-time constant (which it appears to be), this should be fine. The style issues are minor and could be fixed in a follow-up or left as-is.


🤖 Generated with Claude Code

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 30, 2025

More templates

@rivetkit/actor

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

@rivetkit/cloudflare-workers

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

@rivetkit/core

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

@rivetkit/db

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

@rivetkit/framework-base

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

@rivetkit/next-js

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

@rivetkit/react

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

rivetkit

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

@rivetkit/sql-loader

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

@rivetkit/engine-runner

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

@rivetkit/engine-runner-protocol

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

commit: bba545b

@graphite-app
Copy link
Contributor

graphite-app bot commented Oct 30, 2025

Graphite Automations

"Test" took an action on this PR • (10/30/25)

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

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