Skip to content

Conversation

@NathanFlurry
Copy link
Member

No description provided.

@vercel
Copy link

vercel bot commented Nov 10, 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 13, 2025 9:40pm
3 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
rivet-cloud Ignored Ignored Nov 13, 2025 9:40pm
rivet-inspector Ignored Ignored Preview Nov 13, 2025 9:40pm
rivet-site Ignored Ignored Preview Nov 13, 2025 9:40pm

This was referenced Nov 10, 2025
Copy link
Member Author

NathanFlurry commented Nov 10, 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 Nov 10, 2025

Pull Request Review: AsyncAPI Spec Generation

This PR adds AsyncAPI specification generation for RivetKit's WebSocket protocol. Overall, this is a solid addition that improves API documentation. Here are my findings:

✅ Strengths

  1. Good Structure: The AsyncAPI spec correctly follows v3.0.0 format with proper channels, operations, and message definitions
  2. Comprehensive Coverage: All WebSocket message types are documented (Init, Error, ActionResponse, Event, ActionRequest, SubscriptionRequest)
  3. Consistent Pattern: Follows the same pattern as the existing dump-openapi.ts script
  4. Good Examples: Includes helpful payload examples for each message type
  5. Type Safety: Leverages existing Zod schemas for consistency with runtime validation

🐛 Issues Found

1. Missing await in file write operation (Bug)

Location: scripts/dump-asyncapi.ts:323

fs.writeFile(outputPath, JSON.stringify(asyncApiSpec, null, 2));

This should be:

await fs.writeFile(outputPath, JSON.stringify(asyncApiSpec, null, 2));

Impact: The script may exit before the file is written, causing intermittent failures or incomplete writes.

2. Unused helper function

Location: scripts/dump-asyncapi.ts:44-54

The extractSchemas function is defined but never used. Consider removing it to keep the code clean.

3. Inconsistent metadata handling

Location: rivetkit-asyncapi/asyncapi.json:112,370

The metadata field in the Error schema is defined as an empty object {} without a type constraint. Looking at the Zod schema, it uses z.unknown().optional(), but the generated JSON schema shows:

"metadata": {}

This should be more explicit:

"metadata": {
  "type": ["object", "null"]
}

or simply omit it from required fields since it's optional.

4. Type inconsistency for id field

Location: Multiple locations in asyncapi.json

The id field is typed as integer with format: int64, but the example shows a string "123". The examples should use actual integers:

"id": 123

💡 Suggestions

  1. Add error handling: Wrap the file write in a try-catch block to handle potential filesystem errors
  2. Add validation: Consider validating the generated AsyncAPI spec against the official AsyncAPI schema
  3. Document generation: Add a comment explaining when/how this script should be run (e.g., as part of CI, before releases, etc.)
  4. Test coverage: Consider adding a test that validates the generated spec is valid AsyncAPI

📝 Code Quality

  • TypeScript usage: Good use of TypeScript, though liberal use of any types in helper functions could be improved
  • Comments: The code has helpful comments explaining non-obvious transformations
  • Readability: Code is well-structured and easy to follow

🔒 Security

No security concerns identified.

⚡ Performance

No performance concerns for a build-time script.

🧪 Test Coverage

No tests were added for this functionality. Consider adding:

  • A test that runs the script and validates the output
  • A test that ensures the generated spec is valid AsyncAPI v3.0.0

📊 Summary

Approval Status: ⚠️ Approve with changes

The PR is functionally sound but has a critical bug (missing await) that must be fixed. The other issues are minor but should be addressed for code quality.

Required Changes:

  1. Add await to the fs.writeFile call

Recommended Changes:

  1. Remove unused extractSchemas function
  2. Fix example values to match types (use integers, not strings for id)
  3. Add error handling around file write

Generated with Claude Code

@claude
Copy link

claude bot commented Nov 13, 2025

Code Review - AsyncAPI Specification Generation

Thanks for adding AsyncAPI spec generation! This is a valuable addition for documenting the WebSocket protocol. Here's my review:

✅ Strengths

  1. Good structure: The AsyncAPI 3.0.0 spec is well-organized with clear channels, operations, and message definitions
  2. Reuses existing schemas: Leverages the Zod schemas from client-protocol-zod, maintaining single source of truth
  3. Comprehensive examples: Includes helpful examples for each message type
  4. Consistent with OpenAPI approach: Follows similar patterns to the existing dump-openapi.ts script
  5. Proper build integration: Added to Turbo build pipeline correctly

🔍 Code Quality Issues

1. Missing error handling (dump-asyncapi.ts:323)

The file write operation lacks error handling:

fs.writeFile(outputPath, JSON.stringify(asyncApiSpec, null, 2));
console.log("Dumped AsyncAPI spec to", outputPath);

Should be:

await fs.writeFile(outputPath, JSON.stringify(asyncApiSpec, null, 2));
console.log("Dumped AsyncAPI spec to", outputPath);

Impact: The script may exit before the file is fully written, potentially corrupting the output file.

2. Function should be async

The main() function uses fs.writeFile() which returns a Promise, but the function isn't async and doesn't await.

Should be:

async function main() {
  // ... existing code ...
  await fs.writeFile(outputPath, JSON.stringify(asyncApiSpec, null, 2));
  console.log("Dumped AsyncAPI spec to", outputPath);
}

main().catch((error) => {
  console.error("Failed to dump AsyncAPI spec:", error);
  process.exit(1);
});

3. Unused helper function (dump-asyncapi.ts:44-54)

The extractSchemas function is defined but never used. Either use it or remove it.

4. Type safety could be improved

Several uses of any type throughout the helper functions:

  • fixRefs(obj: any) - line 17
  • extractSchemas(jsonSchema: any) - line 44
  • getSchemaWithoutDefinitions(jsonSchema: any) - line 57

Consider using proper TypeScript types or at least unknown instead of any.

📋 Missing Features

1. No validation of generated spec

Consider adding validation to ensure the generated AsyncAPI spec is valid. You could use the @asyncapi/parser package.

2. Missing tests

No tests found for the AsyncAPI generation. Consider adding:

  • Unit tests for helper functions (fixRefs, getSchemaWithoutDefinitions)
  • Integration test to verify the generated spec is valid AsyncAPI 3.0.0
  • Snapshot test to detect unintended changes to the spec

3. Incomplete turbo.json inputs

The dump-asyncapi task lists these inputs:

"inputs": [
  "package.json",
  "packages/rivetkit/src/manager/router.ts"
]

But the script actually depends on:

  • scripts/dump-asyncapi.ts (the script itself)
  • src/schemas/client-protocol-zod/mod.ts (the schemas being converted)
  • src/utils.ts (for VERSION export)

Missing these inputs means the task might not rebuild when these files change.

🔒 Security Considerations

No security concerns identified. The script:

  • Only reads from trusted internal schemas
  • Only writes to a predefined output path
  • Doesn't accept external input

⚡ Performance Considerations

Performance is acceptable for a build-time script. The schema conversions are straightforward and the output is cached by Turbo.

🎯 Recommendations

High Priority:

  1. Fix the async/await issue in main() function
  2. Add proper error handling for file operations
  3. Fix the turbo.json inputs to include all actual dependencies

Medium Priority:
4. Remove unused extractSchemas function
5. Improve type safety by replacing any with proper types
6. Add basic validation test for the generated spec

Low Priority:
7. Add comprehensive test coverage
8. Consider validating the output against AsyncAPI spec

📝 Documentation

The generated AsyncAPI spec looks good and is well-documented with descriptions and examples. Consider adding:

  • A comment at the top of dump-asyncapi.ts explaining its purpose
  • Documentation on how to use/view the generated spec (e.g., with AsyncAPI Studio)

Overall, this is a solid addition! The main concern is the missing await which could cause intermittent build failures. Once the async/await issue is fixed, this should be good to merge.

@claude
Copy link

claude bot commented Nov 13, 2025

Code Review: AsyncAPI Spec Generation

This PR adds AsyncAPI specification generation for RivetKit's WebSocket protocol. Overall, the implementation is clean and follows good patterns. Here are my findings:

✅ Strengths

  1. Good architecture: The script mirrors the existing dump-openapi.ts pattern, maintaining consistency in the codebase
  2. Proper AsyncAPI v3.0.0 compliance: The generated spec follows the AsyncAPI 3.0.0 schema correctly
  3. Comprehensive examples: The spec includes helpful examples for each message type
  4. Clean helper functions: fixRefs and getSchemaWithoutDefinitions are well-designed for transforming Zod schemas
  5. Build integration: Properly integrated into the Turbo build pipeline

🐛 Critical Bug

Missing await on file write (line 323)

fs.writeFile(outputPath, JSON.stringify(asyncApiSpec, null, 2));
console.log("Dumped AsyncAPI spec to", outputPath);

This should be:

await fs.writeFile(outputPath, JSON.stringify(asyncApiSpec, null, 2));
console.log("Dumped AsyncAPI spec to", outputPath);

Without await, the script may exit before the file is fully written, leading to race conditions or incomplete files during builds.

⚠️ Issues & Concerns

  1. Dead code: The extractSchemas function (lines 44-54) is defined but never used. Consider removing it or documenting why it's kept for future use.

  2. Type safety: Extensive use of any types in helper functions (lines 17, 22, 44, 57). Consider adding proper types:

    type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
    interface JsonObject { [key: string]: JsonValue }
    interface JsonArray extends Array<JsonValue> {}
  3. Error handling: The script has no try-catch blocks. If schema conversion or file writing fails, there's no graceful error handling or useful error messages.

  4. Turbo configuration inconsistency: The dump-asyncapi task in turbo.json lists src/manager/router.ts as an input, but the script actually reads from src/schemas/client-protocol-zod/mod.ts. The inputs should be:

    "inputs": [
      "package.json",
      "src/schemas/client-protocol-zod/**"
    ]
  5. Missing parameter schema: The actorId parameter in the channel (line 132-135) lacks a type definition. It should specify:

    "actorId": {
      "description": "The unique identifier for the actor instance",
      "schema": {
        "type": "string",
        "format": "uuid"
      }
    }

📝 Minor Suggestions

  1. Empty else block (line 33-34): The empty else block for the "definitions" key is confusing. Consider adding a comment or using continue in a more explicit way.

  2. Hard-coded paths: The path construction (lines 313-321) uses multiple ".." which is brittle. Consider using a workspace-relative path or configuration.

  3. Missing test coverage: No tests verify the generated AsyncAPI spec is valid or that the schema conversion works correctly.

  4. Documentation: Consider adding a README or comments explaining when to regenerate the spec and how to validate it.

🔒 Security

No security concerns identified. The script operates on local schemas and doesn't handle external input.

🎯 Testing Recommendations

  1. Add a test that validates the generated asyncapi.json against the AsyncAPI 3.0.0 schema
  2. Add a test that ensures all Zod schemas are properly converted
  3. Consider adding the script to CI to verify it runs successfully

📊 Performance

No performance concerns for a build-time script.

Summary

This is a solid implementation that adds valuable API documentation. The critical bug with the missing await should be fixed before merging. The other issues are improvements that could be addressed now or in follow-up PRs depending on urgency.

@NathanFlurry NathanFlurry changed the base branch from 11-10-chore_rivetkit_add_actor_router_to_the_openapi_spec to graphite-base/3442 November 13, 2025 21:33
@graphite-app
Copy link
Contributor

graphite-app bot commented Nov 13, 2025

Merge activity

@NathanFlurry NathanFlurry force-pushed the 11-10-feat_rivetkit_add_asyncapi_spec branch from 9a434c7 to f539782 Compare November 13, 2025 21:39
@NathanFlurry NathanFlurry changed the base branch from graphite-base/3442 to 11-10-chore_rivetkit_add_actor_router_to_the_openapi_spec November 13, 2025 21:39
@claude
Copy link

claude bot commented Nov 13, 2025

PR Review: AsyncAPI Spec Generation

This PR adds AsyncAPI specification generation for the RivetKit WebSocket protocol. Overall, the implementation is solid and follows good patterns from the existing dump-openapi.ts script. Here are my findings:

✅ Strengths

  1. Good architectural consistency: The implementation mirrors the existing dump-openapi.ts pattern, making it easy to maintain alongside the OpenAPI spec generation.

  2. Complete schema coverage: All relevant message types are properly documented (Init, Error, ActionResponse, Event, ActionRequest, SubscriptionRequest).

  3. Excellent documentation: The generated spec includes helpful examples for each message type, making it easy for developers to understand the protocol.

  4. Proper build integration: The turbo.json configuration correctly sets up dependencies and makes the AsyncAPI generation part of the build pipeline.

  5. Clean reference handling: The fixRefs function properly converts zod-to-json-schema's #/definitions format to AsyncAPI's #/components/schemas format.

🔧 Code Quality Issues

  1. Missing await on file write (scripts/dump-asyncapi.ts:323)

    • The fs.writeFile call is not awaited, which could cause the file to not be written before the script exits.
    • Fix: Change to await fs.writeFile(...)
    • Impact: This could cause intermittent build failures or incomplete file writes.
  2. Unused helper function (scripts/dump-asyncapi.ts:44-54)

    • The extractSchemas function is defined but never used.
    • Fix: Remove the unused function or document why it's kept for future use.
    • Impact: Minor code cleanliness issue.
  3. Loose typing with any (scripts/dump-asyncapi.ts:17-70)

    • Multiple functions use any types which reduces type safety.
    • Suggestion: Consider adding proper TypeScript types for the AsyncAPI spec structure, similar to how OpenAPI specs could be typed.
    • Impact: Lower priority - this is a build script, but better types would catch errors earlier.

📋 Suggestions

  1. Error handling

    • Consider adding try-catch blocks around the file write operation to provide clear error messages if the write fails.
  2. Consistency with dump-openapi.ts

    • The dump-openapi.ts script also doesn't await the file write (line 83), so this is a shared issue.
    • Recommendation: Fix both scripts in a follow-up PR.
  3. AsyncAPI version consideration

    • The spec uses AsyncAPI v3.0.0, which is relatively new. Verify that your tooling ecosystem (validators, generators, docs) supports v3.0.0 well.
  4. Parameter schema

    • The actorId parameter in the channel definition lacks a schema type definition. While optional in AsyncAPI, adding schema: { type: 'string' } would improve clarity.

🔒 Security & Performance

  • No security concerns identified: The script generates static documentation from schema definitions.
  • Performance: Appropriate for a build-time script.

🧪 Testing

  • Consider adding: A test that validates the generated AsyncAPI spec is valid according to the AsyncAPI specification (using an AsyncAPI validator library).
  • The turbo.json configuration properly adds the asyncapi dump as a dependency of the build, ensuring it runs at the right time.

📦 Dependencies

  • zod-to-json-schema: Good choice for converting Zod schemas to JSON Schema format. The version constraint ^3.24.6 is appropriately flexible.

Priority Issues

Must fix before merge:

  1. ❗ Add await to fs.writeFile call (line 323)

Should consider:
2. Remove unused extractSchemas function
3. Add error handling around file operations

Overall Assessment

This is a well-structured PR that adds valuable API documentation. The main issue is the missing await on the file write operation, which should be fixed before merging. The implementation follows existing patterns well and integrates cleanly into the build pipeline.

Recommendation: Approve with required changes ✅


Reviewed using Claude Code - following CLAUDE.md conventions

@claude
Copy link

claude bot commented Nov 13, 2025

Pull Request Review: AsyncAPI Spec Generation

I've reviewed PR #3442 which adds AsyncAPI specification generation for the RivetKit WebSocket protocol. Overall, this is a solid addition that improves documentation and enables better tooling integration. Here are my findings:

Strengths

  1. Follows existing patterns: The implementation mirrors the existing dump-openapi.ts script, maintaining consistency in the codebase
  2. Good separation of concerns: The script is standalone and generates static documentation
  3. Comprehensive schema coverage: Covers all WebSocket message types (Init, Error, ActionRequest, ActionResponse, Event, SubscriptionRequest)
  4. AsyncAPI 3.0.0 compliance: Uses the latest AsyncAPI specification version
  5. Helpful examples: Includes practical examples for each message type
  6. Proper integration: Correctly integrated into turbo.json build pipeline

🔍 Issues & Concerns

1. Missing Error Handling (Medium Priority)

Location: scripts/dump-asyncapi.ts:323

fs.writeFile(outputPath, JSON.stringify(asyncApiSpec, null, 2));
console.log("Dumped AsyncAPI spec to", outputPath);

Issue: No error handling or await for the async file write operation. If the write fails, it will fail silently.

Recommendation:

await fs.writeFile(outputPath, JSON.stringify(asyncApiSpec, null, 2));
console.log("Dumped AsyncAPI spec to", outputPath);

Also consider adding try-catch for better error messages:

try {
  await fs.writeFile(outputPath, JSON.stringify(asyncApiSpec, null, 2));
  console.log("Dumped AsyncAPI spec to", outputPath);
} catch (error) {
  console.error("Failed to write AsyncAPI spec:", error);
  process.exit(1);
}

2. Dead Code (Low Priority)

Location: scripts/dump-asyncapi.ts:44-54

The extractSchemas helper function is defined but never used. Consider removing it to keep the codebase clean.

3. Type Safety Issue (Medium Priority)

Location: Throughout the script

Heavy use of any types reduces type safety:

  • Line 17: function fixRefs(obj: any): any
  • Line 44: function extractSchemas(jsonSchema: any): Record<string, any>
  • Line 57: function getSchemaWithoutDefinitions(jsonSchema: any): any

Recommendation: Define proper TypeScript types for JSON Schema objects, or at least use unknown instead of any.

4. Schema Metadata Inconsistency (Low Priority)

Location: scripts/dump-asyncapi.ts:18

The ErrorSchema in client-protocol-zod has:

metadata: z.unknown().optional()

But in the generated AsyncAPI spec (line 111 of asyncapi.json), it appears as:

"metadata": {}

This doesn't preserve the "optional" nature. Consider verifying the JSON Schema conversion handles optionality correctly.

5. Integer Format Inconsistency (Low Priority)

In the generated spec, id fields use:

"type": "integer",
"format": "int64"

But this comes from z.bigint() in Zod. Verify this matches the actual wire format. If JavaScript BigInt is used, standard JSON doesn't support it natively - it would need to be serialized as a string.

📋 Additional Observations

  1. turbo.json inputs: The dump-asyncapi task lists packages/rivetkit/src/manager/router.ts as an input, but the script doesn't actually read from router.ts - it only uses Zod schemas. Consider updating the inputs to be more accurate:

    "inputs": [
      "package.json",
      "src/schemas/client-protocol-zod/mod.ts"
    ]
  2. No test coverage: Consider adding a test that validates:

    • The script runs without errors
    • The generated JSON is valid AsyncAPI 3.0.0
    • The schema structure matches expectations
  3. Documentation: The generated spec is comprehensive, but consider adding a README in the rivetkit-asyncapi directory explaining what the file is and how it's generated.

🎯 Recommendations Priority

Must Fix:

Should Fix:

Nice to Have:

  • Update turbo.json inputs to be more accurate
  • Add basic test coverage
  • Verify BigInt serialization matches actual usage

Summary

This is a useful feature that will help developers understand and integrate with the WebSocket protocol. The implementation is clean and follows existing patterns. The main concern is the missing await on the file write, which could lead to silent failures. Once that's addressed, this should be good to merge.

Recommended Action: Request changes for the missing await, then approve after fix.

Base automatically changed from 11-10-chore_rivetkit_add_actor_router_to_the_openapi_spec to main November 13, 2025 22:10
@NathanFlurry NathanFlurry merged commit 2303c1b into main Nov 13, 2025
19 of 23 checks passed
@NathanFlurry NathanFlurry deleted the 11-10-feat_rivetkit_add_asyncapi_spec branch November 13, 2025 22:25
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