Skip to main content

WorkerClient

Struct WorkerClient 

Source
pub struct WorkerClient { /* private fields */ }
Expand description

A live worker.py subprocess and the plumbing that talks to it.

Implementations§

Source§

impl WorkerClient

Source

pub async fn spawn( python: &Path, script_path: &Path, cwd: Option<&Path>, max_content_size: usize, timeout_secs: u64, ) -> Result<Self, HostError>

Launch worker.py with the venv’s interpreter and start the I/O tasks.

cwd becomes the child’s working directory, which is where a plugin’s relative-path side effects land.

Source

pub fn claim_probe_retry(&self) -> bool

Claim this worker’s single retry of a failed capabilities probe.

True exactly once per worker. A probe that timed out or hit a worker still starting leaves no report, and with no report a cmf.* hook is served through the legacy shim for the worker’s whole life. One retry on first use recovers from a transient failure; bounding it to one keeps a probe that keeps failing from adding a round trip to every call.

Source

pub fn reported_capabilities(&self) -> Option<&WorkerCapabilities>

The handshake report from the last successful Self::capabilities call, or None if the worker was never asked.

Source

pub async fn stderr_lines(&self) -> Vec<String>

The worker’s retained stderr lines, oldest first.

Exposed so a test can assert the credential channel never surfaces here: this buffer is the one place the host copies worker stderr, and the one place it is echoed onward (into a WorkerDied message).

Source

pub fn is_alive(&self) -> bool

Whether the worker’s stdout is still open.

A false here is definitive — the process has closed its output. A true is only as fresh as the reader task’s last observation, so a send can still race a death; that path is covered by the dropped-sender branch in send_task.

Source

pub async fn send_task(&self, task: Value) -> Result<Value, HostError>

Send a task and await its response.

The caller supplies the task body; this method injects the request_id and handles registration, the size check, the write, and the timeout.

Source

pub async fn capabilities(&self) -> Result<WorkerCapabilities, HostError>

Ask the worker which wire-protocol features it implements.

§Why an unsupported task type is not an error here

A worker predating the handshake answers the unknown capabilities task with {"status":"error","message":"task type not supported."}, which send_task surfaces as HostError::WorkerError. That is the expected reply from an old worker, not a transport fault, so it maps to an empty feature set — the conservative answer that makes the caller fail closed for any plugin needing a gated field.

Everything else (a timeout, a dead worker, a malformed frame) stays an error: those mean the probe itself did not complete, and treating them as “no features” would report a specific, wrong diagnosis for a worker that may well be current.

Source

pub async fn shutdown(&self) -> Result<(), HostError>

Ask the worker to exit, then wait out the grace window and kill it.

Idempotent: a second call after the child has been reaped is a no-op, which matters because shutdown may run from both the plugin lifecycle and a drop path.

Trait Implementations§

Source§

impl Debug for WorkerClient

Manual rather than derived: the outbound channel carries serialized task lines, which on a credential-bearing hook include the plaintext token. A derive would put those in any debug dump of the client.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more