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
16 changes: 10 additions & 6 deletions contracts/compute-limit-context/v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
This additive job field uses the typed association Comment v2 carrier. The public
DTO and native carrier have separate version numbers. The public shape is defined
by [schema.json](schema.json). Compatible readers and writers for the applied-record
extension are deployed. Full-cohort metadata migration remains incomplete.
extension are deployed. The accepted source migration is complete. The source
now removes native v1 compatibility; paired activation is tracked separately.

`limit_context` describes native member limits and the account limits and policy
sources last verified by the site writer. Slurm retains the original scheduling reason. The field identifies
Expand Down Expand Up @@ -86,8 +87,8 @@ During upgrades, compatible CLI, Read gateway and Core DTO consumers precede
Site writers for the optional `applied` payload. The v2 frame, SAI native helper and Lua reader are
unchanged. The original policy projector and workers refresh metadata while
numeric limits remain unchanged. The SAI helper uses
standard Slurm APIs, preserves the original manual suffix and supports both
carrier versions before v2 writes start. Slurm source, libraries and protocol
standard Slurm APIs and preserves the original manual suffix. Current codecs,
writers and helpers accept only v2, with explicit limit metadata. Slurm source, libraries and protocol
remain unmodified.

The paired deployment completed with the Site/Read update on 2026-11-10.
Expand All @@ -96,7 +97,10 @@ limit changes. Authenticated remote reads and foreign-job denial passed; the
sampled remote job had no applicable annotation, so positive remote source
attribution remains unverified.

Existing v1 records remain in the accepted cohort. Keep v1 readable until the
original worker completes that cohort's migration. Metadata backfill and the
remaining remote annotation check are tracked in the
The accepted metadata migration and a current complete observation of the
published scope found no v1 marker or supported retryable v1 input. Before
adopting the current pair on another site, verify the same precondition there.
Unmarked native comments are preserved. The v2 path without an `applied`
record is a separate contract and remains supported. Paired activation and the
remaining positive remote annotation check are tracked in the
[roadmap](../../../docs/roadmap.md).
4 changes: 2 additions & 2 deletions contracts/compute-restrictions-source.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"repository": "AI4SAI/sai-portal",
"path": "sai_compute_restrictions.py",
"revision": "e29e8ca2a66fb543b4e65a5caa69e43f92af9751",
"sha256": "2fff6aa7e48392f1e68dd5dfe626463625f9e34fb727e74286151366be4ec5ab"
"revision": "7243928b6b476a453a1df74ce827e7a5a968264a",
"sha256": "3f067727d73f2dbfe0d7ed7ef31022cdd03fda48ddfc277543b75e7ebd1b9c2c"
}
2 changes: 1 addition & 1 deletion contracts/native-slurm-source.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"repository": "AI4SAI/sai-portal",
"path": "sai_native_slurm.py",
"revision": "a4702e72cf2acbe5bd4cafb776f3d1561cdae594",
"revision": "7243928b6b476a453a1df74ce827e7a5a968264a",
"sha256": "2092765b79a1aab6bdc949e5bc5b8815e60eaacd55c808fa5ed7a8db52a413bb"
}
3 changes: 2 additions & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Its optional `applied` record lets the site writer publish verified parent
observations in the existing user association. The shared reader binds that
record to the visible job and current user association using one bounded native
read with `WOPLimits`. Ordinary users need no parent-association privilege.
Older records keep their existing ancestor-read path during migration. The additive
v2 records without `applied` keep their existing ancestor-read path. The retired
v1 native marker is no longer accepted. The additive
[`limit_context` contract](../contracts/compute-limit-context/v1/README.md)
preserves each group billing layer and the nearest explicit `MaxSubmitJobs`
value. Details distinguish recorded account values from current member values,
Expand Down
15 changes: 9 additions & 6 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ not imply production activation or completion of a paired rollout.
had no applicable limit annotation and returned empty context.
- [x] Complete the main account/member source-only metadata batch through the
original projector and workers, with native numeric values unchanged.
- [ ] Finish the remaining organization source records and verify an applicable
limit annotation through an ordinary user's authorized remote read. Retain v1
compatibility until the accepted cohort is complete.
- [ ] Remove temporary v1 marker compatibility after the original worker's
full accepted association cohort has migrated to v2. An `open` funding marker
stays silent throughout and grants no scheduling permission.
- [x] Complete the remaining organization/member source records. A current
observation of the published scope found no v1 markers or retryable v1 input.
- [ ] Verify an applicable limit annotation through an ordinary user's
authorized remote read. Completed source migration is not repeated for this check.
- [x] Remove v1 marker and three-field input compatibility from the shared
codec, Site writer, native helper and Lua notice reader in source.
- [ ] Deploy that paired compatibility removal. An `open` funding marker stays
silent and grants no scheduling permission. Unmarked native comments and the
separate v2 ancestor-read contract retain their existing meaning.

- [x] Implement native account discovery, explicit quota directory selection,
retained query scopes and numbered allocation inspection
Expand Down
7 changes: 5 additions & 2 deletions docs/runtime-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,11 @@ An `open` account-state marker emits no account notice and does not imply a job
can run. Missing or malformed metadata and failed context reads preserve the
native job result, with the existing bounded diagnostic on read failure. The
shared module adds no local policy file, Center lookup or pricing calculation.
v1 markers remain readable for the paired migration only; activation, backfill
and removal of that bridge are pending in the [roadmap](roadmap.md).
The shared codec accepts only the v2 marker and requires writers to supply
`limits` explicitly. Unmarked native comments retain their original meaning.
Deployments must complete the original metadata migration and confirm that no
supported retry can send the retired three-field input before adopting this
reader/writer pair. The public DTO remains `compute-limit-context/v1`.

Native holds, dependencies and selected account/QOS limits use short labels
from the same presenter in local, remote and TUI views. Details retain the native
Expand Down
6 changes: 4 additions & 2 deletions docs/site-local-read-plane.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,10 @@ metadata through standard Slurm association Comments. The diagnostic carrier
has no controller HTTP fetch, timer or dynamic policy file. The
[roadmap](roadmap.md) tracks applied-record activation and metadata refresh.
New readers precede writers because earlier strict decoders reject the added
payload key. The helper and Lua v2 frame stay unchanged. v1 remains readable only until the original worker
has migrated the accepted association cohort. Each site still needs
payload key. The current codec, Site writer, helper and Lua notice reader use
the v2 frame. Adopting this pair requires a completed metadata migration and
confirmation that supported retries contain no retired three-field input.
The separate v2 ancestor-read path remains available. Each site still needs
verification of its actual service-UID read permission and native environment.

The paired `jobs.allocation/v2` projection reads `gres_detail` from that same
Expand Down
13 changes: 3 additions & 10 deletions site/slurm/job_submit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,9 @@ local function notify_account_restriction(job_desc, job_ptr)
local comment = job_desc.assoc_comment
if type(comment) ~= "string" or #comment > 65536 then return end
local header = "^%[sai%.account%-state/v2:([%w_.+%-]+):(%d+):([%da-f%-]+):(%d+):([%w_]+)"
local source, assoc_id, owner_ref, revision, code, boundary
if string.sub(comment, 1, #"[sai.account-state/v2:") == "[sai.account-state/v2:" then
local encoded
source, assoc_id, owner_ref, revision, code, encoded, boundary = string.match(comment,
header .. ":([%w_%-]+)%]()")
if not encoded then return end
else
source, assoc_id, owner_ref, revision, code, boundary = string.match(comment,
"^%[sai%.account%-state/v1:([%w_.+%-]+):(%d+):([%da-f%-]+):(%d+):([%w_]+)%]()")
end
local source, assoc_id, owner_ref, revision, code, encoded, boundary = string.match(comment,
header .. ":([%w_%-]+)%]()")
if not encoded then return end
if not source or #source > 128 or not string.match(source, "^[%w]")
or not restriction_labels[code] or #owner_ref ~= 36
or not string.match(owner_ref, "^%x%x%x%x%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%-%x%x%x%x%x%x%x%x%x%x%x%x$")
Expand Down
47 changes: 18 additions & 29 deletions src/sai_compute_restrictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def _time(value: object) -> int:

_PREFIX = "[sai.account-state/"
_MARKER = re.compile(
r"\[sai\.account-state/(v[12]):([A-Za-z0-9][A-Za-z0-9_.+\-]{0,127}):"
r"\[sai\.account-state/v2:([A-Za-z0-9][A-Za-z0-9_.+\-]{0,127}):"
r"([1-9][0-9]{0,9}):([0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}):"
r"([1-9][0-9]{0,18}):(open|arrears|severe_arrears|no_compute_funding|admin_blocked)"
r"(?::([A-Za-z0-9_-]+))?\]"
r":([A-Za-z0-9_-]+)\]"
)
ASSOCIATION_BATCH_SIZE = 512
_LIMIT_FIELDS = {"billing_tres_limit": 2**64 - 3, "max_submit_jobs": 2**32 - 3}
Expand Down Expand Up @@ -181,18 +181,12 @@ def decode_association_comment(comment: object) -> dict[str, Any] | None:
match = _MARKER.match(comment)
if match is None or (match.end() < len(comment) and comment[match.end()] != " "):
raise ValueError("invalid managed association prefix")
version, account, association_id, owner_ref, revision, reason, encoded = match.groups()
account, association_id, owner_ref, revision, reason, encoded = match.groups()
association_id, revision = int(association_id), int(revision)
if association_id >= 2**32 - 2 or revision > 2**63 - 1:
raise ValueError("invalid managed association generation")
result = {"account": account, "association_id": association_id, "owner_ref": owner_ref,
"revision": revision, "reason": None if reason == "open" else reason}
if version == "v1":
if encoded is not None:
raise ValueError("invalid v1 association metadata")
return result
if encoded is None:
raise ValueError("missing v2 association metadata")
try:
decoded = base64.b64decode(encoded + "=" * (-len(encoded) % 4), altchars=b"-_", validate=True)
metadata = _metadata(json.loads(decoded.decode("ascii")))
Expand All @@ -214,24 +208,20 @@ def strip_association_comment(comment: str | None) -> str:


def encode_association_comment(comment: str | None, *, account: str, association_id: int,
owner_ref: str, revision: int, reason: str | None,
limits: object = _OMITTED, ancestor_ids: object = _OMITTED,
owner_ref: str, revision: int, reason: str | None, limits: object,
ancestor_ids: object = _OMITTED,
member: object = _OMITTED, applied: object = _OMITTED) -> str:
account = _name(account)
validate_reason(reason)
if type(association_id) is not int or type(revision) is not int:
raise ValueError("invalid managed association generation")
version, suffix = "v1", ""
if any(value is not _OMITTED for value in (limits, ancestor_ids, member, applied)):
metadata = {"limits": {} if limits is _OMITTED else limits,
"ancestor_ids": [] if ancestor_ids is _OMITTED else ancestor_ids,
"member": None if member is _OMITTED else member}
if applied is not _OMITTED:
metadata["applied"] = applied
metadata = _metadata(metadata)
suffix = ":" + base64.urlsafe_b64encode(_canonical(metadata)).rstrip(b"=").decode("ascii")
version = "v2"
prefix = f"{_PREFIX}{version}:{account}:{association_id}:{owner_ref}:{revision}:{reason or 'open'}{suffix}]"
metadata = {"limits": limits, "ancestor_ids": [] if ancestor_ids is _OMITTED else ancestor_ids,
"member": None if member is _OMITTED else member}
if applied is not _OMITTED:
metadata["applied"] = applied
metadata = _metadata(metadata)
encoded = base64.urlsafe_b64encode(_canonical(metadata)).rstrip(b"=").decode("ascii")
prefix = f"{_PREFIX}v2:{account}:{association_id}:{owner_ref}:{revision}:{reason or 'open'}:{encoded}]"
decode_association_comment(prefix)
note = strip_association_comment(comment)
value = prefix + (" " + note if note else "")
Expand Down Expand Up @@ -356,7 +346,7 @@ def _applied_matches(row: dict[str, Any], lineage: list[str], marker: dict[str,

def read_job_contexts(jobs: list[dict[str, Any]], association_ids: list[object], *,
cluster: str, fetch, now: float | None = None) -> list[dict[str, Any]]:
"""Read visible job associations and their applied records; old v2 reads parents."""
"""Read visible associations and applied records; v2 without a record reads parents."""
_name(cluster)
if len(jobs) != len(association_ids):
raise ValueError("job association bindings are incomplete")
Expand All @@ -374,11 +364,10 @@ def read_job_contexts(jobs: list[dict[str, Any]], association_ids: list[object],
if marker is not None:
if marker["account"] not in lineage or marker.get("limits"):
raise ValueError("account context is outside the observed association lineage")
if "ancestor_ids" in marker:
if len(marker["ancestor_ids"]) != len(lineage) or row["id"] in marker["ancestor_ids"]:
raise ValueError("native association ancestry changed")
if "applied" not in marker:
ancestor_ids.extend(marker["ancestor_ids"])
if len(marker["ancestor_ids"]) != len(lineage) or row["id"] in marker["ancestor_ids"]:
raise ValueError("native association ancestry changed")
if "applied" not in marker:
ancestor_ids.extend(marker["ancestor_ids"])
prepared[index] = row, lineage, marker
parents = _association_rows(list(dict.fromkeys(ancestor_ids)), cluster=cluster, fetch=fetch)
results = [{} for _ in jobs]
Expand All @@ -404,7 +393,7 @@ def read_job_contexts(jobs: list[dict[str, Any]], association_ids: list[object],
current_parents.append((parent, _parent_marker(parent), association_limit_values(parent)))
reason = jobs[index]["reason_or_nodelist"]
if reason == "AssocGrpJobsLimit" and marker is not None and marker["reason"] is not None:
verified = "ancestor_ids" not in marker or any(
verified = any(
parent["id"] == marker["association_id"] and source is not None
and all(source[key] == marker[key] for key in ("account", "owner_ref", "revision", "reason"))
and numeric["group_jobs_limit"] == 0
Expand Down
37 changes: 31 additions & 6 deletions tests/test_compute_restrictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@
OWNER = "11111111-2222-4333-8444-555555555555"


def encoded(note="", reason="arrears", revision=1):
return encode_association_comment(note, account="org-a", association_id=3,
owner_ref=OWNER, revision=revision, reason=reason)
def encoded(note="", reason="arrears", revision=1, *, account="org-a", leaf="project-a", user="alice"):
lineage = f"/{account}/{leaf}/0-{user}/"
parents = []
for ident, name in ((1, "root"), (3, account), (4, leaf)):
owned = ident == 3
parents.append({"account": name, "association_id": ident,
"owner_ref": OWNER if owned else None, "revision": revision if owned else None,
"reason": reason if owned else None, "limits": {},
"numeric": {"group_jobs_limit": 0 if owned and reason else None,
"billing_tres_limit": None, "max_submit_jobs": None}})
return encode_association_comment(note, account=account, association_id=3,
owner_ref=OWNER, revision=revision, reason=reason, limits={}, ancestor_ids=[1, 3, 4],
applied={"recorded_at": 100, "association_id": 47, "lineage": lineage, "parents": parents})


def test_reason_changes_and_open_preserve_original_note_exactly():
Expand All @@ -18,12 +28,26 @@ def test_reason_changes_and_open_preserve_original_note_exactly():
second = encoded(first, "admin_blocked", 2)
cleared = encoded(second, None, 3)
assert strip_association_comment(first) == strip_association_comment(second) == strip_association_comment(cleared) == note
assert decode_association_comment(second) == {"account": "org-a", "association_id": 3,
"owner_ref": OWNER, "revision": 2, "reason": "admin_blocked"}
marker = decode_association_comment(second)
assert second.startswith("[sai.account-state/v2:")
assert {key: marker[key] for key in ("account", "association_id", "owner_ref", "revision", "reason")} == {
"account": "org-a", "association_id": 3, "owner_ref": OWNER, "revision": 2, "reason": "admin_blocked"}
assert encode_association_comment(second, **marker) == second
assert decode_association_comment(cleared)["reason"] is None
assert strip_association_comment("ordinary [brackets] note") == "ordinary [brackets] note"


def test_retired_prefix_is_rejected_and_encoder_requires_explicit_limits():
old = f"[sai.account-state/v1:org-a:3:{OWNER}:1:arrears] manual note"
for read in (decode_association_comment, strip_association_comment, encoded):
with pytest.raises(ValueError):
read(old)
with pytest.raises(TypeError):
encode_association_comment("note", account="org-a", association_id=3,
owner_ref=OWNER, revision=1, reason="arrears")
assert decode_association_comment("manual " + old) is None


def test_visible_page_deduplicates_native_read_and_existing_job_sees_reason_change():
job = {"state": "PD", "reason_or_nodelist": "AssocGrpJobsLimit", "slurm_account": "project-a",
"slurm_user": "alice", "partition": "gpu"}
Expand All @@ -39,7 +63,8 @@ def fetch(ids):
result = read_job_contexts([job, job, {**job, "state": "R"}], [47, 47, 99],
cluster="cluster-a", fetch=fetch, now=123)
expected = {} if reason is None else {"account_restriction": {
"code": reason, "account": "org-a", "source": "sai_applied_policy", "observed_at": 123}}
"code": reason, "account": "org-a", "source": "sai_applied_policy", "observed_at": 123,
"basis": "applied_record", "recorded_at": 100}}
assert result == [expected, expected, {}]
assert calls == [[47]] * 3 and job == before
assert read_job_contexts([{**job, "reason_or_nodelist": "Resources"}], [47], cluster="cluster-a", fetch=fetch) == [{}]
Expand Down
Loading
Loading