Skip to content

Run each application instance on its own dedicated thread (ADR 0009) - #159

Merged
pragmatrix merged 5 commits into
masterfrom
instance-runtime-isolation
Sep 28, 2026
Merged

pragmatrix merged 5 commits into
masterfrom
instance-runtime-isolation

Conversation

@pragmatrix

@pragmatrix pragmatrix commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner

Why

Every instance future ran on the shell's shared multi-thread runtime. Each instance iteration is one long synchronous poll body — select, shape lines, update the view, submit — and tokio can't preempt synchronous work, so in debug builds an instance under an output burst starved the desktop completely. mt carried an unconditional task::yield_now() per iteration as a mitigation, which is overhead when the desktop is idle and not a real fix.

Summary

  • Each instance now runs on its own named OS thread (massive <id>) with its own tokio runtime, built inside the thread closure so the runtime's lifetime encloses block_on (dropping it early would abort spawn_blocking pty readers).
  • Application gained RuntimeKind (CurrentThread default, MultiThread opt-in for instances with internal parallelism) via Application::with_runtime_kind; the desktop exports it.
  • The instance TaskContext — including the shaping context — is created on the desktop task and moved into the thread explicitly, since the instance thread runs outside the desktop's task-locals.
  • Instance threads are detached: completions arrive on an mpsc channel that join_next() drains; shutdown stays cooperative and the process end reaps unresponsive threads.
  • The thread body is one fallible function driven to completion before a single completion report, so any setup failure (e.g. a failed runtime build) still reaches join_next instead of hanging it.
  • Panic payloads from instance threads are converted to messages with the panic-message crate (zero dependencies, mirrors rustc's own unpacking logic) instead of a hand-rolled downcast chain.
  • ADR 0009 records the decision and rejected options; the old plan doc is folded into it.

Validation

  • cargo check -p massive-desktop, cargo fmt --check -p massive-desktop clean
  • cargo test -p massive-desktop: 46 passed
  • Runtime flavors verified empirically: nested current_thread runtime runs block_on with timers and cross-thread wakes (ADR 0009, "Considered options")

Assisted by an AI coding agent.

@pragmatrix
pragmatrix merged commit a839795 into master Sep 28, 2026
2 checks passed
@pragmatrix
pragmatrix deleted the instance-runtime-isolation branch September 28, 2026 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant