From ce382a8557416be9a08fb1489576d3b74b75595f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 23 Sep 2026 05:32:17 +0200 Subject: [PATCH] Cut 15: subscribe to revisions after any sign-in, not only the redirect flow, and keep a poll fallback (PA.f191) main.ts subscribed to the api/eve/events revision stream exactly once, in an `if (api.hasAuthenticatedSurface())` check that ran right after host.start() and the redirect-flow resumeHeimdallAccess() call resolved. authenticatedSurface reflects whatever the *last* surface() fetch saw, and it can flip from false to true well after that point: a player who signs in through the in-page gate (heimdall.auth_completion_status.v1, resolved entirely inside the vendored host's own submit()/refresh() cycle, on its own 100ms-later timer) never retriggers that one-shot check. That tab never got a revision subscription for the rest of the session, so every answer after the first was refused as stale and the card looked frozen. trySubscribeToRevisions() replaces the one-shot check: idempotent, called after host.start(), after the redirect flow's own refresh, and on a 2s recheck interval, since main.ts has no direct hook into the in-page flow's own completion moment. pollMs moved from 0 to 5000: the app relied entirely on SSE for live updates, so a dropped stream (closed by an intermediary, or simply never subscribed) had no fallback at all. The vendored host's own poll already no-ops when the surface version has not moved, so this is a low-frequency safety net, not a second primary channel. Verified: npm run typecheck (clean) and npm test (3/3, unchanged) in web/. No headless-browser harness exists for main.ts's transport/host wiring; this was verified by tracing the vendored host's own submit()/refresh()/consumeCommandResult control flow (vendor/eve/packages/eve-browser-lowering/dist/index.js) against the fix, not by an automated end-to-end test. Flagging as a follow-up in the Cut 15 report rather than adding test infrastructure out of scope for this cut. Co-Authored-By: Claude Sonnet 5 --- web/src/main.ts | 53 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/web/src/main.ts b/web/src/main.ts index e9e9e62..3df2675 100644 --- a/web/src/main.ts +++ b/web/src/main.ts @@ -99,7 +99,14 @@ const api = new GhostlightEveTransport(); const host = new EveBrowserProviderHost(surfaceHost, api, { body: document.body, clientId: "ghostlight.browser", - pollMs: 0, + // PA.f191: this used to be 0 (no poll at all), relying entirely on the + // `revision` SSE subscription below for every live update. A dropped + // stream — closed by an intermediary, or never subscribed at all (see + // `trySubscribeToRevisions` below) — then froze the card with no recovery + // short of a manual reload. This poll is deliberately low-frequency: it is + // a fallback net, not the primary channel, and `host.refresh()` is already + // a no-op when the surface version has not moved. + pollMs: 5_000, requestedSurfaceId: "ghostlight.play", source: "Ghostlight", statusElement: status, @@ -111,7 +118,34 @@ window.addEventListener("unhandledrejection", event => { status.textContent = event.reason instanceof Error ? event.reason.message : String(event.reason); }); +// PA.f191: `api.hasAuthenticatedSurface()` reflects whatever the *last* +// `surface()` fetch saw, and that flag can flip from false to true well +// after this module's own startup sequence finishes — a player who signs in +// through the in-page gate (`heimdall.auth_completion_status.v1`, resolved +// entirely inside the vendored host's own `submit()`/`refresh()` cycle, +// never observed by this file directly) authenticates on a timer this file +// has no direct hook into. A one-shot check right after startup only ever +// caught the redirect flow (`resumeHeimdallAccess`'s own `complete` +// callback, below); the in-page flow left the tab with no `revision` +// subscription for the rest of the session, so every answer after the first +// was refused as stale and the card looked frozen. `trySubscribeToRevisions` +// is idempotent and cheap to call speculatively — `hasAuthenticatedSurface()` +// is a field read — so it is called at every point this file can observe an +// authentication transition, plus on a short recheck interval to catch the +// in-page flow it cannot observe directly any other way. +let revisionsSubscribed = false; +function trySubscribeToRevisions(): void { + if (revisionsSubscribed || !api.hasAuthenticatedSurface()) return; + revisionsSubscribed = true; + const events = new EventSource("api/eve/events"); + events.addEventListener("revision", () => void host.refresh()); + events.addEventListener("error", () => { + status.textContent = "Live revision notices are unavailable; your authoritative surface remains safe to refresh."; + }); +} + await host.start(); +trySubscribeToRevisions(); await resumeHeimdallAccess({ complete: async handle => { const result = await api.completeAuthentication(handle); @@ -119,13 +153,16 @@ await resumeHeimdallAccess({ await heimdallAccessBrowserAdapter.consumeCommandResult?.(result.pluginPayload); } await host.refresh(); + trySubscribeToRevisions(); }, }, { appSlug: "ghostlight" }); +trySubscribeToRevisions(); -if (api.hasAuthenticatedSurface()) { - const events = new EventSource("api/eve/events"); - events.addEventListener("revision", () => void host.refresh()); - events.addEventListener("error", () => { - status.textContent = "Live revision notices are unavailable; your authoritative surface remains safe to refresh."; - }); -} +// The in-page gate's own completion never calls back into this file: it +// resolves inside the vendored host's `submit()` (a command dispatch) and +// its own `window.setTimeout(() => void host.refresh(), 100)`, which is the +// one place `api.hasAuthenticatedSurface()` gets re-evaluated for that flow. +// This is the only vantage point this file has on that transition; the +// pollMs fallback above shares the same "cheap, idempotent, safe to run +// speculatively" reasoning. +window.setInterval(trySubscribeToRevisions, 2_000);