File size: 4,717 Bytes
0681a6b 3cfcb19 0681a6b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | """Relay v4 models β one clean contract, no artificial caps.
Concepts
--------
Batch β every submission is a batch; the batch as a whole gets one id.
Job β one example (multi-file, shared env, steps). Expanded server-side into
*cells* when it carries a matrix (platform Γ runtime Γ stdin_cases).
Cell β the executable unit (a row in the index). job_id = "<job_id>#<cell>".
Step β a command sequence executed in the SAME workdir/venv, in order
(cross-example dependency, e.g. "create file" β "read it").
Artifact β any file produced under outputs/ β images, audio, logs, binaries.
Stored on disk, downloaded by agents via streaming GET (no base64 bloat).
"""
from typing import Dict, List, Literal, Optional
from pydantic import BaseModel, Field
SCHEMA = 4
class JobStep(BaseModel):
name: str
entry_point: str
timeout: float = 60
dependencies: List[str] = Field(default_factory=list) # pip installs before this step
class JobMatrix(BaseModel):
platforms: List[str] = Field(default_factory=list) # e.g. ["linux", "windows", "macos"]
runtimes: List[str] = Field(default_factory=list) # e.g. ["python-3.11", "python-3.13", "node-22"]
stdin_cases: List[str] = Field(default_factory=list) # e.g. ["1 2\n", "3 4 5\n"]
class JobSubmission(BaseModel):
job_id: Optional[str] = None
platform: str # base platform (used if matrix.platforms empty)
runtime: str # base runtime tag (used if matrix.runtimes empty)
files: Dict[str, str] = Field(default_factory=dict) # base files {relpath: text}
files_variants: Dict[str, Dict[str, str]] = Field(default_factory=dict) # platform -> overlay files
entry_point: Optional[str] = None # single-step compat
steps: Optional[List[JobStep]] = None # preferred: shared env, sequential
dependencies: List[str] = Field(default_factory=list)
network_required: bool = False
stdin: Optional[str] = None
matrix: Optional[JobMatrix] = None
timeout: float = 60 # per step unless step overrides
stop_on_failure: bool = True
class BatchSubmission(BaseModel):
batch_id: Optional[str] = None
jobs: List[JobSubmission] = Field(default_factory=list)
class WorkerRegisterRequest(BaseModel):
worker_id: int
url: str # primary url: runner://<os>/<uuid> or pull:// token
urls: Optional[List[str]] = None # optional tunnel redundancy: tried in order
environment: "Environment"
class Environment(BaseModel):
platform: str
os_version: str
runtimes: List[str] # runtime tags this runner can execute
max_concurrent_jobs: int = 4
notes: Optional[str] = None
class ResultObject(BaseModel):
job_id: str # cell id: "<base>#<cell>"
exit_code: int
timed_out: bool
category: Literal["success", "timeout", "dependency_install_failed",
"infra_failure", "checker_error", "not_applicable"]
steps: List[Dict] = Field(default_factory=list) # per-step {name,stdout,stderr,exit_code,timed_out}
filesystem_state: Optional[Dict[str, str]] = None # relpath -> "sha256:.." | "b64:.."
artifacts: List[Dict] = Field(default_factory=list) # artifact refs declared by runner
failure_reason: Optional[str] = None
WorkerRegisterRequest.model_rebuild()
# ---- internal index row (never serialized to callers) ----
class JobMeta(BaseModel):
job_id: str # cell id
base_job_id: str # original job_id from the batch
batch_id: str
cell: str # e.g. "linux/python-3.12/case-1" or "base"
platform: str
runtime: str
timeout: float
status: str = "queued" # queued | claimed | complete
submitted_at: float
retry_count: int = 0
claimed_by: Optional[int] = None
claimed_worker_url: Optional[str] = None
claimed_at: Optional[float] = None
claim_deadline: Optional[float] = None
completed_at: Optional[float] = None
last_abandon_reason: Optional[str] = None
stdin_case: Optional[int] = None
# ---- artifact metadata (stored in artifacts/<id>.json; bytes in artifacts/<id>.bin) ----
class ArtifactMeta(BaseModel):
artifact_id: str
batch_id: str
job_id: str # cell id
path: str # path inside the job workdir
kind: str # image | audio | file
content_type: str
size: int
sha256: str
created_at: float
|