Repository navigation
refactor: collapse dedup-drift risks (constantTimeEqual, error catalog, concurrency loops, umbrella exports, Studio shard-key hook) - #273
Conversation
The runtime carried a private constantTimeEqual reimplementation whose "keep in sync with shard-do.ts" comment was already stale (shard-do imports the canonical shared/constant-time-equal.ts). A security primitive like this must have exactly one definition, so drop the local copy (which also diverged on codePointAt vs. the canonical charCodeAt) and import the shared helper instead. Add a dedup-guard test that greps packages/*/src and shared/ for a redeclared constantTimeEqual, with a documented allowlist for the pre-existing payment/src/webhook.ts copy (tracked separately).
isInternalCode fails OPEN for any code not in ERROR_CATALOG, so a code
minted outside the catalog echoes its message to the client
unredacted with no test failing. An audit found 81 codes thrown
across the repo (via `code: "X"` or `new LunoraError("X"`) that were
never registered.
Register all of them with a status/title, and flag `internal: true`
on the handful whose message can carry backend/deployment detail
(MISCONFIGURED, CRON_JOB_FAILED, AUTH_AUDIT_READ_FAILED, the
SQLite-in-DO "should never happen" invariants, and the two generic
500 catch-alls) — audited individually so a merely-actionable
"you forgot to configure X" message stays client-visible rather than
getting redacted by default.
Add a repo-level test that greps packages/*/src for both minting
shapes and fails if a future code ships without a catalog entry.
query-coordinator.ts hand-rolled the same shared-cursor worker-pool loop five times (runBoundedFanOut plus four orchestrators), with slightly divergent empty-input guards between them. Extract runBoundedJobs<T, R>(jobs, concurrency, run), unify on the early-return-when-empty guard, and express runBoundedFanOut and the cdcSync/import/applyCdc/rankPage orchestrators as calls into it.
… test The umbrella's exports map is hand-listed and had drifted: @lunora/server's ./otel and @lunora/client's ./upload had no lunorash/* counterpart, and the old re-exports.test.ts was a hand-maintained array that couldn't catch the next drift the same way. Add the two missing one-line re-export subpaths, and rewrite the test to read each upstream package's own exports map and assert every subpath (bar an explicit, reasoned opt-out list — @lunora/platform's ./conformance TCK, the flags/providers/* flattening) has a lunorash/* mapping.
The shard-key input + 400ms-debounce preamble
(useState + useDebounced(shardKey.trim(), 400)) was copy-pasted across
12 Studio panels.
Extract useShardKey(initial, delayMs) returning
{ shardKey, setShardKey, queryShardKey } into packages/studio/src/hooks/,
and migrate all 12 call sites. Beyond dedup, the hook makes a shard
reset driven by the caller's `initial` value (a table/tab switch)
resolve synchronously — queryShardKey snaps to the new shard
immediately instead of leaving a query/subscription pointed at the
previous shard for up to 400ms while the debounce catches up. Comes
with its own debounce implementation (not composing the shared
useDebounced) so the reset can't race a stale pending timer from
before it.
✅ Deploy Preview for lunorash ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Warning Review limit reached
Next review available in: 3 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 (1)
📒 Files selected for processing (1)
WalkthroughThe PR expands the error catalog and Lunora package exports, centralizes runtime helpers and bounded concurrency, and replaces duplicated Studio shard-key debouncing with the shared ChangesError and package API surface
Runtime execution changes
Studio shard-key state
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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! 🙏 |
|
Thank you for following the naming conventions! 🙏 |
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/studio/src/features/schema/hooks/use-schema-explorer.tsx`:
- Line 72: Use queryShardKey consistently for schema reads and cache keys in the
schema explorer: update toggle, the graph probe, diagram cache lookups, and the
table-list loading flow around useShardKey to use the settled key. Keep shardKey
exclusively as the live input value so all displayed schema data corresponds to
the same debounced shard.
🪄 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: 3fef37a2-a67e-4af2-9135-297d564f794e
⛔ Files ignored due to path filters (4)
packages/errors/__tests__/catalog-registration.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/lunora/__tests__/re-exports.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/runtime/__tests__/constant-time-equal-dedup.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/studio/__tests__/hooks/use-shard-key.test.tsxis excluded by!**/__tests__/**and included bypackages/**
📒 Files selected for processing (19)
packages/errors/src/catalog.tspackages/lunora/package.jsonpackages/lunora/src/client/upload.tspackages/lunora/src/server/otel.tspackages/runtime/src/create-worker.tspackages/runtime/src/query-coordinator.tspackages/studio/src/features/advisors/insights-panel.tsxpackages/studio/src/features/data/hooks/use-data-browser.tsxpackages/studio/src/features/database/migrations.tsxpackages/studio/src/features/functions/function-stats.tsxpackages/studio/src/features/issues/issues-panel.tsxpackages/studio/src/features/logs/audit-panel.tsxpackages/studio/src/features/logs/logs-panel.tsxpackages/studio/src/features/logs/subscriptions-panel.tsxpackages/studio/src/features/reports/fanout-panel.tsxpackages/studio/src/features/reports/metrics-panel.tsxpackages/studio/src/features/schema/hooks/use-schema-explorer.tsxpackages/studio/src/features/traces/traces-panel.tsxpackages/studio/src/hooks/use-shard-key.ts
Merging this PR will degrade performance by 0.06%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | flat 3 primitives (the notify.send attribute shape) |
55.7 µs | 62 µs | -10.2% |
| ⚡ | count, no attributes |
64.2 µs | 57.7 µs | +11.23% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing advisor/230-tech-debt-dedup (0011cc2) with alpha (a540991)2
Footnotes
-
27 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(d9791ea) during the generation of this report, so a540991 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
Move the onReady(setShardKey) call in the useShardKey test harness out of render and into an effect. Render must stay pure — React can replay or discard it — so a prop callback invoked during render can fire more than once or for a commit that never lands.
toggle, the graph column probe, and the diagram's cached columns read the live (per-keystroke) shardKey while the table list already loads on the debounced queryShardKey. During the debounce window this let an operator expand a table, or open the graph, against the shard they're still typing rather than the one the displayed tables came from. Key all of them on queryShardKey; shardKey stays only the input's live value.
|
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. |
Five independent dedup/tech-debt fixes, one commit each.
A — runtime
constantTimeEqual→ the canonicalshared/copyThe runtime carried a private reimplementation (using
codePointAtwhere the canonical usescharCodeAt) with a stale "keep in sync with shard-do.ts" comment — but shard-do already imports fromshared/. A security primitive with two definitions is exactly what drifts. Now importsshared/constant-time-equal; the local copy + stale comment are gone. Added a dedup-guard test that grepspackages/*/src+shared/for a redeclaredconstantTimeEqual(with a documented allowlist for the one remaining out-of-scope payment copy → follow-up).B — catalog every minted error code (close the fail-open leak)
isInternalCodefails open for any code not inERROR_CATALOG, so an uncatalogued 500-class code echoes its message to the client with nothing failing. A two-pattern, multi-line-aware grep found 81 uncatalogued codes (the plan's "27" was an example list) — all now registered with correct statuses. 6 flaggedinternal: true, each audited individually:AUTH_AUDIT_READ_FAILED,CRON_JOB_FAILED,MISCONFIGURED(the named live-leak on the public RPC path),NESTED_TRANSACTION,SQL_UNAVAILABLE,INTERNAL_ERROR— all carry backend detail. The*_NOT_CONFIGUREDfamily, codegen build-time diagnostics, and client-SDK/WS codes stayed non-internal (static, actionable messages — not over-flagged). Added a repo-level registration test that fails on any future uncatalogued code.C — one bounded-concurrency helper
Five hand-rolled bounded-fan-out loops in
query-coordinator.ts(with already-divergent guards) collapsed intorunBoundedJobs<T,R>(jobs, concurrency, run);runBoundedFanOutand the cdcSync/import/applyCdc/rankPage orchestrators call it, unified on the early-return-when-empty guard. Thequery-coordinator.*.test.tssuite pins the semantics.D — complete + data-drive the umbrella exports
lunorashwas missingserver/otelandclient/upload, so a one-install app couldn't reach two shipped features. Added both re-exports + export-map entries, and rewrote the parity test to read each upstream package's ownexportsmap and assert alunorash/*mapping for every subpath — with an explicit opt-out list (@lunora/platform's./conformance*) and an alias table (flags/providers/*→flags/*). It now fails on the next upstream subpath drift instead of needing a hand-maintained array.E —
useShardKeyhook (12 duplicated preambles → 1)The shard-key + 400ms-debounce preamble was copy-pasted in 12 panels. Extracted
useShardKey(initial, delayMs)→{ shardKey, setShardKey, queryShardKey }with the debounce + synchronous reset semantics. It uses its ownsetTimeoutdebounce rather than composing the shareduseDebounced— composing let a stale pending debounce clobber a synchronous reset (caught by a regression test), and keeping the diff out ofuse-debounced.tsmeans zero overlap with #264's edit to that file.Verification
runtime 791, errors 528, lunorash 117, studio 967 (hook: 7 tests incl. synchronous-reset + stale-timer). All
lint:types/lint:eslint/lint:package-jsongreen; fullbuild:packages(53 projects) passes.Merge-order notes (all individually mergeable vs alpha)
studio/features/advisors/insights-panel.tsxoverlaps perf(observability,do,studio): take the metrics hot-path off always-throwing DDL/COUNT, bound the sample buffer, signal truncation, batch Studio index enum #272 — this touches only the shard-key preamble; perf(observability,do,studio): take the metrics hot-path off always-throwing DDL/COUNT, bound the sample buffer, signal truncation, batch Studio index enum #272's index-enumeration body is left untouched, so the conflict is trivial context lines (keep both).use-debounced.tsedit here;use-data-browser.tsx's reset is additive to its existing re-seed effect).runtime/create-worker.ts+query-coordinator.ts— resolve against any other runtime PR by keeping both regions.Plan:
plans/230-*.md.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Improvements