Skip to content

Keep lifecycle-descended IndexedDB commits ahead of terminal navigation #878

Closed

Description

@wieslawsoltes

Parent: #269
Release acceptance epic: #227

Problem

A top-level reload/navigation can reach the native host after the first zero-delay tasks queued by beforeunload/pagehide, while persistence work descended from those tasks is still active.

The exact unchanged Code OSS Release package at AppScene cd0a02e / WebScene a7943723 demonstrates the failure:

  1. VS Code accepts and encrypts an MCP input.
  2. IStorageService.flush(SHUTDOWN) fires onWillSaveState.
  3. Its browser storage layer schedules the workspace mcpInputs IndexedDB transaction.
  4. WebScene runs the first lifecycle timer, then publishes reload.
  5. AppScene replaces the realm before descendant transaction timers and the native IndexedDB load/store completion chain finish.
  6. The second workbench retains the encrypted secret provider but has no mcpInputs metadata, and upstream editStoredInput fails while reading the missing entry.

PR #877 correctly established the first browser-task boundary. It intentionally excludes timers created by those timers to prevent an arbitrary self-refilling timer from starving navigation. That bound is too shallow for browser persistence, whose transaction contract necessarily spans descendant zero-delay tasks and native async completion.

Proposed runtime contract

  • Tag non-repeating zero-delay tasks scheduled by terminal lifecycle listeners, their microtasks, or an already tagged task.
  • Propagate that tag into native IndexedDB operations started by the task and through their Promise continuations.
  • Keep only the terminal reload/navigation host request private while tagged persistence work is pending.
  • Publish the request immediately after tagged timers and IndexedDB operations drain.
  • Do not wait for unrelated timers, intervals, animation frames, or pre-existing IndexedDB operations.
  • Preserve bounded host-request capacity, FIFO order, recursive-navigation coalescing, veto/error cleanup, and task-source fairness.

Acceptance

  • An IndexedDB write scheduled from beforeunload through a zero-delay task is durable before the native reload request becomes visible.
  • A native IndexedDB load/store completion and its Promise continuation remain inside the terminal persistence boundary.
  • A nested zero-delay task in that continuation is included.
  • Unrelated/future/repeating timers do not delay navigation.
  • Vetoed and failed lifecycle paths publish no host request and leak no reservations or tagged work.
  • Reload and same-origin navigation preserve FIFO order and exact-once lifecycle dispatch.
  • Focused Release regression covers durable restart visibility and a bounded 1,000-request performance lane.
  • Rebuilt unchanged Code OSS Release completes the two-realm MCP persistence smoke.

Evidence

Exact retained artifact:
vscode-demo/artifacts/smoke-cd0a02e-a7943723-mcp-retry/native-smoke.json

The second realm reports navigation count 2, first beforeunload/pagehide, no IndexedDB conflict, and then TypeError: Cannot read properties of undefined (reading 'value') because the stored MCP input record is absent.

Activity

  1. added
    bug
    vscode-oss/planned
    on Sep 20, 2026
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

    bugvscode-oss/planned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions