Skip to content

fix(advisor): correct lint feeder predicates + quarantine the dead AE feeder (+ runtime-lints spike) - #257

Merged
prisis merged 9 commits into
alphafrom
advisor/225-248-advisor
Aug 1, 2026
Merged

prisis merged 9 commits into
alphafrom
advisor/225-248-advisor

Conversation

@prisis

@prisis prisis commented Aug 1, 2026 •

Copy link
Copy Markdown
Member

Three advisor feeder predicates were wrong in ways that defeated the lints: isUserTableInsert missed insertMany/replace and substring-matched table names (two SECURITY lints went quiet on real account-minting endpoints); handlesErrors was '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-state analyzableBody (SECURITY lints fail-closed on undefined). The dead Analytics-Engine feeder (no writer, no caller) is quarantined. Plus an error_rate_outlier runtime-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

    • Added a runtime check that flags functions with elevated error rates after sufficient call volume.
    • Runtime findings now include affected function paths, error and call counts, error rates, and remediation guidance.
  • Bug Fixes

    • Improved security analysis when procedure code cannot be fully inspected, reducing missed warnings.
    • Enhanced detection of user-data writes, outbound errors, privileged fan-out, CAPTCHA gaps, and unsafe operations.
  • Documentation

    • Updated runtime lint usage guidance and clarified analytics metrics support.

prisis added 7 commits July 31, 2026 23:29
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.
@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@prisis, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 6 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5cb61159-0caa-4ef4-b65b-16a015cb8741

📥 Commits

Reviewing files that changed from the base of the PR and between b427455 and e2e39e6.

⛔ Files ignored due to path filters (4)
  • api-snapshots/advisor.api.md is excluded by none and included by none
  • packages/advisor/__tests__/observability-map.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/advisor/__tests__/security-lints.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/codegen/__tests__/discover-procedure-middleware.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
📒 Files selected for processing (6)
  • packages/advisor/README.md
  • packages/advisor/src/ae-metrics.ts
  • packages/advisor/src/lints/static/user-creating-mutation-without-captcha.ts
  • packages/advisor/src/map/sensitivity.ts
  • packages/advisor/src/procedure-protections.ts
  • packages/codegen/src/discover-procedure-middleware.ts

Walkthrough

The change adds analyzability-aware procedure metadata, conservative handling for unknown static-analysis facts, and the error_rate_outlier runtime lint. It also updates Analytics Engine exports and runtime-lint documentation.

Changes

Advisor analysis and linting

Layer / File(s) Summary
Procedure analysis and metadata contracts
packages/codegen/src/discover-procedure-middleware.ts, packages/codegen/src/ir.ts, packages/shard-engine/src/introspect.ts
Procedure discovery resolves same-file handlers, evaluates outbound error coverage per call site, improves table-write detection, and records optional behavioral facts with analyzableBody.
Fail-closed static lint evaluation
packages/advisor/src/procedure-protections.ts, packages/advisor/src/map/sensitivity.ts, packages/advisor/src/lints/static/*
mightExhibit treats unknown protection facts as potentially present. Static lints use this rule and report unknown handler evidence where applicable.
Runtime error-rate lint
packages/advisor/src/function-metrics.ts, packages/advisor/src/types.ts, packages/advisor/src/lints/runtime/error-rate-outlier.ts, packages/advisor/src/index.ts
Adds per-function runtime metrics and registers error_rate_outlier, which reports functions with at least 20 calls and a 10% error rate.
Analytics export and documentation updates
packages/advisor/src/index.ts, packages/advisor/src/ae-metrics.ts, packages/advisor/README.md
Removes package-root exports for the Analytics Engine event constant and loader. Documents direct counter inputs and the quarantined reader behavior.

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
Loading

Possibly related PRs

  • anolilab/lunora#107: Modifies Advisor procedure-protection lint infrastructure.
  • anolilab/lunora#187: Extends Advisor lint registration and static-analysis surfaces.
  • anolilab/lunora#235: Extends AdvisorProcedureProtection and sensitivity classification with conservative evidence handling.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description gives a clear summary and verification results, but omits the required Linked issues, Test plan, Checklist, Notes, and CLA sections. Add the template sections, record the test-plan checklist and linked issues, complete reviewer notes, and include the exact CLA statement when required.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the advisor predicate fixes, Analytics Engine quarantine, and runtime-lint prototype.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch advisor/225-248-advisor

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Thank you for confirming the Contributor License Agreement! 🙏

@codspeed

codspeed Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 11.03%

⚡ 1 improved benchmark
✅ 250 untouched benchmarks
⏩ 10 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ count, no attributes 64.2 µs 57.8 µs +11.03%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing advisor/225-248-advisor (e2e39e6) with alpha (a540991)2

Open in CodSpeed

Footnotes

  1. 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. ↩

  2. 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. ↩

@netlify

netlify Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

❌ Deploy Preview for lunorash failed.

Name Link
🔨 Latest commit e2e39e6
🔍 Latest deploy log https://app.netlify.com/projects/lunorash/deploys/6a6dcaa038faa8000808d44c

…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>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

The detail asserts an unproven user-table write for the unknown case.

The predicate logic is correct: !mightExhibit(x) is exactly x === false, the provable "no". The comments at Lines 47-50 describe it accurately.

The detail text at Line 68 states that the procedure "writes a user/session/account table". When writesUserTable is undefined, 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 win

Fail-closed evaluation is correct; the user-visible text asserts facts that were never observed. mightExhibit collapses "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.ts already solves this with reasonFor; apply that pattern to the remaining sites. Note that AdvisorProcedureProtection carries no analyzableBody field, 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 no maxOutputTokens bound" assertion with unknown-evidence text.
  • packages/advisor/src/lints/static/insert-many-unsafe-user-data.ts#L38-L43: replace the "calls ctx.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: keep mightExhibit for the level decision, and emit one shared "handler body could not be read" reason for the undefined facts 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 value

List hasEmailArg among the fail-closed fields.

The doc lists callsMail, fanOut, unboundedAiGeneration, usesInsertManyUnsafe, and writesUserTable. packages/advisor/src/lints/static/signup-mutation-without-disposable-gating.ts Line 61 also reads hasEmailArg through mightExhibit. hasEmailArg is 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 value

Use one test for analyzability.

Line 798 tests behaviourRoot for truthiness. Line 801 tests behaviourRoot !== 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 while analyzableBody reports true.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 36421ad and b427455.

⛔ Files ignored due to path filters (9)
  • api-snapshots/advisor.api.md is excluded by none and included by none
  • api-snapshots/shard-engine.api.md is excluded by none and included by none
  • packages/advisor/__tests__/ae-metrics.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/advisor/__tests__/observability-map.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/advisor/__tests__/runtime-lints.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/advisor/__tests__/security-lints.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/codegen/__tests__/advisor.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/codegen/__tests__/discover-procedure-middleware.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • plans/248-runtime-lints-design.md is excluded by none and included by none
📒 Files selected for processing (16)
  • packages/advisor/README.md
  • packages/advisor/src/ae-metrics.ts
  • packages/advisor/src/function-metrics.ts
  • packages/advisor/src/index.ts
  • packages/advisor/src/lints/runtime/error-rate-outlier.ts
  • packages/advisor/src/lints/static/ai-unbounded-generation-public.ts
  • packages/advisor/src/lints/static/insert-many-unsafe-user-data.ts
  • packages/advisor/src/lints/static/privileged-fanout-from-public-procedure.ts
  • packages/advisor/src/lints/static/signup-mutation-without-disposable-gating.ts
  • packages/advisor/src/lints/static/user-creating-mutation-without-captcha.ts
  • packages/advisor/src/map/sensitivity.ts
  • packages/advisor/src/procedure-protections.ts
  • packages/advisor/src/types.ts
  • packages/codegen/src/discover-procedure-middleware.ts
  • packages/codegen/src/ir.ts
  • packages/shard-engine/src/introspect.ts

Comment thread packages/advisor/src/ae-metrics.ts Resolved
Comment thread packages/advisor/src/map/sensitivity.ts Resolved
Comment on lines +381 to +425
/** 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;
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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
@prisis
prisis merged commit 816f910 into alpha Aug 1, 2026
37 of 44 checks passed
@prisis
prisis deleted the advisor/225-248-advisor branch August 1, 2026 10:56
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

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.
Please note this issue tracker is not a help forum. We recommend using our GitHub Discussions tab for questions.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 8, 2026

This branch was previously deployed

1 inactive deployment
benchmarks — e2e39e68 Deployed Aug 1, 2026 by prisis via Benchmarks #1328
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant