Repository navigation
fix(advisor): correct lint feeder predicates + quarantine the dead AE feeder (+ runtime-lints spike) - #257
Conversation
isUserTableInsert only matched a callee named exactly "insert" and
substring-matched the table name, so insertMany/replace writes and
const-held table names went undetected while userPreferences/
sessionReplay false-positived on the substring "user"/"session". The
signup/captcha SECURITY lints depend on this signal to catch real
account-minting endpoints.
Broaden the recognized write methods to insert/insertMany/
insertManyUnsafe/replace, and match the table name on its terminal
camelCase/snake_case word (mirroring isEmailArgumentName) instead of a
bare substring, so a modifier word ("user" in "userPreferences") no
longer counts as the table itself.
handlesErrors asked "is there a TryStatement anywhere in this declaration", so a .catch()-only handler (zero try nodes) flagged as unhandled, and an unrelated try around other code cleared the flag for a genuinely-unguarded outbound call elsewhere in the same body. Compute handlesErrors/reachesOutbound per ctx.<outbound> call site instead: a site counts as guarded when it sits inside a try within the same function, or is the receiver of a .catch(...) (including at the end of a .then()/.finally() chain). handlesErrors is true only when every outbound call site is guarded, so action_without_error_ handling still fires exactly when at least one call site is not.
Behavioural facts (writesUserTable, callsMail, fanOut, unboundedAiGeneration, usesInsertManyUnsafe, and friends) were read off the whole procedure declaration's AST descendants, so an extracted handler (`handler: createHandler`) reported every fact false instead of "not observed" -- silently clearing the SECURITY lints on an account-minting endpoint whose handler just happens to live in a same-file const or function declaration. Add analyzableBody to the IR: true for an inline handler (unchanged scan) or a same-file identifier resolved to its const/function declaration (the same name-based idiom resolveUseArgumentCall uses for a .use(...) alias); false for a genuinely cross-file handler, in which case every behavioural fact is left undefined rather than a false negative. signup_mutation_without_disposable_gating, user_creating_mutation_without_captcha, insert_many_unsafe_user_data, ai_unbounded_generation_public, and privileged_fanout_from_public_ procedure now treat that undefined as fail-closed (the fact might be true) instead of skipping. The sensitivity classifier does the same, so an unreadable handler weighs as sensitive rather than "none". procedure_without_structured_event already skipped on undefined correctly -- it needed no change, only real facts to skip on.
loadAnalyticsRuntimeMetrics reads three Analytics Engine events (lunora.index.hit/shard.request/table.scan) that nothing in the runtime ever writes via ctx.analytics.track, and the one caller shaped to supply it -- the studio's deriveRuntimeAdvisories analyticsMetrics input -- never actually passes it. Wired in as-is it would silently disable index_utilization's dead-index check: an AE read that's merely empty (no writer) reads as "nothing dead" rather than "no data". Drop AE_METRIC_EVENTS and loadAnalyticsRuntimeMetrics from the package's public exports; the module stays as reference groundwork for the day a writer exists, importable directly from ./ae-metrics (as its test now does). AnalyticsRuntimeMetrics and the other types stay exported -- they're the harmless shape of a still-valid, still-optional extension point the studio type already declares.
Formatting-only follow-up on the fail-closed sensitivity test added in the previous commit; no behavioural change.
Plan 248 spike: the runtime-advisor category is thin (3 lints vs 96 static) while `lunora insights` already collects and ranks per- function error rates for a human report. Investigated whether that signal reaches the advisor's runtime harness. Finding: LintContext carries no error-rate/latency field today, but the data isn't unreachable -- the studio Advisors panel already fetches the exact getFunctionStats rows that carry errors/ maxDurationMs (the same rows context.tableScans already draws scannedTables from) and already threads them into deriveRuntimeAdvisories. Reachable at lunora insights' own single-shard granularity via an already-fetched feed; not reachable at hot_shard's cross-shard granularity without new fan-out plumbing this spike deliberately doesn't build. Prototype one lint end-to-end to prove the reach is real, not stubbed: AdvisorFunctionMetrics (calls/errors/maxDurationMs), LintContext.functionMetrics, and error_rate_outlier modeled on hot-shard's threshold-and-floor structure, registered in RUNTIME_LINTS with fixture coverage. Wiring the studio caller to actually populate functionMetrics, a latency counterpart, and the threshold model (absolute vs baseline-relative, sustained-over- window) are left as open follow-on work -- see plans/248-runtime-lints-design.md for the full reachability finding and design questions.
Follow-up to the ADVISOR-03 tri-stating commit: codegen emits analyzableBody as a literal key on every LUNORA_ADVISOR_PROCEDURES row, but the shard-engine mirror of AdvisorProcedureProtection (the type that array literal is checked against in generated code) didn't have the field, so every app/example with at least one procedure failed lint:types with "analyzableBody does not exist in type AdvisorProcedure". Caught by a full-repo pnpm run lint:types after the per-package checks had all passed.
|
Warning Review limit reached
Next review available in: 6 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 (4)
📒 Files selected for processing (6)
WalkthroughThe change adds analyzability-aware procedure metadata, conservative handling for unknown static-analysis facts, and the ChangesAdvisor analysis and linting
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant RuntimeContext
participant RUNTIME_LINTS
participant errorRateOutlier
participant Finding
RuntimeContext->>RUNTIME_LINTS: provide functionMetrics
RUNTIME_LINTS->>errorRateOutlier: execute runtime lint
errorRateOutlier->>Finding: emit qualifying function finding
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 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 following the naming conventions! 🙏 |
|
Thank you for confirming the Contributor License Agreement! 🙏 |
Merging this PR will improve performance by 11.03%
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
❌ Deploy Preview for lunorash failed.
|
…ive on Promise.all(map)
- Regenerate api-snapshots/advisor.api.md (AE_METRIC_EVENTS/loadAnalyticsRuntimeMetrics
removal, errorRateOutlier/AdvisorFunctionMetrics addition) and
api-snapshots/shard-engine.api.md (analyzableBody addition) so api:check passes in CI.
- hasEnclosingTry now resumes the enclosing-try climb through a synchronous-
iteration callback (map/forEach/filter/flatMap/some/every, Promise.all/
allSettled/race) instead of stopping at it, fixing a false-positive
action_without_error_handling fire on try { await Promise.all(items.map(...)) }.
Deferred callbacks (setTimeout, etc.) still correctly stop the climb.
- Update the advisor README's runtime-lints section to match the AE-metrics
quarantine: the loader is no longer part of the public API, only its types.
- Add a shared mightExhibit(fact) predicate for the fail-closed tri-state
read (undefined treated as "might be true") used across the SECURITY lints
and map/sensitivity.ts's SIGNALS, replacing ~12 hand-written `!== false` /
`=== false` call sites; lift the nested ternary in
user-creating-mutation-without-captcha.ts into a reasonFor() helper.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 6
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
packages/advisor/src/lints/static/signup-mutation-without-disposable-gating.ts (1)
51-68: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winThe detail asserts an unproven user-table write for the unknown case.
The predicate logic is correct:
!mightExhibit(x)is exactlyx === false, the provable "no". The comments at Lines 47-50 describe it accurately.The
detailtext at Line 68 states that the procedure "writes a user/session/account table". WhenwritesUserTableisundefined, that was never observed. Word the unknown case as unknown evidence.🤖 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/signup-mutation-without-disposable-gating.ts` around lines 51 - 68, The finding detail in signupMutationWithoutDisposableGating must not assert a user/session/account table write when procedure.writesUserTable is unknown. Update the detail construction to describe that the procedure may write such a table, while preserving the existing wording for proven writes and the disposable-email gate guidance.packages/advisor/src/lints/static/ai-unbounded-generation-public.ts (1)
40-45: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winFail-closed evaluation is correct; the user-visible text asserts facts that were never observed.
mightExhibitcollapses "proven true" and "unknown" into one boolean. Each consumer keeps the finding, which is the intended fail-closed outcome, then emits text written for the proven case. A public procedure with a cross-file handler now reads as proven guilty on every fact at once.packages/advisor/src/lints/static/user-creating-mutation-without-captcha.tsalready solves this withreasonFor; apply that pattern to the remaining sites. Note thatAdvisorProcedureProtectioncarries noanalyzableBodyfield, so add it first to let each site name the unknown case explicitly.
packages/advisor/src/lints/static/ai-unbounded-generation-public.ts#L40-L45: gate the unknown case on some AI evidence, or replace the "runs an AI generation with nomaxOutputTokensbound" assertion with unknown-evidence text.packages/advisor/src/lints/static/insert-many-unsafe-user-data.ts#L38-L43: replace the "callsctx.db.insertManyUnsafe(...)" assertion with unknown-evidence text.packages/advisor/src/lints/static/privileged-fanout-from-public-procedure.ts#L37-L42: replace the "fans work out to a privileged dispatch surface" assertion with unknown-evidence text.packages/advisor/src/lints/static/signup-mutation-without-disposable-gating.ts#L51-L68: replace the "writes a user/session/account table" assertion with unknown-evidence text.packages/advisor/src/map/sensitivity.ts#L15-L24: keepmightExhibitfor the level decision, and emit one shared "handler body could not be read" reason for theundefinedfacts instead of all five proven-behaviour reasons.🤖 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/ai-unbounded-generation-public.ts` around lines 40 - 45, Update AdvisorProcedureProtection to expose analyzableBody, then apply the existing reasonFor pattern from user-creating-mutation-without-captcha.ts so findings distinguish proven facts from unknown cross-file analysis. In packages/advisor/src/lints/static/ai-unbounded-generation-public.ts#L40-L45, packages/advisor/src/lints/static/insert-many-unsafe-user-data.ts#L38-L43, packages/advisor/src/lints/static/privileged-fanout-from-public-procedure.ts#L37-L42, and packages/advisor/src/lints/static/signup-mutation-without-disposable-gating.ts#L51-L68, replace unsupported proven-behavior assertions with explicit unknown-evidence text or gate them on available evidence. In packages/advisor/src/map/sensitivity.ts#L15-L24, retain mightExhibit for level selection but use one shared “handler body could not be read” reason for undefined facts instead of proven-behavior reasons.
🧹 Nitpick comments (2)
packages/advisor/src/procedure-protections.ts (1)
104-120: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueList
hasEmailArgamong the fail-closed fields.The doc lists
callsMail,fanOut,unboundedAiGeneration,usesInsertManyUnsafe, andwritesUserTable.packages/advisor/src/lints/static/signup-mutation-without-disposable-gating.tsLine 61 also readshasEmailArgthroughmightExhibit.hasEmailArgis a declaration fact rather than a handler behaviour, so its inclusion is not obvious from the current text.Add it to the list, so the fail-closed inventory stays complete and grep-able.
🤖 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/procedure-protections.ts` around lines 104 - 120, Update the fail-closed field list in the documentation comment for mightExhibit to include hasEmailArg alongside the existing AdvisorProcedureProtection fields. Do not change the mightExhibit implementation or surrounding rationale.packages/codegen/src/discover-procedure-middleware.ts (1)
791-801: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse one test for analyzability.
Line 798 tests
behaviourRootfor truthiness. Line 801 testsbehaviourRoot !== undefined. Both agree today, because a ts-morph node is always truthy. They encode the same condition twice, and a divergence produces the one combination this design avoids: facts omitted whileanalyzableBodyreportstrue.Bind the condition once.
♻️ Proposed refactor
const behaviourRoot = analyzableBehaviourRoot(declaration, initializer); + const analyzableBody = behaviourRoot !== undefined; // Every key of both fact bags is an IR field, so spreading keeps this in step // automatically when either gains one. `behaviourRoot === undefined` (a // genuinely cross-file handler) spreads nothing, leaving every behavioural // fact `undefined` rather than a false "not observed". return { - ...(behaviourRoot ? behaviourOf(behaviourRoot) : {}), + ...(analyzableBody ? behaviourOf(behaviourRoot) : {}), ...exemptionOf(declaration), ...protections, - analyzableBody: behaviourRoot !== undefined, + analyzableBody,🤖 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/codegen/src/discover-procedure-middleware.ts` around lines 791 - 801, In the return construction around analyzableBehaviourRoot, bind a single boolean indicating whether behaviourRoot is defined and reuse it for both the behaviourOf spread and analyzableBody. Replace the separate truthiness and !== undefined checks while preserving empty behavioural facts for non-analyzable roots.
🤖 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/advisor/src/ae-metrics.ts`:
- Around line 18-24: Update the quarantine documentation for
loadAnalyticsRuntimeMetrics and loadIndexHits: in
packages/advisor/src/ae-metrics.ts lines 18-24 and 231-235, qualify “three empty
arrays” and dead-index statements to distinguish missing metrics from declared
indexes with zero reads; in packages/advisor/README.md line 94, document the
same distinction. Do not change runtime behavior.
In `@packages/advisor/src/lints/static/user-creating-mutation-without-captcha.ts`:
- Around line 7-23: Update AdvisorProcedureProtection and reasonFor so the
fallback message does not claim an unreadable handler when only one protection
fact is undefined; add and propagate analyzableBody?: boolean, then use it to
distinguish an unreadable body from a partially analyzed payload, or remove the
unreadability claim from the fallback text.
In `@packages/advisor/src/map/sensitivity.ts`:
- Around line 15-24: Update the sensitivity reason generation around SIGNALS and
classifySensitivity: retain mightExhibit for fail-closed level classification,
but distinguish proven true facts from undefined facts when composing reasons.
For undefined evidence, emit one shared reason indicating the handler may
exhibit sensitive behavior because its body could not be read, rather than
asserting each signal; preserve proven signal reasons and avoid duplicating the
shared unknown-evidence reason.
In `@packages/codegen/src/discover-procedure-middleware.ts`:
- Around line 661-665: Update the object-literal handling in
analyzableBehaviourRoot to support handler properties declared as both
ShorthandPropertyAssignment and MethodDeclaration, returning each as the
analyzable root alongside the existing PropertyAssignment path. Preserve
undefined for unsupported or missing handler properties.
- Around line 381-425: Update hasEnclosingTry and syncIterationCallToResumeFrom
so an async callback boundary does not resume the enclosing-try climb when its
iteration call is neither awaited nor returned through the same statement chain.
Preserve climbing for synchronous callbacks and for Promise.all/allSettled/race
expressions whose result is awaited inside the try, including
Promise.all(items.map(async ...)).
- Around line 250-252: Update the table-name validation in isUserTableInsert to
accept both string literals and no-substitution template literals. Include
Node.isNoSubstitutionTemplateLiteral(tableArgument) in the literal-type check
before calling getLiteralText(), while preserving the existing isUserTableName
validation and return behavior.
---
Outside diff comments:
In `@packages/advisor/src/lints/static/ai-unbounded-generation-public.ts`:
- Around line 40-45: Update AdvisorProcedureProtection to expose analyzableBody,
then apply the existing reasonFor pattern from
user-creating-mutation-without-captcha.ts so findings distinguish proven facts
from unknown cross-file analysis. In
packages/advisor/src/lints/static/ai-unbounded-generation-public.ts#L40-L45,
packages/advisor/src/lints/static/insert-many-unsafe-user-data.ts#L38-L43,
packages/advisor/src/lints/static/privileged-fanout-from-public-procedure.ts#L37-L42,
and
packages/advisor/src/lints/static/signup-mutation-without-disposable-gating.ts#L51-L68,
replace unsupported proven-behavior assertions with explicit unknown-evidence
text or gate them on available evidence. In
packages/advisor/src/map/sensitivity.ts#L15-L24, retain mightExhibit for level
selection but use one shared “handler body could not be read” reason for
undefined facts instead of proven-behavior reasons.
In
`@packages/advisor/src/lints/static/signup-mutation-without-disposable-gating.ts`:
- Around line 51-68: The finding detail in signupMutationWithoutDisposableGating
must not assert a user/session/account table write when
procedure.writesUserTable is unknown. Update the detail construction to describe
that the procedure may write such a table, while preserving the existing wording
for proven writes and the disposable-email gate guidance.
---
Nitpick comments:
In `@packages/advisor/src/procedure-protections.ts`:
- Around line 104-120: Update the fail-closed field list in the documentation
comment for mightExhibit to include hasEmailArg alongside the existing
AdvisorProcedureProtection fields. Do not change the mightExhibit implementation
or surrounding rationale.
In `@packages/codegen/src/discover-procedure-middleware.ts`:
- Around line 791-801: In the return construction around
analyzableBehaviourRoot, bind a single boolean indicating whether behaviourRoot
is defined and reuse it for both the behaviourOf spread and analyzableBody.
Replace the separate truthiness and !== undefined checks while preserving empty
behavioural facts for non-analyzable roots.
🪄 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: 26a2cc94-ceff-45f7-abc1-d25659d7609f
⛔ Files ignored due to path filters (9)
api-snapshots/advisor.api.mdis excluded by none and included by noneapi-snapshots/shard-engine.api.mdis excluded by none and included by nonepackages/advisor/__tests__/ae-metrics.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/advisor/__tests__/observability-map.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/advisor/__tests__/runtime-lints.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/advisor/__tests__/security-lints.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/codegen/__tests__/advisor.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/codegen/__tests__/discover-procedure-middleware.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**plans/248-runtime-lints-design.mdis excluded by none and included by none
📒 Files selected for processing (16)
packages/advisor/README.mdpackages/advisor/src/ae-metrics.tspackages/advisor/src/function-metrics.tspackages/advisor/src/index.tspackages/advisor/src/lints/runtime/error-rate-outlier.tspackages/advisor/src/lints/static/ai-unbounded-generation-public.tspackages/advisor/src/lints/static/insert-many-unsafe-user-data.tspackages/advisor/src/lints/static/privileged-fanout-from-public-procedure.tspackages/advisor/src/lints/static/signup-mutation-without-disposable-gating.tspackages/advisor/src/lints/static/user-creating-mutation-without-captcha.tspackages/advisor/src/map/sensitivity.tspackages/advisor/src/procedure-protections.tspackages/advisor/src/types.tspackages/codegen/src/discover-procedure-middleware.tspackages/codegen/src/ir.tspackages/shard-engine/src/introspect.ts
| /** Array methods whose callback runs synchronously, within the caller's dynamic extent — safe to climb through. */ | ||
| const SYNC_ITERATION_METHODS: ReadonlySet<string> = new Set(["every", "filter", "flatMap", "forEach", "map", "some"]); | ||
|
|
||
| /** `Promise` combinators whose executor(s) run synchronously, within the caller's dynamic extent — safe to climb through. */ | ||
| const SYNC_PROMISE_COMBINATORS: ReadonlySet<string> = new Set(["all", "allSettled", "race"]); | ||
|
|
||
| /** | ||
| * When the enclosing-`try` climb in {@link hasEnclosingTry} hits a function | ||
| * boundary, decide whether that boundary is itself a callback argument that | ||
| * runs *synchronously* within its caller's dynamic extent — `.map`/`.forEach`/ | ||
| * `.filter`/`.flatMap`/`.some`/`.every`, or a `Promise.all`/`allSettled`/`race` | ||
| * combinator. If so, the call site inside it is still covered by a `try` that | ||
| * wraps the caller, so climbing should resume from that call rather than | ||
| * stopping. Returns the call to resume from, or `undefined` when `boundary` | ||
| * isn't such an argument — e.g. it is a deferred callback (`setTimeout`, | ||
| * `queueMicrotask`, an event listener, a stored/returned function) that does | ||
| * NOT run inside the try's dynamic extent, so it must still stop the climb. | ||
| */ | ||
| const syncIterationCallToResumeFrom = (boundary: TsNode): CallExpression | undefined => { | ||
| const parent = boundary.getParent(); | ||
|
|
||
| if (!parent || !Node.isCallExpression(parent) || !parent.getArguments().includes(boundary)) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const callee = parent.getExpression(); | ||
|
|
||
| if (!Node.isPropertyAccessExpression(callee)) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const methodName = callee.getName(); | ||
|
|
||
| if (SYNC_ITERATION_METHODS.has(methodName)) { | ||
| return parent; | ||
| } | ||
|
|
||
| const receiver = callee.getExpression(); | ||
|
|
||
| if (Node.isIdentifier(receiver) && receiver.getText() === "Promise" && SYNC_PROMISE_COMBINATORS.has(methodName)) { | ||
| return parent; | ||
| } | ||
|
|
||
| return undefined; | ||
| }; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
An async iteration callback is not inside the caller's dynamic extent.
SYNC_ITERATION_METHODS climbing assumes the callback runs synchronously. That holds for a synchronous callback. It does not hold for an async callback whose returned promise is settled outside the try:
let pending: Promise<Response>[] = [];
try {
pending = items.map(async (item) => ctx.fetch(item)); // rejection is not caught here
} catch {
/* never reached for a fetch failure */
}
await Promise.all(pending);hasEnclosingTry resumes the climb from items.map(...), finds the try, and reports the call as guarded. handlesErrors then reads true for a genuinely unguarded outbound call.
Stop the climb when the boundary is an async function and the resumed call is neither awaited nor returned inside the same statement chain. The Promise.all(items.map(async …)) form stays covered, because the combinator call is normally awaited inside the try.
🐛 Sketch of the boundary check
const syncIterationCallToResumeFrom = (boundary: TsNode): CallExpression | undefined => {
const parent = boundary.getParent();
if (!parent || !Node.isCallExpression(parent) || !parent.getArguments().includes(boundary)) {
return undefined;
}
+
+ // An `async` callback's body past its first suspension point escapes the
+ // caller's dynamic extent unless the produced promise is settled in it.
+ const isAsyncCallback = (Node.isArrowFunction(boundary) || Node.isFunctionExpression(boundary)) && boundary.isAsync();
const callee = parent.getExpression();
if (!Node.isPropertyAccessExpression(callee)) {
return undefined;
}
const methodName = callee.getName();
if (SYNC_ITERATION_METHODS.has(methodName)) {
- return parent;
+ return isAsyncCallback && !isSettledInPlace(parent) ? undefined : parent;
}🤖 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/codegen/src/discover-procedure-middleware.ts` around lines 381 -
425, Update hasEnclosingTry and syncIterationCallToResumeFrom so an async
callback boundary does not resume the enclosing-try climb when its iteration
call is neither awaited nor returned through the same statement chain. Preserve
climbing for synchronous callbacks and for Promise.all/allSettled/race
expressions whose result is awaited inside the try, including
Promise.all(items.map(async ...)).
- ae-metrics: qualify "three empty arrays" docs — indexHits reports
real zero-read entries when declaredIndexes is supplied, not an
absence-of-data placeholder
- user-creating-mutation-without-captcha: add analyzableBody to
AdvisorProcedureProtection so the fallback reason only blames an
unreadable handler when that's actually proven, not for a partial
payload with one fact proven false
- sensitivity: an unreadable handler (analyzableBody: false / all
facts undefined) no longer asserts five unproven specific claims —
it stays "high" but collapses to one shared "could not be read"
reason, with proven-true facts still getting their specific reason
- discover-procedure-middleware: accept a no-substitution template
literal table name in isUserTableInsert (ctx.db.insert(`users`, ..)
was silently read as writesUserTable: false); accept a shorthand or
method `handler` property ({ handler } / { handler() {} }) as an
analyzable root instead of falling through to "unreadable"
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ZbZz7EjzFsuuubvUyyJWN
|
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. |
Three advisor feeder predicates were wrong in ways that defeated the lints:
isUserTableInsertmissed insertMany/replace and substring-matched table names (two SECURITY lints went quiet on real account-minting endpoints);handlesErrorswas 'is there a try anywhere' (a .catch() flagged; an unrelated try cleared the whole procedure); behavioural facts were file-local, so an extracted handler reported everything false. Fixed to per-call-site facts + a tri-stateanalyzableBody(SECURITY lints fail-closed on undefined). The dead Analytics-Engine feeder (no writer, no caller) is quarantined. Plus anerror_rate_outlierruntime-lint spike.Verified: advisor 454, codegen 980, goldens byte-identical; zero real findings moved in-repo.
⚠ Touches codegen/discover-procedure-middleware.ts — merge-order vs #243/#244/#248.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Documentation