Skip to content

fix: avoid sibling-provider context refreshes - #2073

Merged
trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/scoped-context-refresh
Oct 15, 2026
Merged

trueadm merged 1 commit into
octanejs:mainfrom
openai-oss-forks:fix/scoped-context-refresh

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Changing one provider of a Context currently rerenders consumers beneath a memoized sibling even when their nearest provider's value is unchanged. Keep the existing context-wide invalidation walk, but let direct local reads confirm their actual provider value before rerunning the consumer body.

Fixes #2069.

  • Record the local provider and value in the existing direct-dependency map; compare with Object.is on a later version change. Genuine provider changes still update consumers.
  • Retain conservative version invalidation for hosted, replayed, default, multi-provider and externally invalidated reads. No subscription index, scheduler change or new Block/Scope fields.
  • Add observable-value/state/host-identity regressions, a deterministic production benchmark at 128/512 consumers in both sibling orders, and an octane patch changeset.

Validation

  • pnpm format:check — full hosted check passes; scoped local check also passes for all nine changed files.
  • pnpm typecheck — full hosted check passes; scoped local check also passes for the four changed runtime/test/fixture files.
  • pnpm test — all four hosted runtime shards and their aggregate pass, alongside all React-parity shards, Chromium, package/loader/Astro, website and example coverage.
  • targeted tests: 19 files / 201 tests pass in development and again in production; eight DOM-template tests also pass after integration with 2623e7ab1.
  • pnpm sync and git diff --check pass; generation leaves no additional diff.
  • Production sibling-provider benchmark: unchanged consumers 128 → 0 and 512 → 0 against 2623e7ab1, in both sibling orders. Real provider updates remain 128/512; visible values and retained hosts are asserted. The new ratio guards run in the existing manual/weekly Bench workflow; ordinary PR CI covers the semantic tests.
  • Negative control: removing the value comparison makes both new behavioral tests fail, including the 0/-0 case.
  • perf-review: independent read-only review found no remaining must-fix or needs-evidence source findings; mechanical diff scan has zero candidates. Hot paths are direct context recording, provider writes, and memo invalidation (runtime.ts:16654, 19124, 19142, 41022). No DOM, scheduling, compiler-output, runtime-import, or public-export changes. Production Context objects retain one V8 map through local changes and external invalidation followed by the numeric -1 fallback; an extra-property negative control changes the map (Node 22.22.3 / V8 12.4). This does not establish all dependency-witness IC behavior or browser latency.
  • Allocation probe: with a pinned 1 MiB semi-space, a synthetic 512-consumer genuine-provider-change workload allocates approximately 1,124 → 1,186 bytes per consumer read (+62, +5.5%) over 102,400 measured reads. This is total runtime/DOM-emulator/harness allocation, not isolated retained witness size. GC-traced timing is not used as a browser speedup claim.
  • concise-code: runtime +70 / −11; one internal read type, one helper and one numeric Context provenance field. Four new files own the semantic fixture/test, render-count benchmark and changeset. Value-only comparison would lose forced external invalidation; a provider subscription index would add unnecessary ownership/lifecycle machinery. The selected-export esbuild probe grows 757 minified bytes; complete production bundle deltas are recorded below.

Hosted performance evidence

PR benchmark run 38657660063 passed for head 20ad2a764995eee49fd4124f8a6037097d606977. The measured synthetic merge and landed commit have the same Git tree. All 64 work counters are unchanged; all 20 paired timing operations remain within the report's noise/resolution policy, with no faster/slower verdict.

Complete emitted application JavaScript totals (gzip compressed per file and summed):

Target / scenario Raw base→head Raw Δ Gzip base→head Gzip Δ
octane-tsrx / js-framework 87,374→87,542 +168 29,130→29,181 +51
octane-tsrx / todo 100,114→100,282 +168 33,731→33,788 +57
octane-tsrx / chat 99,450→99,618 +168 33,641→33,703 +62
octane-tsrx / weather 134,171→134,372 +201 44,490→44,572 +82
octane-tsrx / bindings 680,570→681,326 +756 224,150→224,427 +277
octane-tsrx / wayfinder 457,472→458,228 +756 148,867→149,135 +268
octane-tsrx / threadline_oxc 146,123→146,324 +201 48,989→49,064 +75
octane-tsrx / threadline_esbuild 173,391→173,594 +203 58,200→58,302 +102
octane-tsrx / pagecraft_oxc 540,934→541,690 +756 169,400→169,658 +258
octane-tsrx / pagecraft_esbuild 591,165→591,930 +765 188,826→189,098 +272
octane-jsx / js-framework 166,609→167,274 +665 54,066→54,270 +204
octane-jsx / shell 389,858→390,521 +663 122,483→122,666 +183
octane-jsx / shell_client 324,209→324,872 +663 101,306→101,514 +208

These are complete application totals, not framework-only portions or initial network transfers. Gzip growth is 51–277 bytes across all 13 scenarios. The public-import context scenario grows 756 raw / 245 gzip bytes. This is the measured byte cost of scoped invalidation, with no regression detected in the measured work/timing suite. The owning provider-scope counts remain separate local/Bench evidence.

Risk / follow-ups

  • Local fresh dependency installation is blocked by the existing [email protected] registry metadata/minimum-release-age check. Focused validation used the prepared dependency environment with unchanged third-party lock entries; no lockfile or package-admission policy was changed.
  • Local direct reads now allocate a provider/value witness; repeated reads in the same render reuse it. The allocation tradeoff above is accepted to avoid rerunning unaffected consumer bodies; the coarse traversal remains. Hosted/ambiguous reads intentionally retain the previous conservative behavior.
  • The maintainer merged this PR at ea438fb4fc981b34123e579949de4fd6c04f8268 while the final PR test shard was running. The close event cancelled that shard (24 jobs had passed, none failed). Merged-commit CI subsequently passed all 27 jobs on ea438fb4fc981b34123e579949de4fd6c04f8268; no release or deployment was performed by this task.

Provenance

  • An agent produced this diff (agent-authored)

Implementation: Codex task, host com-79386.


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


Note

Medium Risk
Touches production memo bailout and context invalidation hot paths; behavior change is scoped but affects all useContext consumers behind memo when multiple providers share one context.

Overview
Fixes memo bailout incorrectly treating any bump to a shared Context's $$version as a direct dependency change, which forced full consumer refreshes when only a sibling provider updated.

Direct context reads now record nearest provider + value (with $$providerVersion tracking local vs external invalidation). Memo invalidation compares the live nearest value with Object.is before rerunning consumer bodies; hosted, replayed, default, multi-provider, and externally forced bumps stay conservative.

Adds regression coverage (fixture + tests), extends the external-bump epoch test with sibling updates, and wires a provider-scope memo-wall benchmark with ratio guards (0 extra renders at 128/512 consumers when the retained provider is unchanged).

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

@domgan-oai
domgan-oai marked this pull request as ready for review October 15, 2026 00:02
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 15, 2026
@trueadm
trueadm merged commit ea438fb into octanejs:main Oct 15, 2026
51 of 52 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 15, 2026
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.

Sibling providers of the same context unnecessarily refresh consumers below memo

2 participants