Skip to content

[P0][Concurrency] Replace the global RuntimeBridge lock with bounded per-workspace sessions #691

Description

@wesleysimplicio

Objective

Allow independent workspaces and safe read-only calls to use Runtime concurrently while preserving strict ordering for conflicting effects within one workspace.

RuntimeBridge currently owns one global re-entrant lock around process selection and tool calls. This serializes unrelated workspaces and prevents the Loop Hub from realizing bounded multi-task throughput.

Required concurrency model

  • One lazy Runtime MCP session per canonical workspace identity.
  • Per-workspace lifecycle lock for start/reconnect/shutdown.
  • Per-resource effect leases for writes.
  • Concurrent reads only when advertised safe by Runtime capabilities.
  • Global governor only for configured CPU/RAM/process ceilings, not for all calls.
  • Fair bounded queues, deadlines, cancellation and backpressure.

Implementation steps

  1. Define WorkspaceSession state machine: absent, starting, ready, draining, reconnecting, failed, closed.
  2. Canonicalize workspace identity safely and reject symlink/path replacement attacks.
  3. Replace the bridge-wide call lock with a concurrent session registry plus per-session locks.
  4. Add bounded inflight and queue limits per workspace and globally.
  5. Classify tools as read, write, process or exclusive from the Runtime capability manifest.
  6. Route conflicting write sets through leases/fencing; permit safe non-conflicting reads.
  7. Implement request correlation so out-of-order MCP responses are matched correctly.
  8. Add cancellation at safe boundaries and deterministic timeout results.
  9. Reconnect with session generation IDs; never replay uncertain writes automatically.
  10. Drain and close sessions without orphan processes.
  11. Publish queue depth, wait time, inflight count, reconnects and throttling receipts.
  12. Benchmark one workspace serial safety and multiple workspace parallel throughput.

Failure tests

  • Two simultaneous writes to the same path.
  • Reads during a write.
  • Independent workspaces under load.
  • Runtime crash with queued and inflight calls.
  • Timeout followed by late response.
  • Cancellation during process execution.
  • Workspace deletion/replacement.
  • Queue saturation and fairness.
  • Shutdown while requests are pending.
  • Duplicate idempotency keys across reconnect.

Acceptance criteria

  • Independent workspaces execute concurrently up to configured bounds.
  • Conflicting effects inside one workspace remain serialized/fenced.
  • No response can be delivered to the wrong request.
  • Queueing and backpressure are observable and bounded.
  • Reconnect does not duplicate uncertain effects.
  • Shutdown leaves zero owned Runtime processes.
  • p50/p95 throughput and RSS are measured against the current global-lock baseline.
  • Quality/evidence coverage does not regress.
  • Tests run locally/containerized without paid GitHub Actions.

Relations

  • Runtime build/resource leases: wesleysimplicio/simplicio-runtime#3035
  • Runtime warm serve: wesleysimplicio/simplicio-runtime#2983

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions