Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import Any

from ..effect_runtime import _node_executable
from ..runtime.node_probe import node_typescript_flags


BRIDGE_CLOSE_TIMEOUT_SECONDS = 5.0
Expand Down Expand Up @@ -164,7 +165,13 @@ def preview(self, *, command: list[str], workspace: Path, release: Path,
)
bridge = Path(__file__).with_name("delegation_preview_bridge.ts")
self._process = subprocess.Popen(
[_node_executable(), "--no-warnings", "--experimental-strip-types", str(bridge)],
[
_node_executable(),
"--no-warnings",
"--experimental-strip-types",
*node_typescript_flags(),
str(bridge),
],
env=environment, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL, text=True, encoding="utf-8",
start_new_session=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ def check_remote_authority_gateway_status(
if not credential:
return {**projection, "status": "unavailable", "reason_code": "remote_authority_credential_required"}
from ..effect_runtime import EffectRuntimeStartupError, _node_executable
from ..runtime.node_probe import node_typescript_flags

try:
# The user-owned registry supplies the origin and optional private CA.
# Pass the credential and binding through the private pipe, not argv.
bridge = Path(__file__).with_name("remote_authority_probe.ts")
completed = subprocess.run(
[_node_executable(), "--no-warnings", "--experimental-strip-types", str(bridge)],
[_node_executable(), "--no-warnings", "--experimental-strip-types", *node_typescript_flags(), str(bridge)],
input=json.dumps({
**{key: cfg[key] for key in _REQUIRED_BINDING},
"goal_id": goal_id, "credential": credential, "ca_file": cfg.get("ca_file"),
Expand Down
3 changes: 3 additions & 0 deletions loopx/control_plane/effect_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
MINIMUM_NODE_VERSION_TEXT as MINIMUM_NODE_VERSION_TEXT,
STARTUP_READY_TIMEOUT_SECONDS as STARTUP_READY_TIMEOUT_SECONDS,
node_probe_remediation,
node_typescript_flags as _node_typescript_flags,
probe_node as _probe_node,
)
from .content_digest import BARE_SHA256_PATTERN
Expand Down Expand Up @@ -1324,6 +1325,7 @@ def _start_runtime(*, fingerprint: str, info_path: Path) -> dict[str, Any]:
_node_executable(),
"--no-warnings",
"--experimental-strip-types",
*_node_typescript_flags(),
"--import",
# ESM specifiers require file URLs on Windows; encode
# reserved path characters on every platform as well.
Expand Down Expand Up @@ -1440,6 +1442,7 @@ def _start_stdio_runtime(fingerprint: str) -> _StdioRuntime:
_node_executable(),
"--no-warnings",
"--experimental-strip-types",
*_node_typescript_flags(),
str(_control_plane_root() / "effect_runtime_stdio.ts"),
fingerprint,
],
Expand Down
2 changes: 2 additions & 0 deletions loopx/control_plane/quota/scheduler_ack.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path

from ..effect_runtime import _node_executable
from ..runtime.node_probe import node_typescript_flags
from ..runtime.time import now_local_iso
from ..scheduler.state import (
CODEX_APP_STATEFUL_BACKOFF_STATE_KEY,
Expand Down Expand Up @@ -217,6 +218,7 @@ def _run_native_followup(
_node_executable(),
"--no-warnings",
"--experimental-strip-types",
*node_typescript_flags(),
str(
Path(__file__).resolve().parents[1]
/ "scheduler"
Expand Down
25 changes: 25 additions & 0 deletions loopx/control_plane/runtime/node_probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@
"""
from __future__ import annotations

import platform
import re
import shutil
import subprocess
import sys
from dataclasses import dataclass
from enum import StrEnum

MINIMUM_NODE_VERSION = (22, 22, 3)
MINIMUM_NODE_VERSION_TEXT = ".".join(str(part) for part in MINIMUM_NODE_VERSION)
STARTUP_READY_TIMEOUT_SECONDS = 15.0
_LINUX_X86_MACHINES = frozenset({"x86_64", "amd64"})
_LINUX_X86_TYPESCRIPT_V8_FLAGS = (
"--liftoff-only",
"--no-wasm-tier-up",
"--no-wasm-dynamic-tiering",
)
HOST_PERMISSION_RECOMMENDATION = (
"retry the same registry, Goal, Agent and Turn through host-approved "
"local runtime access; do not enable optional capabilities, replace "
Expand Down Expand Up @@ -135,3 +143,20 @@ def probe_node(*, timeout: float = STARTUP_READY_TIMEOUT_SECONDS) -> NodeProbe:
if prerelease is not None:
version_text += f"-{prerelease}"
return NodeProbe(outcome, executable, version_text)


def node_typescript_flags(
*,
system: str | None = None,
machine: str | None = None,
) -> tuple[str, ...]:
"""Return V8 Wasm baseline flags for Node TypeScript stripping on Linux x86_64.

Under QEMU/TCG or Linux PKU environments Node's Amaro Wasm TypeScript
stripper can trap in V8 ThreadIsolation during TurboFan Wasm tier-up.
"""
resolved_system = (sys.platform if system is None else system).lower()
resolved_machine = (platform.machine() if machine is None else machine).lower()
if resolved_system.startswith("linux") and resolved_machine in _LINUX_X86_MACHINES:
return _LINUX_X86_TYPESCRIPT_V8_FLAGS
return ()
15 changes: 15 additions & 0 deletions loopx/control_plane/runtime/node_version.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
const MINIMUM_NODE_VERSION = [22, 22, 3] as const;
const NODE_VERSION_PATTERN = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
const LINUX_X86_TYPESCRIPT_V8_FLAGS = [
"--liftoff-only",
"--no-wasm-tier-up",
"--no-wasm-dynamic-tiering",
] as const;

export function isSupportedNodeVersion(version: string): boolean {
const match = NODE_VERSION_PATTERN.exec(version);
Expand All @@ -12,3 +17,13 @@ export function isSupportedNodeVersion(version: string): boolean {
}
return match[4] === undefined;
}

export function nodeTypescriptFlags(
platform: string = process.platform,
arch: string = process.arch,
): string[] {
if (platform === "linux" && (arch === "x64" || arch === "amd64")) {
return [...LINUX_X86_TYPESCRIPT_V8_FLAGS];
}
return [];
}
2 changes: 2 additions & 0 deletions loopx/control_plane/state_recovery_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from typing import Any, BinaryIO, Iterator, NoReturn

from .effect_runtime import _node_executable, effect_runtime_result, effect_runtime_request_scope
from .runtime.node_probe import node_typescript_flags

MAX_ARCHIVE_BYTES = 128 * 1024 * 1024
MAX_EXPANDED_BYTES = 512 * 1024 * 1024
Expand Down Expand Up @@ -87,6 +88,7 @@ def _runtime(method: str, request: dict[str, Any]) -> dict[str, Any]:
def _audit_owners(request: dict[str, Any]) -> dict[str, Any]:
command = [_node_executable(), "--no-warnings", "--max-old-space-size=512",
"--experimental-sqlite", "--experimental-strip-types",
*node_typescript_flags(),
str(Path(__file__).with_name("state_recovery_worker.ts"))]
try:
completed = subprocess.run(command, input=json.dumps(request), text=True, encoding="utf-8",
Expand Down
2 changes: 2 additions & 0 deletions loopx/control_plane/testing/authority_e2e_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from ..coordination.coordination_state_contract_generated import (
LOCAL_AUTHORITY_SHADOW_CONFIG_SCHEMA,
)
from ..runtime.node_probe import node_typescript_flags

REPO_ROOT = Path(__file__).resolve().parents[3]
TS_READBACK_PROBE = Path("tests") / "control_plane_ts" / "authority_store_readback_probe.ts"
Expand Down Expand Up @@ -541,6 +542,7 @@ def ts_readback(
node,
"--no-warnings",
"--experimental-strip-types",
*node_typescript_flags(),
str(REPO_ROOT / TS_READBACK_PROBE),
"--directory",
str(directory or workspace.shadow_directory),
Expand Down
5 changes: 4 additions & 1 deletion loopx/control_plane/testing/authority_e2e_ladder.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
QUALIFIED_NOKV_API_VERSION as QUALIFIED_NOKV_API_VERSION,
QUALIFIED_NOKV_SDK_VERSION as QUALIFIED_NOKV_SDK_VERSION,
)
from ..runtime.node_probe import node_typescript_flags
from .authority_e2e_row_support import (
AGENT_A,
RowAssertionError,
Expand Down Expand Up @@ -208,7 +209,7 @@ def _row_local_conformance(context: RowContext, provider: str) -> RowOutcome:
return unverified("local_conformance_suite_missing")
summary = tap_summary(
[node, "--no-warnings", "--experimental-sqlite", "--experimental-strip-types",
"--test", "--test-reporter=tap", str(suite)],
*node_typescript_flags(), "--test", "--test-reporter=tap", str(suite)],
env=context.environ,
timeout=900,
)
Expand Down Expand Up @@ -347,6 +348,7 @@ def _row_nokv_live_qualification(context: RowContext) -> RowOutcome:
node,
"--no-warnings",
"--experimental-strip-types",
*node_typescript_flags(),
str(REPO_ROOT / NOKV_QUALIFICATION_SCRIPT),
"--execute-live",
"--config-json",
Expand Down Expand Up @@ -457,6 +459,7 @@ def _row_postgresql_conformance_live(context: RowContext) -> RowOutcome:
node,
"--no-warnings",
"--experimental-strip-types",
*node_typescript_flags(),
"--test",
"--test-reporter=tap",
str(PG_INTEGRATION_TEST),
Expand Down
12 changes: 11 additions & 1 deletion loopx/control_plane/testing/canary_harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from pathlib import Path
from typing import Any, Iterable

from ..runtime.node_probe import node_typescript_flags


REPO_ROOT = Path(__file__).resolve().parents[3]

Expand Down Expand Up @@ -302,7 +304,15 @@ def advance_fixture_authority(
"process.stdout.write(JSON.stringify(result));"
)
process = subprocess.run(
["node", "--no-warnings", "--experimental-strip-types", "--input-type=module", "-e", script],
[
"node",
"--no-warnings",
"--experimental-strip-types",
*node_typescript_flags(),
"--input-type=module",
"-e",
script,
],
input=json.dumps({"root": str(runtime_root), "goal": goal_id,
"projection": projection, "operation_id": operation_id}),
capture_output=True, text=True, encoding="utf-8", check=False, timeout=45,
Expand Down
2 changes: 2 additions & 0 deletions loopx/control_plane/turn_driver/host_process_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from ...file_lock import lock_holder_host_label
from ..effect_runtime import _node_executable
from ..runtime.node_probe import node_typescript_flags
from .host_bridge_transport import GuardedHostBridge

# Keep Python's Windows executable/batch launcher compatibility. No timeout,
Expand Down Expand Up @@ -347,6 +348,7 @@ def run_host_process(
_node_executable(),
"--no-warnings",
"--experimental-strip-types",
*node_typescript_flags(),
str(bridge),
*launch_arguments,
],
Expand Down
2 changes: 2 additions & 0 deletions loopx/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path

from . import __version__
from .control_plane.runtime.node_probe import node_typescript_flags


def pin_utf8_stdio() -> None:
Expand Down Expand Up @@ -123,6 +124,7 @@ def _native_scheduler_followup_argv(raw_argv: list[str]) -> list[str] | None:
node,
"--no-warnings",
"--experimental-strip-types",
*node_typescript_flags(),
str(entry),
*raw_argv,
]
Expand Down
10 changes: 9 additions & 1 deletion loopx/extensions/turn_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pathlib import Path

from ..control_plane.effect_runtime import _node_executable
from ..control_plane.runtime.node_probe import node_typescript_flags
from ..control_plane.goals.goal_ref_validation import exact_goal_ref
from ..control_plane.turn_driver.executor import validate_loopx_turn_host_result
from ..control_plane.turn_driver.host_candidate import (
Expand Down Expand Up @@ -37,4 +38,11 @@ def supervised_stdio_command(command: Sequence[str]) -> list[str]:
if not command or any(not isinstance(arg, str) or "\0" in arg for arg in command) or not command[0]:
raise ValueError("a stdio command argv is required")
bridge = Path(__file__).resolve().parents[1] / "control_plane" / "turn_driver" / "host_stdio_bridge.ts"
return [_node_executable(), "--no-warnings", "--experimental-strip-types", str(bridge), *command]
return [
_node_executable(),
"--no-warnings",
"--experimental-strip-types",
*node_typescript_flags(),
str(bridge),
*command,
]
5 changes: 3 additions & 2 deletions loopx/semantics/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import subprocess
from typing import Any, Callable

from ..control_plane.runtime.node_probe import node_typescript_flags
from .inventory import SourceFile
from .python_production import Production, enum_members, scan_python_production

Expand Down Expand Up @@ -292,7 +293,7 @@ def probe_settlement_binding_production(vocabulary: dict[str, Any]) -> list[Prod
for count in (2, 3) for group in combinations(bindings, count)]
probes.extend(conflicts)
completed = subprocess.run(
['node', '--no-warnings', '--experimental-strip-types',
['node', '--no-warnings', '--experimental-strip-types', *node_typescript_flags(),
str(root / 'scripts/settlement_binding_witness.mts')],
input=json.dumps({'probes': probes}), capture_output=True, text=True,
encoding='utf-8', check=False,
Expand Down Expand Up @@ -337,7 +338,7 @@ def probe_quota_run_decision_production(vocabulary: dict[str, Any]) -> list[Prod
root = Path(__file__).resolve().parents[2]
try:
completed = subprocess.run(
['node', '--no-warnings', '--experimental-strip-types',
['node', '--no-warnings', '--experimental-strip-types', *node_typescript_flags(),
str(root / 'scripts/quota_run_decision_witness.mts')],
input=json.dumps({'values': vocabulary['values']}), capture_output=True,
text=True, encoding='utf-8', check=False, timeout=30,
Expand Down
10 changes: 9 additions & 1 deletion loopx/usage_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from typing import Any

from . import __version__
from .control_plane.runtime.node_probe import node_typescript_flags
from .paths import select_default_runtime_root

STATE_FILENAME = "usage-ping.json"
Expand Down Expand Up @@ -120,7 +121,14 @@ def _command() -> list[str]:
raise UsageSettingsUnavailable(message="Usage settings require the supported Node.js runtime.")
# Keep the Python sender's proxy behavior when moving I/O to Node. This
# native flag is available in the repository's supported Node versions.
return [node, "--no-warnings", "--use-env-proxy", "--experimental-strip-types", str(_ENTRY)]
return [
node,
"--no-warnings",
"--use-env-proxy",
"--experimental-strip-types",
*node_typescript_flags(),
str(_ENTRY),
]


def control(action: str, path: Path | None = None, **fields: Any) -> dict[str, Any]:
Expand Down
7 changes: 6 additions & 1 deletion loopx/zcode_goal_mode/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ..control_plane.goals.activation import goal_is_stopped
from ..control_plane.goals.goal_ref_validation import exact_goal_ref, require_goal_id
from ..control_plane.runtime.goal_project_route import resolve_goal_project_route
from ..control_plane.runtime.node_probe import node_typescript_flags
from ..control_plane.projects.registry_codec import load_registry
from ..host_loop_activation import normalize_agent_type
from ..registry import registry_goals
Expand Down Expand Up @@ -274,7 +275,11 @@ def zcode_goal_operation(
request["task_body"] = _heartbeat_task(binding, loopx_command)
if action in {"bind", "start", "resume"}:
request["goal_basis"] = _goal_basis(binding)
payload = _run_json([node, "--experimental-strip-types", str(Path(__file__).with_name("cli.ts"))], project=binding["project"], request=request)
payload = _run_json(
[node, "--experimental-strip-types", *node_typescript_flags(), str(Path(__file__).with_name("cli.ts"))],
project=binding["project"],
request=request,
)
for key in ("goal_id", "goal_ref", "goal_creation_operation_id", "agent_id"):
if key not in payload or payload[key] != binding[key]:
raise ZCodeGoalBridgeError("ZCode readback did not match the exact Goal and Agent requested.", code="zcode_goal_invalid_readback", status=409)
Expand Down
5 changes: 3 additions & 2 deletions loopx/zcode_goal_mode/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {ZCODE_GOAL_ACTIONS, isGoalBasis, sameBinding, ZCodeGoalError, safeFailur
import {NativeGoalController, readState, atomicState, type BindingState} from "./runtime.ts";
import {ZCodeAppServer} from "./app-server.ts";
import {acquireFileMutationLock, releaseFileMutationLock, durableWriteJson} from "../control_plane/effect_runtime_io.ts";
import {nodeTypescriptFlags} from "../control_plane/runtime/node_version.ts";

const MAX_INPUT = 64 * 1024;
const MAX_RESPONSE = 1024 * 1024;
Expand Down Expand Up @@ -153,7 +154,7 @@ async function serve(request: NativeRequest): Promise<void> {
const storage = request.state_path + ".host";
await mkdir(storage, {recursive: true, mode: 0o700});
const guardedCommand = [process.execPath, "--no-warnings", "--experimental-strip-types",
fileURLToPath(new URL("./guard.ts", import.meta.url)), "--", ...selected.cli_command];
...nodeTypescriptFlags(), fileURLToPath(new URL("./guard.ts", import.meta.url)), "--", ...selected.cli_command];
const host = new ZCodeAppServer(guardedCommand, selected.project, {
...process.env, ZCODE_STORAGE_DIR: storage, ZCODE_DATA_BASE_DIR: storage, ZCODE_SESSION_DB_PATH: join(storage, "sessions.db"),
}, {guardian: true, onExit: () => {void shutdown();}});
Expand Down Expand Up @@ -272,7 +273,7 @@ async function dispatch(request: NativeRequest): Promise<ZCodeGoalReadback> {
if (!state && !request.cli_command) throw new ZCodeGoalError("ZCode CLI was not found");
await validate(request, ["pause", "stop"].includes(request.action));
const child = spawn(process.execPath, ["--no-warnings", "--experimental-strip-types",
fileURLToPath(import.meta.url), "--serve"], {cwd: request.project, detached: true,
...nodeTypescriptFlags(), fileURLToPath(import.meta.url), "--serve"], {cwd: request.project, detached: true,
windowsHide: true, stdio: ["pipe", "ignore", "ignore"], env: process.env});
child.on("error", () => {});
child.stdin!.end(JSON.stringify(request));
Expand Down
Loading
Loading