Conversation
📝 WalkthroughWalkthroughThe PR renames the headroom tracking system to metrics terminology, replacing Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
convex/bandwidth.test.ts (1)
154-206: Please add coverage forgetFunctionMetadata()too.This file already exercises the syscall surface directly, so it’s a good place to add one happy-path case and one invalid-context case for
1.0/getFunctionMetadata. That would catch context-wiring regressions alongside the new metrics assertions.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@convex/bandwidth.test.ts` around lines 154 - 206, Add two tests invoking the syscall "1.0/getFunctionMetadata" via (global as any).Convex.asyncSyscall: one happy-path test inside a valid execution context (use t.query or t.mutation like the existing tests) that calls asyncSyscall("1.0/getFunctionMetadata", JSON.stringify({})) and asserts the parsed result contains the expected metadata fields (e.g., non-empty function name/id/path/runtime) and one invalid-context test that calls the same syscall outside a valid Convex execution context and asserts it fails or returns the error shape you expect; reference the existing test helpers and symbols (convexTest, t.query, t.mutation, getTransactionMetrics usage, and (global as any).Convex.asyncSyscall) so the tests are added alongside the current getTransactionMetrics tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@index.ts`:
- Around line 1408-1419: getFunctionMetadata currently throws when
executionContextStorage has no store, which occurs for HTTP actions because
fetch() doesn’t install an ExecutionContext before calling httpActionGeneric;
either seed an ExecutionContext for HTTP actions in the fetch() path or narrow
the syscall. Fix by, in the fetch() flow before invoking httpActionGeneric,
create an ExecutionContext (populating udfPath and componentPath from the HTTP
action metadata) and call executionContextStorage.run(storeObj, () =>
httpActionGeneric(...)) so getFunctionMetadata can read ctx; alternatively,
change getFunctionMetadata to detect missing ctx and return a clear value/error
that excludes HTTP actions (adjust the error message and return contract)
instead of assuming executionContextStorage is always present.
---
Nitpick comments:
In `@convex/bandwidth.test.ts`:
- Around line 154-206: Add two tests invoking the syscall
"1.0/getFunctionMetadata" via (global as any).Convex.asyncSyscall: one
happy-path test inside a valid execution context (use t.query or t.mutation like
the existing tests) that calls asyncSyscall("1.0/getFunctionMetadata",
JSON.stringify({})) and asserts the parsed result contains the expected metadata
fields (e.g., non-empty function name/id/path/runtime) and one invalid-context
test that calls the same syscall outside a valid Convex execution context and
asserts it fails or returns the error shape you expect; reference the existing
test helpers and symbols (convexTest, t.query, t.mutation, getTransactionMetrics
usage, and (global as any).Convex.asyncSyscall) so the tests are added alongside
the current getTransactionMetrics tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cc997d0d-1518-474a-b76b-59d9430bb43e
📒 Files selected for processing (3)
convex/bandwidth.test.tsindex.tstransactionMetrics.ts
| case "1.0/getFunctionMetadata": { | ||
| const ctx = executionContextStorage.getStore(); | ||
| if (!ctx) { | ||
| throw new Error( | ||
| "getFunctionMetadata() can only be called from within a Convex function.", | ||
| ); | ||
| } | ||
| return JSON.stringify({ | ||
| name: ctx.udfPath, | ||
| componentPath: ctx.componentPath, | ||
| }); | ||
| } |
There was a problem hiding this comment.
getFunctionMetadata() will reject inside HTTP actions.
Line 1409 assumes every Convex function runs with executionContextStorage, but this file’s fetch() path does not install that context before invoking httpActionGeneric. As written, the new syscall throws from HTTP actions even though they are still Convex functions. Please either seed an ExecutionContext for HTTP actions or narrow the syscall contract/error message to exclude them explicitly.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@index.ts` around lines 1408 - 1419, getFunctionMetadata currently throws when
executionContextStorage has no store, which occurs for HTTP actions because
fetch() doesn’t install an ExecutionContext before calling httpActionGeneric;
either seed an ExecutionContext for HTTP actions in the fetch() path or narrow
the syscall. Fix by, in the fetch() flow before invoking httpActionGeneric,
create an ExecutionContext (populating udfPath and componentPath from the HTTP
action metadata) and call executionContextStorage.run(storeObj, () =>
httpActionGeneric(...)) so getFunctionMetadata can read ctx; alternatively,
change getFunctionMetadata to detect missing ctx and return a clear value/error
that excludes HTTP actions (adjust the error message and return contract)
instead of assuming executionContextStorage is always present.

Implement getFunctionMetadata syscall and rename transaction metrics APIs
Rename transaction metrics components
HeadroomTrackerclass toTransactionMetricsTrackerheadroom.tsfile totransactionMetrics.tsgetTransactionHeadroom()method togetTransactionMetrics()1.0/headroomsyscall with1.0/getTransactionMetricsAdd getFunctionMetadata syscall
1.0/getFunctionMetadatasyscall that returns function name and component pathEnhance transaction metrics testing
Summary by CodeRabbit
New Features
1.0/getFunctionMetricssyscall to retrieve current function metadata including name and component path.Refactor
1.0/headroomsyscall to1.0/getTransactionMetricswith expanded metric reporting.