pub struct WorkerClient { /* private fields */ }Expand description
A live worker.py subprocess and the plumbing that talks to it.
Implementations§
Source§impl WorkerClient
impl WorkerClient
Sourcepub async fn spawn(
python: &Path,
script_path: &Path,
cwd: Option<&Path>,
max_content_size: usize,
timeout_secs: u64,
) -> Result<Self, HostError>
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.
Sourcepub fn claim_probe_retry(&self) -> bool
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.
Sourcepub fn reported_capabilities(&self) -> Option<&WorkerCapabilities>
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.
Sourcepub async fn stderr_lines(&self) -> Vec<String>
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).
Sourcepub fn is_alive(&self) -> bool
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.
Sourcepub async fn send_task(&self, task: Value) -> Result<Value, HostError>
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.
Sourcepub async fn capabilities(&self) -> Result<WorkerCapabilities, HostError>
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.
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.
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.