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
81 changes: 81 additions & 0 deletions docs/apps-module-migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -528,5 +528,86 @@
"tests/harness/test_parallel_round.py",
"tools/parallel_round.py"
]
},
{
"old": "inferrsi.apps.artifacts",
"canonical": "inferrsi.apps.storage.artifacts",
"exports": [
"REPLACE_ATTEMPTS",
"REPLACE_DELAY_SECONDS",
"atomic_write_json",
"digest",
"file_lock",
"sha256",
"write_json"
],
"consumers": [
"docs/skill-evaluation/local-skill-evaluation.md",
"src/inferrsi/apps/artifacts.py",
"src/inferrsi/apps/delivery/__init__.py",
"src/inferrsi/apps/delivery/projection.py",
"src/inferrsi/apps/delivery/snapshot.py",
"src/inferrsi/harness/artifact_primitives.py",
"src/inferrsi/harness/atomic_json.py",
"src/inferrsi/harness/input_binding.py",
"tests/_gate_policy_support.py",
"tests/apps/test_anthropic_agent.py",
"tests/apps/test_goal_checkpoint.py",
"tests/apps/test_inspection.py",
"tests/apps/test_legacy_run_split.py",
"tests/apps/test_result_delivery.py",
"tests/apps/test_yibuapi_runtime.py",
"tests/benchmark/test_image_modules.py",
"tests/campaigns/test_qwen21_task.py",
"tests/check_installed.py",
"tests/fixtures/harness_improvement_demo.py",
"tests/fixtures/service_reuse.py",
"tests/fixtures/skill_eval_compare_support.py",
"tests/fixtures/skill_eval_pr_support.py",
"tests/harness/test_session_lock_across_processes.py",
"tests/repository/test_target_module_import_gate.py",
"tests/session_lock_probe.py",
"tests/skill_eval/test_skill_eval_compare.py",
"tests/skill_eval/test_skill_eval_diagnostic.py",
"tests/skill_eval/test_skill_eval_feedback.py",
"tests/skill_eval/test_skill_eval_generation.py",
"tests/skill_eval/test_skill_eval_historical_job.py",
"tests/skill_eval/test_skill_eval_local.py",
"tests/skill_eval/test_skill_eval_pipeline.py",
"tests/skill_eval/test_skill_eval_planned_guidance.py",
"tests/skill_eval/test_skill_eval_planning_boundaries.py",
"tests/skill_eval/test_skill_eval_pr.py",
"tests/skill_eval/test_skill_eval_pr_diagnostic.py",
"tests/skill_eval/test_skill_eval_retention.py",
"tests/skill_eval/test_skill_eval_review_guidance.py",
"tests/skill_eval/test_skill_evaluation.py",
"tests/test_artifact_helper_copies.py",
"tools/goal_checkpoint.py",
"tools/skill_eval_auto.py",
"tools/skill_eval_cloud_export.py",
"tools/skill_eval_compare.py",
"tools/skill_eval_historical_job.py",
"tools/skill_eval_improve.py",
"tools/skill_eval_local.py",
"tools/skill_eval_pilot.py",
"tools/skill_eval_pr.py"
]
},
{
"old": "inferrsi.apps.inspection",
"canonical": "inferrsi.apps.host.prepared_environment",
"exports": [
"inspect_environment"
],
"consumers": [
"docs/contracts/current-design.md",
"docs/module-layout.md",
"src/inferrsi/apps/cli/__init__.py",
"src/inferrsi/apps/inspection.py",
"tests/apps/test_inspection.py",
"tests/check_installed.py",
"tests/repository/test_architecture_closed_loop.py",
"tests/repository/test_first_wave_isolation_policy.py"
]
}
]
4 changes: 2 additions & 2 deletions docs/contracts/current-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Historical candidate text, review dispositions, and the earlier Proposed drafts

## D001 — One distribution, three cores plus Apps, document contracts rather than shared business DTOs

Decision: keep Knowledge, Harness, and Benchmark as sibling independent cores; Apps is the only assembler. Each core owns its types. Cross-boundary traffic uses versioned JSON envelopes with explicit conversion; there is no shared business `contracts` package. The technical-only `inferrsi.contracts` package re-exports only `RunSpec`, defined once in `contracts/runspec.py`; `contracts/claim.py` owns the same Verdict enum re-exported by Harness. These are not shared business DTOs. The old root `contracts.py`, `runspec.py`, `claim.py`, and `_json_v1.py` files are retired without forwarding shells, and so are the old root `_repo_pack_data.py` and `evidence_paths.py`. R1 (#412) retired eleven more root modules the same way: the seven Knowledge compatibility shells, the three old-run forwarders `evaluation.py`, `execution.py` and `reporting.py`, and root `inspection.py`, whose host binding is now `inferrsi.apps.inspection` over the facts API in `inferrsi.apps.host.inspection`. [`CHANGELOG.md`](../../CHANGELOG.md) maps every retired path to its replacement and states the import and pickle impact.
Decision: keep Knowledge, Harness, and Benchmark as sibling independent cores; Apps is the only assembler. Each core owns its types. Cross-boundary traffic uses versioned JSON envelopes with explicit conversion; there is no shared business `contracts` package. The technical-only `inferrsi.contracts` package re-exports only `RunSpec`, defined once in `contracts/runspec.py`; `contracts/claim.py` owns the same Verdict enum re-exported by Harness. These are not shared business DTOs. The old root `contracts.py`, `runspec.py`, `claim.py`, and `_json_v1.py` files are retired without forwarding shells, and so are the old root `_repo_pack_data.py` and `evidence_paths.py`. R1 (#412) retired eleven more root modules the same way: the seven Knowledge compatibility shells, the three old-run forwarders `evaluation.py`, `execution.py` and `reporting.py`, and root `inspection.py`, whose host binding is now `inferrsi.apps.host.prepared_environment` over the facts API in `inferrsi.apps.host.inspection`. [`CHANGELOG.md`](../../CHANGELOG.md) maps every retired path to its replacement and states the import and pickle impact.

Permitted shared technical leaves are only:

Expand Down Expand Up @@ -143,7 +143,7 @@ Decision: see [`gate-policy-runstore-and-first-prs.md`](gate-policy-runstore-and

Decision: old entry points, arguments, `Path`, stdout, stderr, and old run 0/1/2 stay byte-for-byte compatible. New Apps naming/envelope/exit mapping is fixed by D022, but K01/H01 do not implement a CLI.

Current reading: this covers the CLI commands and the `inferrsi` and `python -m inferrsi` entry points. It no longer covers old root Python module paths. The revised delivery decision in #412, #451 and #408 retires those paths without aliases, in the change that moves their last consumers. R1 (#412) removed the old-run root modules `evaluation`, `execution` and `reporting` together with root `inspection`; the old run is `inferrsi.apps.legacy` and the host inspection binding is `inferrsi.apps.inspection`. A1 (#408) then moved root `cli.py` and `arguments.py` to `inferrsi.apps.cli` and `inferrsi.apps.cli.arguments` and deleted both root files; the console script and `python -m inferrsi` call `inferrsi.apps.cli:main`.
Current reading: this covers the CLI commands and the `inferrsi` and `python -m inferrsi` entry points. It no longer covers old root Python module paths. The revised delivery decision in #412, #451 and #408 retires those paths without aliases, in the change that moves their last consumers. R1 (#412) removed the old-run root modules `evaluation`, `execution` and `reporting` together with root `inspection`; the old run is `inferrsi.apps.legacy` and the host inspection binding is `inferrsi.apps.host.prepared_environment`. A1 (#408) then moved root `cli.py` and `arguments.py` to `inferrsi.apps.cli` and `inferrsi.apps.cli.arguments` and deleted both root files; the console script and `python -m inferrsi` call `inferrsi.apps.cli:main`.

## D014 — events remain local, not a new shared event schema

Expand Down
4 changes: 2 additions & 2 deletions docs/module-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,10 @@ R1 (#412) deleted these eleven root modules with no forwarding shell,
| `inferrsi.evaluation` | `inferrsi.apps.legacy.evaluation` |
| `inferrsi.execution` | `inferrsi.apps.legacy.run` |
| `inferrsi.reporting` | `inferrsi.apps.legacy.reporting` |
| `inferrsi.inspection` | `inferrsi.apps.inspection` |
| `inferrsi.inspection` | `inferrsi.apps.host.prepared_environment` |

Root `inspection.py` was not an alias. It bound the Infra facts API to the
host, and `apps/inspection.py` now holds that binding: `_command` is
host, and `apps/host/prepared_environment.py` now holds that binding: `_command` is
`apps.host.commands.probe_command` and `repository_identity` is
`apps.host.targets.repository_identity`, both read from the module on each call,
so a test replaces either name there. `apps/host/inspection.py`, moved from
Expand Down
6 changes: 5 additions & 1 deletion docs/skill-evaluation/local-skill-evaluation.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ without silently changing its contract:

```python
from inferrsi.benchmark.skill_eval_engineering import REQUEST
from inferrsi.apps.artifacts import write_json
from inferrsi.apps.storage.artifacts import write_json

write_json("cases.json", [{
"id": "serving-response-v1", "split": "development",
Expand All @@ -75,6 +75,10 @@ python tools/skill_eval_compare.py prepare --repo /path/to/repo \

Keep the returned frozen-plan SHA externally with the acceptance record. This
freezes task, schema, starter, verifier/controllers and both selected bundles.
Every later operation on that plan, including `report`, must use its original
checkout and controller revision. When an upgrade moves or changes a controller,
reopen retained results with the original wheel or checkout recorded by the plan;
do not substitute the current controller or bypass `plan/freeze.json` verification.
Before any real agent call separately establish trustworthy **whole-run cost
bounds**, model identity, tool access, isolated environment, run order/repeats,
timeout and treatment of failed/retried attempts. A plan hash is not permission
Expand Down
114 changes: 21 additions & 93 deletions src/inferrsi/apps/artifacts.py
Original file line number Diff line number Diff line change
@@ -1,93 +1,21 @@
# Apps-owned file digests, file locks and JSON evidence writes. The function bodies equal
# those in the other cores' copies; tests/test_artifact_helper_copies.py keeps them equal.
# Apps imports no other inferrsi module here.

import errno
import hashlib
import json
import os
import time
import uuid
from contextlib import contextmanager
from pathlib import Path

# Windows refuses os.replace while another handle holds the destination open.
# A bounded retry covers the observed contention without hiding a real failure.
REPLACE_ATTEMPTS = 8
REPLACE_DELAY_SECONDS = 0.05


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

try:
msvcrt.locking(stream.fileno(), msvcrt.LK_NBLCK, 1)
except PermissionError as error:
if error.errno != errno.EACCES:
raise
# LK_NBLCK reports a lock violation as EACCES.
raise BlockingIOError(errno.EAGAIN, "File lock is held", path) from error
else:
import fcntl

fcntl.flock(stream.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
try:
# Windows can lock past EOF. Only the owner may initialize byte zero.
if os.fstat(stream.fileno()).st_size == 0:
stream.write(b"0")
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()


def write_json(path, value):
Path(path).parent.mkdir(parents=True, exist_ok=True)
Path(path).write_text(
json.dumps(value, ensure_ascii=False, indent=2, allow_nan=False) + "\n", encoding="utf-8"
)


def atomic_write_json(path: Path, value: object) -> None:
path = Path(path)
# A per-writer temporary name keeps two writers from sharing one file.
temporary = path.with_name(f"{path.name}.{os.getpid()}.{uuid.uuid4().hex[:8]}.tmp")
temporary.write_text(
json.dumps(value, ensure_ascii=False, indent=2, allow_nan=False) + "\n", encoding="utf-8"
)
try:
for attempt in range(REPLACE_ATTEMPTS):
try:
temporary.replace(path)
return
except PermissionError:
if attempt + 1 == REPLACE_ATTEMPTS:
raise
time.sleep(REPLACE_DELAY_SECONDS)
finally:
if temporary.exists():
temporary.unlink()
"""Compatibility exports for :mod:`inferrsi.apps.storage.artifacts`."""

from .storage.artifacts import (
REPLACE_ATTEMPTS,
REPLACE_DELAY_SECONDS,
atomic_write_json,
digest,
file_lock,
sha256,
write_json,
)

__all__ = [
"REPLACE_ATTEMPTS",
"REPLACE_DELAY_SECONDS",
"atomic_write_json",
"digest",
"file_lock",
"sha256",
"write_json",
]
2 changes: 1 addition & 1 deletion src/inferrsi/apps/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from ...knowledge.catalog import get_knowledge, search_knowledge
from ...knowledge.knowledge_operations import KnowledgeReader
from ...knowledge.research import research_knowledge
from ..inspection import inspect_environment
from ..host.prepared_environment import inspect_environment
from ..legacy.reporting import write_report
from ..workflows.campaign import capture_context, create_campaign
from ..workflows.knowledge import knowledge_reader
Expand Down
2 changes: 1 addition & 1 deletion src/inferrsi/apps/delivery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from tempfile import TemporaryDirectory

from ... import __version__
from ..artifacts import file_lock
from ..storage import archive
from ..storage.artifacts import file_lock
from . import adapters
from .projection import iterative
from .render import reports
Expand Down
2 changes: 1 addition & 1 deletion src/inferrsi/apps/delivery/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re

from ...harness.usage import normalize_usage
from ..artifacts import digest
from ..storage.artifacts import digest
from .schema import gap, number, timestamp


Expand Down
2 changes: 1 addition & 1 deletion src/inferrsi/apps/delivery/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pathlib import Path, PurePosixPath

from ...harness import candidates
from ..artifacts import sha256
from ..storage.artifacts import sha256
from .schema import decode

MAX_DOCUMENT_BYTES = 8 * 1024 * 1024
Expand Down
33 changes: 33 additions & 0 deletions src/inferrsi/apps/host/prepared_environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Prepared-environment inspection bound to this host.

``apps.host.inspection.inspect_environment`` is the facts API: it takes the
command probe and the repository snapshot as ports. This composition supplies the
real host probe and the Git repository identity. The facts module keeps both probes injectable.
"""

from .commands import probe_command as _command
from .inspection import inspect_environment as _inspect_environment
from .targets import repository_identity


def inspect_environment(
repo: str,
repo_type: str,
backend: str,
*,
device_ids: tuple[str, ...] = (),
device_model: str | None = None,
python: str | None = None,
) -> dict:
# Both ports are read from this module on every call, so replacing
# ``_command`` or ``repository_identity`` here changes the next inspection.
return _inspect_environment(
repo,
repo_type,
backend,
device_ids=device_ids,
device_model=device_model,
python=python,
command=_command,
snapshot=repository_identity,
)
39 changes: 7 additions & 32 deletions src/inferrsi/apps/inspection.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
"""Prepared-environment inspection bound to this host.
"""Compatibility exports for :mod:`inferrsi.apps.host.prepared_environment`."""

``apps.host.inspection.inspect_environment`` is the facts API: it takes the
command probe and the repository snapshot as ports. This composition supplies the
real host probe and the Git repository identity. The host package imports nothing
from here.
"""
from .host.prepared_environment import (
inspect_environment,
)

from .host.commands import probe_command as _command
from .host.inspection import inspect_environment as _inspect_environment
from .host.targets import repository_identity


def inspect_environment(
repo: str,
repo_type: str,
backend: str,
*,
device_ids: tuple[str, ...] = (),
device_model: str | None = None,
python: str | None = None,
) -> dict:
# Both ports are read from this module on every call, so replacing
# ``_command`` or ``repository_identity`` here changes the next inspection.
return _inspect_environment(
repo,
repo_type,
backend,
device_ids=device_ids,
device_model=device_model,
python=python,
command=_command,
snapshot=repository_identity,
)
__all__ = [
"inspect_environment",
]
Loading
Loading