Skip to content

feat(runtime-python): cross-tool bridge — typed returns + q-orca invocation - #13

Merged
jascal merged 2 commits into
mainfrom
feat/cross-tool-bridge-python
May 30, 2026
Merged

feat(runtime-python): cross-tool bridge — typed returns + q-orca invocation#13
jascal merged 2 commits into
mainfrom
feat/cross-tool-bridge-python

Conversation

@jascal

@jascal jascal commented May 30, 2026

Copy link
Copy Markdown
Owner

Implements the orca side of the cross-tool bridge (design doc docs/cross-tool-invoke-and-returns.md, merged in #12) in the Python runtime — the first runtime to adopt the protocol. A classical orca orchestrator can now invoke a q-orca quantum child over the bridge.

Full runtime-python suite: 105 passed (12 new), no regressions.

What's here

  • Parser: ## returns section → ReturnDef; InvokeDef.returns/shots via inline (invoke: QForward input:{…} shots:1024 returns:{prob: prob_bits_0}) and multi-line forms.
  • bridge.py: the q-orca bridge-protocol contract mirrored at version 1.0 — descriptor / invocation / result envelopes, BridgeError, and dispatch_foreign (invocation on stdin → result on stdout over a process boundary).
  • Runtime: OrcaMachine.register_foreign_runner(...) + outbound dispatch in start_child_machine — a foreign child is dispatched over the bridge, its returns bound into the parent context, and on_done/on_error fired.
  • Public API: ReturnDef, InvokeDef, and the bridge functions exported from the package.
  • Tests (tests/test_bridge.py): parser, protocol/conformance, dispatch over a real subprocess, and the end-to-end runtime path (orca Trainer → mock foreign quantum child ⇒ prob == 0.73, transitions to final). The mock runner keeps the suite free of a q-orca dependency.

Docs

Adds a Multi-Runtime Adoption section: the protocol is runtime-agnostic (JSON + process boundary, no shared AST/FFI), what TS/Go/Rust would each need, the outbound-cheap / inbound-needs-auto-driver asymmetry, and the shared-conformance-suite rationale.

Scope

First cut is the outbound direction (classical orchestrator → quantum child — the motivating QPC workflow). Inbound (orca as the invoked child) is symmetric protocol-wise but needs a per-runtime auto-driver for reactive machines — noted as follow-up.

Pairs with q-orca's bridge-protocol capability (implemented + archived on that side).

🤖 Generated with Claude Code

jascal and others added 2 commits May 29, 2026 22:01
…cation

Implements the orca side of the cross-tool bridge protocol (docs/cross-tool-invoke-and-returns.md)
in the Python runtime — a classical orca orchestrator can now invoke a q-orca quantum child.

- Parser: ## returns section -> ReturnDef; InvokeDef.returns/shots via inline
  (`invoke: QForward input:{...} shots:1024 returns:{prob: prob_bits_0}`) and multi-line forms.
- bridge.py: the q-orca bridge-protocol contract mirrored at version 1.0 — descriptor / invocation /
  result envelopes, BridgeError, and dispatch_foreign (invocation on stdin -> result on stdout).
- Runtime: OrcaMachine.register_foreign_runner() + outbound dispatch in start_child_machine
  (foreign child -> bridge), binding the child's returns into parent context and firing on_done/on_error.
- Public API: ReturnDef, InvokeDef, and the bridge functions exported from the package.
- 12 tests (parser, protocol/conformance, dispatch over a real subprocess, and the end-to-end
  runtime path with a mock foreign quantum child). Full runtime-python suite: 105 passed.

Docs: adds a "Multi-Runtime Adoption" section explaining the protocol is runtime-agnostic
(JSON + process boundary) and what TS/Go/Rust would each need, plus the shared-conformance-suite
rationale. Scoped to the outbound direction (orchestrator -> quantum child); inbound needs a
per-runtime auto-driver for reactive machines.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- dispatch_foreign: surface the foreign runner's stderr in BridgeError messages
  (both the non-zero-exit and exit-0-but-unusable-output cases).
- Document the return-binding precedence: a bound value overwrites the parent
  field; a return the child did not produce is skipped (soft), leaving the field
  unchanged; a malformed envelope / bad version is a hard BridgeError.
- Test: missing return field leaves the parent field at its default and on_done
  still drives the machine to final (13 bridge tests; full suite 106 passed).
- Docs: add the binding-semantics note to the invoke-returns section.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jascal
jascal merged commit ed7f1ba into main May 30, 2026
3 checks passed
@jascal
jascal deleted the feat/cross-tool-bridge-python branch May 30, 2026 02:11
jascal added a commit that referenced this pull request May 30, 2026
PyPI 0.1.27 was cut 2026-04-17, before the cross-tool bridge merged (#13),
so the published 0.1.27 lacks `register_foreign_runner` / the `bridge` module
even though main was still labeled 0.1.27. Bump to 0.1.28 so the bridge is
actually released, and re-sync the lagging `__init__.__version__` (was 0.1.26).

No code changes — version metadata only. 106 runtime-python tests pass.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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