mixle.pool.core module¶
Pool jobs, results, and backend protocol.
A PoolJob describes a runnable unit of work, its input manifest, the
placement reason, estimated cost, and budget. A Backend executes the
job and returns a PoolResult whose artifact can be used by the
submitter locally.
The included LocalBackend runs jobs in-process and is useful for tests
or systems without a remote pool. Billable backends must require explicit
confirmation, and jobs whose estimated cost exceeds their budget are rejected
before execution. A backend is third-party code, so its response is not taken on
trust either: submit() settles it against the job it was given (identity,
status vocabulary, finite economics, realized cost within budget) before the
caller ever sees ok == True.
- class PoolJob(run, kind='block', reason='', est_cost=0.0, budget=inf, inputs=<factory>, id=<factory>)[source]
Bases:
objectA runnable unit of work destined for local-or-pool execution, with its reason and budget.
runis any callable returning an artifact (a fitted model, an index, a dataset).est_costis the estimated dollar cost the economics assigned;budgetis the ceiling the submitter set.reasonis the placement justification the planner produced (“8.2 TFLOP gradient residual”).
- POOL_STATUSES = frozenset({'done', 'error', 'rejected'})
The closed status vocabulary a
PoolResultmay use.submit()refuses anything outside this set rather than letting an unrecognized status ride through:PoolResult.okonly tests equality with"done", so an unknown status would read as “not ok” while carrying none of the error handling a real failure gets.
- class PoolResult(job_id, status, artifact=None, cost=0.0, duration_s=0.0, reason='', telemetry_error='')[source]
Bases:
objectThe outcome of a pool job: the artifact that round-trips home, plus realized cost/timing.
- Parameters:
- property ok: bool
Whether the job completed successfully.
- property telemetry_recorded: bool
Whether this submission’s
pool_jobevent actually reached the telemetry sink.Separate from
ok: the job itself can succeed while its record is lost, and the two failures need different responses – a dropped event means the spend and duration behind this result are missing from whatever ledger reconciles them.
- class Backend(*args, **kwargs)[source]
Bases:
ProtocolExecutes a
PoolJob. Real backends setbillable=Trueand honor the confirm gate.- submit(job)[source]
Execute
joband return aPoolResult.- Parameters:
job (PoolJob)
- Return type:
PoolResult
- class LocalBackend(clock=None)[source]
Bases:
objectThe pool degraded to this machine: runs the job in-process, free, no confirm needed.
This is what a user with no remote pool configured gets: the abstraction works end-to-end and every result is a real local artifact.
clockis injectable for deterministic timing in tests.- Parameters:
clock (Callable[[], float] | None)
- submit(job)[source]
Run
jobin this process and wrap the outcome as a pool result.- Parameters:
job (PoolJob)
- Return type:
PoolResult
- submit(job, backend=None, *, confirm=False, telemetry=None)[source]
Submit
jobtobackend(defaultLocalBackend), enforcing budget + confirm rails.A job whose
est_costexceeds itsbudgetis REJECTED before running. A BILLABLE backend (a real GPU pool) additionally requiresconfirm=True– spend is never incurred implicitly. Every submission emits apool_jobtelemetry event (features + realized outcome). A telemetry sink that fails does not fail the job – but it does not disappear either: the reason lands onresult.telemetry_error(andresult.telemetry_recordedgoes false), so a caller reconciling spend against that event stream can see which rows are missing from it.The confirm gate demands the literal Boolean
True, not merely a truthy value:confirmis routinely threaded through JSON payloads, CLI flags and form fields, where the string"false"(or"0", or an empty-but-present marker object) is a perfectly ordinary way to spell “no” – and every one of those is truthy in Python. Anything other thanTruetherefore leaves the job unconfirmed and rejected rather than silently authorizing billable execution.job.est_costmust be finite and non-negative andjob.budgetmust be non-negative (infallowed, meaning “no ceiling”) – raisesValueErrorotherwise. Costs are a dollar estimate, never a credit: a NaN or negative value would defeat the comparison below rather than be caught by it (NaN compares false against everything, soest_cost > budgetsilently passes; a negative value can “refund” budget that was never spent), so both are rejected outright rather than routed through the ordinary rejected-PoolResultpath.The backend’s response is checked too, by
_settle(): it must be aPoolResultfor this exact job, with a status inPOOL_STATUSESand a finite non-negativecostandduration_sthat settles withinjob.budget. A response failing any of those is returned as an"error"result instead of being passed through, so.okis never true for work whose identity or economics do not check out. A backend that raises rather than responding is likewise an"error"result naming the backend and the exception, not an exception out ofsubmit: the return contract and the telemetry guarantee both have to hold on the path where the pool is down, which is the path an operator most needs a record of.Submission is NOT idempotent and deliberately keeps no durable job state: submitting the same
PoolJobtwice runs it twice, even when itsidis a caller-supplied constant rather than the default fresh UUID (idis a correlation handle for telemetry and settlement, not a deduplication key). A caller whose work is irreversible or billable – and any orchestrator that retries after a crash or a lost response – must therefore carry its own idempotency key and committed-result lookup; that needs durable storage, and this library layer does no I/O.