feat(host): add worker resource-provider transport v1
- Add a host-managed helper process speaking framed JSON (4-byte BE length) with ping/open/read/write/close/shutdown, max 1 MiB frames and structured error mapping (ADR-0035). - Add StdHost::register_worker_resource_provider using the same protocol, kind-conflict and name-grant checks as the in-process provider; pure/strict refuse provider kinds. - Tests spawn a Python helper and cover round-trip, grant/mode denial and missing-program failure; no parser/Value/runtime/HostOp change. - Update ADR/spec/status/README/changelog and evidence; C ABI binding remains open. Gate: fmt, clippy -D warnings, 433 tests passed.
This commit is contained in:
1 parent
12be02e24b
commit
01f6fe46a7
12 files changed
+585
-8
No files matched your search
+8
-2
@@ -136,6 +136,9 @@ This is still a **local VM lane**, not a self-hosted GitHub Actions security URL
|
||||
PluginHandle `plugin/export` are read-only observation members (host id
|
||||
private); `stdlib/format.mq.md` reproduces builtin `打印`/`repr` for all 15
|
||||
value types, including Formula/Code/FunctionRef and Code UTF-8 byte length.
|
||||
- Worker resource provider transport (CM-A09, ADR-0035): host-managed helper
|
||||
process with framed JSON, ping/open/read/write/close; project-mode + name
|
||||
grant; trusted, not a sandbox; C ABI binding still open.
|
||||
- HTTP framing and client (P5/C10): `stdlib/net/http.mq.md` parses status,
|
||||
headers and `Transfer-Encoding: chunked`, builds requests, and an end-to-end
|
||||
test parses a loopback TCP response; fixture 71 pins the same logic. No host
|
||||
@@ -210,9 +213,9 @@ behavior. This table records only what is in this tree now.
|
||||
| P0 freeze (ADRs, spec deltas, baseline) | **P1 + partial P2 slice done** | ADR-0022 freezes CM-A01/CM-A02/CM-A03; ADR-0023 freezes CM-A04 (minimal List/Map/Text/Table observation and construction); ADR-0024 freezes CM-A05 (recoverable `Result` map convention); `spec/expression.ebnf`, `spec/evaluation.md`, `spec/value-wire.md`, `spec/analysis-v2.md`, `spec/security.md` updated; existing AST/value goldens unchanged |
|
||||
| P1 Memory + place assignment | **Implemented locally** | `Value::Memory`, run-scoped `MemoryStore` (64 KiB pages, 64 MiB total / 16 MiB region), `memory.new/size/grow`, `m[i]` read, `m[i] = byte`; semantic fixtures 45–47, runtime negatives 13–18, `examples/memory-buffer.mq.md`; evidence [`evidence/2026-11-20-memory-p1.md`](evidence/2026-11-20-memory-p1.md) |
|
||||
| P2 Marqdo-written allocator/data structures + minimal structure observation | **PASS (local pure lane); external stdlib repo publication pending** | `.mq.md`-only evidence: bump allocator with u32 codec, linked list, failed-allocation atomicity (48–50); CM-A04 structure primitives and a table filter (51–54, ADR-0023); a first-fit free-list allocator with block reuse, splitting, address-adjacent coalescing and `Result` maps (55, ADR-0024), a `Memory`-backed binary tree with recursive insert/in-order traversal (56), a `.mq.md` CSV row splitter (57), an open-addressing hash table with linear probing, update and `hash.full` (58), a `.mq.md` UTF-8 encoder over `Memory` (59), a validating UTF-8 decoder rejecting truncated, bad-continuation and surrogate/overlong input (60), a `Memory`-backed graph adjacency list (61), a recursive JSON parser for nested arrays/objects, strings with escapes, integers, booleans, null and error Results (62), a `Memory`-backed stack bytecode VM with PUSH/ADD/MUL/JMP/JZ/HALT (63), big-endian 16/32/64-bit plus LEB128 integer codecs (64), a `.mq.md` table sort rebuilding a new table from `table.row/columns/cell` (65), a table join (67), a quoted/escaped CSV row parser (68), table group (69), an Int matrix multiply (70), and a sparse-matrix multiply (73); the first-fit allocator also detects double free (`alloc.double_free`). Evidence: [`memory-p2-closure`](evidence/2026-11-20-memory-p2-closure.md), [`structure-api-p2`](evidence/2026-11-20-structure-api-p2.md), [`result-and-free-list-p2`](evidence/2026-11-20-result-and-free-list-p2.md). Local gate PASS: `crates/cli/tests/p2_closure.rs` runs 21 C01–C06/C11/C12 fixtures plus the stdlib table self-test in `--mode pure` (no foreign/plugin/import grants), scans sources for foreign/plugin/import shortcuts and compares value/stdout to goldens; evidence [`p2-closure-gate`](evidence/2026-11-20-p2-closure-gate.md). The bundled `stdlib/` tree, `std:` imports, digest verification, Analysis identity and frozen-CLI closure test are implemented (ADR-0028). Remaining outside C01–C12: publication as a separate external stdlib repository, and no remote CI URL. |
|
||||
| P3 Resource/Stream ABI | **PARTIAL** | ADR-0025/0026 CM-A06 slices: opaque `Resource`, `resource.open/read/write/close`, stdout write in pure/project, granted project-file read and buffered project-file write in project, EOF/closed/handle errors, wire/host rejection; strict permits only stdio/stdout and refuses file/network resources. Fixture 66 + CLI/host tests. CM-A07 **Compat-C** is implemented: when a program calls `打印/print`, the loader injects the bundled `stdlib/io.mq.md` and the runtime routes to `io.写值` (all 15 value types, UTF-8 via `Memory`, `resource.write(stdout)`); `HostOp::Print` and the legacy `Value::display()` print path are removed, and a missing bundle fails with `kernel.unavailable`. Strict permits only the existing stdio console channel. Still missing: directories, network, generic provider registry, Table storage, strict file/network resources. |
|
||||
| P3 Resource/Stream ABI | **PARTIAL** | ADR-0025/0026 CM-A06 slices: opaque `Resource`, `resource.open/read/write/close`, stdout write in pure/project, granted project-file read and buffered project-file write in project, EOF/closed/handle errors, wire/host rejection; strict permits only stdio/stdout and refuses file/network resources. Fixture 66 + CLI/host tests. CM-A07 **Compat-C** is implemented: when a program calls `打印/print`, the loader injects the bundled `stdlib/io.mq.md` and the runtime routes to `io.写值` (all 15 value types, UTF-8 via `Memory`, `resource.write(stdout)`); `HostOp::Print` and the legacy `Value::display()` print path are removed, and a missing bundle fails with `kernel.unavailable`. Strict permits only the existing stdio console channel. Providers are registered through ADR-0033 (in-process) and ADR-0035 (worker helper). Still missing: directories, C ABI provider binding, provider packages, strict provider support. |
|
||||
| P4 Table logical/physical migration | **PASS (local gate); T1/T2/T3 future** | ADR-0032/CM-A08: `Value::Table` semantics and GFM AST laziness unchanged; `stdlib/data/table.mq.md` provides select/filter/sort/append/set/join/group/`转GFM` as value-returning `.mq.md` functions with input immutability; zero Rust table algorithms were added. Cross-storage equivalence is pinned by fixture 72 (row Table vs `.mq.md` columnar store, identical headers/rows/cells). The optional T1/T2/T3 physical-storage/column-store migration was not required by the gate and is not implemented. |
|
||||
| P5 third-party Provider / TCP / HTTP | **PASS (local gate); external network/CI and C-Worker transport open** | C10: `stdlib/net/http.mq.md` + fixture 71 parse HTTP/1.1 status/headers/chunked bodies and build requests; `http_over_tcp.rs` runs a loopback HTTP exchange wholly in `.mq.md` over `resource.open("tcp",...)`. ADR-0034 IP-literal blocking TCP endpoint (exact IP grant, project-only, 5s timeouts) and ADR-0033 in-process `ResourceProvider` v1 (registration, protocol/kind checks, name grant, mock read/write provider) are tested. External DNS/TLS/UDP, host HTTP, provider packages and the C/Worker provider transport remain out of scope. |
|
||||
| P5 third-party Provider / TCP / HTTP | **PASS (local gate); external network/CI and C-Worker transport open** | C10: `stdlib/net/http.mq.md` + fixture 71 parse HTTP/1.1 status/headers/chunked bodies and build requests; `http_over_tcp.rs` runs a loopback HTTP exchange wholly in `.mq.md` over `resource.open("tcp",...)`. ADR-0034 IP-literal blocking TCP endpoint (exact IP grant, project-only, 5s timeouts) and ADR-0033 in-process `ResourceProvider` v1 (registration, protocol/kind checks, name grant, mock read/write provider) and ADR-0035 host-managed worker provider transport (framed JSON helper, ping/open/read/write/close, trusted-only) are tested. External DNS/TLS/UDP, host HTTP, provider packages and the C ABI provider binding remain out of scope. |
|
||||
| P6 performance / native backends | **BASELINE ONLY** | reproducible profile harness `tools/perf/bench.py` and [`p6-profile`](evidence/2026-11-20-p6-profile.md) for 7 workloads; no bytecode/JIT/columnar numeric backend or equivalence/optimization gate yet |
|
||||
|
||||
The P1 memory domain is pure computation: it needs no grant and is available in
|
||||
@@ -258,6 +261,9 @@ user-written allocator is explicitly **not** claimed.
|
||||
echo tests.
|
||||
- [`evidence/2026-11-20-table-cross-storage.md`](evidence/2026-11-20-table-cross-storage.md)
|
||||
— P4 row-store Table vs `.mq.md` columnar store equivalence for sort/filter.
|
||||
- [`evidence/2026-11-20-worker-provider.md`](evidence/2026-11-20-worker-provider.md)
|
||||
— ADR-0035 trusted worker resource-provider transport, framed-JSON helper
|
||||
round-trip and grant/mode/error tests.
|
||||
- [`evidence/2026-11-20-http-over-tcp.md`](evidence/2026-11-20-http-over-tcp.md)
|
||||
— P5/C10 `.mq.md` HTTP framing over a loopback TCP stream, stdlib module and
|
||||
end-to-end client test.
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
# ADR-0035: Worker resource-provider transport v1
|
||||
|
||||
Status: **Accepted (trusted helper transport; C ABI binding still open)**
|
||||
Date: 2026-11-20
|
||||
Relates to: `docs/MARQDO_COMPUTE_CORE_STDLIB_MIGRATION_RFC_0002.md`
|
||||
(CM-A09, CM-A11, P5), ADR-0033, ADR-0034
|
||||
Specs: `spec/evaluation.md`, `spec/security.md`
|
||||
Evidence: `docs/evidence/2026-11-20-worker-provider.md`
|
||||
|
||||
## Context
|
||||
|
||||
ADR-0033 provides an in-process `ResourceProvider` v1. CM-A09 also asks for a
|
||||
process boundary so an adapter can crash or hang without taking down the
|
||||
interpreter, and for a transport that can later be implemented by the C/Worker
|
||||
plugin ecosystem. This ADR adds the first process-boundary transport: a
|
||||
host-managed helper process speaking framed JSON.
|
||||
|
||||
It deliberately does **not** claim the C ABI or OS sandbox: the helper runs as
|
||||
the host user and is trusted. The existing plugin Worker transport remains the
|
||||
untrusted-plugin path; this is a resource-provider transport for explicitly
|
||||
trusted adapters.
|
||||
|
||||
## Decision
|
||||
|
||||
### 1. Framing and protocol v1
|
||||
|
||||
* 4-byte big-endian length + JSON, maximum 1 MiB per frame.
|
||||
* A `ping` handshake must succeed before the provider is registered.
|
||||
* Operations:
|
||||
|
||||
```text
|
||||
{"op":"open","kind","descriptor","rights"} -> {"ok":true,"token":u64}
|
||||
{"op":"read","token","max_bytes"} -> {"ok":true,"bytes":[u8...],"eof":bool}
|
||||
{"op":"write","token","bytes":[u8...]} -> {"ok":true,"count":u64}
|
||||
{"op":"close","token"} -> {"ok":true}
|
||||
{"op":"shutdown"} -> process exit
|
||||
{"ok":false,"code","message"} -> structured failure
|
||||
```
|
||||
|
||||
* Provider tokens stay in the helper; the host still issues the opaque language
|
||||
`ResourceHandle`. Bytes are copied per call.
|
||||
* The host maps helper error codes to the existing categories
|
||||
(`permission.denied`, `resource.closed`, `resource.exhausted`,
|
||||
`resource.unsupported`, otherwise `host.error`) and attaches the callsite
|
||||
span.
|
||||
* The provider is killed on drop; a protocol/IO failure is `host.error`, never a
|
||||
fallback to another transport.
|
||||
|
||||
### 2. Registration and authorization
|
||||
|
||||
* `StdHost::register_worker_resource_provider(name, kinds, program, args)` is a
|
||||
host embedding API. It validates name/kinds with the same rules as ADR-0033
|
||||
(non-empty, not `stdio`/`file`, no duplicate kind), then registers the
|
||||
provider under its kinds.
|
||||
* `resource.open` still requires the provider name grant and project mode.
|
||||
Pure/strict refuse provider kinds; strict remains fail-closed.
|
||||
* Language code cannot spawn a helper; registration is not reachable from
|
||||
`.mq.md` or a package import.
|
||||
|
||||
### 3. Security boundary
|
||||
|
||||
* The helper runs as the host user with full host privileges. It is **trusted**;
|
||||
this transport is not a sandbox and does not make arbitrary native code safe.
|
||||
* The project-mode + name-grant checks are the same as ADR-0033. The helper's
|
||||
own descriptor/rights validation is additional, not a substitute.
|
||||
* No network, filesystem or process rights are delegated implicitly by
|
||||
registration; the helper is responsible for its own behavior, and the host
|
||||
grant only authorizes the resource kind.
|
||||
|
||||
### 4. What remains for CM-A09
|
||||
|
||||
* A C ABI / plugin-Worker binding for `ResourceProvider` (buffer handoff,
|
||||
ownership, version negotiation through the plugin ABI).
|
||||
* Provider package installation, signatures and discovery.
|
||||
* Untrusted-provider isolation and strict-mode provider support.
|
||||
* The transport is versioned (`protocol_version() == 1`); future versions need a
|
||||
new ADR and negotiation.
|
||||
|
||||
## Consequences
|
||||
|
||||
* A trusted adapter can live in its own process and be reached through the same
|
||||
`resource.*`/`Result` language surface without touching the parser, `Value`,
|
||||
runtime dispatch or `HostOp`.
|
||||
* A helper crash/exit is a structured host error; the interpreter never falls
|
||||
back to a different provider.
|
||||
* The helper protocol is small enough to reimplement in C/Worker adapters later.
|
||||
|
||||
## Verification
|
||||
|
||||
`docs/evidence/2026-11-20-worker-provider.md` records a Python helper exercising
|
||||
ping/open/read/write/close, grant/pure/strict denial, missing-program error and
|
||||
the full workspace gate.
|
||||
@@ -0,0 +1,62 @@
|
||||
# RFC-CM CM-A09 evidence: worker resource-provider transport v1
|
||||
|
||||
Date: 2026-11-20 (Asia/Shanghai)
|
||||
Repository: `marqdo-cli`
|
||||
Baseline: `12be02e` plus this step's changes.
|
||||
Decision record: [ADR-0035](../adr/0035-worker-resource-provider-transport.md)
|
||||
Related: [in-process provider](2026-11-20-provider-abi-cm-a09.md),
|
||||
[STATUS §5](../STATUS.md).
|
||||
Scope: trusted host-managed helper process; not a sandbox and not the C ABI binding.
|
||||
|
||||
## Transport
|
||||
|
||||
`crates/marqdo-host/src/provider_worker.rs` implements the ADR-0035 framed-JSON
|
||||
transport:
|
||||
|
||||
```text
|
||||
4-byte BE length + JSON, max 1 MiB
|
||||
ping handshake
|
||||
open -> token
|
||||
read -> bytes+eof
|
||||
write -> count
|
||||
close
|
||||
shutdown on drop
|
||||
```
|
||||
|
||||
`StdHost::register_worker_resource_provider(name, kinds, program, args)` spawns
|
||||
the helper and registers it through the same validation/grant path as ADR-0033.
|
||||
The helper token never enters a language `Value`; the host still issues the
|
||||
opaque `ResourceHandle`.
|
||||
|
||||
## Tests
|
||||
|
||||
`crates/marqdo-host/tests/worker_provider.rs` (3 tests):
|
||||
|
||||
```text
|
||||
worker_provider_round_trips_through_framed_json
|
||||
Python helper: ping/open/read 5 "hello"/read rest " world" eof/write 3/close;
|
||||
second close resource.closed.
|
||||
|
||||
worker_provider_registration_requires_a_grant_and_project_mode
|
||||
no name grant -> permission.denied; pure/strict -> permission.denied.
|
||||
|
||||
missing_worker_program_is_a_structured_error
|
||||
non-existent helper -> kernel.unavailable (no fallback).
|
||||
```
|
||||
|
||||
No runtime, `HostOp`, `Value` or parser change was needed; language code still
|
||||
uses `resource.*`.
|
||||
|
||||
## Security boundary
|
||||
|
||||
The helper runs as the host user with host privileges. Registration is an
|
||||
embedding API, project-mode only, and requires a provider-name grant. It is
|
||||
trusted infrastructure, **not** an OS sandbox; the untrusted-plugin path remains
|
||||
the separate plugin Worker transport.
|
||||
|
||||
## Not done
|
||||
|
||||
* C ABI / plugin-Worker binding for `ResourceProvider`.
|
||||
* Provider package installation/signatures/discovery.
|
||||
* Untrusted-provider isolation; strict-mode provider support.
|
||||
* External DNS/TLS/network endpoint work beyond the IP-literal TCP slice.
|
||||
Reference in new issue
Block a user