Skip to main content

Module session_task

Module session_task 

Source
Expand description

Per-session actor. Owns one Arc<AgentHandle>’s event drain (AgentHandle::take_events) plus a per-session Command receiver. Translates each AgentEvent into the matching SessionUpdate envelope and emits onto the workspace-wide fan-out, which hands one update to every subscriber. Mutates DomainSession inline before each emit so workspace-side projections stay current.

SessionTask::run is the sole consumer of the AgentHandle event stream.

Re-exportsΒ§

use std::sync::Arc; πŸ”’
use forge_agent::AgentHandle; πŸ”’
use forge_agent::client::AgentEvent; πŸ”’
use forge_primitives::SessionId; πŸ”’
use parking_lot::Mutex; πŸ”’
use tokio::sync::mpsc; πŸ”’
use tracing::Instrument; πŸ”’
use crate::SessionSlot; πŸ”’
use crate::domain_session::DomainSession; πŸ”’
use crate::domain_session::PendingAutoContinue; πŸ”’
use crate::handoff; πŸ”’
use crate::protocol::Command; πŸ”’
use crate::protocol::NoticeSeverity; πŸ”’
use crate::protocol::PendingInteractionSlot; πŸ”’
use crate::protocol::PromptSource; πŸ”’
use crate::protocol::SessionUpdate; πŸ”’
use crate::update_fanout::UpdateFanout; πŸ”’

StructsΒ§

Moved πŸ”’
What one event MOVED in the domain’s whole sets.
SessionTask πŸ”’

EnumsΒ§

MonitorOrigin πŸ”’
Which side of the session a monitor was folded from, which decides the state it starts in.
MovedTurnEnd πŸ”’
What a turn’s end was, for the caller to announce.

ConstantsΒ§

API_RETRY_SUBTYPE πŸ”’
The wire subtype of the retry frame, where the CLI names an authentication failure on the retry path. A view matches the same literal.

FunctionsΒ§

apply_event_to_domain πŸ”’
Apply an AgentEvent to a DomainSession. Pure mutation; no I/O, no async, no sends. Called from inside SessionTask::translate_event under the domain’s lock.
clear_runtime_identity πŸ”’
Drop every fact that describes one run of a session: the hook’s mode and effort, the model it resolved, the two bridge snapshots that describe a subprocess tree, and the monitor set that run started.
drain_settled_monitors πŸ”’
Drop the monitor set once every entry in it is terminal.
execute_command_via_handle πŸ”’
Forward a Command straight to handle. Pure transport - no pending-interaction bookkeeping; the only commands that consult PendingInteractionSlot (RespondPermission / RespondQuestion) must be handled by the caller before delegation here.
failure_reason πŸ”’
What the failure is called in the nudge: the CLI’s own errors when the result frame reported any, else its subtype, else a plain fallback.
fill_of πŸ”’
The fill a reading states, against the CLI’s own effective window.
fold_monitor πŸ”’
Fold one wire message into the session’s monitor set: the Monitor tool call that starts one, the task id the CLI assigns it, and the lifecycle message that settles it.
held_while_swapping πŸ”’
The words a permission answer carried, where it carried any: the box’s own notes, the one field a dictation into the ask lands in (#1360). Hold a prompt aimed at a seat that is swapping its occupant, answering whether it went into the hold.
hold_view_facts πŸ”’
The facts this event carries that a view reads through the view surface: the hook observation’s mode and effort, the two bridge snapshots, the resolved model, and the monitor set.
maybe_kick_lead_on_connected πŸ”’
A lead’s first turn after a boot spawn handed it a stored session id to resume: the restart note the spawn stamped on the domain when the boot read the seat as mid-turn. The hook takes the note, so a reconnect repeats nothing, and a parked seat, a first boot or --new never stamped one.
maybe_kick_worker_on_connected πŸ”’
Shared worker-kick hook: when the session that connected is a worker, dispatch a Command::Prompt carrying the live worker’s stored kick to it. Claude sessions don’t act until a user-turn arrives, so without this kick a worker would sit idle indefinitely after spawn (its charter would shape behaviour IF prompted, but nothing prompts it).
maybe_respawn_workers_on_connected πŸ”’
Shared worker Connected hook: when the session that connected is a project’s lead and no live workers exist for the project yet, (re-)spawn its workers - one SpawnWorker per persisted worker row. Called from SessionTask::translate_event (production) and on_connected_for_test (tests). Idempotent; safe to call multiple times for the same session - the live_workers.is_empty() gate guards against double-spawn on /new reconnects or transient retries, and respawn_workers_for_lead no-ops when the project has no worker rows.
monitor_status_from_wire πŸ”’
The status a terminal task_updated names, in the vocabulary the renderers use. None for a status that is not terminal, and for one forge does not know: a patch that only stamps an end time carries no status at all.
permission_words πŸ”’
question_words πŸ”’
The words a question answer carried, where it carried any: its own note, for the same reason as permission_words.
reconcile_model_from_init πŸ”’
Take the model a turn’s system/init names, which is how a switch reaches a reader: /model re-fires the frame with the model the turn runs under, and the frame arrives at the head of every turn besides.
settle_monitor πŸ”’
spawn_permission_response_forwarder πŸ”’
Forward an awaited permission outcome to the agent so the bridge can complete the round-trip with the CLI subprocess.
spawn_question_response_forwarder πŸ”’
Forward an awaited question outcome to the agent so the bridge can complete the round-trip with the CLI subprocess.
task_status_is_terminal πŸ”’
Whether a task_updated patch names a status that ends the task.
warn_no_session πŸ”’