Skip to content

fix(compiler): let Strong catch clauses run after an awaited call rejects - #1488

Merged
trueadm merged 6 commits into
mainfrom
fix/strong-async-try-clauses
Oct 1, 2026
Merged

trueadm merged 6 commits into
mainfrom
fix/strong-async-try-clauses

Conversation

@trueadm

@trueadm trueadm commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Strong mode rejected the standard effect loading pattern:

useEffect(() => {
  let ignore = false;
  (async () => {
    try {
      const v = await api.get(props.id);
      if (!ignore) setD(v);
    } catch (e) {
      if (!ignore) setErr(e); // OCTANE_STRONG_EFFECT_STATE_UPDATE
    }
  })();
  return () => { ignore = true; };
});

The analyzer gave the catch clause, the finally clause, and the code after a try the phase that was in effect when the try began. Even try { setD(await p); } catch (e) { setErr(e); } was rejected, though nothing in it can throw before the yield.

The rule

Inside an async function whose try starts in the render or effect-setup phase:

  • A catch is synchronous only if something before the try block's first guaranteed await can throw.

  • A finally, and the code after the try, is synchronous only if the try, or a catch entered synchronously, can finish before one.

  • Settled awaits: in effect work, fix(compiler): require Strong effect cleanup to cancel or ignore async state updates #1482 on main no longer treats an await that resumes without waiting (await null, await Promise.resolve()) as a yield. This analysis builds on the same alwaysAwaits, so such an await doesn't end the synchronous prefix. A settled await also counts as able to throw, so await Promise.reject(err) keeps the catch synchronous. Finishing means throwing, return/break/continue, or falling through.

  • Can throw: calls, new, throw, iteration (spread, array destructuring, for…of), classes, and any syntax the analyzer doesn't model.

  • Can't throw: reading an identifier, this, super or import.meta; property reads; operators; and object destructuring. This matches Strong's existing assumption that a property read runs no code.

  • Trusted calls are assumed to fail by rejecting. Their callees and arguments are evaluated first and still count. Three kinds of call are trusted:

    • the awaited call;
    • any call it chains from through .then/.catch/.finally;
    • each call written as an element of an array literal passed as the first argument to an awaited Promise.all, allSettled, any or race.

    Async functions and web APIs such as fetch guarantee this. The combinator trust is off if the module binds Promise anywhere: an import (including TypeScript import … = require), declaration, parameter, class, enum, namespace or catch binding.

Accepted now Still rejected
await api.get(props.id) if (!id) throw … before the await
await fetch(url) then await res.json() const key = api.key(id); await api.get(key)
await api.get(id).then((r) => r.data) await api.get(api.key(id))
await Promise.all([api.a(id), api.b(id).then(parse)]), and allSettled/any/race await Promise.all(ids.map(load)) or await Promise.all([...requests])
await import('./x'), await new Promise(…) await api.client().get(id), or api.all([…]) on a non-Promise object
a nested try/finally whose finally runs only after its own await Promise.all([…]) in a module that declares its own Promise (for example import Promise from 'bluebird')
if (!id) return; before the await a finally reachable through an early return

A catch that is now deferred is still checked like any other code after an await. For example, setCount(count + 1) there reports OCTANE_STRONG_STALE_STATE_UPDATE, added on main by #1497, instead of the synchronous-update error.

Changes

  • strong-mode.js:
    • A small outcome analysis (SYNC_THROW / SYNC_EXIT / SYNC_NORMAL) drives the catch phase, the finally phase, statementAlwaysAwaits(TryStatement), and the do-while control analysis for try, so the model stays consistent.
    • The Promise combinator trust, with a lazy module-wide check for any binding named Promise.
    • This only changes which diagnostics are reported.
  • Tests: a Strong effect try clauses block in strong-effects.test.ts.
    • 22 accepted cases (21 in the shared case list plus the reported fixture). Each pins Strong-compiled code identical to compatibility mode, empty Volar diagnostics, and identical plain .ts custom-hook output.
    • 20 rejected cases. Each pins that compatibility mode still compiles, that Strong throws, that Volar reports the error at the right update call, and that the .ts hook form also throws.
    • 7 Promise-shadowing cases, a stale-update case, and a fetch-continuation regression.
    • The fixtures render their state so they don't trip main's new OCTANE_STRONG_WRITE_ONLY_STATE check.
  • Two existing strong-mode.test.ts cases pinned the old behaviour with await Promise.resolve(). They move to the accepted list, and synchronous-throw and early-exit variants keep pinning rejection.
  • docs/differences-from-react.md documents the rule, and a changeset is included (octane patch).
  • The branch merges origin/main up to 1c44df5 (fix(compiler): require Strong effect cleanup to cancel or ignore async state updates #1482).

Validation

  • pnpm format:check on the merged head.
  • pnpm typecheck on the merged head.
  • pnpm test, run as the four CI shards (vitest.ci-sharded.config.js --shard=N/4) on the first commit, e453e82. A single unsharded local run exhausts the main Vitest process's heap on this machine.
    • Shards 1, 2 and 4 passed fully.
    • Shard 3 failed one test: a 5 s timeout in octane-prod hmr.test.ts, which doesn't use Strong mode and passes when run alone.
    • After the combinator change and the merge, I re-ran only the compiler suite locally; CI runs the full suite on this head.
  • targeted tests: packages/octane/tests/compiler/ plus strong-state-runtime.test.ts on the current merged head (74 files, 3,186 tests).
    • Every accepted case failed before the fix.
    • I broke each branch of the analysis one at a time (38 mutations, including each combinator condition and each Promise binding kind), and each made at least one test fail.
  • pnpm sync produced no generated changes.

Risk / follow-ups

  • A promise-returning function that throws synchronously instead of rejecting now goes unreported when it is a trusted call. That is the contract trade-off described above.
  • Loops, switch and classes before the first await are still treated conservatively and keep the catch synchronous.
  • The extra compile work is limited to try statements in async functions in Strong modules. The Promise binding scan walks the module at most once, and only when an awaited combinator appears in such a try. Emitted code doesn't change. I didn't benchmark compile time.

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 effect-phase rules for async try/catch in Strong modules; trusted promise calls may miss synchronous throws, but runtime behavior is unchanged.

Overview
Strong mode no longer flags OCTANE_STRONG_EFFECT_STATE_UPDATE on the usual async fetch pattern: try { setData(await api.get(id)); } catch (e) { setError(e); }. The compiler now decides whether catch, finally, and code after try run in the effect-setup phase or only after a yield.

A catch stays synchronous only if the try can throw (calls, new, throw, iteration, etc.) before its first guaranteed await. Awaited calls—and then/catch/finally chains and Promise.all/allSettled/any/race array-literal elements (when the module does not bind Promise)—are treated as rejecting rather than throwing; callees and arguments still count. finally and post-try code use the same “can finish before yield” rule.

Implementation adds sync-outcome analysis (SYNC_THROW / SYNC_EXIT / SYNC_NORMAL), bindsName for Promise shadowing, and visits catch/finally in deferred phase when appropriate. Docs and a patch changeset document the rule; extensive compiler tests cover accept/reject cases. Emitted code is unchanged—only diagnostics.

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

…ects

Strong mode visited a try statement's catch clause, finally clause and
continuation with the phase in effect when the try began. Inside an async
function started by an effect, the canonical loading pattern

    try { setData(await api.get(id)); } catch (error) { setError(error); }

reported OCTANE_STRONG_EFFECT_STATE_UPDATE on setError, even when nothing
before the await could throw (`await p` was rejected too).

A catch clause now keeps the starting phase only when the try block can throw
before its first guaranteed await. A finally clause, and code after the try,
keep it only when try or a synchronously entered catch can finish (throw,
return/break/continue, or complete) first. The same rule now drives
statementAlwaysAwaits and the do-while control analysis for try statements, so
the model stays consistent.

Calls, `new`, `throw`, iteration (spread, array patterns, for-of), classes and
unmodelled syntax count as throw points. Property reads, operators and object
destructuring do not, matching Strong's existing getter assumption. The
awaited call, and calls it chains from through then/catch/finally, are trusted
to report failure by rejecting; their callee and arguments still count, so
`await api.get(key(id))` and `await Promise.all([a(), b()])` keep the catch
synchronous.

Diagnostics only: emitted code, compatibility mode and Volar parity are
unchanged and pinned by tests. Two strong-mode tests that pinned the old
conservative behaviour with `await Promise.resolve()` now sit in the accepted
list, with synchronous-throw and early-exit variants pinning rejection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 1, 2026
@trueadm
trueadm marked this pull request as ready for review October 1, 2026 08:33
trueadm and others added 2 commits October 1, 2026 10:29
`await Promise.all([api.a(id), api.b(id)])` kept a catch clause synchronous
because the element calls run before the combinator is awaited. Promise.all,
allSettled, any and race consume each element of an array-literal first
argument as a promise, so a call written there now gets the same trust as the
awaited call: it is assumed to report failure by rejecting, including through
then/catch/finally chains.

The elements' own callees and arguments still count as throw points, as do
spread elements, non-literal arguments such as `ids.map(load)`, later
arguments, and `.all()` on any object other than Promise. A module that binds
`Promise` anywhere (import, declaration, parameter, class, enum or catch
binding) turns the combinator trust off.

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

# Conflicts:
#	packages/octane/src/compiler/strong-mode.js

@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: This treated as throwing
    • Added ThisExpression, Super, and MetaProperty to the inert-expression cases in throwsBeforeAwait so they return false instead of falling through to the default that returns true.
  • ✅ Fixed: Promise binding walk incomplete
    • Added TSImportEqualsDeclaration and TSModuleDeclaration to the bindsName switch so their id is recorded as a binding, correctly disabling Promise combinator trust.

Create PR

Or push these changes by commenting:

@cursor push 18a4e2588c
Preview (18a4e2588c)
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
@@ -282,6 +282,8 @@
 			case 'ClassDeclaration':
 			case 'ClassExpression':
 			case 'TSEnumDeclaration':
+			case 'TSImportEqualsDeclaration':
+			case 'TSModuleDeclaration':
 				addPatternNames(node.id, bindings, true);
 				break;
 			case 'ImportSpecifier':
@@ -2333,6 +2335,9 @@
 		switch (node.type) {
 			case 'Literal':
 			case 'Identifier':
+			case 'ThisExpression':
+			case 'Super':
+			case 'MetaProperty':
 			case 'FunctionExpression':
 			case 'ArrowFunctionExpression':
 				return false;

diff --git a/packages/octane/tests/compiler/strong-effects.test.ts b/packages/octane/tests/compiler/strong-effects.test.ts
--- a/packages/octane/tests/compiler/strong-effects.test.ts
+++ b/packages/octane/tests/compiler/strong-effects.test.ts
@@ -507,6 +507,10 @@
 			'do-while exits from catch clauses entered only after yielding',
 			'do { try { setData(await api.get(props.id)); } catch (e) { break; } } while (props.retry); setLoading(false);',
 		],
+		[
+			'awaited calls through this, super and import.meta receivers',
+			'try { setData(await this.api.get(props.id)); } catch (e) { setError(e); }',
+		],
 	])('allows updates in try clauses reached only after yielding: %s', (_label, body) => {
 		const source = load(body);
 		expect(compile(source, '/src/App.tsrx', { strong: true }).code).toBe(
@@ -644,6 +648,8 @@
 		['', 'function wrap(Promise) { return Promise; }'],
 		['', 'class Promise {}'],
 		['', 'try {} catch (Promise) {}'],
+		['import Promise = Bluebird.Promise;', ''],
+		['', 'namespace Promise { export const resolve = 1; }'],
 	])(
 		'does not trust Promise combinator elements when the module binds Promise: %s%s',
 		(imports, local) => {

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

Reviewed by Cursor Bugbot for commit dea2c33. Configure here.

trueadm and others added 3 commits October 1, 2026 11:02
…rong try analysis

`await this.api.get(id)` and `await api.get(import.meta.env.API)` kept a
catch clause synchronous because ThisExpression and MetaProperty fell through
to the unmodelled-syntax default. Reading them is no more able to throw than
reading an identifier, so they, and Super, are now inert like identifiers.

The Promise binding scan also skipped TypeScript namespaces and import-equals
declarations. `namespace Promise { ... }` compiles in .tsrx and .ts, and
`import Promise = require(...)` compiles in plain .ts hooks, so both now turn
the Promise combinator trust off.

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

# Conflicts:
#	packages/octane/src/compiler/strong-mode.js
…clauses

# Conflicts:
#	packages/octane/src/compiler/strong-mode.js
#	packages/octane/tests/compiler/strong-effects.test.ts
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

No benchmark report for this commit yet: PR bench is still running or skipped this change.

CI job durations

  • 🟡 11 job(s) slower than every recent main run: heavy integration (package builds, eval corpus, runtime loaders, Astro), typecheck checks, React parity shard (3/4), example apps (2/3), React parity shard (1/4), test shard (Node 24, 3/4), test shard (Node 24, 1/4), test shard (Node 24, 4/4), example apps (3/3), lint checks, validate publishable packages

Compares the CI run for 2a35b23c2 (run) with the last 5 successful main push runs. A job is only slower or faster outside the whole main range, by at least 10% and 15s.

job main median main range this PR Δ
wall clock (first job start to last job end) 17m 05s 12m 35s–23m 15s 39m 22s +22m 17s (+130%) 🟡 slower
total job time 184m 21s 144m 08s–242m 49s 272m 11s +87m 50s (+48%) 🟡 slower
heavy integration (package builds, eval corpus, runtime loaders, Astro) 5m 28s 4m 36s–16m 52s 38m 44s +33m 16s (+609%) 🟡 slower
typecheck checks 9m 23s 7m 20s–11m 01s 19m 23s +10m 00s (+107%) 🟡 slower
React parity shard (3/4) 13m 10s 10m 59s–18m 01s 22m 26s +9m 16s (+70%) 🟡 slower
example apps (2/3) 4m 15s 3m 26s–9m 58s 10m 28s +6m 13s (+146%) 🟡 slower
React parity shard (1/4) 14m 25s 10m 05s–18m 11s 20m 37s +6m 12s (+43%) 🟡 slower
test shard (Node 24, 3/4) 11m 56s 9m 44s–15m 12s 17m 37s +5m 41s (+48%) 🟡 slower
test shard (Node 24, 1/4) 14m 01s 11m 10s–17m 32s 19m 18s +5m 17s (+38%) 🟡 slower
test shard (Node 24, 4/4) 12m 54s 10m 24s–16m 16s 18m 07s +5m 13s (+40%) 🟡 slower
example apps (3/3) 3m 49s 3m 34s–5m 33s 8m 10s +4m 21s (+114%) 🟡 slower
lint checks 8m 49s 7m 43s–12m 27s 12m 38s +3m 49s (+43%) 🟡 slower
validate publishable packages 4m 32s 3m 45s–5m 20s 5m 53s +1m 21s (+30%) 🟡 slower
All 26 timed jobs
job main median main range this PR Δ
heavy integration (package builds, eval corpus, runtime loaders, Astro) 5m 28s 4m 36s–16m 52s 38m 44s +33m 16s (+609%) 🟡 slower
typecheck checks 9m 23s 7m 20s–11m 01s 19m 23s +10m 00s (+107%) 🟡 slower
React parity shard (3/4) 13m 10s 10m 59s–18m 01s 22m 26s +9m 16s (+70%) 🟡 slower
example apps (2/3) 4m 15s 3m 26s–9m 58s 10m 28s +6m 13s (+146%) 🟡 slower
React parity shard (1/4) 14m 25s 10m 05s–18m 11s 20m 37s +6m 12s (+43%) 🟡 slower
test shard (Node 24, 3/4) 11m 56s 9m 44s–15m 12s 17m 37s +5m 41s (+48%) 🟡 slower
test shard (Node 24, 1/4) 14m 01s 11m 10s–17m 32s 19m 18s +5m 17s (+38%) 🟡 slower
test shard (Node 24, 4/4) 12m 54s 10m 24s–16m 16s 18m 07s +5m 13s (+40%) 🟡 slower
React parity shard (2/4) 10m 50s 9m 32s–19m 40s 15m 18s +4m 28s (+41%) ⚪ within noise
example apps (3/3) 3m 49s 3m 34s–5m 33s 8m 10s +4m 21s (+114%) 🟡 slower
website integration suite 7m 24s 5m 45s–11m 41s 11m 29s +4m 05s (+55%) ⚪ within noise
lint checks 8m 49s 7m 43s–12m 27s 12m 38s +3m 49s (+43%) 🟡 slower
validate publishable packages 4m 32s 3m 45s–5m 20s 5m 53s +1m 21s (+30%) 🟡 slower
heavy integration (browser - chromium) 12m 52s 11m 12s–19m 08s 14m 04s +1m 12s (+9%) ⚪ within noise
example apps (1/3) 3m 36s 3m 07s–9m 27s 4m 05s +29s (+13%) ⚪ within noise
React parity shard (4/4) 13m 38s 11m 39s–22m 17s 13m 58s +20s (+2%) ⚪ within noise
Lynx compatibility 2m 00s 1m 34s–2m 55s 2m 08s +8s (+7%) ⚪ within noise
Three compatibility 3m 28s 2m 51s–4m 23s 3m 33s +5s (+2%) ⚪ within noise
classify changeset release 16s 14s–21s 17s +1s (+6%) ⚪ within noise
lint 4s 4s–5s 5s +1s (+25%) ⚪ within noise
React parity checks 15s 14s–16s 16s +1s (+7%) ⚪ within noise
CI provenance 4s 3s–4s 5s +1s (+25%) ⚪ within noise
examples 4s 4s–4s 4s ±0s (±0%) ⚪ within noise
typecheck 4s 3s–4s 4s ±0s (±0%) ⚪ within noise
test (24) 4s 3s–5s 4s ±0s (±0%) ⚪ within noise
test shard (Node 24, 2/4) 13m 32s 10m 24s–15m 53s 13m 20s −12s (−1%) ⚪ within noise

@trueadm
trueadm merged commit 2b69559 into main Oct 1, 2026
30 checks passed
@trueadm
trueadm deleted the fix/strong-async-try-clauses branch October 1, 2026 19:11
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