Complete proposal reduce convex ref escape hatches#16
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Review Summary by QodoEliminate unsafe object-cast escape hatches with explicit typed function references
WalkthroughsDescription• Replaced unsafe anyApi object-cast escape hatches with explicit typed function references • Extracted push function references to dedicated push/functionRefs.ts module for reusability • Introduced ConvexRef type aliases and helper functions for shallow runner casts • Added comprehensive test coverage to enforce type safety guardrails across hotspots • Updated API type definitions to include new push function references module Diagramflowchart LR
A["anyApi object-casts"] -->|Replace with| B["makeFunctionReference"]
B -->|Create typed| C["ConvexRef types"]
C -->|Use in| D["aiAgentActions.ts"]
C -->|Use in| E["outboundMessages.ts"]
C -->|Use in| F["carousels/triggering.ts"]
C -->|Use in| G["widgetSessions.ts"]
H["push.ts refs"] -->|Extract to| I["push/functionRefs.ts"]
I -->|Import in| J["push.ts"]
K["Test guards"] -->|Enforce| L["No broad anyApi casts"]
L -->|Except| M["lib/authWrappers.ts"]
File Changes1. packages/convex/convex/_generated/api.d.ts
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewⓘ The new review experience is currently in Beta. Learn more |
There was a problem hiding this comment.
Pull request overview
This PR reduces Convex backend “escape hatch” usage by replacing broad anyApi object-casts with explicit, strongly-typed FunctionReference constants and shallow runner helpers, particularly in AI agent actions and outbound/carousel push triggering flows.
Changes:
- Refactored several Convex modules to use explicit
makeFunctionReference-based refs plusgetShallowRunQuery/getShallowRunMutationhelpers instead ofanyApicasts. - Introduced
packages/convex/convex/push/functionRefs.tsand updatedpush.tsto consume the extracted typed refs/helpers. - Strengthened guard tests to enforce the reduced surface area for
anyApicasts and runner-cast patterns.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/convex/tests/runtimeTypeHardeningGuard.test.ts | Adds repo-wide scanning assertions to constrain anyApi casts and runner-cast patterns. |
| packages/convex/tests/aiAgentActionsPath.test.ts | Updates assertions to the new fixed ref name/path for internal bot-message persistence. |
| packages/convex/convex/aiAgentActions.ts | Replaces anyApi access with explicit typed refs and shallow run helpers in the AI agent action. |
| packages/convex/convex/outboundMessages.ts | Replaces anyApi usage with explicit typed refs and uses shared routeEventRef. |
| packages/convex/convex/carousels/triggering.ts | Replaces anyApi usage with explicit typed refs and uses shared routeEventRef. |
| packages/convex/convex/widgetSessions.ts | Introduces typed internal mutation ref and shallow runner helper for identity verification mutation calls. |
| packages/convex/convex/push/functionRefs.ts | Adds extracted typed refs and shallow runner helpers for push orchestration internals. |
| packages/convex/convex/push.ts | Switches to importing push refs/helpers from the new push/functionRefs module. |
| packages/convex/convex/_generated/api.d.ts | Updates generated API typings to include the new push/functionRefs module. |
| openspec/changes/reduce-convex-backend-ref-escape-hatches/tasks.md | Marks the refactoring/verification checklist items as completed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CI Feedback 🧐A test triggered by this PR failed. Here is an AI-generated analysis of the failure:
|
Broader fix for calling makeFunctionReference inside components
…ttps://github.com/opencom-org/opencom into openspec/reduce-convex-backend-ref-escape-hatches
This pull request focuses on reducing unsafe object-cast "escape hatches" in the Convex backend by replacing broad, untyped API references with explicit, strongly-typed function references and helpers. The changes improve backend type safety and maintainability, particularly in AI agent actions and carousel triggering logic. Additionally, the project task checklist has been updated to reflect the completion of these refactoring tasks.
Refactoring for Type Safety and Explicitness
Replaced all usages of broad
anyApiobject-cast access inaiAgentActions.tswith explicit, strongly-typed function references usingmakeFunctionReferenceand a newConvexReftype. This includes defining all argument and return types for backend functions and updating all invocations to use these typed references. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]Similarly, replaced broad object-cast access in
carousels/triggering.tswith explicit function references, introducing a localConvexReftype and updating all backend calls to use these references. [1] [2]Helpers and Utilities
getShallowRunQueryandgetShallowRunMutationin both files to enforce correct typing when running queries and mutations, further reducing reliance on unsafe casting. [1] [2]Project Management
openspec/changes/reduce-convex-backend-ref-escape-hatches/tasks.mdto mark all major refactoring and verification tasks as completed.These changes collectively make the backend codebase safer, easier to understand, and more robust against accidental misuse of internal APIs.