Skip to content

explorer: document the 'every loadRes caller chases with tryEnterPointModeIfNeeded' invariant #194

@rdhyee

Description

@rdhyee

Follow-up from #191 (issue #190 fix 2).

Context

tryEnterPointModeIfNeeded() (introduced in #191) short-circuits when currentRes !== 8 && loading === true:

async function tryEnterPointModeIfNeeded() {
    if (mode === 'point') return;
    if (viewer.camera.positionCartographic.height >= ENTER_POINT_ALT) return;

    let res8Ready = currentRes === 8;
    if (!res8Ready && !loading) {        // ← here
        res8Ready = await loadRes(8, h3_res8_url, { ... });
    }
    ...
}

This is safe in the current code because every loadRes call site in the cell is followed by an await tryEnterPointModeIfNeeded(), so any in-flight load that prevents this call from acting will itself trigger a chase when it settles.

But the safety relies on this invariant — and a future contributor adding a new loadRes call site without the chase would silently break supersession recovery. The bug would only surface as a rare liveness regression that's hard to attribute back to the missing chase.

Proposed change

One-line comment near the !loading guard plus a short note in the helper's existing doc-block:

async function tryEnterPointModeIfNeeded() {
    if (mode === 'point') return;
    if (viewer.camera.positionCartographic.height >= ENTER_POINT_ALT) return;

    let res8Ready = currentRes === 8;
    // Invariant: when an unrelated loadRes is in flight (`loading === true`),
    // we leave recovery to that call site's own post-await chase. Every
    // loadRes caller in this cell must call tryEnterPointModeIfNeeded()
    // afterwards — otherwise this short-circuit can strand the user.
    if (!res8Ready && !loading) {
        ...
    }
    ...
}

And a parallel sentence in the doc-block at the top of the helper.

Verification

grep -n 'loadRes(' explorer.qmd should return only call sites that are immediately followed by await tryEnterPointModeIfNeeded(), OR are inside tryEnterPointModeIfNeeded() itself, OR are in code paths where the user can't be at point altitude (e.g. inside exitPointMode flow).

Refs

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