Skip to content

fix(compiler): count zero-delay effect callbacks and custom-hook updaters as Strong effect setup - #1481

Closed
trueadm wants to merge 16 commits into
mainfrom
claude/gracious-germain-f38126
Closed

trueadm wants to merge 16 commits into
mainfrom
claude/gracious-germain-f38126

Conversation

@trueadm

@trueadm trueadm commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

First of four stacked PRs that stop agents from getting around Strong mode's effect rules with trivial rewrites (tracking issue #1027). Each PR is one diagnostic family and targets main so CI runs on it; each later branch contains the commits below it. Please merge in order.

  1. This PR: zero-delay deferrals and custom-hook tuples (OCTANE_STRONG_EFFECT_STATE_UPDATE)
  2. fix(compiler): require Strong effect cleanup to cancel or ignore async state updates #1482: async updates need a cleanup that cancels or ignores them (OCTANE_STRONG_EFFECT_DATA_FETCH)
  3. feat(compiler): reject hidden dependencies in Strong effect setup #1483: hidden dependencies in effect setup (OCTANE_STRONG_EFFECT_HIDDEN_DEPENDENCY)
  4. feat(compiler): require Strong effect cleanup to release platform resources #1484: unreleased platform resources (OCTANE_STRONG_EFFECT_RESOURCE_LEAK)

What changed here. A synchronous state update in effect setup was an error, but deferring it by zero delay compiled cleanly. Callbacks that run before the next paint now count as effect setup:

  • startTransition, including import aliases, Octane.startTransition, local aliases, and optional calls;
  • a useTransition start function, from a tuple pattern, an index, or an alias;
  • queueMicrotask, including window./globalThis. members and aliases;
  • .then/.catch/.finally on a promise that may already be settled: Promise.reject(), or Promise.resolve(value) of a value that is not a promise on some path;
  • setTimeout(fn) or setTimeout(fn, delay) whose delay is statically <= 0, NaN, or undefined;
  • code after an await that resumes without waiting on some path, including await null, await Promise.resolve(), and await (flag ? load() : null). Like if (flag) await load();, the code after an await counts as deferred only when every path waits. Literal and const operands, including a bare undefined, decide &&, ||, ??, and ?:.

requestAnimationFrame, timers with a positive or unknown delay, and external subscription callbacks stay legal, as specified.

Strong also follows what a same-module custom hook returns: return useState(0), a tuple binding, a repacked [value, setValue] array, a { value, setValue } object, a returned updater, a toggle callback, a transition start, or a useTransition() tuple. This works through nested and aliased hooks, in .tsrx, .tsx, and plain .ts. Each call gets its own derived state identity, including state read by callbacks the hook returns, so two calls of one hook never form a false OCTANE_STRONG_EFFECT_CHAIN. A value the hook received from its caller keeps the caller's identity. As a consequence, getters and updaters returned by custom hooks are now also caught by the existing render-phase checks.

The classification lives in a new packages/octane/src/compiler/strong-effects.js policy module, called from a few hooks in strong-mode.js. That limits conflicts with the parallel Strong work on state purity and render/DOM checks.

Validation

  • pnpm format:check: repo-wide, run on the complete stack; pnpm format:files:check on this layer.
  • pnpm typecheck: full run on the complete stack. On this layer, pnpm typecheck:files on the changed tests shows only the TS7016 errors main already has.
  • pnpm test: run on the complete stack through the four CI shards (vitest.ci-sharded.config.js).
    • Shards 1, 2 and 4 pass.
    • Shard 3 had one 5 s timeout in hmr.test.ts ('preserves state and live events … consecutive vite replacements'). That file compiles no Strong code, and it passes 74/74 three times in isolation.
    • An unsharded local pnpm test runs out of memory in the Vitest main process on this machine, which is a known local limit.
  • targeted tests: strong-effects, strong-mode, strong-hook-policy, strong-html, and strong-template-policy pass on this layer (1243 tests). Every reported snippet for this family is rejected, and snippets for later families still compile.
    • New fixtures cover aliases, shadowed names, namespace imports, optional chains, .tsrx, .tsx, plain .ts custom hooks, and the likely agent rewrites.
    • Output pins show identical client, server, and plain-.ts output with and without Strong. Editor diagnostics are source-located.
  • pnpm sync produced no changes.

Compiler throughput, complete stack. I timed analyzeStrongMode on pre-parsed ASTs of 506 repo .tsrx/.tsx modules that use effects, with HEAD and candidate in interleaved processes on a loaded machine. The Strong analyzer is about 3% slower: best-min 776 ms vs 803 ms, and a median ratio of 1.03 over 6 rounds. The analyzer is a fraction of a full compile, and modules that are not Strong pay nothing because the analyzer returns early.

Risk / follow-ups

  • This intentionally flips existing fixtures that treated setTimeout(fn, 0), queueMicrotask, Promise.resolve().then, or await Promise.resolve() inside an effect as deferred. The yield-matrix fixtures now await an opaque pending load instead.
  • Render-phase zero-delay updates are unchanged.
  • setTimeout(fn, 1) and requestAnimationFrame still defer by design.
  • for await over an array, and .then chains beyond a settled root, are not treated as zero-delay.
  • After review, await (flag ? Promise.resolve() : props.pending) is rejected; one fixture that kept it legal flipped. This matches how if (flag) await pending; was already treated.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


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 compile-time Strong diagnostics and intentionally rejects patterns that previously compiled; runtime output is unchanged but existing Strong-enabled code may need fixture/test updates.

Overview
Tightens Strong mode so state updates can’t be smuggled past effect-setup rules with “deferred” scheduling that still runs before paint.

A new strong-effects.js policy module centralizes classification of zero-delay continuations—startTransition / useTransition starters (including aliases), queueMicrotask, setTimeout with delay ≤ 0 / undefined / NaN, .then/.catch/.finally on promises that may already be settled, and await paths that don’t actually wait on every branch—so updates inside them report OCTANE_STRONG_EFFECT_STATE_UPDATE like a direct synchronous write. requestAnimationFrame, positive/unknown timer delays, and external subscription callbacks stay allowed.

The same work threads custom-hook return shapes (tuple/object updaters, repacked state, transition starters, nested/aliased hooks across .ts/.tsx/.tsrx) into Strong’s state identity so hook-returned updaters are attributed correctly and duplicate hook calls don’t false-trigger OCTANE_STRONG_EFFECT_CHAIN. strong-mode.js delegates to the policy via a small hook surface; fixtures and tests are expanded for common agent rewrites.

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

…ters as Strong effect setup

OCTANE_STRONG_EFFECT_STATE_UPDATE could be bypassed by deferring the update
by zero delay or by returning the state tuple from a same-module custom hook.

Callbacks that run before the next paint now count as synchronous effect
setup: startTransition (imports, aliases, namespaces, optional calls), a
useTransition start function, queueMicrotask, .then/.catch/.finally on
Promise.resolve(value) or Promise.reject(), setTimeout without a positive
delay, and code after awaiting a value that is not a pending promise.
requestAnimationFrame, positive-delay timers, and external subscription
callbacks remain event-driven.

Synchronous calls to local functions now record what they return, so state
tuples, updaters, callbacks, and transition starts returned by same-module
custom hooks keep their provenance in the caller. Each call gets its own
state identity so separate calls never read as one state in effect graphs.

The classification lives in a new strong-effects.js policy module. Emitted
code and compatibility modules are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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 2 potential issues.

Autofix Details

Bugbot Autofix prepared fixes for both issues found in the latest run.

  • ✅ Fixed: Shape merge uses reference equality
    • Replaced reference equality (===) in mergeShapes with a shapesEqual helper that structurally compares returned-array elements and returned-object property maps, so two branches returning the same repacked tuple now merge correctly.
  • ✅ Fixed: Zero-delay await misses compounds
    • Extended zeroDelayPromise to recurse through AwaitExpression, SequenceExpression, ConditionalExpression, and LogicalExpression, checking each leaf with nonPromise || zeroDelayPromise so compound forms that settle before the next paint are correctly recognized.

Create PR

Or push these changes by commenting:

@cursor push 0c29294ec4
Preview (0c29294ec4)
diff --git a/packages/octane/src/compiler/strong-effects.js b/packages/octane/src/compiler/strong-effects.js
--- a/packages/octane/src/compiler/strong-effects.js
+++ b/packages/octane/src/compiler/strong-effects.js
@@ -179,6 +179,22 @@
 		if (node?.type === 'Identifier') {
 			return depth < 8 && zeroDelayPromise(stableInitOf(node), depth + 1);
 		}
+		if (node?.type === 'AwaitExpression')
+			return nonPromise(node.argument) || zeroDelayPromise(node.argument, depth);
+		if (node?.type === 'SequenceExpression')
+			return zeroDelayPromise(node.expressions?.at(-1), depth);
+		if (node?.type === 'ConditionalExpression') {
+			return (
+				(nonPromise(node.consequent) || zeroDelayPromise(node.consequent, depth)) &&
+				(nonPromise(node.alternate) || zeroDelayPromise(node.alternate, depth))
+			);
+		}
+		if (node?.type === 'LogicalExpression') {
+			return (
+				(nonPromise(node.left) || zeroDelayPromise(node.left, depth)) &&
+				(nonPromise(node.right) || zeroDelayPromise(node.right, depth))
+			);
+		}
 		if (node?.type !== 'CallExpression') return false;
 		const callee = unwrap(node.callee);
 		if (callee?.type !== 'MemberExpression' || keyOf(callee.object) !== 'g:Promise') return false;

diff --git a/packages/octane/src/compiler/strong-mode.js b/packages/octane/src/compiler/strong-mode.js
--- a/packages/octane/src/compiler/strong-mode.js
+++ b/packages/octane/src/compiler/strong-mode.js
@@ -2739,9 +2739,28 @@
 		return shapeMember(node, scope);
 	}
 
+	function shapesEqual(a, b) {
+		if (a === b) return true;
+		if (a == null || b == null || a.kind !== b.kind) return false;
+		if (a.kind === 'returned-array') {
+			return (
+				a.elements.length === b.elements.length &&
+				a.elements.every((element, index) => element === b.elements[index])
+			);
+		}
+		if (a.kind === 'returned-object') {
+			if (a.properties.size !== b.properties.size) return false;
+			for (const [key, value] of a.properties) {
+				if (b.properties.get(key) !== value) return false;
+			}
+			return true;
+		}
+		return false;
+	}
+
 	function mergeShapes(shapes) {
 		const [first] = shapes;
-		return first != null && shapes.every((shape) => shape === first) ? first : null;
+		return first != null && shapes.every((shape) => shapesEqual(shape, first)) ? first : null;
 	}
 
 	function bindReturnedShape(pattern, shape, bind) {

You can send follow-ups to the cloud agent here.

…y awaits

Two review findings on the Strong zero-delay and custom-hook checks:

- mergeShapes required every return of a custom hook to yield the same
  shape object, but each `return [value, setValue]` or object literal builds
  a fresh shape, so a hook returning its tuple on two paths lost updater
  provenance. Array and object shapes now merge element by element, keeping
  each value that every path returns.
- Zero-delay awaits only matched a direct Promise.resolve/reject call.
  Sequence, conditional, and logical forms now recurse, and an await result
  counts as a non-promise, so `await (await null)`,
  `await (0, Promise.resolve())`, and `await (flag ? Promise.resolve() : null)`
  stay in effect setup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Logical await misclassified as zero-delay
    • Added an explicit AwaitExpression case to settled() that recurses into the argument, so settled(await load()) is false when load() is an opaque promise, preventing await (null ?? await load()) from being misclassified as zero-delay.

Create PR

Or push these changes by commenting:

@cursor push 145f0b66ec
Preview (145f0b66ec)
diff --git a/packages/octane/src/compiler/strong-effects.js b/packages/octane/src/compiler/strong-effects.js
--- a/packages/octane/src/compiler/strong-effects.js
+++ b/packages/octane/src/compiler/strong-effects.js
@@ -204,6 +204,8 @@
 	function settled(expression, depth = 0) {
 		const node = unwrap(expression);
 		switch (node?.type) {
+			case 'AwaitExpression':
+				return settled(node.argument, depth);
 			case 'SequenceExpression':
 				return settled(node.expressions?.at(-1), depth);
 			case 'ConditionalExpression':

You can send follow-ups to the cloud agent here.

trueadm and others added 2 commits October 1, 2026 09:45
Review finding: an await result counts as settled, so the outer await in
`await (null ?? await load())` or `await (true ? await load() : null)` is
zero-delay, and the yield belongs to the inner await. alwaysAwaits only
inspected the left operand of a logical expression and required both
branches of a conditional, so it missed that inner await and a later update
was rejected as effect setup. A literal left operand or literal test now
selects the operand that always runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review October 1, 2026 09:27

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

Resolve conflicts with the Strong state checks (#1497): keep both the
effect and state policies, visit non-zero-delay synchronous callbacks
in the event phase, and render the state in effect fixtures so they
are not write-only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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

This comment has been minimized.

trueadm and others added 2 commits October 1, 2026 10:59
…eck every await path

- Derive state identity per call for setters, tuples, and returned
  callbacks, including nested hooks; values passed in keep the caller's
  identity. Forward nested call shapes and useTransition tuples.
- Keep updater purity checks on custom-hook state.
- An await ends synchronous setup only when every path waits: a branch
  that resumes in a microtask, a literal-decided operand, or a bare
  undefined operand is decided like `if (c) await work;`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`const p = flag ? await load() : pending; await p` waits on every path,
like the inline form. A local `const` initialized in the same function
keeps the paths of its initializer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@blacksmith-sh

This comment has been minimized.

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

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Var initializers credited before they run
    • Added a guard in localInit to return null when the binding's declaration kind is var, since var hoisting means the initializer may not have executed at the point of reference, unlike const/let which have TDZ guarantees.

Create PR

Or push these changes by commenting:

@cursor push 509f453c3f
Preview (509f453c3f)
diff --git a/packages/octane/src/compiler/strong-effects.js b/packages/octane/src/compiler/strong-effects.js
--- a/packages/octane/src/compiler/strong-effects.js
+++ b/packages/octane/src/compiler/strong-effects.js
@@ -276,14 +276,17 @@
 			return maySettle(argument);
 		},
 		// The stable initializer of a binding declared in the function that reads
-		// it: that initializer ran earlier on the same path.
+		// it: that initializer ran earlier on the same path. `var` is excluded
+		// because its hoisted binding is `undefined` before the declaration runs.
 		localInit(expression) {
 			const node = unwrap(expression);
 			if (node?.type !== 'Identifier') return null;
 			const scope = nodeScopes.get(node);
 			const binding = bindingOf(node);
 			if (scope === undefined || binding == null || binding.scope == null) return null;
-			return functionScopeOf(binding.scope) === functionScopeOf(scope) ? stableInit(binding) : null;
+			if (functionScopeOf(binding.scope) !== functionScopeOf(scope)) return null;
+			if (declarator(binding)?.kind === 'var') return null;
+			return stableInit(binding);
 		},
 		// A provably known operand value, as `{ value }`, or null.
 		literal(expression) {

You can send follow-ups to the cloud agent here.

…t awaits

A `var` is hoisted and holds undefined until its declaration runs, so
only `const` and `let` keep their initializer's paths, and a `var`
read above its declaration in the same function may resume before paint.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cursor

This comment has been minimized.

trueadm and others added 2 commits October 1, 2026 12:01
`awaitYields` re-entered through `alwaysAwaits` with a fresh depth, so
`const ready = await ready` overflowed the stack. Track the initializers
being followed instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…await

A `var` declared directly in the function body above the read has run on
every path, so `var ready = flag ? await load() : pending; await ready`
waits like the `const` form. A `var` declared in a branch still does not
count.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

…has run

An unbraced `if (c) var ready = …` shares the function body scope, so
scope and position could not prove it ran. A `var` now counts as
initialized only in the rest of the statement list that holds it, the
body of a loop whose head declares it, the rest of a `for` that
initializes it, or anywhere for a module-level declaration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Export var skipped by region marking
    • Added an ExportNamedDeclaration unwrap at the top of the mark() function so that export var declarations at module scope are correctly registered in varRegions and treated as initialized.

Create PR

Or push these changes by commenting:

@cursor push 5a10e3d110
Preview (5a10e3d110)
diff --git a/packages/octane/src/compiler/strong-effects.js b/packages/octane/src/compiler/strong-effects.js
--- a/packages/octane/src/compiler/strong-effects.js
+++ b/packages/octane/src/compiler/strong-effects.js
@@ -234,6 +234,7 @@
 		if (varRegions === null) {
 			varRegions = new Map();
 			const mark = (declaration, start, end) => {
+				if (declaration?.type === 'ExportNamedDeclaration') declaration = declaration.declaration;
 				if (declaration?.type !== 'VariableDeclaration' || declaration.kind !== 'var') return;
 				for (const decl of declaration.declarations ?? []) {
 					varRegions.set(decl, [start ?? decl.end, end]);

You can send follow-ups to the cloud agent here.

…effects

`export var` wraps the declaration in ExportNamedDeclaration, so it
missed the module-wide region of a bare module `var`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cursor

cursor Bot commented Oct 1, 2026

Copy link
Copy Markdown

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Unbraced var treated as always initialized
    • Replaced the scope-based direct check with an AST-structural isDirectBodyVar check that verifies the VariableDeclarator belongs to a VariableDeclaration that is a direct child statement of a function/module body, correctly rejecting vars in unbraced if/while/do bodies.

Create PR

Or push these changes by commenting:

@cursor push 52f91fd46c
Preview (52f91fd46c)
diff --git a/packages/octane/src/compiler/strong-effects.js b/packages/octane/src/compiler/strong-effects.js
--- a/packages/octane/src/compiler/strong-effects.js
+++ b/packages/octane/src/compiler/strong-effects.js
@@ -53,6 +53,22 @@
 export function createStrongEffectPolicy({ ast, analysis, callNames, report }) {
 	const { nodeScopes, declarators } = analysis;
 	let declaratorInfo = null;
+	let directBodyVars = null;
+	function isDirectBodyVar(decl) {
+		if (directBodyVars === null) {
+			directBodyVars = new WeakSet();
+			const mark = (statements) => {
+				for (const stmt of statements) {
+					if (stmt.type === 'VariableDeclaration' && stmt.kind === 'var') {
+						for (const d of stmt.declarations ?? []) directBodyVars.add(d);
+					}
+				}
+			};
+			mark(ast.body ?? []);
+			for (const { node } of analysis.functions ?? []) mark(node.body?.body ?? []);
+		}
+		return directBodyVars.has(decl);
+	}
 	// undefined: not an analyzed reference; null: an unshadowed global.
 	function bindingOf(identifier) {
 		const scope = nodeScopes.get(identifier);
@@ -300,10 +316,7 @@
 			const fn = functionScopeOf(scope);
 			if (info === null || functionScopeOf(binding.scope) !== fn) return null;
 			if (info.kind === 'var') {
-				// The function body is a block scope directly inside the function scope.
-				const declScope = nodeScopes.get(info.decl);
-				const direct = declScope === fn || (declScope?.kind === 'block' && declScope.parent === fn);
-				if (!direct || node.start < info.decl.end) return null;
+				if (!isDirectBodyVar(info.decl) || node.start < info.decl.end) return null;
 			} else if (info.kind !== 'const' && info.kind !== 'let') {
 				return null;
 			}

You can send follow-ups to the cloud agent here.

Keep the custom-hook return collector and per-call state owners around
main's visitSynchronousCall, which runs helpers called from an Effect
Event with current values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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 2 potential issues.

Fix All in Cursor

Bugbot Autofix prepared fixes for both issues found in the latest run.

  • ✅ Fixed: Hook setters missed on member bindings
    • Added returnedShapeElement helper to resolve member accesses on call shapes and returned-shape bindings, extended bindDeclaration to re-trigger binding for member expressions on calls, removed the identifier exclusion in bindReturnedShape for returned-array/returned-object, and used the helper in callableValue for callee resolution.
  • ✅ Fixed: Destructured globals skip zero-delay checks
    • Applied the same g:window member flattening in keyOf's declarator path that the MemberExpression path already uses, so destructured globals like const { queueMicrotask } = window produce g:queueMicrotask instead of g:window.queueMicrotask and are correctly recognized by globalFunction.

Create PR

Or push these changes by commenting:

@cursor push a8f31512a9
Preview (a8f31512a9)
diff --git a/packages/octane/src/compiler/strong-effects.js b/packages/octane/src/compiler/strong-effects.js
--- a/packages/octane/src/compiler/strong-effects.js
+++ b/packages/octane/src/compiler/strong-effects.js
@@ -123,7 +123,12 @@
 				const init = info === null ? null : unwrap(info.decl.init);
 				if (init?.type === 'Identifier' || init?.type === 'MemberExpression') {
 					const base = keyOf(init, depth + 1);
-					if (base !== null) return info.path.length === 0 ? base : `${base}.${info.path[0]}`;
+					if (base !== null) {
+						if (info.path.length === 0) return base;
+						if (base === 'g:window')
+							return GLOBAL_OBJECTS.has(info.path[0]) ? base : `g:${info.path[0]}`;
+						return `${base}.${info.path[0]}`;
+					}
 				}
 			}
 			return `b${binding.id}`;

diff --git a/packages/octane/src/compiler/strong-mode.js b/packages/octane/src/compiler/strong-mode.js
--- a/packages/octane/src/compiler/strong-mode.js
+++ b/packages/octane/src/compiler/strong-mode.js
@@ -2745,8 +2745,11 @@
 				} else if (prop) bindPropPattern(declaration.id, bind);
 			}
 		}
-		const shape = initial?.type === 'CallExpression' ? callShapes.get(initial) : undefined;
-		if (shape !== undefined && stateTuple === null) {
+		let shape = initial?.type === 'CallExpression' ? callShapes.get(initial) : undefined;
+		if (shape === undefined && stateTuple === null && initial?.type === 'MemberExpression') {
+			shape = returnedShapeElement(initial, scope);
+		}
+		if (shape != null && stateTuple === null) {
 			bindReturnedShape(declaration.id, shape, scope, bind);
 		}
 	}
@@ -2895,11 +2898,37 @@
 		return null;
 	}
 
+	function returnedShapeElement(node, scope) {
+		if (node?.type !== 'MemberExpression') return undefined;
+		const object = unwrap(node.object);
+		const shape =
+			object?.type === 'CallExpression'
+				? callShapes.get(object)
+				: object?.type === 'Identifier'
+					? resolve(scope, object.name)
+					: null;
+		if (shape?.kind === 'returned-array') {
+			if (!node.computed) return undefined;
+			const key = staticPrimitiveValue(node.property, scope);
+			const index = typeof key === 'number' ? key : typeof key === 'string' ? Number(key) : NaN;
+			return Number.isInteger(index) && index >= 0 ? shape.elements[index] : undefined;
+		}
+		if (shape?.kind === 'returned-object') {
+			const key = node.computed
+				? staticPrimitiveValue(node.property, scope)
+				: node.property?.type === 'Identifier'
+					? node.property.name
+					: null;
+			return typeof key === 'string' ? shape.properties.get(key) : undefined;
+		}
+		return undefined;
+	}
+
 	function bindReturnedShape(pattern, shape, scope, bind) {
 		if (shape === TRANSITION_TUPLE_BINDING) {
 			bindTransitionPattern(pattern, scope, bind);
 		} else if (pattern?.type === 'Identifier') {
-			if (shape.kind !== 'returned-array' && shape.kind !== 'returned-object') bind(pattern, shape);
+			bind(pattern, shape);
 		} else if (pattern?.type === 'ArrayPattern' && shape.kind === 'returned-array') {
 			pattern.elements?.forEach((element, index) => {
 				const value = shape.elements[index];
@@ -3105,7 +3134,11 @@
 		bindDeclarationValue(declaration, declarationKind, scope);
 		visit(declaration.init, scope, phase);
 		// Visiting a local call records what it returned; bind that provenance.
-		if (callShapes.has(unwrap(declaration.init))) {
+		const initNode = unwrap(declaration.init);
+		if (
+			callShapes.has(initNode) ||
+			(initNode?.type === 'MemberExpression' && callShapes.has(unwrap(initNode.object)))
+		) {
 			bindDeclarationValue(declaration, declarationKind, scope);
 		}
 		return visitPatternExpressions(
@@ -3489,6 +3522,8 @@
 		const setter = stateTupleUpdater(node, scope);
 		if (setter !== null) return setter;
 		if (stateTupleGetter(node, scope)) return STATE_GETTER_BINDING;
+		const member = returnedShapeElement(node, scope);
+		if (isCallableValue(member)) return member;
 		if (node?.type === 'SequenceExpression') {
 			return callableValue(node.expressions?.[node.expressions.length - 1], scope);
 		}

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 388bbb7. Configure here.

trueadm and others added 3 commits October 1, 2026 13:21
… Strong effects

- A stored same-module hook result keeps its returned array or object, so
  `thing[1](x)`, `thing.setValue(x)`, aliases of those members, and a
  stored transition start are tracked.
- `const { queueMicrotask } = window` names the global like
  `window.queueMicrotask`, so destructured zero-delay APIs are checked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ing early

- A falsy left operand of `&&` is the awaited value and is never a
  thenable, so `await (cond && work)` and `Promise.resolve(cond && p)`
  may resume before paint.
- Aliases of a stored hook result, and a stored result passed to a local
  helper, keep its returned array or object.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#1482 landed on main as a squash that contains this branch's changes in
their latest form, so every conflict resolves to main's side.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm

trueadm commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

Closing as superseded: #1482 landed on main as a squash (1c44df5) that includes all of this PR's changes in their latest form, and this branch now has no diff against main.

🤖 Closed by Claude Code

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