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
8 changes: 5 additions & 3 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ loading the delivery [commands](../src/loopzero/cli.py), which implement the con
target branch and required CI. The receipt must record a clean passing run
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, including the effective
allowlisted environment, without recording raw environment values. Waiters
check for policy changes on every poll.
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.
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
3 changes: 3 additions & 0 deletions src/loopzero/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ 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:

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: The explicit-grant guard never applies because config.env holds (name, value) pairs

Config.env is declared as tuple[tuple[str, str], ...] in types.py:44. Because of that, "HEAVY_SLOT_GRANTED_CORES" not in config.env compares the string against pairs, so it is always True. The grant is therefore removed from settings["environment"] even when it was set explicitly in checks.env.

The acceptance criterion still holds today, but only by accident: _execution_settings also copies the raw env field from asdict(config) into the digest, so a changed explicit value still changes the fingerprint. The guard looks like it does something it doesn't. If the redundant env key is ever dropped from the settings, the bug will surface silently.

Smallest fix: test against dict(config.env), or {name for name, _ in config.env}. Also add a test case that sets the grant through checks.env, changes its value, and asserts that _current_check_report returns None. That would cover the second acceptance bullet, which has no test right now.

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: A variable name from one downstream project is hardcoded into a generic fingerprint

The exemption names HEAVY_SLOT_GRANTED_CORES directly inside settings_fingerprint. It applies to any project that allowlists that name, whatever the project uses the value for. Readiness then ignores a value that the trusted base forwards into the sandbox, and nothing here confirms the value only controls worker count.

This is acceptable as a narrow fix. Moving the name to a module-level constant next to SANDBOX_ENV, with a comment explaining why it is excluded, would make the exception easier to find. It would also make it easier to replace later with a configurable list of transient inputs.

# The inherited local worker limit is transient. Stage reuse still binds it.
settings["environment"].pop("HEAVY_SLOT_GRANTED_CORES", None)
payload = [settings, config.inputs]
return hashlib.sha256(json.dumps(payload, sort_keys=True).encode()).hexdigest()

Expand Down
11 changes: 10 additions & 1 deletion tests/test_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,10 +749,13 @@ def cache(config, *, clean=False, verify_reuse=False):

@pytest.mark.parametrize('change', ['other', 'input', 'shared', 'command', 'network', 'environment', 'version',
'failed', 'boolean_exit_code', 'dirty_receipt', 'keyless',
'dirty_tree', 'legacy'])
'dirty_tree', 'legacy', 'grant'])
def test_declared_input_reuse(git_repo, bwrap_log, monkeypatch, fetched_base, change):
cfg = make_config(checks=('echo one', 'echo two'),
inputs={'echo one': ('*.md',), 'echo two': ('*.md',), '*': ('shared',)})
if change == 'grant':
cfg = replace(cfg, env_allowlist=(*cfg.env_allowlist, "HEAVY_SLOT_GRANTED_CORES"))
monkeypatch.setenv("HEAVY_SLOT_GRANTED_CORES", "2")
for inputs in ({}, {'*': ()}, {'*': ('uv.lock',)}):
assert sandbox._input_key(replace(cfg, inputs=inputs), git_repo, 'unlisted', fetched_base) is None
whole = replace(cfg, inputs={'*': ('.',)})
Expand All @@ -776,6 +779,12 @@ def test_declared_input_reuse(git_repo, bwrap_log, monkeypatch, fetched_base, ch
cfg = replace(cfg, network=True)
elif change == 'environment':
monkeypatch.setenv('LZ_KEEP', 'changed')
assert _current_check_report(git_repo, cfg, fetched_base) is None
elif change == 'grant':
monkeypatch.setenv("HEAVY_SLOT_GRANTED_CORES", "4")
assert _current_check_report(git_repo, cfg, fetched_base) is not None
monkeypatch.delenv("HEAVY_SLOT_GRANTED_CORES")
assert _current_check_report(git_repo, cfg, fetched_base) is not None
elif change == 'version':
monkeypatch.setattr(sandbox, '__version__', 'new')
else:
Expand Down
Loading