fix(m0.6): worker manifest independence and status reconciliation

- pass workers an explicit temporary manifest so plugin.yaml naming is not a
  hidden constraint
- remove temporary manifests after handshake
- reconcile STATUS with implemented multi-export, broker, worker, handle,
  Git/env and CI behavior; document strict isolation as the remaining blocker
This commit is contained in:
cflmy committed 2026-11-20 11:53:07 +08:00
1 parent 44c2df2361
commit c779f6c24e
2 files changed
+77 -47

No files matched your search

+44 -17
View File
@@ -39,21 +39,35 @@ impl std::fmt::Debug for WorkerPlugin {
impl WorkerPlugin { impl WorkerPlugin {
/// Spawn a worker for `manifest` and wait for its ready frame. /// Spawn a worker for `manifest` and wait for its ready frame.
pub fn spawn(manifest: &PluginManifest, base_dir: &Path) -> Result<Self, PluginError> { pub fn spawn(manifest: &PluginManifest, base_dir: &Path) -> Result<Self, PluginError> {
let manifest_path = if base_dir.join("plugin.yaml").is_file() { // The worker receives an explicit serialized manifest, so it does not
base_dir.join("plugin.yaml") // depend on the manifest file being named `plugin.yaml`.
} else { let manifest_path = std::env::temp_dir().join(format!(
return Err(PluginError::load( "marqdo-plugin-worker-manifest-{}-{}.json",
"worker_manifest_missing", std::process::id(),
format!("no plugin.yaml in `{}`", base_dir.display()), std::time::SystemTime::now()
)); .duration_since(std::time::UNIX_EPOCH)
}; .map(|duration| duration.as_nanos())
.unwrap_or(0)
));
let manifest_bytes = serde_json::to_vec(manifest).map_err(|error| {
PluginError::manifest(
"worker_manifest_encode_failed",
format!("cannot encode manifest for worker: {error}"),
)
})?;
std::fs::write(&manifest_path, manifest_bytes).map_err(|error| {
PluginError::load(
"worker_manifest_unwritable",
format!("cannot write worker manifest: {error}"),
)
})?;
let executable = std::env::current_exe().map_err(|error| { let executable = std::env::current_exe().map_err(|error| {
PluginError::load( PluginError::load(
"worker_spawn_failed", "worker_spawn_failed",
format!("cannot find the current executable: {error}"), format!("cannot find the current executable: {error}"),
) )
})?; })?;
let mut child = Command::new(executable) let mut child = match Command::new(executable)
.arg(WORKER_COMMAND) .arg(WORKER_COMMAND)
.arg(&manifest_path) .arg(&manifest_path)
.arg(base_dir) .arg(base_dir)
@@ -61,12 +75,16 @@ impl WorkerPlugin {
.stdout(Stdio::piped()) .stdout(Stdio::piped())
.stderr(Stdio::inherit()) .stderr(Stdio::inherit())
.spawn() .spawn()
.map_err(|error| { {
PluginError::load( Ok(child) => child,
Err(error) => {
let _ = std::fs::remove_file(&manifest_path);
return Err(PluginError::load(
"worker_spawn_failed", "worker_spawn_failed",
format!("cannot start plugin worker: {error}"), format!("cannot start plugin worker: {error}"),
) ));
})?; }
};
let Some(stdin) = child.stdin.take() else { let Some(stdin) = child.stdin.take() else {
let _ = child.kill(); let _ = child.kill();
return Err(PluginError::load( return Err(PluginError::load(
@@ -98,10 +116,19 @@ impl WorkerPlugin {
format!("cannot start worker reader: {error}"), format!("cannot start worker reader: {error}"),
) )
})?; })?;
let ready = frames.recv_timeout(HANDSHAKE_TIMEOUT).map_err(|_| { let ready = match frames.recv_timeout(HANDSHAKE_TIMEOUT) {
let _ = child.kill(); Ok(frame) => frame,
PluginError::invoke("plugin.timeout", "plugin worker handshake timed out") Err(_) => {
})??; let _ = std::fs::remove_file(&manifest_path);
let _ = child.kill();
return Err(PluginError::invoke(
"plugin.timeout",
"plugin worker handshake timed out",
));
}
};
let _ = std::fs::remove_file(&manifest_path);
let ready = ready?;
if ready.get("kind").and_then(serde_json::Value::as_str) != Some("ready") { if ready.get("kind").and_then(serde_json::Value::as_str) != Some("ready") {
let _ = child.kill(); let _ = child.kill();
return Err(PluginError::load( return Err(PluginError::load(
+33 -30
View File
@@ -67,10 +67,10 @@ cargo clippy --workspace --all-targets -- -D warnings
| **P1** Interpreter, expressions, control flow | **Done** | `marqdo-expression`, `marqdo-ir`, `marqdo-frontend`, `marqdo-runtime`; factorial/countdown examples run without Python (`examples/factorial.mq.md`, `examples/hello.mq.md`); 36 execution goldens in `tests/conformance/semantics/`; runtime tests `crates/marqdo-runtime/tests/interpreter.rs`; prose invariance `crates/cli/tests/properties.rs`. | | **P1** Interpreter, expressions, control flow | **Done** | `marqdo-expression`, `marqdo-ir`, `marqdo-frontend`, `marqdo-runtime`; factorial/countdown examples run without Python (`examples/factorial.mq.md`, `examples/hello.mq.md`); 36 execution goldens in `tests/conformance/semantics/`; runtime tests `crates/marqdo-runtime/tests/interpreter.rs`; prose invariance `crates/cli/tests/properties.rs`. |
| **P2** Modules, references, CLI experience | **Partial** | Imports/ModuleId/UnitId/anchor/cycle detection + `run/call/check/inspect/fmt` (`crates/cli`), multi-module example and `multi_module_imports_and_cycles` CLI test; `check --refs` reference validation (all loaded documents, on-demand static analysis of link targets) and `inspect --refs` static graph. Missing: cross-module link calls, rename/interface-lock tooling, canonical AST-preserving `fmt` (see §3). | | **P2** Modules, references, CLI experience | **Partial** | Imports/ModuleId/UnitId/anchor/cycle detection + `run/call/check/inspect/fmt` (`crates/cli`), multi-module example and `multi_module_imports_and_cycles` CLI test; `check --refs` reference validation (all loaded documents, on-demand static analysis of link targets) and `inspect --refs` static graph. Missing: cross-module link calls, rename/interface-lock tooling, canonical AST-preserving `fmt` (see §3). |
| **P3** Package environment | **Partial** | `marqdo.yaml`/`marqdo.lock` types+validation, `init`, `add`/`remove`, deterministic `lock`, `sync --locked`; M0.6 adds pinned Git fetch/cache, transitive `@alias` resolution and atomic `.marqdo/env` materialization. Missing: registry, `tree/update/vendor`, `--offline`, full conflict solver. | | **P3** Package environment | **Partial** | `marqdo.yaml`/`marqdo.lock` types+validation, `init`, `add`/`remove`, deterministic `lock`, `sync --locked`; M0.6 adds pinned Git fetch/cache, transitive `@alias` resolution and atomic `.marqdo/env` materialization. Missing: registry, `tree/update/vendor`, `--offline`, full conflict solver. |
| **P4** Security core and isolation | **Partial** | `CapabilityHost`, capabilities at execution points (console and math included), project-rooted FS with traversal rejection, budgets, effect trace, pure/project modes, **strict refuses without OS isolation** (`marqdo-sandbox`); CLI test `strict_mode_refuses_without_isolation`; host unit tests. Missing: OS isolation adapter, plugin worker, network enforcement. | | **P4** Security core and isolation | **Partial** | `CapabilityHost`, capabilities at execution points (console and math included), project-rooted FS with traversal rejection, budgets, effect trace, pure/project modes, **strict refuses without OS isolation** (`marqdo-sandbox`); CLI test `strict_mode_refuses_without_isolation`; host unit tests. Missing: OS isolation adapter and network enforcement; isolated plugin workers exist but are not an OS sandbox. |
| **P5** Math and Foreign | **Partial (documented subset)** | `marqdo-math` exact-rational formula kernel for the grammar in `spec/math.md`; `math.parse/eval/substitute` host ops; `marqdo-foreign` Python/Node one-shot kernels with typed `foreign.call`; tests `crates/marqdo-math/tests/kernel.rs`, `crates/marqdo-foreign/tests/kernels.rs`; examples `math.mq.md`, `python-foreign.mq.md`. Missing: `simplify`/`differentiate`, matrices/series/symbolic algebra, foreign sessions, Python environment management. | | **P5** Math and Foreign | **Partial (documented subset)** | `marqdo-math` exact-rational formula kernel for the grammar in `spec/math.md`; `math.parse/eval/substitute` host ops; `marqdo-foreign` Python/Node one-shot kernels with typed `foreign.call`; tests `crates/marqdo-math/tests/kernel.rs`, `crates/marqdo-foreign/tests/kernels.rs`; examples `math.mq.md`, `python-foreign.mq.md`. Missing: `simplify`/`differentiate`, matrices/series/symbolic algebra, foreign sessions, Python environment management. |
| **P6** Plugin ABI and developer experience | **Partial** | Frozen `include/marqdo_plugin_abi_v1.h`; C ABI mirrors/layout assertions, version negotiation, `plugin.yaml` validation, target triple + sha256 verification, wire envelopes, native loader (`marqdo-plugin-abi`); Rust SDK macro (`marqdo-plugin-sdk`); C demo (`examples/plugin-demo`); CLI `plugin inspect` and explicitly trusted in-process invocation (`--plugin`, `--trust-native-plugin`, `--allow-plugin`); tests `plugin_inspect_and_explicit_trusted_invocation`, `crates/marqdo-plugin-abi/tests/loader_unix.rs`. Missing: isolated worker transport, plugin capability bridge, installation, Rust plugin example crate. | | **P6** Plugin ABI and developer experience | **Partial** | Frozen `include/marqdo_plugin_abi_v1.h`; C ABI mirrors/layout assertions, version negotiation, `plugin.yaml` validation, target triple + sha256 verification, wire envelopes, native loader; complete-name multi-export routing; `CapabilityBroker`; isolated worker transport with handshake/call timeouts; host handle table; Rust SDK; CLI `plugin inspect`, `check --plugin`, trusted native invocation. Missing: Wasm, vendor handlers, plugin installation, Rust plugin example crate. |
| **P7** Performance, release, CI | **Partial** | `.github/workflows/ci.yml` runs fmt/clippy/workspace tests plus CLI example smoke tests (including plugin inspect and invocation) on Linux x86_64. Missing: benchmarks, bytecode backend, cross-platform matrix, signed releases and supply-chain checks. Tree-walk interpreter only. | | **P7** Performance, release, CI | **Partial** | `.github/workflows/ci.yml` runs fmt/clippy/workspace tests plus CLI example smoke tests (including plugin inspect and invocation) on Linux x86_64. Missing: benchmarks, bytecode backend, full cross-platform test matrix (Windows/macOS currently `cargo check` only), signed releases and supply-chain checks. Tree-walk interpreter only. |
## 2. Feature evidence (selected commands) ## 2. Feature evidence (selected commands)
@@ -145,23 +145,23 @@ and `crates/cli/tests`.
### P3 ### P3
* Git dependencies can be declared (`git` + `rev`, validated) but cannot be * Pinned Git dependencies resolve through a content-addressed cache; floating
resolved or locked: `lock` errors "git dependencies are not supported by this branches, submodules and dependency install scripts remain unsupported.
build". * Transitive `@alias` imports resolve from each package's own manifest, but the
* No transitive dependency graph, conflict resolution, registry, publishing, lock is still flat; there is no full conflict solver, registry, publishing,
signing, `tree`, `update`, `vendor`, `--offline`, or `lock --locked`. signing, `tree`, `update`, `vendor`, `--offline`, or `lock --locked`.
* No environment materialization (`.marqdo/env`, caches, kernels, sessions); * `sync` materializes `.marqdo/env` atomically; kernel/session environments are
`sync` verifies but never installs or rewrites. not materialized.
* `add`/`remove` are shallow manifest editors; adding a git dependency succeeds * `add`/`remove` are shallow manifest editors.
at the manifest level even though `lock` will later refuse it.
* JSON errors from `add`/`remove`/`lock`/`sync` are plain stderr even with * JSON errors from `add`/`remove`/`lock`/`sync` are plain stderr even with
`--json`. `--json`.
### P4 ### P4
* **Strict mode cannot run at all**: no OS isolation adapter (Linux * **Strict mode cannot run at all**: no OS isolation adapter (Linux
namespaces/seccomp/cgroups, Windows Job Object/appcontainer, macOS sandbox) namespaces/seccomp/cgroups, Windows Job Object/appcontainer, macOS sandbox);
and `worker_processes: false`; `run --mode strict` exits 1 (ADR-0004). `run --mode strict` exits 1 (ADR-0004). Isolated plugin workers are
implemented but a child process is not an OS sandbox.
* `console` is a capability checked in `op_print`; it is granted by default in * `console` is a capability checked in `op_print`; it is granted by default in
`pure`/`project` mode and is not a bypass of the capability boundary. `pure`/`project` mode and is not a bypass of the capability boundary.
* Network capability (`net_hosts`, `check_net`) exists but no host operation * Network capability (`net_hosts`, `check_net`) exists but no host operation
@@ -172,8 +172,9 @@ and `crates/cli/tests`.
bounded only by fuel and available memory. bounded only by fuel and available memory.
* Effect trace does not record argument values or paths (privacy-positive, but * Effect trace does not record argument values or paths (privacy-positive, but
less diagnostic detail); trace is opt-in and implicitly on for `--json`. less diagnostic detail); trace is opt-in and implicitly on for `--json`.
* `plugin_handle` wire values are structurally reconstructable, not * `plugin_handle` wire values are structurally reconstructable; authority now
unforgeable capability tokens. requires the host-owned owner/run/generation table, and untrusted output
containing handles is rejected (ADR-0014).
### P5 ### P5
@@ -187,21 +188,23 @@ and `crates/cli/tests`.
`MathErrorKind::Type`), not `runtime.division_by_zero`; documented divergence. `MathErrorKind::Type`), not `runtime.division_by_zero`; documented divergence.
* Foreign kernels are one-shot only: no sessions, state bridge, Python/Node * Foreign kernels are one-shot only: no sessions, state bridge, Python/Node
environment management, or network policy for child processes. environment management, or network policy for child processes.
* Foreign child processes are terminated only when the direct child is killed; * Foreign child processes form a process group on Unix, so timeout/overflow
grandchildren are not tracked. kills grandchildren too; non-Unix targets still track only the direct child.
* Foreign per-call timeout (10 s) and output cap (1 MiB) are not CLI-configurable. * Foreign per-call timeout (10 s) and output cap (1 MiB) are not CLI-configurable.
### P6 ### P6
* No isolated plugin worker (length-prefixed IPC) or Wasm transport; only * Native in-process loading still requires explicit trust and a crash is a host
explicitly trusted in-process native loading. A native plugin crash is a host crash. The isolated worker transport (length-prefixed IPC, handshake/call
crash (`spec/plugin-abi.md` §1/§9). timeouts) is implemented for crash isolation, not as an OS sandbox.
* No plugin capability bridge from the CLI: plugins are loaded with no * Wasm and hot unload/reload remain unsupported.
capability handler, so every plugin `request_capability` is denied. * The `CapabilityBroker` enforces core grants and vendor policy entries, but no
* Plugin calls are not statically validated; unknown namespaces are runtime concrete vendor handler or worker-side capability bridge is shipped.
`symbol.unknown`. Positional plugin arguments are rejected. * Plugin calls are statically validated only with `check --plugin <manifest>`;
* One namespace per plugin (first export prefix); multi-prefix manifests are not without a descriptor a missing export is a runtime `symbol.unknown`.
reachable beyond the first prefix. Positional plugin arguments are rejected.
* Multi-prefix exports are registered by complete name; explicit alias syntax
for two packages using the same export is still pending.
* No plugin installation/package management; `plugins:` in `marqdo.yaml` is * No plugin installation/package management; `plugins:` in `marqdo.yaml` is
declarative only. No Rust plugin example crate (SDK has doc examples/tests). declarative only. No Rust plugin example crate (SDK has doc examples/tests).
* No hot unload/reload (ABI v1 design). * No hot unload/reload (ABI v1 design).
@@ -225,9 +228,9 @@ and `crates/cli/tests`.
| No heuristic downgrade of execution semantics; accurate source locations for invalid execution nodes | **Mostly met** | hard errors with spans for function-body executable shapes and negative corpus. Gaps: inert executable outside functions is a warning by design (ADR-0002); cross-module runtime error spans resolve against the entry file only; some lazy nested nodes are inert without a warning. | | No heuristic downgrade of execution semantics; accurate source locations for invalid execution nodes | **Mostly met** | hard errors with spans for function-body executable shapes and negative corpus. Gaps: inert executable outside functions is a warning by design (ADR-0002); cross-module runtime error spans resolve against the entry file only; some lazy nested nodes are inert without a warning. |
| `check`/`inspect` side-effect free; imports, calls and static references verifiable across files | **Mostly met** | static load/analysis only; imports + cycle detection; cross-module calls validated; `check --refs` validates references across loaded documents and statically analyses link targets; `inspect --refs` prints the entry graph. | | `check`/`inspect` side-effect free; imports, calls and static references verifiable across files | **Mostly met** | static load/analysis only; imports + cycle detection; cross-module calls validated; `check --refs` validates references across loaded documents and statically analyses link targets; `inspect --refs` prints the entry graph. |
| Minimal manifest, lock file, path/Git dependencies and environment sync | **Partial** | manifest/lock/path works, `sync --locked` verifies; git resolution, transitive deps, environment materialization and `--offline` missing. | | Minimal manifest, lock file, path/Git dependencies and environment sync | **Partial** | manifest/lock/path works, `sync --locked` verifies; git resolution, transitive deps, environment materialization and `--offline` missing. |
| All host side effects capability-authorized; untrusted code/native plugins cannot masquerade as strict sandbox | **Mostly met** | capability checks at execution points; strict refuses; native plugins require explicit trust and are documented as unsandboxed. Gaps: network enforcement not implemented (no network builtin is exposed), no worker isolation. | | All host side effects capability-authorized; untrusted code/native plugins cannot masquerade as strict sandbox | **Mostly met** | capability checks at execution points; strict refuses; native plugins require explicit trust and are documented as unsandboxed. Gaps: network enforcement not implemented (no network builtin is exposed); worker isolation is crash isolation, not an OS sandbox. |
| Formula computational subset explicit/testable; Foreign I/O, timeout and permissions explicit | **Met for the documented subset** | `spec/math.md`, `spec/foreign.md`; math kernel tests; foreign tests (timeout, protocol, output cap, env); permission gating tests/smoke. Simplification/differentiation explicitly unsupported. | | Formula computational subset explicit/testable; Foreign I/O, timeout and permissions explicit | **Met for the documented subset** | `spec/math.md`, `spec/foreign.md`; math kernel tests; foreign tests (timeout, protocol, output cap, env); permission gating tests/smoke. Simplification/differentiation explicitly unsupported. |
| Plugin C ABI v1, Rust SDK, C example, isolated worker basic path, ABI compat error tests | **Partial** | ABI/SDK/C example/loader/ABI-error tests exist; **isolated worker path missing**. | | Plugin C ABI v1, Rust SDK, C example, isolated worker basic path, ABI compat error tests | **Partial** | ABI/SDK/C example/loader/ABI-error tests exist; isolated worker with timeout/crash tests exists. Missing: Wasm, vendor handlers, plugin installation. |
| CI has at least one full research pipeline: Markdown function → Math → Foreign → Plugin → controlled output | **Partial** | CI now runs fmt/clippy/tests and CLI smoke tests; individual math/foreign/plugin paths are covered by examples and tests, but no single end-to-end pipeline document/test exists yet. | | CI has at least one full research pipeline: Markdown function → Math → Foreign → Plugin → controlled output | **Partial** | CI now runs fmt/clippy/tests and CLI smoke tests; individual math/foreign/plugin paths are covered by examples and tests, but no single end-to-end pipeline document/test exists yet. |
| Examples, README, AGENTS and contributor docs allow a first change without legacy context | **Met** | `README.md`, `AGENTS.md`, this guide, `docs/STATUS.md`, specs, ADRs, `tests/README.md`, examples. | | Examples, README, AGENTS and contributor docs allow a first change without legacy context | **Met** | `README.md`, `AGENTS.md`, this guide, `docs/STATUS.md`, specs, ADRs, `tests/README.md`, examples. |
@@ -243,8 +246,8 @@ end-to-end pipeline (P7).
options/versions is a language change. options/versions is a language change.
* Strict mode is a refusal, not an isolation implementation. `project` mode is * Strict mode is a refusal, not an isolation implementation. `project` mode is
cooperative and in-process. cooperative and in-process.
* Native plugins are trusted in-process code; there is no isolated plugin * Native plugins are trusted in-process code and a crash takes down the host.
worker, and a plugin crash takes down the host. `kind: worker` isolates crashes/timeouts but is not an OS sandbox.
* Ints are arbitrary precision; finite floats are binary64 and wire round-trip * Ints are arbitrary precision; finite floats are binary64 and wire round-trip
is exact (`float_roundtrip` enabled), but decimal-vs-binary formatting still is exact (`float_roundtrip` enabled), but decimal-vs-binary formatting still
applies when displaying values. applies when displaying values.