Skip to content

TUI hangs on a blank screen when the server worker fails to bootstrap; two unit tests flake in CI #7

Description

@mohsensadr

Description

Two related problems, both in the TUI worker/RPC path and its test coverage.

  1. Worker bootstrap failure hangs the TUI

#5 fixed early RPC requests being dropped by having the client hold requests
until the worker posts rpc.ready. That closes the drop, but not the hang: if
the worker dies before it reaches Rpc.listen(), rpc.ready never arrives and
every call sits in the client outbox forever. The user sees the same blank
screen #5 set out to fix, just from a different cause.

worker.onerror only logs, and neither the transport setup nor
validateSession has a timeout, so there is no path that ever rejects.

Two smaller issues in the same file:

  • listen() looks methods up with a bare rpc[method], which resolves through
    Object.prototype. A request for toString/constructor invokes it and
    replies with a bogus rpc.result instead of an unknown-method error.
  • The queue() comment claims it must be "the first statement" in the worker.
    That is not achievable: ESM evaluates imports before the module body, and
    worker.ts transitively imports core/global, which has a top-level await, so
    execution yields to the event loop before queue() runs. queue() narrows
    the window; the rpc.ready handshake is what actually guarantees delivery.
    Worth correcting so nobody later relies on queue() for a new pre-ready
    message type.
  1. Unit tests failing in CI

unit (linux) and unit (windows) have both been intermittently red on main,
independent of the above.

  • linux: mcp.McpOAuthCallback > ensureRunning starts a server that isRunning() reflects. The callback server is a module-level singleton and bun shares
    module state across test files in one process, so a server left listening by
    an earlier file makes the test's opening
    expect(isRunning()).toBe(false) fail in ~1ms. The leak is
    oauth-auto-connect.test.ts: authenticate() starts the server and the file
    never stops it.

  • windows: rotating timeout flakes rather than real bugs. Three red runs hit
    three different tests, each a hardcoded per-test budget that a loaded runner
    exceeds (e.g. cancel with queued callers resolves all cleanly timing out at
    3s, in a file where sibling tests already take 2-8.5s on windows).

Plugins

No response

PhysicsCode version

No response

Steps to reproduce

Worker hang:

  1. Make the TUI worker fail during bootstrap (e.g. force Log.init to throw,
    or make an XDG directory unwritable so core/global's mkdir fails).
  2. Run physicscode tui.
  3. The TUI sits on a blank screen indefinitely. No error, no timeout.

oauth singleton leak:

  1. bun test test/mcp/oauth-auto-connect.test.ts
  2. Observe McpOAuthCallback.isRunning() is still true afterwards.
  3. Run any file ordered after it that asserts the server is stopped, e.g.
    test/mcp/oauth-callback.test.ts, and its first assertion fails
    (Expected: false / Received: true).

Screenshot and/or share link

No response

Operating System

Ubuntu 22.04 + Windows 11 (CI runners)

Terminal

No response

Activity

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions