Skip to content

docker: add the quota supervisor, its tests and its runtime contract - #713

Closed
luisleo526 wants to merge 1 commit into
mainfrom
docker/quota-supervisor
Closed

luisleo526 wants to merge 1 commit into
mainfrom
docker/quota-supervisor

Conversation

@luisleo526

Copy link
Copy Markdown
Collaborator

What this adds

docker/pf_quota_run.py, the supervisor that runs one command under the launcher-hosted run_quota ledger service and reports a trusted receipt on a descriptor the child never inherits: the ledger verdict, the wait status or signal, the kernel's out-of-memory attribution and the deadline.

  • An absent --deadline-seconds means no expiry and no deadline kill. A present value must be a strict positive finite decimal.
  • A refused memory.events observation is reported as a nullable oom.diagnostic (the existing launcher error envelope, the exact requested path, never opened or created) and stays nonfatal.
  • When the interpreter has no os.pidfd_open or signal.pidfd_send_signal (an old C library under a new kernel), the supervisor calls the kernel syscalls (434 and 424, the same numbers on x86_64 and aarch64) through ctypes and raises the same errors. Any other architecture keeps the typed linux_containment_unavailable refusal. The native functions are used whenever they exist.

docs/design/quota-supervisor-runtime-contract.md states the contract.

Tests

  • docker/run_json_quota_supervisor_test.py: 129 non-root rows, collected by the preflight glob. They run with and without the native pidfd functions (eight rows hide them in a real subprocess and check descriptors, errors, signals and the typed refusal against the real kernel).
  • docker/pf_quota_run_privileged_proof.py: 176 root rows, run explicitly on a root host.
  • docker/pf_quota_policy_privileged_proof.py: 47 root policy rows, run explicitly on a root host.

No test waits on a clock: waits block on events (EOF, child exit, readable descriptor). The rows that exercise the caller's --deadline-seconds keep an explicit deadline because the supervisor arms its clock at admission; they assert at most a lower bound on elapsed time.

Evidence

  • Preflight on the CLOUD interpreter, which has no native pidfd functions: green, 61 stages, including the 129 non-root rows.
  • The 129 non-root rows pass on an Ubuntu host that has the native functions. At the commit that adds the rows but not the fallback, eight of them fail for the missing fallback; two deliberate mutations of the fallback (a wrong syscall number for pidfd_open, and for pidfd_send_signal) make five and three of them fail.
  • The root and policy proofs ran once on a disposable Linux box (x86_64, cgroup v2 with the memory controller, kernel 7.0): 176 passed, 0 skipped; the policy proof exited 0. The box ran this tree plus the one script that drives the two proofs.

What the root run does and does not show

  • The policy proof result is derived from its exit 0 and the controller source (pf_quota_policy_privileged_proof.py: the controller returns 0 only when every required row ran, none is red and the sources are unchanged); its result file was not copied back, and the 47 rows were not recounted from a file.
  • The junit XML was not copied back. The counts (176 tests, 0 failures, 0 errors, 0 skipped) are printed by the driving script, which was verified byte for byte, and pytest's own last line says 176 passed.
  • The image identity is by input (the image name the launcher was asked for; it does not report the booted image back). pytest is 9.1.1 as pinned; pluggy 1.7.0 and iniconfig 2.3.1 are a patch above the pinned 1.6.0 and 2.3.0.
  • Identity 61001 is shown by the setpriv command line in the log, not by a printed id. The script's shell is an unprivileged user; the root acts are its sudo -n lines.

Review scope

  • Read in full: docker/pf_quota_run.py (receipt built from real wait, ledger and cgroup facts; verified privilege drop; gated exec; cleanup by process group, pidfd and subreaper with the pid held by waitid(WNOWAIT); kernel-credential authentication; no default deadline; no descendant cap).
  • Sampled: the runtime contract (its first 120 lines) and the test rows (a search of all three test files for skip, xfail, importorskip and constant returns found none; a meta-test pins the root inventory and bans skips; the sampled fault-injection row uses a real seccomp filter and EMFILE).
  • Executed: the root run above, on a real root box, with these exact file contents.

🤖 Generated with Claude Code

Add docker/pf_quota_run.py, the supervisor that runs one command under the
launcher-hosted run_quota ledger service and reports a trusted receipt on a
descriptor the child never inherits: the ledger verdict, the wait status or
signal, the kernel's out-of-memory attribution and the deadline. An absent
--deadline-seconds means no expiry and no deadline kill; a present value must be
a strict positive finite decimal. A refused memory.events observation is
reported as a nullable oom.diagnostic and stays nonfatal.

When the interpreter has no os.pidfd_open or signal.pidfd_send_signal (an old C
library under a new kernel), the supervisor calls the kernel syscalls (434 and
424, the same numbers on x86_64 and aarch64) through ctypes and raises the same
errors; any other architecture keeps the typed refusal.

Tests: docker/run_json_quota_supervisor_test.py (129 non-root rows, run by the
preflight glob with or without the native pidfd functions),
docker/pf_quota_run_privileged_proof.py (176 root rows) and
docker/pf_quota_policy_privileged_proof.py (47 root policy rows) run as
explicit separate actions. No row has a time limit of its own. The contract is in
docs/design/quota-supervisor-runtime-contract.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
"assertion_id": error.assertion_id, "expected": error.expected, "actual": error.actual,
})
return result_files(directory, result, 1, complete=True)
except BaseException as error:
verdict = "RED" if any(row.get("verdict") == "RED" for row in result["rows"]) else "GREEN"
result.update(state="COMPLETE", verdict=verdict)
return result_files(directory, result, 1 if verdict == "RED" else 0, complete=True)
except BaseException as error:
Comment thread docker/pf_quota_run.py
handed_to_serve = True
q.serve(self.ledger, self.channel, owner)
return
except BaseException as error:
Comment thread docker/pf_quota_run.py
if owner is not None and not handed_to_serve:
try:
self.ledger.disconnect(owner)
except BaseException as error:
Comment thread docker/pf_quota_run.py
self.errors.record(error, "endpoint_disconnect")
try:
self.channel.close()
except BaseException as error:

@graphify-labs graphify-labs Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

View in Graphify

Graphify reviewed this change.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 5 advisory finding(s) below merit a look before merge.

Not checked: tests were not run; no formal proof of the changed code.


Graphify review — findings

Adds a root-only policy proof script that runs the shipped supervisor as a subprocess, never importing it, across registered rows: a deliberate-crash recorder control, normal/refusal/cleanup/signal/deadline controls, the refused-path diagnostic rows, and the absent-deadline rows. Each work process gets its own RESULT, completion binding and recorded controller wait, a failed control halts the run, and missing facilities or broken evidence report INCOMPLETE rather than target RED. A name-based guard refuses sensitive paths (.ssh, .aws, .env, and the like) before any read, and output is meant to stay under .policy-author-scratch, but that confinement is checked lexically, so a symlinked parent can still let writes escape it, and forked actors and the traced-run exit status are where the recorded evidence could go wrong.

Worth a look

  • new_file scratch-confinement check ignores the symlink-resolved parent, so writes can land outside scratch — docker/pf_quota_policy_privileged_proof.py:141 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
  • mkdir_new scratch-confinement check also bypassable via a symlinked parent — docker/pf_quota_policy_privileged_proof.py:191 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
  • Traced path never sets returncode, so wait() in finally fabricates exit status 0 — docker/pf_quota_policy_privileged_proof.py · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
  • Forked 'reuse' child returns from workload() instead of calling os._exit — docker/pf_quota_policy_privileged_proof.py · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
  • Forked tree actors can unwind into parent code paths when a check fails — docker/pf_quota_policy_privileged_proof.py:390 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review

Review partial — this diff was larger than one review pass covers, so later files were not reviewed; some findings may be missing.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 287 functions depend on the 286 functions this change touches.

Health — this change adds coupling hotspots:

  • new: _admission() — 12 callers, 6 callees
  • new: main() — 1 callers, 16 callees
  • new: _exercise_outside_hello() — 2 callers, 8 callees
  • new: new_file() — 5 callers, 3 callees
  • new: _exercise_shared_endpoints() — 2 callers, 7 callees
  • new: worker() — 1 callers, 13 callees
  • new: controller() — 1 callers, 12 callees
  • new: main() — 1 callers, 11 callees
  • …and 18 more — each is listed as a finding

Verification — 287 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 287 function(s) in the blast radius were not formally verified this run

Docs that may be stale (advisory)

…and 10 more.

· 7 grounded finding(s) anchored inline below; 19 more finding(s) on lines outside this diff (see the check run).

return read_bytes(path).decode("ascii")


def new_file(path, data):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — new_file()

high coupling complexity (Ca·Ce = 15).

Grounded coupling-delta finding (deterministic), not an LLM guess.

client.close()


def workload(args, row):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — workload()

fans out to 9 callees (efferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

return status


def worker(args, row, directory):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — worker()

fans out to 13 callees (efferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

return result


def controller(args, directory):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — controller()

fans out to 12 callees (efferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

return result_files(directory, result, 2, complete=False)


def main():

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — main()

fans out to 11 callees (efferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

Comment thread docker/pf_quota_run.py
fcntl.fcntl(fd, fcntl.F_SETFL, flags)


def main(argv=None):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — main()

fans out to 16 callees (efferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

return int(fields[1]), int(fields[2]), int(fields[3]), int(fields[19])


def _admission(*, policy=POLICY, omit=None, overrides=None,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — _admission()

fans out to 6 callees (efferent coupling); 12 callers depend on it (afferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

@luisleo526

Copy link
Copy Markdown
Collaborator Author

Merged via #717 (squash 8d0f9e7), which carries this change. Closing; the branch is kept.

@luisleo526 luisleo526 closed this Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant