Skip to content

Captured local query reads resolve separate instance cells across extracted @try frames #1485

Closed

Description

@callie-openai

On Octane 0.7.1, commit 676a4ee6db59854d6b711921f4ac808845dcdbcd,
a query declared in a template starts twice when setup reads its snapshot and an
extracted @try frame reads the same captured handle. Reading it through a local
derived$ reproduces the same split.

import { query$ } from 'octane/signals';

export function App(props) @{
 const record$ = query$(() => 'record', props.load);
 const state = record$.snapshot();
 @try { <output>{record$.get() as string}</output>; }
 @pending { <i>waiting</i>; }
}

props.load returns a controlled promise and counts calls. Expected: one loader
attempt for this declaration and selection. Observed: two calls before the first
promise settles.

The attached test uses the public source compiler fixture helper and real renderer.
Its two cases read the query directly or through a local derived facade. Both fail
at the initial expect(requests).toHaveLength(1) on the pristine pinned source;
both observe two requests. Both pass with one request after the source repair.

Reproduction setup

The public repository's stock checkout and install are prerequisites for a maintainer
running the attachments. These stock install commands were not executed unchanged
in the reported qualification. The pinned root declares [email protected] and
Node >=22.22.2:

git clone https://github.com/octanejs/octane.git octane-query-owner
cd octane-query-owner
git checkout --detach 676a4ee6db59854d6b711921f4ac808845dcdbcd
corepack pnpm install --frozen-lockfile

Copy upstream-reproduction.test.ts into packages/octane/tests/ and
vitest.query-owner-reproduction.config.mjs into the repository root. Run:

OCTANE_TEST_COMPILE_MODE=prod pnpm exec vitest run --config vitest.query-owner-reproduction.config.mjs

The reported runs used an isolated source graph with Node 26.2.0 and pnpm
11.25.0. Source was obtained from the exact commit archive:

https://codeload.github.com/octanejs/octane/tar.gz/676a4ee6db59854d6b711921f4ac808845dcdbcd
SHA-256: 88786afc05fb9431e536e8ebf816306d9ec3ac764892cc272340969c14eb08ee

The isolated graph retained packages/octane, packages/stylex, scripts, and
the scoped-signals native-presentation benchmark fixture. The frozen dependency
recipe used Vite 8.2.2, Vitest 4.1.11, JSDOM 30.0.1, and TypeScript 5.9.3;
paired TSRX core 0.4.0/runtime 0.2.4 source was installed through registry carrier
versions 0.2.0. The parser wrapper and matching native parser were 0.15.0.
The stock source's parser 0.16.0 was not part of this qualification. This graph
preserved its 10,080-minute package age policy and installed with this exact command:

CI=true pnpm install --frozen-lockfile --ignore-scripts
OCTANE_TEST_COMPILE_MODE=prod pnpm exec vitest run --config vitest.query-owner-reproduction.config.mjs

Only the source repair differs between the reported before and after runs. They
use the same compiler fixture, runtime source, dependency graph, and attachments:

Source Passed Initial loader attempts in each case
Pristine pinned source 0/2 2
Repaired pinned source 2/2 1

Proposed repair

The facade resolves an instance cell from the consuming renderer owner. Setup
and extracted child reads therefore select different cells for the same compiler
i: declaration site. Mark factories authored in a template's own lexical body
and lazily retain that declaration owner when captured reads cross extracted frames.
The attached reproduction confirms that setup and @try then share one attempt.

upstream-reproduction.test.ts
import { describe, expect, it } from 'vitest';
import { act, createRoot } from '../src/index.js';
import * as signals from '../src/signals/index.js';
import { loadCompiledFixtureSource } from './_server-fixture.js';

describe('captured local query declaration ownership', () => {
 it.each(['direct', 'derived'])('uses one query attempt for setup and %s @try reads', async kind => {
  const client = loadCompiledFixtureSource(`
import { query$, derived$ } from 'octane/signals';
export function App(props) @{
 const record$ = query$(() => 'record', props.load);
 const selected$ = derived$(() => record$.get());
 const state = record$.snapshot();
 @try { <output>{${kind === 'direct' ? 'record$' : 'selected$'}.get() as string}</output>; }
 @pending { <i>waiting</i>; }
}`, {
   id: '/src/query-owner-reproduction.tsrx', mode: 'client',
   compileOptions: { dev: false, strong: true, hmr: false },
   runtimeModules: { 'octane/signals': signals },
  });
  const requests: Array<{resolve: (value: string) => void}> = [];
  const load = () => new Promise<string>(resolve => requests.push({resolve}));
  const container = document.createElement('div');
  const root = createRoot(container);
  try {
   await act(() => root.render(client.App, {load}));
   expect(requests).toHaveLength(1);
   await act(() => requests[0]!.resolve('ready'));
   expect(container.querySelector('output')?.textContent).toBe('ready');
   expect(requests).toHaveLength(1);
  } finally { root.unmount(); }
 });
});
vitest.query-owner-reproduction.config.mjs
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { defineConfig } from 'vitest/config';
import { octane } from './packages/octane/src/compiler/vite.js';

const packageRoot = resolve(import.meta.dirname, 'packages/octane');
const pkg = JSON.parse(readFileSync(resolve(packageRoot, 'package.json'), 'utf8'));
const aliases = Object.entries(pkg.exports).map(([name, target]) => ({
 find: name === '.' ? 'octane' : 'octane' + name.slice(1),
 replacement: resolve(packageRoot, typeof target === 'string' ? target : target.default),
})).sort((a, b) => b.find.length - a.find.length);
export default defineConfig({
 resolve: { alias: aliases },
 plugins: [octane({ hmr: false })],
 test: {
  environment: 'jsdom',
  setupFiles: ['packages/octane/tests/_per-test-setup.ts'],
  include: ['packages/octane/tests/upstream-reproduction.test.ts'],
 },
});

—Codex

Activity

  1. trueadm commented on Oct 1, 2026

    @trueadm
    Collaborator

    Thanks for the report and the reproduction. The fix is up in #1530.

    Cause. A facade handle resolves its cell in the owner that reads it. On the client, every extracted directive arm (@try, @pending, @catch, @if, @switch, nested @try) and every signal-reading @for row had its own renderer owner. A declaration from setup that was read again in one of those frames got a second cell with the same key, and with it a second loader attempt. The derived$ case splits the same way: the derived resolves in the reading frame, and its compute then reads the query there. Under a nested component, hydration also refetched instead of resuming the server request.

    Fix. Arm and row owners now record their enclosing owner, on both client and server. A descriptor remembers the instance that declared it, and a reader whose enclosing chain contains that instance resolves the declaring cell. When a row alone starts the query, the server's streamed-attempt observer now records it under the owner that holds the cell.

    This differs a little from the proposed repair. Always retaining the declaration owner would also redirect child components that receive the handle as a prop. Those keep their own cell by design: an existing test pins it, and the streamed hydration protocol relies on it. Arms and rows also still own the declarations they evaluate themselves, and reset them on remount like hook state.

    Both attached cases pass. packages/octane/tests/hydration/signal-declaration-owner.test.ts adds:

    • each frame shape, read directly and through derived$, in root and nested components;
    • client mount and SSR→hydrate (one server request, no browser request);
    • dev, prod and Strong compilation.

    Posted by Claude Code (an AI agent) on behalf of a maintainer.

  2. added a commit that references this issue on Oct 2, 2026
    6c50c70
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions