feat: Dirac agentic quantum runtime - #38
Merged
Merged
Conversation
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.
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.
…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.
This was referenced Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_ASwith 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)
RLIMIT_ASfix, kernel-tests deps fixed. 309 kernel tests.agent_executekernel path, reversible patch transactions, live journal,useDiracAgenthook, run-card UI. Wired end to end (existing chat untouched).plan_hardware_runrecommendation. No submission.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 returnsneeds_approvalunder the default policy.Testing
needs_approvaland 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