Skip to main content

Module runtime

Module runtime 

Source
Expand description

Background runtime for Client - owns the subprocess reader, decodes incoming frames, dispatches inbound control_requests on detached tasks, and routes outbound control_responses to the PendingControls map so send_control callers can await their typed reply.

ยงLifecycle

  1. Client::spawn runs the init handshake inline (sends the initialize control_request, drains the response, captures any pre-init Messages).
  2. Once init completes, spawn_reader_task takes ownership of the Subprocess, the dispatch handle, the events channel, and any pre-init Messages.
  3. The reader task pre-pumps the buffered messages, then loops on subprocess.read_line() until shutdown / EOF / I/O error.
  4. On exit, the reader task closes the subprocess and drains pending_controls with an EOF error so blocked send_control callers wake up.

Re-exportsยง

use std::collections::HashMap; ๐Ÿ”’
use std::sync::Arc; ๐Ÿ”’
use parking_lot::RwLock; ๐Ÿ”’
use tokio::sync::Mutex; ๐Ÿ”’
use tokio::sync::mpsc; ๐Ÿ”’
use tokio::sync::oneshot; ๐Ÿ”’
use tokio::task::JoinHandle; ๐Ÿ”’
use crate::Error; ๐Ÿ”’
use crate::client::ControlDispatchHandle; ๐Ÿ”’
use crate::transport::codec::DecodedLine; ๐Ÿ”’
use crate::transport::codec::decode_dispatch; ๐Ÿ”’
use crate::transport::process::Subprocess; ๐Ÿ”’
use forge_primitives::Message; ๐Ÿ”’

Structsยง

SkipCounters ๐Ÿ”’
Consecutive skips of unparsable lines. At UNPARSABLE_ESCALATE_AFTER in a row the stream is not speaking stream-json, and the near-100%-malformed session would otherwise present to the user as a silent hang.

Enumsยง

LineOutcome ๐Ÿ”’
What handle_line decided about one decoded line.

Constantsยง

UNPARSABLE_ESCALATE_AFTER ๐Ÿ”’
Consecutive unparsable lines after which the reader escalates once to a session-visible error. A sparse bad frame still just skips.

Functionsยง

close_subprocess ๐Ÿ”’
control_request_id ๐Ÿ”’
request_id of line when it is a control_request, else None.
drain_pending ๐Ÿ”’
excerpt ๐Ÿ”’
First max_chars of line for logs and error strings - a corrupt line can be arbitrarily large.
handle_line ๐Ÿ”’
Process one decoded line. Returns LineOutcome::Stop only when the events channel has closed and the read loop should exit; a line that fails to decode is skipped and the loop continues.
spawn_reader_task ๐Ÿ”’
Spawn the post-init reader task.

Type Aliasesยง

ControlOutcome ๐Ÿ”’
Outcome of one outbound control_request - either the success payload (the inner response JSON) or a typed error.
InflightDispatches ๐Ÿ”’
In-flight inbound control_request dispatch tasks. Keyed by request_id so a subsequent control_cancel_request can abort the matching task instead of letting the slow callback finish and write back a control_response the CLI has already moved past.
PendingControls ๐Ÿ”’
In-flight outbound control_requests waiting on responses.
SharedSessionId ๐Ÿ”’
Shared session-id container - held by Client, ControlDispatchHandle, and the reader task. Reader updates it as messages arrive; consumers read the current value.