Skip to content

Lynx first-screen warm-plan drain loop is unbounded: a cyclic warm graph stalls the main thread #72

Closed as not planned

Description

@Huxpro

Found by an adversarial audit of the #58 L0–L3 equivalence claims.

This is a pre-existing defect, not a regression from the #59→#63→#64→#65 stack. It reproduces identically on base 6079a6804 (verified in a worktree). It is filed because the audit surfaced it and it is the most severe finding of that audit, not because it counts against any stack claim.

Root cause

packages/lynx/src/main-renderer.ts:1358:

for (let index = 0; index < ACTIVE_FIRST_SCREEN_WARM_PLANS.length; index++) {
	warmFirstScreenPlan(ACTIVE_FIRST_SCREEN_WARM_PLANS[index]);
}

The loop bound is re-evaluated on every iteration, and warmFirstScreenPlan can append to the very array being iterated — useBatch's early-return path at packages/lynx/src/main-renderer.ts:1345-1348 does exactly that:

if (items.length === 0) {
	if (warm !== undefined) ACTIVE_FIRST_SCREEN_WARM_PLANS.push(warm);
	return;
}

So a cycle in the warm graph grows the queue faster than the loop drains it. FIRST_SCREEN_WARM_DEPTH_CAP (64) does not apply on this path: it bounds nesting depth, not queue length.

Reproduction

Two mutually recursive components whose warm plans are useBatch([], () => warmChild(Other, {})) — the compiler-generated warm shape, matching the repo's own fixtures at packages/lynx/tests/main-renderer.test.ts:280 and :320.

W1 (direct-recursion control): maxNestedDepth 63     ← cap works here
W2 (useBatch-mediated cycle):  expected 200001 to be less than or equal to 64

200,001 warm-plan invocations in 97 ms, terminated only by the probe's own guard — nothing inside the renderer stops it. Raising the guard to 20,000 yields 20,001; to 200,000 yields 200,001. It does not converge.

W1 is the control that establishes the cap is real and intended, which is what makes W2 a defect rather than a design choice.

Consumer impact

An unbounded synchronous stall on the Lynx main thread during the first screen — the exact code path issue #58 L3 exists to make fast. Reaching it requires a cycle in the warm graph (mutually recursive components, or a self-warming recursive component). Authors can create that without touching the renderer, because the warm-plan shape is compiler-generated rather than hand-written.

Suggested direction

Snapshot the queue length before draining, or track visited plans across the drain, so a cyclic warm graph terminates the way direct recursion already does under FIRST_SCREEN_WARM_DEPTH_CAP.

Verification performed

Reproduced independently of the finding agent. Base-vs-head comparison performed by the finding agent in a 6079a6804 worktree and reported as identical. No red test is committed for this on the audit branch: that branch is scoped to counterexamples against the stack's own equivalence claims, and this is neither caused by nor claimed against them.

Activity

  1. added
    bug
    on Aug 18, 2026
  2. Huxpro commented on Aug 18, 2026

    @Huxpro
    OwnerAuthor

    Withdrawing this — the compiler cannot emit the shape the unbounded loop requires

    This report is wrong and I am closing it. A refuter established the reachability question I never asked, and every point holds.

    The precondition is unreachable

    The drain loop at main-renderer.ts:1358 re-reads .length, so it is unbounded only if a __warm plan's body calls useBatch([], warm) — that early-return path is the sole push site into ACTIVE_FIRST_SCREEN_WARM_PLANS.

    I justified that precondition by citing packages/lynx/tests/main-renderer.test.ts:280 and :320 as "byte-for-byte the compiler warm shape." That was a misreading. Those lines are component bodies:

    defineUniversalComponent('lynx', () => { useBatch([], () => warmChild(...)); return universalTry(...) })

    The repo's only actual __warm example is line 314:

    (Branch as any).__warm = (props) => warmChild(props.child, props.childProps)   // no useBatch

    I moved a body-level construct into a warm plan and called it the same shape.

    The real compiler shape, established by execution

    buildWarmArtifacts (packages/octane/src/compiler/compile.js:15185-15201) emits the plan as (__wp) => { const props = __wp; <warmMemo(...)>; <warmChild(...)> } — only warmMemo and warmChild calls, each optionally if-guarded. Compiling two mutually recursive async components, and the repo's own packages/octane/tests/_fixtures/parallel-use.tsrx (32 emitted plans), yields zero useBatch inside any __warm body. The empty-items registration _$useBatch([], () => _$warmChild(B, ...)) is emitted in the component body, structurally disjoint from the drain.

    So the push site and the drain site cannot meet: pushes come only from component bodies during render; the drain executes only __warm plans, which contain no pushes.

    The one non-compiler __warm in the renderer is lazy's (main-renderer.ts:580), whose initialize starts the chunk load and never calls useBatch; the useBatch([thenable!]) at :569 is in the wrapper's render body with a non-empty array, which takes the drain branch, not the push branch.

    With the real shape, every cycle is bounded

    Running the identical warm-graph cycles I claimed were unbounded, using the compiler's actual output: A↔B mutual recursion 63, warmMemo+warmChild cycle 63, self-recursion 63 — exactly the FIRST_SCREEN_WARM_DEPTH_CAP behaviour I described as "the intended bound" and wrongly claimed does not apply. Each commits the correct pending arm in ~1 ms.

    Two further points against the report: the compiler already carries a deliberate guard for the pure-self-recursion case (compile.js:15100-15111), and the main client runtime's runActiveWarmPlans (runtime.ts:9207-9238) snapshots into a local array before draining, so it is structurally immune regardless.

    What went wrong on my side

    I reproduced the 200,001 iterations myself and treated that as confirmation. It confirmed the mechanism, not the reachability — the probe fed a hand-written __warm plan, and I never asked whether the compiler emits that shape. That is the same error the panel caught in #71, #76, #77 and #73: a real mechanism, an unreachable trigger, and a severity claim built on the gap between them.

    I called this the most severe finding of the audit. It is not a finding at all.

    Closing as not-planned. No change is warranted.


    Generated by Claude Code

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

    agent-authoredbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions