Orchestrata Ultimate › Plans › briefs › p6a-identity-tool-tree-instances-builder
P6a — identity verifier judges tool-tree template instances against their own root: builder brief (orchestrator's picks, 2026-10-07)
Source: plans/briefs/p6a-identity-tool-tree-instances-builder.md at 8a2cb42ad · last changed 2026-10-07 · first committed 2026-10-07 · 156 lines.
Prose pending.
Plan text
P6a — identity verifier judges tool-tree template instances against their own root: builder brief (orchestrator's picks, 2026-10-07)
Plan: plans/ast-daemon-deployment-plan.md § "P6a". Read it first; it holds the measured failure,
the six executed rules and the acceptance. This brief holds the exact source at the sites, the
changes per rule, the test plan and the gates. Design authority: ADR-0067 (Accepted) R1 "an
enabled instance names data, not code" and P3 "the unit executes deployed code only"; the plan
section records the rules as applications of those, not as new decisions.
1. Exact source at a3728f5a0
Read every symbol below with .venv/bin/python scripts/serialize_codebase_ast.py source <qname> --no-daemon
(qualified names omit orchestrata_ultimate.; module residue with --residue).
promotion.identity.check_identity(identity.py:97-202). Relevant part: after the ROOT checks it computesvenv_python = (root_path / ".venv" / "bin" / "python").resolve(), discovers units overSERVICE_GLOBSfor both scopes, and per unit runscheck_path_directives(unit, _PATH_DIRECTIVES, report),check_c0(unit, root_resolved, report),check_liveness(unit, run, scope, name, report),_check_process_identity(name, properties, root_resolved, venv_python, version, proc_root, report).promotion.identity._check_process_identity(identity.py:205-254): skips.timernames andType=oneshot; readsMainPID; callscheck_process(pid, proc_root, root_resolved, venv_python, name, report); comparesExecMainStartTimestampwithversion.deployed(start_time < version.deployedis a mismatch "start-time: expected >= …").promotion.identity_core.check_process(identity_core.py:97-134):/proc/<pid>/cwdmust equalstr(root);cmdline[0]must start withf"{root}/";exemust equalvenv_python.promotion.identity_checks.check_c0(identity_checks.py:145-224): collects path-like tokens from ExecStart argv (argv0 and rest),ExecStart path=,ExecStartPre/ExecStartPost,WorkingDirectory,EnvironmentFiles,Environment,Standard*, thenif not resolves_safely(token, root): report.mismatches.append(f"{unit.name}: {source}: {token} resolves outside ROOT and system prefixes").promotion.identity_checks.resolves_safely(identity_checks.py:122-136): true for the root, its descendants,/lib*, andSYSTEM_PREFIXES.promotion.identity_scopeconstants (identity_scope.py:29-106):SYSTEM_PREFIXESends with"/opt/orchestrata-tools";UNIT_PROPERTIES;PATH_DIRECTIVES;DEFAULT_GLOBS = ("orchestrata-*.service", "orchgraph-*.service", "*.timer");SERVICE_GLOBS.UnitFacts(identity_scope.py:118-122) is@dataclasswithname,scope,properties.VersionRecord,parse_version(text),IdentityReport(render(),as_dict()) live here too.promotion.identity_skips.resolve_skip(identity_skips.py:70-87): canvas skip by name (R8), not-runnable skip aftershow.- The template,
deploy/systemd/orchestrata-ast-daemon@.service(installed copy at~/.config/systemd/user/orchestrata-ast-daemon@.service, byte-identical):
[Service]
Type=simple
WorkingDirectory=/opt/orchestrata-tools
Environment=PYTHONUNBUFFERED=1
ExecStartPre=/usr/bin/test -e /%I/.git
ExecStart=/opt/orchestrata-tools/bin/ast-daemon --repo-root /%I --socket /%I/.claude/run/ast-daemon.sock
MemoryMax=3G
Restart=always
RestartSec=10
- The live instance (measured 2026-10-07 05:xx EDT): name
orchestrata-ast-daemon@home-mohamed-workspace-orchestrata\x2dultimate\x2dworktrees-wt\x2dSPEC\x2d110.service,MainPID=4030232,ExecMainStartTimestamp=Wed 2026-10-07 02:24:51 EDT,WorkingDirectory=/opt/orchestrata-tools, cmdline/opt/orchestrata-tools/.venv/bin/python /opt/orchestrata-tools/lib/scripts/ast_daemon.py --repo-root /home/mohamed/workspace/orchestrata-ultimate-worktrees/wt-SPEC-110 --socket …/.claude/run/ast-daemon.sock, cwd/opt/orchestrata-tools./opt/orchestrata-tools/VERSION:commit b3a3c26cc…,deployed 2026-10-07T05:07:55-04:00(same key/value format as/opt/orchestrata/VERSION). - The verifier's output on it (from
scratchpad/ph1_ship2.log), six lines:ExecStart: /home/…/wt-SPEC-110 resolves outside ROOT and system prefixes,ExecStart: /home/…/wt-SPEC-110/.claude/run/ast-daemon.sock resolves outside …,ExecStartPre: /home/…/wt-SPEC-110/.git resolves outside …,/proc/4030232/cwd: expected /opt/orchestrata, got /opt/orchestrata-tools,/proc/4030232/cmdline[0]: expected under /opt/orchestrata, got /opt/orchestrata-tools/.venv/bin/python,start-time: expected >= 2026-10-07T08:47:34+00:00, got 2026-10-07T06:24:51+00:00. deploy/install-tools.sh(632 lines): verification section starts at line 287 (echo "==> verifying",fail()at 293);echo "==> systemd templates"at 575 installs/verifies the two templates; VERSION is promoted at lines 625-629 ($SUDO mv "$VERSION_STAGING" "$PREFIX/VERSION",VERSION_PROBE=0, backup removed). The script has nosystemctl restarttoday. Its tests:tests/deploy/test_install_tools.py(fixturesshort_dir,installed,fixture_repo; seetest_installer_puts_daemon_templates_under_the_prefix_and_leaves_user_units_aloneat line 409 for how the user-unit directory is isolated withUNIT_DEST).- Test fixtures:
tests/promotion/_identity_fixtures.py_transient_unit(name, *, working_directory, exec_start, scope="user", type_="simple", on_active=None, extra_properties=(), expect_success=True)creates a REAL transient user unit (systemd-run) and yields it;tests/promotion/test_identity_integration_basic.py(test_full_happy_path_real_unit_real_proc, line 86) shows a complete real-unit identity proof against atmp_pathroot withVERSIONand.venv/bin/python;test_identity_integration_scope.pyandtest_identity_skips.pyshow the scope and skip shapes.
2. The changes (one per plan rule)
- Per-unit root (
identity.py). Add a pure helpertool_tree_root(name: str, properties: Mapping[str, str]) -> Path | Noneinidentity_scope.py: returnsPath("/opt/orchestrata-tools")when the unit name has an instance ("@" in name.split(".service")[0]and the part after@is non-empty) ANDextract_argv0(properties["ExecStart"])resolves under/opt/orchestrata-tools(string prefix afterresolves_safely's leading-slash normalisation, no filesystem access); elseNone. Make the tools root a module constantTOOLS_ROOT = Path("/opt/orchestrata-tools")next toSYSTEM_PREFIXESand derive the prefix entry from it. Incheck_identity, per discovered unit, call it; when it returns a root, read that root'sVERSIONwithparse_version(an unreadable or malformed tools VERSION is anerrorsentry naming the path, never a silent pass) and use(tools_root, tools_root / ".venv" / "bin" / "python", tools_version)in place of(root_resolved, venv_python, version)forcheck_c0and_check_process_identity. Read the tools VERSION once per run, lazily. - Instance parameter is data (
identity_checks.py).check_c0gains a keyword-onlydata_prefixes: Sequence[str] = (); a token equal to one of them or under one (same testresolves_safelyapplies to the root) is exempt.check_identitypasses(instance_path,)for tool-tree instances, whereinstance_pathis"/" + systemd_unescape(instance)computed in pure Python (implementsystemd_unescapeinidentity_scope.py:-to/,\xHHto the byte; the live name decodes to/home/mohamed/workspace/orchestrata-ultimate-worktrees/wt-SPEC-110), with a unit test on that exact name. Nosystemd-escapesubprocess. - Report names the root.
UnitFactsgainsroot: Path | None = None(default keeps every existing constructor call valid).IdentityReport.render()prints, for each unit with a root, one linejudged <name> against <root> (ADR-0067 R1: instance parameter is data);as_dict()includes"judged_against"per unit. Existing output for other units is unchanged byte-for-byte (the CLI tests pin it). - A tools deploy restarts live instances (
deploy/install-tools.sh). Directly after VERSION is promoted (after line 629), for each templatetinorchestrata-ast-daemon orchestrata-codemod-daemon: list active instances withsystemctl --user list-units --plain --no-legend --all "$t@*.service"(the--plainrule fromidentity_scope.discover's docstring), and for every line whose ACTIVE column isactive,systemctl --user restart <unit>and echoOK restarted <unit> (code under $PREFIX changed beneath it); a restart failure isfail "restart <unit>"(the deploy is then refused AFTER VERSION promotion — say so in the message:VERSION promoted; <unit> did not come back). Inactive/failed instances are not touched. Respect the script's existingSYSTEMCTL/dry-run seams if it has them; if it has none, readtests/deploy/test_install_tools.pyto see how systemd is kept out of the test and follow it; if neither exists, STOP and report (do not invent a seam). - Tests.
- New
tests/promotion/test_identity_tool_tree_instances.py, real transient units via_transient_unitwith a tools-shaped root undertmp_path(VERSIONin thecommit/deployedformat,.venv/bin/pythonas the python the transient unit runs; the existingtest_full_happy_path_real_unit_real_procshows the shape). Because the real tools root is the constant, add a seam:check_identity(..., tools_root: Path = TOOLS_ROOT)threaded totool_tree_root; production passes nothing. Cases: (a) a template-named transient unit (name="orchestrata-ast-daemon@<escaped tmp repo>.service"— confirmsystemd-runaccepts a@instance name; if it refuses, use thepatternseam plus a unit file written under an isolated--unit-dest-style directory astest_install_tools.pydoes, and say which in the report) whose argv0 is under the tools root, with--repo-root /<tmp repo>and a socket path under it: zero mismatches, report line names the tools root; (b) same unit plus a token under/home/<user>/workspace/…-shaped path outside both roots: one c0 mismatch naming it; (c) a template-named unit whose argv0 is under a checkout-shaped dir: judged against the product root, fails as today; (d) a plain unit: unchanged result and unchanged render; (e) start-time below the toolsdeployed: one start-time mismatch citing the tools timestamp; (f)systemd_unescapeon the live name above and on-/\x2dmixes; (g) unreadable tools VERSION: anerrorsentry, exit code non-zero. tests/deploy/test_install_tools.py: the restart block restarts onlyactiveinstances of the two templates and nothing else, and a failed restart refuses with the message above.tests/promotion/test_identity_cli.pyand the other identity modules stay green and unchanged.
- New
- Docs.
docs/ship-and-deploy.md(the/opt/orchestrata-toolssection) anddeploy/systemd/README.md: one paragraph each — template instances are judged against the tools root, the instance parameter is data (R1), a tools deploy restarts active instances.@traces: the promotion package's existing decorators tell you which spec ids it cites; cite only ids that spec defines (check_spec_authority.pyis the gate); if the package cites none, add none.
3. Gates and done-when
- Pytest only as
OPENBLAS_NUM_THREADS=1 OMP_NUM_THREADS=1 MKL_NUM_THREADS=1 PYTHONPATH=scripts timeout 300 .venv/bin/python -m pytest <modules> -p orchestrata_pytest_observer -p orchestrata_ultimate.core.threading.pytest_live_observer -q -p no:cacheprovider -rs, background + log +echo "rc=$?" >> <log>, waited withtimeout 290 bash -c 'until grep -q "^rc=" <log>; do sleep 10; done'. Modules: alltests/promotion/test_identity_*.py(group under the cap),tests/deploy/test_install_tools.py,tests/deploy/test_deploy_assets.py,tests/scripts/test_promote_env*.py. Zero skips. - Coverage ≥ 90% on
identity.py,identity_checks.py,identity_scope.py(report the numbers). uv run ruff check,uv run black --checkon changed.py;uv run python scripts/check_spec_authority.pyrc 0;uv run python claude/scripts/gen_plugin.py --check(the plugin mirrorsdeploy/systemd/and may mirrorinstall-tools.sh; regenerate withgen_plugin.pyand commit the regenerated copies if it reports drift).- Live proof, read-only:
PYTHONPATH=scripts .venv/bin/python scripts/verify_deployment_identity.py --root /opt/orchestrata --expect-sha $(git -C /opt/orchestrata rev-parse HEAD)(checkbuild_parserfor the exact flags) before and after: before, the six AST-daemon lines; after, none of them (the stale start-time line may remain until the instance restarts — say so; do not restart the instance yourself). - Commits as
git -c user.name=Mohamed -c user.email=msamy@sufigeeks.org commit, on top of a3728f5a0, no AI attribution, no "should" in the diff, tree clean except hook litter (restoredocs/CODEBASE_MAP.md docs/CODEBASE_MAP_FULL.md reports/.ship-verified reports/run-tests-latest.jsonby name). - Report: shas, per-module counts with log paths, coverage numbers, the before/after live verifier output, deviations. A design fork not settled above (for example a transient template instance that
systemd-runcannot create) is a STOP-and-report, not a guess.