Skip to content
Merged
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
52 changes: 47 additions & 5 deletions .github/workflows/ci-ready.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ jobs:

host-compatibility:
# GitHub-hosted Windows and macOS CPU evidence, separate from the Ubuntu jobs above:
# a pass on Linux is not a pass on these hosts. It runs only the eight plugin and DSH
# nodes that an earlier Windows run recorded as failing (63 passed, 8 failed), then an
# installed-wheel check. A pass here does not rewrite that record. No GPU, remote
# service or credential is used; the DSH node talks to the fake SSH server that its
# own check starts. One host at a time, one pytest process, no full suite.
# a pass on Linux is not a pass on these hosts. It runs the eight plugin and DSH nodes
# that an earlier Windows run recorded as failing (63 passed, 8 failed), on Windows the
# Harness artifact-primitive and writer nodes, then an installed-wheel check. A pass
# here does not rewrite that record. No GPU, remote service or credential is used; the
# DSH node talks to the fake SSH server that its own check starts. One host at a time,
# one pytest process per step, no full suite.
strategy:
fail-fast: false
max-parallel: 1
Expand Down Expand Up @@ -171,6 +172,46 @@ jobs:
print(counts, flush=True)
if counts != {"tests": len(nodes), "errors": 0, "failures": 0, "skipped": 0}:
raise SystemExit("every selected host node must run and pass")
- name: Test the Harness artifact-primitive and writer nodes on Windows
# #412 R2: Harness owns copies of the Infra digest, hash, file lock and atomic
# writer. On Windows the lock is an msvcrt byte range that even denies a read of
# the locked byte, which no Linux job can show. macOS uses the same fcntl lock as
# the Linux jobs, so only Windows runs these nodes. Runs even if the step above
# failed, so both results are recorded.
if: ${{ !cancelled() && runner.os == 'Windows' }}
shell: python
env:
RESULTS: ${{ runner.temp }}/host-primitives-results.xml
run: |
import os
import subprocess
import sys
import xml.etree.ElementTree as ET

nodes = [
"tests/test_skill_evaluation.py::test_harness_artifact_primitives_match_infra_bytes_and_semantics",
"tests/test_skill_evaluation.py::test_harness_owned_writes_and_digests_match_infra_bytes",
"tests/test_legacy_run_split.py::test_harness_writer_bytes_equal_the_infra_writer",
"tests/test_legacy_run_split.py::test_harness_writer_rejects_nan_and_leaves_no_file",
"tests/test_legacy_run_split.py::test_sampling_sha256_matches_the_infra_hasher",
"tests/test_optimization_session.py::test_runtime_identity_covers_migrated_process_domain_and_not_removed_executor",
"tests/test_agent_sessions.py",
]
results = os.environ["RESULTS"]
command = [sys.executable, "-m", "pytest", "-vv", "-rs", "-o", "addopts=",
"--junitxml=" + results, *nodes]
status = subprocess.run(
command, cwd=os.environ["GITHUB_WORKSPACE"], check=False
).returncode
if status:
raise SystemExit(status)
# pytest exits 0 with skips, and a skipped node is not a pass.
suite = next(ET.parse(results).getroot().iter("testsuite"))
counts = {name: int(suite.get(name))
for name in ("tests", "errors", "failures", "skipped")}
print(counts, flush=True)
if counts["skipped"]:
raise SystemExit("every selected primitive node must run and pass")
- name: Check a wheel built from the sdist in a fresh environment outside the checkout
# Runs even if a node above failed, so both results are recorded; either failure
# still fails the job.
Expand Down Expand Up @@ -244,5 +285,6 @@ jobs:
name: host-compatibility-${{ matrix.os }}
path: |
${{ runner.temp }}/host-compatibility-results.xml
${{ runner.temp }}/host-primitives-results.xml
${{ runner.temp }}/host-wheel.log
retention-days: 30
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@

### Changed

- Six Harness modules stop importing Infra (Refs #412, R2). `agent_sessions`,
`candidates`, `optimization`, `optimization_session`, `project` and
`task_protocol` take `digest`, `sha256` and `file_lock` from the new
`harness/artifact_primitives.py` and `atomic_write_json` from the existing
`harness/atomic_json.py`. The function bodies equal those in
`infra/artifacts.py`, so digests, file hashes, JSON bytes, atomic replace and
lock files are unchanged, and a Harness lock and an Infra lock on the same
path still exclude each other. `infra/artifacts.py` stays for its other users.
- `first_wave_report()` no longer reports `harness reaches model/infra`; it had
12 hits, the package-level `inferrsi.infra` and `inferrsi.infra.artifacts`
edge from each of the six modules. Harness has no `inferrsi.model` edge.
- The optimization session's runtime identity adds
`harness/artifact_primitives.py`. The six edited modules are already in it,
so a session started before this change does not resume after it.
- Isolation is still incomplete: the five runtime resource loaders (R3, #412)
remain.

- The local MindIE adapter moves into the Apps package and its four root files
are removed (Refs #452, M1), with no forwarding shell, `sys.modules` alias or
import fallback:
Expand Down Expand Up @@ -39,6 +56,7 @@
- Isolation is still incomplete: the 12 Harness hits into Infra (R2, #412)
and the five runtime resource loaders (R3, #412) remain.


- The campaign chart renderer and the single-task launcher move into the Apps
package and the two root modules are removed (Refs #408, A2), with no
forwarding shell, `sys.modules` alias or import fallback. Both files move
Expand Down
16 changes: 11 additions & 5 deletions docs/module-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,23 @@ present; or the scan reports a violation. The three packages may appear in stage
A clean graph for the new cores is reported separately as "new core business
closure isolated" and never sets overall `isolation_complete` to true.

On the tree after A1 (#408), `first_wave_report()` has no violation and two
blockers, so `isolation_complete` is false and A1 does not claim otherwise:
On the tree after R2 (#412), `first_wave_report()` has no violation and one
blocker, so `isolation_complete` is false and R2 does not claim otherwise:

| Blocker | Cause | Closed by |
| --- | --- | --- |
| `harness reaches model/infra` (12 hits) | `agent_sessions`, `candidates`, `optimization`, `optimization_session`, `project` and `task_protocol` each reach `inferrsi.infra` and `inferrsi.infra.artifacts` | R2 (#412) |
| `runtime resource loaders: 5` | The five declared loaders in the table above | R3 (#412) |

R1 cleared the `allowlist` and `legacy run forwarders` blockers, and A1 cleared
the `temporary leaf importers` blocker that R1 left for root `arguments.py`. The loaders
also keep `new_core_closure_isolated` false.
the `temporary leaf importers` blocker that R1 left for root `arguments.py`. R2
cleared `harness reaches model/infra` (12 hits): `agent_sessions`, `candidates`,
`optimization`, `optimization_session`, `project` and `task_protocol` each reached
`inferrsi.infra` and `inferrsi.infra.artifacts`. They now take `digest`, `sha256`
and `file_lock` from `harness/artifact_primitives.py` and `atomic_write_json` from
`harness/atomic_json.py`, whose function bodies equal those in `infra/artifacts.py`.
`infra/artifacts.py` stays for its other users. No Harness module reaches
`inferrsi.infra` or `inferrsi.model`. The loaders also keep
`new_core_closure_isolated` false.

`knowledge-model-policy` stays the only required status. Until a separate
process decision makes this import gate required, every migration PR attaches
Expand Down
3 changes: 2 additions & 1 deletion src/inferrsi/harness/agent_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import uuid
from pathlib import Path

from ..infra.artifacts import atomic_write_json, digest, file_lock, sha256
from .artifact_primitives import digest, file_lock, sha256
from .atomic_json import atomic_write_json
from .usage import normalize_usage

TERMINAL = {"completed", "failed", "cancelled"}
Expand Down
51 changes: 51 additions & 0 deletions src/inferrsi/harness/artifact_primitives.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Harness-owned digest, file hash and file lock. Each function body equals the one in
# infra.artifacts, so digests, hashes and lock files are byte-identical and the two locks
# exclude each other on the same path; Harness does not import that module here.

import hashlib
import json
import os
from contextlib import contextmanager
from pathlib import Path


@contextmanager
def file_lock(path: Path):
"""Hold a nonblocking OS file lock, released even if the process crashes."""
with path.open("a+b") as stream:
if os.fstat(stream.fileno()).st_size == 0:
stream.write(b"0")
stream.flush()
stream.seek(0)
if os.name == "nt":
import msvcrt

msvcrt.locking(stream.fileno(), msvcrt.LK_NBLCK, 1)
else:
import fcntl

fcntl.flock(stream.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
try:
yield
finally:
stream.seek(0)
if os.name == "nt":
msvcrt.locking(stream.fileno(), msvcrt.LK_UNLCK, 1)
else:
fcntl.flock(stream.fileno(), fcntl.LOCK_UN)


def digest(value):
return hashlib.sha256(
json.dumps(
value, sort_keys=True, separators=(",", ":"), ensure_ascii=False, allow_nan=False
).encode()
).hexdigest()


def sha256(path):
hasher = hashlib.sha256()
with Path(path).open("rb") as stream:
for block in iter(lambda: stream.read(1024 * 1024), b""):
hasher.update(block)
return hasher.hexdigest()
2 changes: 1 addition & 1 deletion src/inferrsi/harness/candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import stat
from pathlib import Path

from ..infra.artifacts import digest, sha256
from .artifact_primitives import digest, sha256


def members(source: Path, includes: list[str] | None = None) -> dict[str, Path]:
Expand Down
3 changes: 2 additions & 1 deletion src/inferrsi/harness/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import uuid
from pathlib import Path

from ..infra.artifacts import atomic_write_json, digest, file_lock, sha256
from . import candidates
from .artifact_primitives import digest, file_lock, sha256
from .atomic_json import atomic_write_json
from .usage import normalize_usage, usage_totals


Expand Down
8 changes: 4 additions & 4 deletions src/inferrsi/harness/optimization_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ def _session_assess(root, directory, plan, execution):


def _project_execute(root, directory, plan, deadline):
from inferrsi.harness.atomic_json import atomic_write_json
from inferrsi.harness.candidates import identity, members, retain
from inferrsi.harness.project import inspect_step, steps
from inferrsi.harness.scenarios.external import execute_trial
from inferrsi.infra.artifacts import atomic_write_json

output = directory / "execution"
output.mkdir()
Expand Down Expand Up @@ -107,13 +107,13 @@ def _project_execute(root, directory, plan, deadline):


def _runtime_identity():
from inferrsi.infra.artifacts import sha256
from inferrsi.harness.artifact_primitives import sha256

root = Path(str(files("inferrsi")))
names = ("harness/optimization_session.py", "harness/optimization.py",
"harness/local_process.py",
"infra/processes.py", "infra/artifacts.py", "harness/scenarios/external.py",
"harness/atomic_json.py",
"harness/atomic_json.py", "harness/artifact_primitives.py",
"harness/usage.py", "harness/agent_sessions.py", "harness/task_protocol.py",
"harness/candidates.py", "harness/project.py",
"harness/records/knowledge_capture.py", "apps/campaign.py",
Expand All @@ -130,9 +130,9 @@ def session_command(args, *, task_source: Path | None = None, knowledge_reader=N
if args.session_action == "start":
import math

from inferrsi.harness.artifact_primitives import sha256
from inferrsi.harness.candidates import identity, retain
from inferrsi.harness.task_protocol import prepare
from inferrsi.infra.artifacts import sha256

if args.rounds < 1 or any(not math.isfinite(value) or value <= 0 for value in (
args.max_minutes, args.evaluation_timeout_seconds
Expand Down
2 changes: 1 addition & 1 deletion src/inferrsi/harness/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pathlib import Path
from statistics import median

from ..infra.artifacts import sha256
from .artifact_primitives import sha256


def validate(settings: dict) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/inferrsi/harness/task_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import shutil
from pathlib import Path

from ..infra.artifacts import sha256
from .artifact_primitives import sha256


def protocol(root: Path):
Expand Down
38 changes: 38 additions & 0 deletions tests/test_first_wave_isolation_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,44 @@ def test_returning_skill_evaluation_infra_edge_fails(self) -> None:
)
self.assertFalse(report.isolation_complete)

def test_returning_r2_harness_infra_edges_fail(self) -> None:
# #412 R2 removed infra.artifacts from six Harness modules. Putting one edge back,
# relative or absolute, top-level or inside a function, reports both the package
# and the module edge; reaching another infra module or model also counts.
infra = {"infra/__init__.py": "", "infra/artifacts.py": "VALUE = 1\n",
"infra/processes.py": "VALUE = 1\n", "model/__init__.py": "",
"model/metrics.py": "VALUE = 1\n"}
primitives = {"harness/artifact_primitives.py": "VALUE = 1\n",
"harness/atomic_json.py": "VALUE = 1\n"}
modules = ("agent_sessions", "candidates", "optimization", "optimization_session",
"project", "task_protocol")
clean = {f"harness/{name}.py": "from .artifact_primitives import VALUE\n"
for name in modules}
cleared = _report({**infra, **primitives, **clean}, manifest=EMPTY_ALLOWLIST,
base=CLEARED_TREE)
self.assertEqual(cleared.harness_model_infra, ())
self.assertTrue(cleared.isolation_complete)
sources = (
("from ..infra.artifacts import VALUE\n", "inferrsi.infra.artifacts"),
("def late():\n from inferrsi.infra.artifacts import VALUE\n",
"inferrsi.infra.artifacts"),
("from ..infra import processes\n", "inferrsi.infra.processes"),
("from inferrsi.model import metrics\n", "inferrsi.model.metrics"),
)
for name in modules:
for source, target in sources:
with self.subTest(module=name, source=source):
report = _report({**infra, **primitives, **clean,
f"harness/{name}.py": source},
manifest=EMPTY_ALLOWLIST, base=CLEARED_TREE)
package = target.rsplit(".", 1)[0]
self.assertEqual(
report.harness_model_infra,
(f"inferrsi.harness.{name} -> {package}",
f"inferrsi.harness.{name} -> {target}"),
)
self.assertFalse(report.isolation_complete)

def test_mixed_harness_tree_is_not_an_isolated_core(self) -> None:
tree = {"__init__.py": "", "harness/__init__.py": "", "harness/runner.py": "VALUE = 1\n"}
report = _report({}, base=tree)
Expand Down
18 changes: 5 additions & 13 deletions tests/test_knowledge_compatibility_shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,20 +282,12 @@ def test_package_init_and_infra_inspection_load_no_knowledge_body():

def test_knowledge_closure_is_clean_while_overall_stays_false():
# K01-5: the Knowledge package exists and its closure is clean. R1 cleared the
# allowlist and the old-run forwarders. The parser entry due in A1, the twelve
# harness -> infra hits (R2) and the five runtime resource loaders (R3) remain,
# and the loaders keep new_core_closure_isolated false.
# allowlist and the old-run forwarders, A1 the parser entry and R2 the twelve
# harness -> infra hits from six modules. The five runtime resource loaders (R3)
# remain, and they keep new_core_closure_isolated false.
report = first_wave_report()
assert report.violations == ()
assert report.blockers == (
"harness reaches model/infra: inferrsi.harness.agent_sessions -> inferrsi.infra (12 hits)",
"runtime resource loaders: 5",
)
assert len(report.harness_model_infra) == 12
assert {path.split(" -> ")[0] for path in report.harness_model_infra} == {
f"inferrsi.harness.{name}"
for name in ("agent_sessions", "candidates", "optimization", "optimization_session",
"project", "task_protocol")
}
assert report.blockers == ("runtime resource loaders: 5",)
assert report.harness_model_infra == ()
assert not report.new_core_closure_isolated
assert not report.isolation_complete
6 changes: 2 additions & 4 deletions tests/test_legacy_run_forwarder_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ def test_real_tree_holds_no_forwarder_and_stays_incomplete():
assert report.violations == ()
for name in RETIRED_FORWARDERS:
assert not (support.ROOT / f"{name}.py").exists(), name
# What is left belongs to R2 and R3, plus the parser entry due in A1.
assert support.blocker_kinds(report) == {
"harness reaches model/infra", "runtime resource loaders",
}
# What is left belongs to R3: R2 closed the harness -> infra hits.
assert support.blocker_kinds(report) == {"runtime resource loaders"}
assert not report.isolation_complete
2 changes: 2 additions & 0 deletions tests/test_optimization_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ def test_runtime_identity_covers_migrated_process_domain_and_not_removed_executo
identity = optimization_session._runtime_identity()
root = Path(str(files("inferrsi")))
assert "harness/local_process.py" in identity
# #412 R2: the Harness-owned primitives replace infra.artifacts in six modules.
assert "harness/artifact_primitives.py" in identity
assert "infra/executors/local.py" not in identity
for name in identity:
assert (root / name).is_file(), name
Loading
Loading