PtcRunner.Kernel.BoundedWorker (PtcRunner v0.14.0)

Copy Markdown View Source

Internal one-shot worker for heap- and time-bounded host computation.

Results use a process alias so timeout cleanup can invalidate and drain a late reply before returning to the caller. Callers that are themselves disposable workers may opt into :cancel_with_caller; the bounded worker is then linked for the duration of the call so an untrappable caller kill also terminates blocked work. A caller may also supply a :cancel_with process; its termination cancels the worker without coupling the two owners.

Summary

Functions

Classifies the result of a bounded provider callback that answers :ok.

Classifies a bounded provider callback that may answer with one payload.

Runs a zero-arity function in a monitored process under explicit limits.

Functions

classify_callback(arg1)

@spec classify_callback(term()) ::
  :ok | :timed_out | {:error, atom() | {atom(), pos_integer()}}

Classifies the result of a bounded provider callback that answers :ok.

Both callers of this — the audited-local and unverified phase-7 steps, and the connectivity probe — must translate a callback's outcome the same way, and the rule is load-bearing rather than cosmetic: an exhausted budget is reported as the bare :timed_out atom rather than through the {:error, reason} translation, so a callback returning the timeout reason itself cannot forge the code its caller mints for a real timeout. Anything unrecognised fails closed. Drift between two copies of that would be a defect in the one that drifted, so there is one copy.

A reason may also carry one positive integer position — the line of a declared input file the callback refused. Nothing else is admitted, because the position is the only per-instance detail a caller may publish and a wider grammar would let a callback hand its caller an arbitrary payload.

classify_payload_callback(result)

@spec classify_payload_callback(term()) ::
  :ok | {:ok, term()} | :timed_out | {:error, atom() | {atom(), pos_integer()}}

Classifies a bounded provider callback that may answer with one payload.

The connectivity probe's shipped callback reports what its request spent, so a success may carry a term beside :ok. Only that one shape is added: every other outcome, a bare :ok included, is translated by classify_callback/1, so the failure rule above stays the single copy both callers share. The payload is opaque here and stays untrusted — the caller closes its shape before publishing it, on the same terms as the position above.

run(function, opts)

@spec run(
  (-> term()),
  keyword()
) ::
  {:ok, term()}
  | {:error, :timeout | :cancelled | :heap_exceeded | :worker_failed}

Runs a zero-arity function in a monitored process under explicit limits.