Repository navigation
fix(advisor,codegen,cli): close the silent-failure gaps behind #283-#287 - #289
Conversation
✅ Deploy Preview for lunorash ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thank you for following the naming conventions! 🙏 |
|
Warning Review limit reached
Next review available in: 14 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (19)
📒 Files selected for processing (14)
WalkthroughThe PR updates advisor severity and storage-key classification, adds unmodified argument analysis and procedure visibility to codegen, bootstraps generated types, emits D1 admin-import wiring, corrects CLI boolean options, preserves logger binding, and adds an error catalog entry. ChangesAdvisor analysis
Codegen analysis and bootstrap
CLI and runtime support
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant runCodegen
participant GeneratedDeclarations
participant FunctionDiscovery
participant StorageKeyDiscovery
participant GeneratedD1Worker
participant importGlobalRows
runCodegen->>GeneratedDeclarations: write schema-only declarations
runCodegen->>GeneratedDeclarations: refresh generated source files
runCodegen->>FunctionDiscovery: discover functions
runCodegen->>StorageKeyDiscovery: analyze accesses with function visibility
StorageKeyDiscovery-->>runCodegen: return classified storage-key accesses
GeneratedD1Worker->>importGlobalRows: import global rows through D1 context
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
|
Thank you for confirming the Contributor License Agreement! 🙏 |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
packages/advisor/src/lints/static/storage-key-from-user-args.ts (1)
34-66: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDuplicated
emit()shape between the internal and default branches.Both branches build the same
cacheKey, reusemetadata, and callemit(storageKeyFromUserArgs, {...}), differing only indetail(andfacing/levelfor the internal case). Consider a singleemit()call with the branch computing only the varying fields (detail, and an optionalfacing/leveloverride object).As per path instructions, "Follow DRY principles" for
packages/**/*.ts.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/advisor/src/lints/static/storage-key-from-user-args.ts` around lines 34 - 66, The internal and default branches in the storage-key lint duplicate the emit call and shared fields. Refactor the map callback around storageKeyFromUserArgs to compute the branch-specific detail plus optional internal facing/level values, then invoke emit once with the shared cacheKey and metadata while preserving the existing messages and defaults.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/codegen/src/emit-app.ts`:
- Around line 916-926: Update buildGlobalImporter so its rows mapping preserves
each row.line when constructing the input for importGlobalRows, allowing
non-contiguous global-row errors to report the original NDJSON line. Keep the
existing doc and table mapping and startLine behavior unchanged.
In `@packages/codegen/src/run-codegen.ts`:
- Around line 473-519: Update the bootstrap block around emitServer and
writeIfChanged so disk writes occur only when the generated bootstrap targets
are missing, avoiding replacement of warm-run full output with schema-only
content. Check bootstrapDataModelPath and bootstrapServerPath existence before
writing, while still registering the bootstrap contents with
project.createSourceFile when needed for in-memory discovery; preserve the final
full-feature emission and existing dry-run behavior.
In `@packages/server/docs/index.mdx`:
- Around line 132-140: Update the OCC documentation in the idempotency section
to remove the undefined ConflictError reference and describe the 409 response
and caller-controlled retry behavior without naming a specific error class.
Preserve the existing x-lunora-mutation-id and (identity, mutationId)
deduplication documentation unchanged.
---
Nitpick comments:
In `@packages/advisor/src/lints/static/storage-key-from-user-args.ts`:
- Around line 34-66: The internal and default branches in the storage-key lint
duplicate the emit call and shared fields. Refactor the map callback around
storageKeyFromUserArgs to compute the branch-specific detail plus optional
internal facing/level values, then invoke emit once with the shared cacheKey and
metadata while preserving the existing messages and defaults.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 2e447e99-986b-4400-b270-b97b1978de10
⛔ Files ignored due to path filters (7)
packages/advisor/__tests__/nondeterministic-query-mutation.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/advisor/__tests__/storage-key-from-user-args.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/cli/__tests__/commands/option-parsing.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/codegen/__tests__/discover-storage-key-accesses.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/codegen/__tests__/emit-app-global.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/codegen/__tests__/fixtures/simple/expected/_generated/app.tsis excluded by!**/_generated/**,!**/__tests__/**and included bypackages/**packages/codegen/__tests__/run-codegen-cold-start.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**
📒 Files selected for processing (13)
packages/advisor/src/lints/static/nondeterministic-query-mutation.tspackages/advisor/src/lints/static/storage-key-from-user-args.tspackages/advisor/src/storage-key-accesses.tspackages/cli/src/commands/advisor/index.tspackages/cli/src/commands/codegen/index.tspackages/cli/src/commands/deploy/index.tspackages/codegen/src/argument-taint.tspackages/codegen/src/discover-argument-derived-accesses.tspackages/codegen/src/discover-storage-key-accesses.tspackages/codegen/src/emit-app.tspackages/codegen/src/ir.tspackages/codegen/src/run-codegen.tspackages/server/docs/index.mdx
Merging this PR will regress 1 benchmark
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | in-batch: single IN(...) query + id->doc re-projection |
790.1 µs | 949.9 µs | -16.82% |
| ⚡ | batched: one IN-list UNION-ALL probe across all tables (locateTablesByIds) |
1.8 ms | 1.4 ms | +26.97% |
| ⚡ | count, no attributes |
67.1 µs | 60.4 µs | +11.08% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing fix/advisor-gate-and-codegen-emission (c14cbf5) with alpha (6a4dd72)2
Footnotes
-
10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
-
No successful run was found on
alpha(9f7af4d) during the generation of this report, so 6a4dd72 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
storage_key_from_user_args had no reachability model: it flagged any ctx.storage.* call whose key textually referenced args, with no regard for whether the enclosing procedure has an untrusted caller, and no check that the value reaches the sink unmodified. Both real false positives were internalActions receiving a content-addressed id minted server-side. Mirror owner_field_from_args_not_auth's existing visibility split: attach the enclosing procedure's visibility to each storage-key access and drop internal-procedure findings to INFO (pointing at the public callers instead), and add isUnmodifiedArgumentPassthrough so a value rebuilt by an intervening call (a hash, an encoder) is no longer treated as caller-controlled input reaching the sink verbatim. Because storage_key_from_user_args is the only ERROR-level advisory gating `lunora codegen`, these two false positives silently broke any chained `lunora codegen && <next step>` script. Separately, the gate itself ignored its own documented default. cerebro synthesizes a `--strict-advisories` counterpart from a `no-*`-only declaration by cloning its description verbatim (so both flags showed the same "Don't fail..." help text) and giving the synthesized option an unconditional `defaultValue: true` — so `options.strictAdvisories` was never `undefined`, permanently overriding the CI-vs-local fallback and making `lunora codegen`/`lunora deploy` strict locally regardless of `--help`'s claim otherwise. Declaring both the positive and negative forms explicitly, each with its own accurate description and no default, fixes both. Also fixes `lunora advisor --no-write`: the option was registered under its positive name (`write`), so cerebro never synthesized the `no-*` counterpart the command's own --help already advertised, and the flag was rejected as unknown. Declaring it as `no-write` (matching every other negatable flag in this CLI) makes the documented invocation work. Closes #284, #285
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Cluster A — the advisor gate silently breaks codegen chains (#284, #285)
storage_key_from_user_argshas no reachability model — false-positive ERRORs gate codegen #284:storage_key_from_user_argshad no reachability model. Both realhits were
internalActions receiving a content-addressed storage id mintedserver-side. Fixed both suggested angles: attaches the enclosing procedure's
visibility(mirroringowner_field_from_args_not_auth's existing split)and drops an
internal*finding to INFO instead of ERROR, pointing at thepublic callers as the real audit surface; and added
isUnmodifiedArgumentPassthroughso a key rebuilt by an intervening call (ahash, an encoder) is no longer treated as caller-controlled input reaching
the sink verbatim. No new suppression mechanism added.
advisor --no-writerejected #285: all three parts.no-strict-advisories-only declaration — cerebro synthesizes the positive--strict-advisoriescounterpart with an unconditionaldefaultValue: true, sooptions.strictAdvisorieswas neverundefinedand theCI-vs-local fallback in
resolveStrictAdvisoriesnever ran. Now declaresboth
--strict-advisoriesand--no-strict-advisoriesexplicitly (inboth
codegenanddeploy), neither with a default, so the fallbackactually fires.
option clones the negative flag's
descriptionverbatim. Declaring bothforms ourselves gives each its own accurate text.
lunora advisor --no-writewas rejected as unknown because the optionwas declared under its positive name (
write) — cerebro onlysynthesizes a
no-*counterpart for ano-*-named declaration.Redeclared as
no-write, matching the conventioncodegen/devalreadyuse correctly.
Cluster B — codegen emits too little, silently (#283, #287)
_generated/— first run writes collapsed{}return types #283: codegen wasn't reproducible from a cold_generated/— pass 1inferred handler return types before
Doc<T>/Id<T>/typedctx.dbexistedfor a handler to resolve against, so a dependent return type collapsed to
unknownand got written intoapi.ts/functions.ts. Bootstrapped:runCodegennow emitsdataModel.ts(schema-only) and a provisionalserver.ts(schema-only core builders) beforediscoverFunctionsruns,so pass 1 sees what pass 2 used to. The full
server.tsoverwrites theprovisional one before the run returns, so a warm run pays nothing beyond
two cheap string renders. Added a regression test that runs codegen from a
genuinely cold
_generated/and asserts the first pass already matches asecond pass.
resolveTableSharding/importGlobals— omitting them makes admin import a silent no-op #287:POST /_lunora/admin/importneededresolveTableShardingandimportGlobalswired by hand; omitting either was silent (a.global()table routes to the default shard and
GLOBAL_NOT_CONFIGUREDnever fires —200 with
inserted: {}). Codegen now emits both inside the existing.global()block:resolveTableShardingis a mechanical lookup over eachtable's already-known
shardMode, andimportGlobalsroutes rows throughthe same D1 writer via
@lunora/d1'simportGlobalRows, mirroringrunShardImport's shard-local twin. Verified against a real schema(
apps/playground's.global()tables) withtsc --noEmiton the emittedoutput — no new type errors (one pre-existing, unrelated
D1Database.batchnarrowing error is untouched by this change).
Not done: a
.shardBy()-only project with no.global()/Hyperdrivetable doesn't get
resolveTableShardingemitted (the schema import iscurrently gated on
hasGlobal/hasHyperdriveGlobal) — narrower than thereported bug (which is specifically about lost
.global()tables), flaggedas a follow-up rather than folded into this fix.
Golden fixture regenerated (
app.tsonly — the two new imports and two newmodule-level helpers;
dataModel.ts/server.ts/api.ts/functions.tsarebyte-identical).
Cluster C —
nondeterministic_query_mutation(#286, a question)I verified the runtime claim myself before acting, per the ticket's ask:
packages/do/src/shard-do.ts(~4331-4341): a mutation replay is deduped by(currentRequestUserId, mutationId)and short-circuits to the cachedresult before
handleRpc(the handler) is ever called.packages/shard-engine/src/transaction.ts: an OCC conflict throwsConflictError(409) back to the caller;shard-do.ts's dispatch catchblock records it and propagates it — there is no internal catch-and-retry
loop that re-invokes the handler.
So my own investigation confirms the reporter's finding for mutations: an
ordinary mutation handler runs at most once per logical write, and the rule's
"may be re-run on OCC retry" premise does not hold here. It does not
contradict — no STOP condition hit.
One refinement my reading adds: the premise does hold for queries — a
live subscription genuinely re-runs its query when a table it reads changes
(
shard-do.ts'srefreshSubscriptions), soDate.now()in a query canlegitimately flicker between evaluations. The codegen feeder already tags each
finding with
kind: "query" | "mutation", so rather than a blanket downgrade Isplit on that: query stays WARN, mutation drops to INFO (not silenced
— a mutation dispatched from a workflow step or queue consumer that itself
replays is a real residual caveat, so the finding stays as a breadcrumb to
that). Documented the guarantee in
packages/server/docs/index.mdxunder anew "Determinism: what actually replays" section, including that
step/consumer caveat.
Closes #283
Closes #284
Closes #285
Closes #287
Summary by CodeRabbit
New Features
Bug Fixes
Documentation