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
9 changes: 5 additions & 4 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ loading the delivery [commands](../src/loopzero/cli.py), which implement the con
at that head with the current commands and check settings digest. A settings
change or an older receipt without the digest requires a fresh check. The
digest covers execution and stage reuse settings without recording raw
environment values. It excludes only inherited `HEAVY_SLOT_GRANTED_CORES`
for local sandbox receipts. Explicit settings, delegated runner environments
and stage reuse keys still bind the grant. Waiters check for policy changes
on every poll.
environment values. For local sandbox receipts it omits inherited `PATH`,
`LANG`, `LC_ALL`, `TERM`, and `HEAVY_SLOT_GRANTED_CORES` so readiness can
run in a different host environment. Explicit settings, delegated runner
environments, and stage reuse keys still bind these values. Waiters check
for policy changes on every poll.
Local readiness and hosted eligibility carry a review forward only across
a first-parent chain of verified merges from the configured PR base. They
reconstruct each merge in an isolated Git repository and compare its tree
Expand Down
8 changes: 5 additions & 3 deletions src/loopzero/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,11 @@ def settings_fingerprint(config: Config, worktree: Path, *, base: str | None = N
settings = _execution_settings(config, base)
if config.check_runner and settings["runner_executable"] is None:
return None
if not config.check_runner and "HEAVY_SLOT_GRANTED_CORES" not in config.env:
# The inherited local worker limit is transient. Stage reuse still binds it.
settings["environment"].pop("HEAVY_SLOT_GRANTED_CORES", None)
if not config.check_runner:
# Inherited host settings can differ at readiness. Stage reuse still binds them.
host_env = {"PATH", "LANG", "LC_ALL", "TERM", "HEAVY_SLOT_GRANTED_CORES"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Host-environment exclusion set is an inline literal duplicating existing base-env lists

{"PATH", "LANG", "LC_ALL", "TERM", "HEAVY_SLOT_GRANTED_CORES"} is rebuilt on every call. It repeats runners.BASE_ENV (("PATH", "LANG", "LC_ALL", "TERM")) and the default env_allowlist in types.py:40. If one of those lists changes later, nothing keeps this exclusion set in step, so readiness portability and the documented list in ARCHITECTURE.md could drift apart. Smallest fix: define a module-level constant, e.g. _PORTABLE_HOST_ENV = frozenset({...}), next to SANDBOX_ENV, add a comment saying it must match the docs, and use it here. Behaviour is otherwise correct. _hash_inputs still passes the full _execution_settings environment into each stage key, so stages rerun when these values change. Explicit config.env entries are still bound, and the check_runner path is unchanged.

for name in host_env - dict(config.env).keys():
settings["environment"].pop(name, None)
payload = [settings, config.inputs]
return hashlib.sha256(json.dumps(payload, sort_keys=True).encode()).hexdigest()

Expand Down
27 changes: 15 additions & 12 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3125,26 +3125,29 @@ def test_ready_matches_effective_inherited_check_environment(capsys, monkeypatch
assert code == 1 and "not ready: check receipt has an incompatible settings fingerprint." in out


@pytest.mark.parametrize("worker", ["legacy", "different-path", "matching"])
@pytest.mark.parametrize("worker", ["legacy", "different-environment", "matching"])
def test_ready_checks_transferred_whole_job_receipt(wt, gh, capsys, head, tmp_path, monkeypatch, worker):
policy = WORKFLOW.replace(
'[checks]', '[checks]\nenv_allowlist = ["PATH", "LANG", "LC_ALL", "TERM", "HEAVY_SLOT_GRANTED_CORES"]')
publish_workflow(wt, policy.replace('[delivery]', '[checks.inputs]\n"*" = ["."]\n\n[delivery]'))
arm_approved_ready_pr(gh, head, wt, readiness={"local_exit": None}, isDraft=False)
with monkeypatch.context() as worker_env:
if worker == "different-path":
if worker == "different-environment":
worker_env.setenv("PATH", str(tmp_path / "worker-bin"), prepend=":")
for name, value in {"LANG": "en_US.UTF-8", "LC_ALL": "en_US.UTF-8",
"TERM": "dumb", "HEAVY_SLOT_GRANTED_CORES": "2"}.items():
worker_env.setenv(name, value)
assert run(capsys, "check")[0] == 0

receipt = wt / ".loopzero/checks.json"
payload = json.loads(receipt.read_bytes())
if worker == "legacy":
# Older producers serialize these results without a settings fingerprint.
receipt = wt / ".loopzero/checks.json"
payload = json.loads(receipt.read_bytes())
del payload["settings_sha256"]
# Whole-job transport preserves the producer's fields.
receipt.write_text(json.dumps(payload))
assert run(capsys, "ready")[0] == (0 if worker == "matching" else 1)

if worker != "matching":
assert run(capsys, "check")[0] == 0
assert run(capsys, "ready")[0] == 0
receipt.write_text(json.dumps(payload))
assert run(capsys, "ready")[0] == int(worker == "legacy")
assert run(capsys, "check")[0] == 0
assert all(bool(stage.reused_from) == (worker == "matching") for stage in cli._load_report(wt).results)
assert run(capsys, "ready")[0] == 0


def test_ready_ignores_forged_markers(wt: Path, gh: FakeGh, capsys, head) -> None:
Expand Down
Loading