Skip to content

Captured local query reset targets a child cell when a callback is forwarded #1680

Closed

Description

@callie-openai

A callback that closes over a component-local query resolves a different cell when a child component invokes it. After the first query rejects, a forwarded Retry resets the child's cell while the declaring component's query remains rejected. A direct callback under the declaring component's template owner recovers.

Confirmed against unmodified public Octane source at 76799518eed060f48732ecde3d05510dee089efc (the #1530 revision; packages/octane/package.json reports 0.7.1). This report identifies that exact source revision; it does not claim that the npm 0.7.1 tarball contains #1530 or that every later revision is affected.

Shape of the failure

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

function RetryButton(props) @{
  <button onClick={() => props.retry()}>Retry</button>
}

export function Panel(props) @{
  const result$ = query$(() => 1, props.load);
  @try {
    <output>{result$.get() as string}</output>
  } @pending {
    <span>Loading</span>
  } @catch (_error, reset) {
    <RetryButton retry={() => { result$.reset(); reset(); }} />
  }
}

Have load reject its first promise and resolve subsequent promises to loaded. The parent-created callback captures result$, but the nested button invokes it while the child owns the native event. Replacing RetryButton with a native button in the catch arm is the direct control.

Executed source reproduction

The standalone Node script below uses the real native query and signal implementation and synthetic renderer identity tokens matching #1530's component/arm relationships. It explicitly exercises declaration, rejection, callback invocation and owner retirement. It does not execute the template compiler, DOM renderer, SSR, or hydration; the TSRX above describes the corresponding component arrangement. No server or network request is needed.

Use Node 26.2.0. Save the script below as repro.mjs, then run from the same directory:

curl -fL https://codeload.github.com/octanejs/octane/tar.gz/76799518eed060f48732ecde3d05510dee089efc -o octane-source.tgz
mkdir octane-source
tar -xzf octane-source.tgz --strip-components=1 -C octane-source
npm install --prefix tools --cache ./npm-cache --no-save --no-audit --no-fund [email protected] [email protected]
node repro.mjs ./octane-source

The downloaded archive SHA-256 is f47d5736adfaf1bea4881d099ad0e1df40cb6a47c2aa30805c397c8383dcd7b5. No Octane package build is required: the script strips TypeScript in memory with esbuild and maps source .js imports to their .ts files. Its only runtime dependency is the public [email protected] package. The executed run used source files extracted unchanged from this archive and fresh registry copies of these two dependencies.

Expected: both direct and forwarded Retry make the declaring query ready, with one initial load and one retry. Passing a descriptor directly to a child must continue to give the child its own cell.

Observed output (exit status 1):

{
  "node": "v26.2.0",
  "direct": {
    "status": "ready",
    "value": "loaded",
    "loaderCalls": 2
  },
  "forwarded": {
    "status": "error",
    "error": "first load failed",
    "loaderCalls": 3
  },
  "childHandle": {
    "parent": 4,
    "child": 7
  }
}
FAIL: forwarded retry did not reset the declaring component query

The extra forwarded attempts occur because resolving the descriptor first creates the child's resource and then reset() retries that resource. Retiring the child/fallback cannot clear the original error retained by the parent.

Source diagnosis and repair direction

Native event invocation runs callbacks under the native host's signal owner. Descriptor resolution remembers the declaration owner but uses it only when it occurs in the reader's enclosing chain. A genuine child component has a separate chain, so invoking the parent's closure there selects the child cell.

#1485 and #1530 address captured handles read from a component's extracted arms/rows. #1530 deliberately retains separate cells when a child receives a handle as a prop. That is a useful control, and the reproduction confirms it remains intact (parent: 4, child: 7). This callback case needs to preserve the lexical access without globally changing reader-owned descriptor semantics.

A possible compiler/runtime repair is to resolve scope-proven free references to local descriptors inside escaping callbacks against the declaration owner, lazily at the reference site. Direct handle props should keep their existing behavior. This is a repair direction, not a claim of a completed upstream fix. Regression coverage should include forwarded Retry, descriptor access after await, nested shadowed identifiers, and unchanged query/derived producer semantics.

This is an ordinary functional recovery defect: a reusable child button can leave a failed query stuck after Retry. No security or data-isolation failure is asserted.

repro.mjs
import assert from 'node:assert/strict';
import { existsSync, readFileSync } from 'node:fs';
import { createRequire, registerHooks } from 'node:module';
import { resolve } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';

// Native source-level reproduction, with synthetic renderer identities.
// No browser, compiler transform, server, or network request is simulated.
// Usage: node repro.mjs ./octane-source
const source = resolve(process.argv[2], 'packages/octane/src');
const requireTool = createRequire(new URL('./tools/package.json', import.meta.url));
const { transformSync } = requireTool('esbuild');
const alienSystem = pathToFileURL(requireTool.resolve('alien-signals/system')).href;
registerHooks({
  resolve(specifier, context, next) {
    if (specifier === 'alien-signals/system') {
      return next(alienSystem, context);
    }
    try { return next(specifier, context); }
    catch (error) {
      if (error.code !== 'ERR_MODULE_NOT_FOUND' || !specifier.startsWith('.') ||
          !specifier.endsWith('.js') || !context.parentURL?.startsWith('file:')) throw error;
      const ts = new URL(specifier.slice(0, -3) + '.ts', context.parentURL);
      if (!existsSync(fileURLToPath(ts))) throw error;
      return next(ts.href, context);
    }
  },
  load(url, context, next) {
    if (!url.startsWith('file:') || !url.endsWith('.ts')) return next(url, context);
    return { format: 'module', shortCircuit: true,
      source: transformSync(readFileSync(fileURLToPath(url), 'utf8'), {
        loader: 'ts', format: 'esm', target: 'esnext',
      }).code };
  },
});
const load = name => import(pathToFileURL(resolve(source, name)).href);
const { __queryAt } = await load('signals/query-facade.ts');
const { __signalAt } = await load('signals/facade.ts');
const { runWithSignalOwner: enter, retireSignalOwnerIdentity: retire } =
  await load('signals/owner-context.ts');

function component(documentOwner, instanceKey) {
  return { scopeKey: documentOwner.scopeKey, documentOwner,
    instanceOwner: {}, instanceKey };
}
function arm(parent) {
  return { ...parent, instanceOwner: {}, enclosingOwner: parent };
}
async function settle() {
  for (let i = 0; i < 16; i++) await Promise.resolve();
}
function sample(owner, query) {
  try { return { status: 'ready', value: enter(owner, () => query.get()) }; }
  catch (error) {
    return typeof error?.then === 'function' ? { status: 'pending' } :
      { status: 'error', error: error.message };
  }
}
async function retry(forwarded) {
  const documentOwner = { scopeKey: forwarded ? 'forwarded' : 'direct' };
  const panel = component(documentOwner, 'Panel');
  const failedArm = arm(panel);
  const fallback = arm(panel);
  const button = component(documentOwner, 'RetryButton');
  const nextArm = arm(panel);
  let calls = 0;
  let reject;
  const first = new Promise((_, fail) => { reject = fail; });
  const query = enter(panel, () => __queryAt('i:result', () => 1, () => {
    calls++;
    return calls === 1 ? first : Promise.resolve('loaded');
  }));
  try {
    assert.equal(sample(failedArm, query).status, 'pending');
    reject(new Error('first load failed'));
    await settle();
    assert.equal(sample(failedArm, query).status, 'error');
    retire(failedArm);

    // Parent-created closure, invoked by either its native host or a child host.
    const callback = enter(fallback, () => () => query.reset());
    enter(forwarded ? button : fallback, callback);
    // Model boundary reset replacing the fallback with a fresh try arm.
    retire(button);
    retire(fallback);
    sample(nextArm, query);
    await settle();
    return { ...sample(nextArm, query), loaderCalls: calls };
  } finally {
    for (const owner of [nextArm, button, fallback, failedArm, panel, documentOwner]) retire(owner);
  }
}
function childHandleControl() {
  const documentOwner = { scopeKey: 'handle-control' };
  const parent = component(documentOwner, 'Parent');
  const child = component(documentOwner, 'Child');
  const count = enter(parent, () => __signalAt('i:count', 0));
  try {
    enter(parent, () => count.set(4));
    assert.equal(enter(child, () => count.get()), 0);
    enter(child, () => count.set(7));
    const result = { parent: enter(parent, () => count.get()), child: enter(child, () => count.get()) };
    assert.deepEqual(result, { parent: 4, child: 7 });
    return result;
  } finally {
    for (const owner of [child, parent, documentOwner]) retire(owner);
  }
}
const direct = await retry(false);
const forwarded = await retry(true);
assert.deepEqual(direct, { status: 'ready', value: 'loaded', loaderCalls: 2 });
const childHandle = childHandleControl();
console.log(JSON.stringify({ node: process.version, direct, forwarded, childHandle }, null, 2));
if (forwarded.status !== 'ready') {
  console.error('FAIL: forwarded retry did not reset the declaring component query');
  process.exitCode = 1;
}

Activity

  1. added a commit that references this issue on Oct 4, 2026
    4601dd3
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