Skip to main content

SessionsRegistry

Struct SessionsRegistry 

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

The cross-window session registry.

The in-memory, TTL-reaped set of running Claude sessions plus the companion window-embedding reports used to tag a session’s Source. Hosted by SessionsService.

Implementations§

Source§

impl SessionsRegistry

Source

pub fn new() -> Self

Creates the registry with the default liveness TTLs. Cheap — no I/O.

Source

pub fn delivery(&self) -> DeliveryStats

How events have reached the registry since it was created (#2136).

Source

pub fn subscribe_changes(&self) -> Receiver<u64>

A change-notification receiver for the push subscription: it observes a new value each time the rendered session state changes (see bump). Created with the current version already marked seen, so the first watch::Receiver::changed resolves on the next change — the subscriber sends its own initial snapshot up front and then waits for deltas (#1414).

Source

pub fn observe(&self, req: ObserveRequest)

Records (upserts) a session sighting, running the SessionState inference and refreshing liveness. Reaps stale entries first, then — only when a genuinely new session would grow the map past [MAX_SESSIONS] — evicts the longest-silent entry. Infallible: an upsert never evicts.

Best-effort fields (cwd/transcript_path/repo/model) fill in on an existing entry and never overwrite known data with None, so a later hook enriches a watcher-discovered session without a race losing data.

bumps only when the sighting changed something a consumer renders — a brand-new session, a SessionState transition, a best-effort field taking a new value, or a reap that dropped a sibling. A repeat sighting that merely refreshes liveness does not, since hooks fire on every tool call (the heartbeat precedent in WorktreesRegistry).

For the daemon’s own in-process feeds: it is the Local origin, which DeliveryStats does not count. The control socket’s feed goes through observe_stamped as the Socket origin.

Source

pub fn end( &self, session_id: &str, reason: Option<&str>, pid: Option<u32>, ) -> bool

Marks a session ended (SessionEnd), so list shows it as ended for a short window ([ENDED_SESSION_TTL]) before it is reaped. Returns whether the session was known. A no-op for an already-unknown session (a duplicate/late SessionEnd).

Also a no-op when pid is a process the session was taken over from: an in-place resume (a VS Code window reload) starts a new process on the same session_id without waiting for the old one to exit, so the old process’s SessionEnd can arrive after the new one’s SessionStart (#1948). Any other end — no pid, the owning pid, or a pid never seen (a wrapped hook command whose parent is a per-hook shell) — ends the session, so the rule can only ever keep a session the old process no longer owns.

For the daemon’s own in-process feeds, as observe is (the Local origin).

Source

pub fn report_window(&self, report: WindowReport)

Records (upserts) a companion window-embedding report and refreshes its liveness. Reaps stale windows first, then caps like observe.

bumps only when the report changes the Source join a consumer renders — a new window, different folders, or an embedding that appeared or vanished — never on the unchanged ~10 s refresh every open window sends, which would otherwise put a permanent push floor under the daemon proportional to the window count.

Source

pub fn unregister_window(&self, key: &str) -> bool

Drops a companion window-embedding report (the window closed). Returns whether an entry was present.

Source

pub fn credit_window_outage(&self, outage: Duration)

Pauses the window-report liveness clock for outage: advances every live report’s last_active by that long, never past now (#2111).

For a stretch when the daemon could not accept connections, so no window’s ~10 s refresh could arrive. Without this the first window op after the outage reaps every other report that has been quiet more than the 30 s TTL, and the sessions in those windows flip from vscode to terminal until each window reports again — the same failure WorktreesRegistry::credit_outage fixes for the window registry.

outage is measured on a monotonic Instant, the same awake time as the [AwakeClock] the reports are stamped on, so the two compose: the credit shifts a stamp by time the daemon was awake but deaf, and a system sleep still ages nothing (#2108).

Only window reports are credited. A session’s own last_active is not: a live one has a five-minute TTL that an outage rarely approaches, and an ended one’s short linger is not worth stretching. Not a visible change, so it does not bump the change-notify.

Source

pub fn list(&self) -> Vec<SessionEntry>

Reaps stale sessions and windows, then returns the live sessions with each Source resolved and sorted for deterministic output.

Two independent locks, each held only for pure-CPU work and never nested: the sessions snapshot is taken and the lock dropped, then the windows snapshot, then the join runs lock-free. Path matching is a pure prefix compare (no canonicalization / disk I/O), honouring the Mutex-never-across-.await and no-I/O-under-lock invariants.

Deliberately does not bump, even when its inline reap drops an entry: this is the body of every subscription’s snapshot(), so bumping here would feed the stream loop back into itself. A read-path reap reaches other subscribers on the server’s next periodic re-sample, whose diff sees the shrunken list — the WorktreesRegistry::list arrangement.

Source

pub fn focus_folder(&self, session_id: &str) -> Option<PathBuf>

The first workspace folder of the still-live window a session is embedded in, if any — used by the tray “focus” action to resolve a session to a folder to open in VS Code. None when the session has no cwd, or is not matched to a reporting window with a folder.

Trait Implementations§

Source§

impl Default for SessionsRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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