Skip to content
This repository was archived by the owner on Dec 3, 2026. It is now read-only.

refactor: meta_core owns the workspace domain and the one process owner; the meta crate is a binary only [[tasks/harmony-3076]] - #162

Merged
gold-silver-copper merged 4 commits into
mainfrom
refactor/core-owns-workspace-domain
Nov 4, 2026
Merged

gold-silver-copper merged 4 commits into
mainfrom
refactor/core-owns-workspace-domain

Conversation

@gold-silver-copper

@gold-silver-copper gold-silver-copper commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Step 1 of the meta architecture plan: meta_core owns the workspace domain, the meta crate is only a binary, and one owner in meta_core::children starts, checks and stops every process group meta makes. Based on f44f0a4 (the #161 merge).

What changes for users

  • Linux and macOS: one fix, otherwise nothing changes. Cancelling a meta-mcp tool call no longer leaves processes that ignore SIGTERM running. Programs meta-mcp starts now get META_OWNER_DEPTH=1 like every child the owner starts, so a meta that meta-mcp runs gives its own children 1 s instead of 2 s to stop after a signal, and has killed them before meta-mcp's own 2 s grace kills it. Independent test on Linux: main left 5 orphaned processes in 6 of 9 cancels, this PR 0 in 9; the other 48 CLI scenarios are byte-identical to main.
  • Windows: when an MCP tool call is cancelled, or a plugin doesn't answer --meta-plugin-info within 5 s, meta now ends everything that program started (its job object), not just the program. Before, a .cmd/node wrapper died and the processes it started kept running and kept the pipe open. A release is needed before install.ps1 users get this.

What moved, and what replaces it

Before After
meta_cli::worktree, repo_filter, dependency_graph, query (the meta crate's library) meta_core::worktree, repo_filter, dependency_graph, query, unchanged
meta_cli::context, meta_cli::run_list private modules of the meta binary (only it used them)
the meta crate's [lib] target deleted; meta_git_lib, meta_git_cli, meta_project_cli and meta-mcp depend on meta_core only (cargo tree -p meta_git_lib lists no meta)
process groups started and killed by hand in meta_mcp/src/run.rs (group_alive, stop), meta_mcp/src/batch.rs and meta_cli/src/subprocess_plugins.rs, each with its own Unix branch and fallback meta_core::children::spawn_group plus Owned::{stdout, try_wait, group_alive, stop}
// before (meta_mcp/src/run.rs)
#[cfg(unix)]
std::os::unix::process::CommandExt::process_group(command, 0);
let mut child = command.spawn()?;
// ... group_alive(&child), stop(&mut child, kill), each with #[cfg(unix)] / #[cfg(not(unix))]

// after
let mut child = meta_core::children::spawn_group(command)?;
// ... child.try_wait()?, child.group_alive(), child.stop(kill)

A grouped child is registered like any other children::spawn child, so on Unix a signal meta owns reaches it, and try_wait takes it off the list before it is reaped (no reused pid gets signalled). On Windows the group is a job object (the win32job crate: a safe API, so the workspace keeps unsafe_code = "forbid"). The job only kills its processes when stop is called: a job closed after a normal run leaves whatever its program left running, as a Unix group does.

Also in this PR, as separate commits (crate-audit 2026-11-03, which the plan puts before this step):

  • K0146: meta_project_cli no longer lists meta_git_lib, which it never used.
  • K0148: [workspace.dependencies] holds one version of each shared dependency (rayon was 1.5 in two crates and 1.7 in one). The release workflow's "Pin the meta_core requirement" step now rewrites the one meta_core line in the root Cargo.toml instead of one line in each of two crates.

Numbers

base f44f0a4 this PR
#[test] functions 647 648 (+1, Windows only; below)
cargo tests run on Linux (box2, cargo test --workspace) — 644 passed, 0 failed
new pub items in meta_core 9: 4 modules (their 46 items were already public from the meta crate's library), spawn_group, Owned::stdout, try_wait, group_alive, stop
lines, hand-written (Cargo.lock excluded) +479 / −286, net +193: process owner +233 / −90 (production, docs included) and +37 (the Windows test); module move +75 / −83; workspace dependencies +140 / −118; K0146 −1
macOS integration job 8 min 02 s (run 41761897563) 9 min 37 s on the final head 0737751 (run 41766486649); 8 min 11 s on 32d2554
whole CI run 8 min 07 s 9 min 42 s on 0737751; 8 min 17 s on 32d2554

Target revised: net lines. The plan estimated net −150 for this step. Measured: net +193. Evidence: the move is −8 (git sees renames; the +26/−26 in worktree.rs are meta_core:: → crate::); the three hand-written group copies in meta-mcp and the probe went from 86 lines to 25; what the estimate didn't count is the owner itself: the Windows job objects (about +80 lines, two nested jobs after review) and the Unix try_wait that keeps a reaped pid off the signal list (about +40), each with its doc, plus the workspace dependency table (+22 net, one version per dependency). Cost: the Windows behaviour above, which the plan asks this step to land.

Test budget revised: +1 test. The plan said 0 added. The cross-platform audit's premortem asks for one native Windows test that a grandchild is gone after a stop, and nothing else checks the job-object code: stopping_a_group_ends_what_its_program_started (meta_core/src/children.rs, #[cfg(windows)]) runs on the Windows CI lane only.

Fresh-Docker agentic test

A clean rust:1-bookworm container on box2 (no caches, no host target dir) cloned a bundle of base f44f0a4 and head 32d2554, built each with cargo build --workspace --bins, and ran the same commands in a fresh workspace for each: a root repo with app (one modified file), platform (meta: true, with its own .meta.yaml listing inner, cloned at platform/inner) and missing (in the config, not cloned). Script: run.sh in the ledger folder.

Base and head printed identical output for every command (diffed). Head's output:

head 32d2554
################ head: meta 0.2.22 (git 32d2554 2026-11-03)
$ meta git status
warning: missing is not cloned; `meta git clone-missing` clones it

✓ . (ws):
On branch main
nothing to commit, working tree clean

✓ ./app:
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   README.md

no changes added to commit (use "git add" and/or "git commit -a")

✓ ./platform:
On branch main
Your branch is up to date with 'origin/main'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	inner/

nothing added to commit but untracked files present (use "git add" to track)

3 commands complete
[exit 0]
$ meta -r git worktree create t
Error: Specify repos with --repo <alias> or use --every-repo
[exit 1]
$ meta --strict git worktree list
No worktrees found.
[exit 0]
$ meta -r git status --short
warning: missing is not cloned; `meta git clone-missing` clones it

✓ ./app:
 M README.md

✓ ./platform:
?? inner/

4 commands complete
[exit 0]
$ meta -r git worktree create t --every-repo
warning: 'missing' at /ws/missing: not cloned (run 'meta git clone-missing'), skipping
✓ Created worktree 't' at /ws/.worktrees/t
  . -> t (new from HEAD (main))
  app -> t (new from origin/main)
  platform -> t (new from origin/main)
  platform/inner -> t (new from origin/main)
[exit 0]
$ meta --strict git worktree list
t
  .            -> t                    (clean)
  app          -> t                    (clean)
  platform     -> t                    (modified)
  platform/inner -> t                    (clean)

[exit 0]
$ meta git worktree status t
t:
  ✓ .            t                    clean
  ✓ app          t                    clean
  ● platform     t                    1 untracked
  ✓ platform/inner t                    clean
[exit 0]

meta -r git worktree create t refuses without --every-repo on both, as the command requires a repo choice; the run with --every-repo creates the set across the nested repo and skips the uncloned one.

$ cargo tree -p meta_git_lib -e normal | grep ' meta v'     # head: nothing
$ (base)
├── meta v0.2.22 (/src/base/meta_cli)

The process-owner commit changed after this run (review rounds 1-2: Windows code, a compile_error message, comments); the Unix code it ran is unchanged.

Decisions taken alone

  1. context and run_list were in the meta crate's library but only the binary used them: they became private binary modules instead of moving to meta_core (less public surface).
  2. Windows job objects through win32job (safe API) rather than windows-sys with unsafe (the workspace forbids it) or process-wrap (its child type waits for the whole job and doesn't say whether the job is empty).
  3. Each grouped child is put in two jobs: an outer one that only tracks its processes, and a nested one that stop tells to kill and closes. So a stop kills the whole tree, group_alive still sees the processes until they have really exited (as a Unix group is waited for), a finished run's leftovers live on as on Unix, and a stop that fails to set kill-on-close keeps the job for the next stop to try again.
  4. A process the child starts in the instant before it is assigned to its job is not in the job (std can't start a process suspended without unsafe). Said in the module doc.
  5. On Windows, if a job can't be created or assigned, the grouped child is killed and the call fails with the error (no silent fallback to an ungrouped child).
  6. Targets other than Unix and Windows get compile_error! instead of a guessed fallback (meta ships for Linux, macOS and Windows).
  7. rustix is now a dev-dependency of meta and gone from meta-mcp: only tests use it.

Plugins stay plugins

Owner decision received during this PR: meta git, meta cargo, meta project and meta mcp stay separate plugin executables on top of meta, so anyone can write meta jj or meta grep the same way. This PR is consistent with it: plugins now reach the workspace domain through meta_core (and the protocol crate) and no longer link the host crate; nothing moves into the meta binary. The plan's later step that bundled plugins into the host (PR 3) is dropped. The revised plan (13 PRs) keeps this PR unchanged; its next step moves this process owner from meta_core::children into the plugin SDK (meta_plugin::process) so the host and every plugin share it.

The revision also takes release work out of scope. This PR still edits release.yml's "Pin the meta_core requirement" step, because moving meta_core into [workspace.dependencies] (K0148) moves the line that step rewrites; without the edit its check would fail the publish job.

Overlaps with other runs

CI time

The macOS integration job took 9 min 37 s on the final head, against 8 min 02 s on the base run and 8 min 11 s on this PR's first head (32d2554), whose integration-relevant code is the same. The plan recorded 8.7-10.0 min for this job; the difference looks like runner variance, not this PR (it adds no bats test and no integration step), but it is one sample. Under the 10 min ceiling.

Review

Team-repo panel, read-only, Claude Opus and Codex gpt-6.1-sol, perspectives rotated each round, two to three reviewers at a time:

Round Head Correctness Portability / Windows / CI Simplicity Data / packaging Tests User-facing / docs
1 32d2554 / 5418990 yes (Opus) no (Sol): Windows stop lost track of dying descendants yes (Opus) yes (Sol) yes (Opus) yes (Sol)
2 7b59ec6 / 037f93a yes (Sol) no (Opus): compile_error! text read as a meta … command by the docs test yes (Sol) yes (Opus) yes (Sol) yes (Opus)
3 0737751 (final) yes (Opus) yes (Sol) yes (Opus)

Both must-fixes are fixed (two nested jobs; reworded message). Round 2's second wave saw 037f93a; the only change since is meta_core's crates.io description. Notes taken: doc comments name spawn_group, a comment on the Finish path, a one-second head start in the Windows test against flakes. Notes left, as follow-ups: group_alive could take &self; clippy on the Windows CI lane (it fails today on meta_core/src/config.rs:2061, cross-platform audit AO-meta-1); the "<1" comment in the root Cargo.toml still mentions child-repo CI. CodeRabbit was rate-limited and left no review.

Not verified

  • The Windows job-object code was checked with cargo clippy --target x86_64-pc-windows-msvc -p meta_core on Linux and runs only in the Windows CI lane; nobody drove meta-mcp cancellation on a Windows machine.
  • Clippy isn't run on Windows in CI; meta_core/src/config.rs:2061 (an eprintln! in a test, already on main) fails it there.

Try it

cd ~/code/gitkb-dev/harmony/.worktrees/meta-arch-pr1/open-source/meta && cargo build --workspace --bins && cargo tree -p meta_git_lib -e normal | grep -c ' meta v'  # 0

…st [[tasks/harmony-3076]]

crate-audit K0148. Members inherit with dep.workspace = true and keep their
own extra features. release.yml pins the meta_core requirement in the root
manifest, its one place now.
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 38 billable files and costs up to $9.50.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 39 seconds for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 101 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Team
  • Run ID: de28ccda-8635-42a0-af74-48c8a32dec46
Commits

Reviewing files that changed from the base of the PR and between f44f0a4 and 0737751.

Files ignored due to path filters: 1
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing: 38
  • .github/workflows/release.yml
  • Cargo.toml
  • README.md
  • docs/architecture_overview.md
  • docs/mcp_server.md
  • loop_cli/Cargo.toml
  • loop_lib/Cargo.toml
  • meta_cli/Cargo.toml
  • meta_cli/src/context.rs
  • meta_cli/src/lib.rs
  • meta_cli/src/main.rs
  • meta_cli/src/subprocess_plugins.rs
  • meta_core/Cargo.toml
  • meta_core/src/children.rs
  • meta_core/src/dependency_graph.rs
  • meta_core/src/lib.rs
  • meta_core/src/query.rs
  • meta_core/src/repo_filter.rs
  • meta_core/src/worktree.rs
  • meta_git_cli/Cargo.toml
  • meta_git_cli/src/commands/worktree/add.rs
  • meta_git_cli/src/commands/worktree/create.rs
  • meta_git_cli/src/commands/worktree/exec.rs
  • meta_git_cli/src/commands/worktree/list.rs
  • meta_git_cli/src/commands/worktree/prune.rs
  • meta_git_cli/src/commands/worktree/status.rs
  • meta_git_cli/src/update.rs
  • meta_git_lib/Cargo.toml
  • meta_git_lib/src/worktree/helpers.rs
  • meta_mcp/Cargo.toml
  • meta_mcp/src/batch.rs
  • meta_mcp/src/run.rs
  • meta_mcp/src/tools.rs
  • meta_plugin_protocol/Cargo.toml
  • meta_project_cli/Cargo.toml
  • meta_project_cli/src/lib.rs
  • meta_rust_cli/Cargo.toml
  • meta_test_support/Cargo.toml
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@gold-silver-copper
gold-silver-copper force-pushed the refactor/core-owns-workspace-domain branch 3 times, most recently from 7b59ec6 to 037f93a Compare November 4, 2026 03:17
…y graph and queries; the meta crate is a binary only [[tasks/harmony-3076]]

worktree, repo_filter, dependency_graph and query move from meta_cli's
library into meta_core, unchanged. context and run_list, which only the
meta binary uses, become its private modules. meta_git_lib, meta_git_cli,
meta_project_cli and meta-mcp no longer depend on the meta crate.
…lled tool call or a plugin that doesn't answer stops everything it started [[tasks/harmony-3076]]

meta_core::children::spawn_group starts a child in a process group of its
own (a job object on Windows) and Owned::{try_wait, group_alive, stop}
check on and stop the whole group. meta-mcp's cancellable runs, its
finish-on-cancel git runs and meta's --meta-plugin-info probe use it, so
their three copies of the Unix group code and their three fallbacks
elsewhere are gone. On Windows, cancelling a tool call or a probe timing
out now ends the processes the program started too, not just the program
(cross-platform audit CX-meta-1, CO-meta-1, BX-meta-1, BO-meta-3).
@gold-silver-copper
gold-silver-copper force-pushed the refactor/core-owns-workspace-domain branch from 037f93a to 0737751 Compare November 4, 2026 03:20
@gold-silver-copper
gold-silver-copper merged commit 898dc88 into main Nov 4, 2026
14 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant