Skip to content

feat: Dirac agentic quantum runtime - #38

Merged
calelamb merged 9 commits into
mainfrom
feat/dirac-agent-runtime
Jul 10, 2026
Merged

feat: Dirac agentic quantum runtime#38
calelamb merged 9 commits into
mainfrom
feat/dirac-agent-runtime

Conversation

@calelamb

@calelamb calelamb commented Jul 10, 2026

Copy link
Copy Markdown
Owner

Implements the approved Dirac agentic quantum runtime spec (docs/superpowers/specs), taking over from PR #37 with a corrected foundation. Full plan and delivered status: docs/dirac-agent/PLAN.md.

Why this replaces PR #37

A verified review found PR #37's 26k lines delivered only a dead-on-arrival OS-sandbox harness: it can never activate on a real user's machine (provisioning disabled by design), the macOS gate can never pass (Darwin rejects finite RLIMIT_AS with EINVAL), the actual agentic-coder feature was 0% built, and two CI walls were red for ~10h. This branch pivots to the vision: salvage the sound pieces, cut the dead-code sandbox, and build the closed-loop agent on right-sized subprocess isolation that ships.

Stages (all delivered on this branch, each green)

  • Stage 0 — Salvage & green pipeline: disposable Python agent worker (strict protocol + best-effort cross-platform rlimits + import denylist), macOS RLIMIT_AS fix, kernel-tests deps fixed. 309 kernel tests.
  • Stage 1 — Closed-loop simulator agent: framework-neutral multi-turn orchestrator, isolated agent_execute kernel path, reversible patch transactions, live journal, useDiracAgent hook, run-card UI. Wired end to end (existing chat untouched).
  • Stage 2 — Quantum intelligence: resource estimation, curated no-false-positive validators, distribution comparison (worst-delta + TVD) as agent tools.
  • Stage 3 — Hardware planner (shadow): compatibility filtering + explainable scoring + plan_hardware_run recommendation. No submission.
  • Stage 4 — Budgeted hardware autonomy: deterministic policy engine, atomic budget ledger + idempotency, submit/poll/cancel/analyze tools, live SocketSubmitPort, Settings toggle. Real-money submission ships OFF by default and cannot be enabled by model text — only by a human toggling Settings. Simulator runs freely; real QPU returns needs_approval under the default policy.

Testing

  • 461 frontend tests + 309 kernel tests pass; tsc, eslint, and production build clean.
  • Safety test enforced: under the default policy a real-QPU submission returns needs_approval and the submit port is never called.

Deferred (honest scope; noted in PLAN.md)

Full symbolic Quantum Program IR / T-count / algorithm-invariant library / golden corpus; real backend-specific transpilation previews (need provider SDKs in the kernel); provider-specific cost models + the full paid-submission reconciliation state machine + live-QPU smoke tests.

🤖 Generated with Claude Code

Salvages the sound, self-contained pieces of the Dirac agent runtime as the
right-sized execution isolation for model-generated code, and drops the
unshippable OS-sandbox harness (per docs/dirac-agent/PLAN.md).

- Add agent_protocol (strict wire contract), agent_limits (best-effort
  rlimits), agent_worker (disposable one-request subprocess with import
  denylist + bounded output), and their tests.
- Make apply_worker_limits cross-platform: skip RLIMIT_AS on macOS, which
  rejects any finite value with EINVAL (the bug that made the original Rust
  runtime unspawnable on Darwin); apply limits best-effort and independently.
- Install qiskit/qiskit-aer/cirq in kernel-tests.yml so the worker's real
  execution tests run (fixes the Kernel Tests wall).
- Salvage executor/qsharp_adapter improvements for the disposable worker.

301 kernel tests pass locally.
@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
landing Ready Ready Preview, Comment Jul 10, 2026 7:48am
nuclei Ready Ready Preview, Comment Jul 10, 2026 7:48am

calelamb added 3 commits July 10, 2026 00:52
Stage 1A of the Dirac agentic runtime: the multi-turn tool-use loop that
drives Claude to write, parse, simulate, compare, and repair a quantum program
through deterministic, typed, journaled, reversible services. Pure TypeScript
with dependency-injected ports (no React) so it is fully unit-tested.

- orchestrator: bounded multi-turn loop; feeds structured tool_result evidence
  back into the next model turn (true agentic loop); iteration + wall budgets;
  abort-signal cancellation; journaled state transitions.
- 8 typed tools (inspect/read/apply_patch/rollback/parse/simulate/compare/finish)
  with strict schemas; deterministic executors that never throw (errors become
  evidence for bounded repair).
- InMemoryWorkspace with hash-checked reversible patch transactions + conflict
  detection; append-only journal with (de)serialization.
- Live adapters: HttpModel (non-streaming Anthropic tool loop) and SessionKernel
  (promise wrapper over the serial kernel WebSocket).

50 new tests; 308 frontend tests pass; tsc + eslint clean.
Wires the Stage 0 isolated worker into the live kernel: a new agent_execute
WebSocket message runs one model-generated parse/simulate request in a fresh
subprocess (kernel/agent_worker.py, python -I) with resource limits + import
denylist, isolated from provider credentials and editor state, and returns a
correlated agent_result the frontend orchestrator awaits by request_id.

309 kernel tests pass (8 new end-to-end worker tests: real cirq parse/simulate,
credential-import block, protocol errors, request-id correlation).
Stage 1B: the agent orchestrator now runs against live app state end to end.

- liveKernel (SessionKernel) speaks the isolated-worker agent_execute/agent_result
  protocol, correlated by request_id, supporting concurrent in-flight requests.
- StoreWorkspace: WorkspacePort over the editor buffer with hash-checked
  reversible patch transactions + conflict detection.
- agentRunStore + StoreJournal: live run state/journal/patches for the UI.
- useDiracAgent: dedicated kernel socket, HttpModel + SessionKernel + workspace +
  journal + AbortController; desktop/API-key guards; all failure paths resolve to
  a failed run.
- AgentRunCard + AgentEntryPoint in the Dirac panel (existing chat untouched).

343 frontend tests pass (35 new); tsc + eslint + production build clean.
calelamb added 5 commits July 10, 2026 01:17
…rison)

Stage 2: give the agent real quantum-analysis capabilities in its loop.

- analysis.ts: pure estimateResources (qubit/gate/depth/two-qubit/histogram),
  validateProgram (curated no-false-positive structural/semantic checks: range,
  control==target, arity, measurement presence), compareDistributions (worst
  delta + total variation distance).
- New agent tools estimate_quantum_resources and validate_quantum_program;
  compare_quantum_results now reports TVD + ordered per-state deltas.

371 frontend tests pass (28 new); tsc + eslint clean.
Stage 3: the agent can recommend a compatible quantum backend with explainable
scoring, in shadow mode — no submission of any kind.

- hardwarePlanner.ts: pure filterCompatible (qubit count, online status,
  gate-set coverage with CNOT/CX synonyms, conservative to avoid false
  rejects), scoreBackend (weighted queue/error/headroom/status factors), and
  planHardwareRun (ranked candidates + rejected reasons + selection rationale).
- New plan_hardware_run agent tool; getBackends threaded through AgentDeps ->
  ToolContext; useDiracAgent supplies the live backend list.

388 frontend tests pass (17 new); tsc + eslint clean; no submission paths.
Stage 4A: the deterministic safety core for autonomous hardware submission.
Real-money submission is OFF by default and cannot be enabled by model text.

- policy.ts: evaluateSubmission — simulator allowed by default; real QPU returns
  needs_approval whenever autonomousHardwareEnabled is false (dominates every
  other check); allow only when provider/shots/qubits/depth/cost all pass.
  DEFAULT_POLICY is safe (autonomous off, allowQpu off, maxSpend 0).
- budgetLedger.ts: atomic reserve/commit/release + idempotency keys +
  JSON persistence.
- submitPort.ts: injected SubmitPort interface + deterministic FakeSubmitPort.
- submit/poll/cancel/analyze_hardware_result tools that submit ONLY on an
  'allow' decision, are idempotent, and degrade to evidence (never throw).

Safety test enforced: under DEFAULT_POLICY a real-QPU submit returns
needs_approval and the submit port is never called. 439 tests pass; tsc/eslint clean.
Stage 4B: wire the policy-gated submission machinery to the app, default OFF.

- settingsStore agentHardware group (autonomousHardwareEnabled:false, allowQpu:
  false, maxSpend:0, ...) persisted with a safe-default overlay so a corrupt blob
  can never silently enable autonomy.
- policyFromSettings maps settings -> AutonomyPolicy (default => autonomous off).
- SocketSubmitPort: SubmitPort over the kernel socket (submit/status/results/
  cancel correlated by job id; counts->probabilities).
- costEstimate: 0 for simulator, null (unmodeled) for QPU.
- useDiracAgent builds policy/ledger/submitPort/estimateCost fresh per run and
  passes them to runAgent; submit port reuses the one socket and is disposed.
- SettingsPanel: 'Agent Hardware Autonomy' toggle (off) + max-spend, with a
  real-money warning.

461 frontend tests pass (22 new); tsc + eslint + build clean; defaults verified safe.
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