Skip to content

fix: preserve guarded property reads in inferred hook dependencies - #1123

Merged
domgan-oai merged 6 commits into
octanejs:mainfrom
openai-oss-forks:fix/guarded-hook-dependencies
Sep 18, 2026
Merged

domgan-oai merged 6 commits into
octanejs:mainfrom
openai-oss-forks:fix/guarded-hook-dependencies

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Preserve control-flow guards when inferring hook dependencies without losing stable own data fields and callbacks. A guarded read such as if (item) console.log(item.name) no longer invokes a property getter or throws on an absent receiver while rendering.

Why

The dependency collector traversed conditional branches and possible exits as unconditional reads. Tracking only whole receivers avoided premature getters, but made effects rerun when props containers or subscribed-store snapshots changed despite stable fields and actions.

Changes

Track guarded branches and possible early exits during read-only dependency analysis. Consume labeled exits only at their own target. Extend the existing runtime dependency discriminator with a guarded descriptor probe: own data properties compare their values, accessors and inherited properties compare their receivers, and failed reflection probes fall back to receiver identity. Separate module-local nullish markers distinguish a failing receiver read from a successful own-data read of null or undefined. Update the full compiler and both plain-hook emitters together. Preserve ordinary method inference, explicit dependency arrays, opaque execution contexts and parsed AST immutability. Add generic runtime, server-rendering and hydration regressions, document the tradeoff, and include a patch changeset.

Validation

  • The new missing-receiver regressions fail in four development/production cases before the latest fix; they cover compiled and plain hooks, nullish-to-own-data transitions, reverse transitions and stable fresh-container updates. The original optional-receiver regressions failed before the initial fix. The guarded method-getter case failed in both development and production before its follow-up, and six label-target precision cases failed before their follow-up.
  • Current-head scoped repository tests pass 321 cases across 11 files in the development and production projects. This includes the existing subscribed-store effects, Strong cache, computed-key stability and AST immutability suites, with unchanged assertions and timeouts.
  • Package and public TypeScript checking, changed-file formatting and pnpm sync pass. The follow-up is signed and the worktree is clean.
  • Matched benchmarks/hook-memo/run.mjs runs against signed ed2416b and the current 005d980 implementation use Node 24.19.0 and the same installed dependencies. All semantic and observer controls pass; all recorded creation counters and compiled/bundled byte metrics are equal for these fixtures. This does not measure guarded native descriptor allocations or establish a timing improvement.
  • The preceding CI head also had a WebKit history integration timeout. Its complete production test file passed all 19 cases locally on Node 24.19.0 macOS; the CI runner uses Linux and Node 24.13.0. The preceding 71f84f8 heavy integration job passes; the preceding timeout cause remains unclassified.
  • The current signed 005d980 head passes all active CI checks, including all four Node 24 test shards, Chromium browser integration, package/evaluation/runtime/Astro integration, React parity, compatibility, examples, lint, typechecks and publishable-package validation. Passing current-head run. All three automated review findings are resolved. The preceding 71f84f8 run also passed.

Risk / follow-ups

Guarded descriptor probes allocate a descriptor on each applicable render. Accessors and inherited fields track broader receiver identities; arbitrary Proxy reflection can have side effects even though getter values are not evaluated. Ordinary unguarded method calls retain their allocation-free path. Compiler output using the guarded flag must be paired with the matching runtime.

Provenance

  • An agent produced this diff (agent-authored)

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Changes compiler-inferred dependency arrays and __methodDep runtime semantics; guarded descriptor probes allocate per render and Proxy reflection can have side effects, so compiler output must match the updated runtime.

Overview
Inferred hook dependencies now respect control-flow guards so dependency comparison during render does not run property reads that the callback only performs behind a condition, early return, short-circuit, loop, or try/catch.

The dependency walker marks guarded member reads and method calls, including labeled break/continue precision, and emits __methodDep(root, name, true) from the full compiler and plain-hook paths. Guarded runtime probing uses getOwnPropertyDescriptor for own data values without calling getters; accessors and inherited properties compare the receiver; nullish receivers use distinct module-local symbols so missing receivers do not alias successful null/undefined data reads.

Unguarded method inference stays allocation-free. Docs and a patch changeset describe the behavior; new client, hydration, and fixture tests cover getters, optional receivers, memos, and reflection failures.

Reviewed by Cursor Bugbot for commit 005d980. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Sep 18, 2026
@domgan-oai
domgan-oai marked this pull request as ready for review September 18, 2026 18:18

@cursor cursor 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.

Stale Bugbot comment from a previous run.

@cursor cursor 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.

Stale Bugbot comment from a previous run.

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.

Reviewed by Cursor Bugbot for commit 71f84f8. Configure here.

Comment thread packages/octane/src/method-dep.ts Resolved
@domgan-oai
domgan-oai merged commit 3814f71 into octanejs:main Sep 18, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant