Skip to content

Expose a session's runtime process id (read-only) so hosts can show its memory #231

Closed

Description

@xxchan

What

A host can't tell which OS process a Session runs. Please expose it, read-only, for observation: e.g. Session.processId: number | undefined (or Session.process(): { pid: number } | undefined), the pid of the runtime process while it lives; undefined for in-process runtimes (cursor via @cursor/sdk) and once it has exited.

Why (use case)

Ferry (D086, branch host-stats) is adding a live device panel to a machine's page: CPU, memory, disk, the daemon's own memory, and "3 agent processes · 266 MB": how much memory the runtimes Ferry's sessions run take, with everything they started (MCP servers, shells, dev servers). People use it to see why a machine is slow and which agent is responsible.

Ferry must not signal or kill those processes (oar owns their lifecycle), but reading their resident size is fine: one ps -axo pid,ppid,rss (or pgid) call, summing each session's process and its descendants. For that it needs the pid. Today it can only count sessions with a live run.

Evidence (oar 0.39.0)

  • contracts/session.d.ts: Session / AdapterSession carry no pid or process handle.
  • shared/executable/process.d.ts: LineProcess (what claude, codex, grok and the ACP runtimes run) exposes spawned, exited, stdin, stdout, diagnostics(), kill(), but not the ChildProcess or its pid; it's internal and not exported from any entry point (., ./kernel, ./observe, ...).
  • oar already spawns each POSIX child detached as its process group leader (OWN_PROCESS_GROUP), so pid is also the group id: a host could sum RSS by pgid too, which catches what the runtime started even after it re-parents.
  • oar already has the walk internally (shared/executable/process-tree.ts descendantsOf), used by killTree.

Suggestion

  • readonly processId?: number on Session (a getter: set once spawned resolves, cleared at exit), documented as observation only: "never signal it; dispose() stops it". Optionally processGroup?: number when it differs.
  • Or, if oar would rather own the walk: Session.resources?(): Promise<{ rss: number; processes: number }> (the runtime process and its descendants, one ps call), undefined for in-process runtimes.

Either lets Ferry fill agents.rss in its machine.stats RPC; until then it shows only the count of live sessions.

Activity

  1. xxchan commented on Oct 8, 2026

    @xxchan
    MemberAuthor

    Decided by @cindy: oar owns the walk, and the pid stays inside oar.

    A pid on the public Session would be the first handle a host could signal behind oar's back. The host only needs a reading, and oar already has the process-table walk (shared/executable/process-tree.ts), so:

    • New optional member: Session.resources?(): Promise<SessionResources | null>, with SessionResources = { rss: number; processes: number }.
      • rss is in bytes, summed over the runtime process, its process group and its descendants, read from one process-table snapshot.
      • processes is how many were counted.
      • null once the runtime process has exited.
    • Where it is absent: runtimes with no process of their own (pi's SDK, cursor's SDK), whose memory is the host's own. Absent means unsupported, as with steer and withdraw.
    • Platforms: Linux reads /proc/<pid>/stat and statm; macOS uses ps -A -o pid=,ppid=,pgid=,rss=; Windows answers null until it gets its own reader. The docs say so.
    • Observation only:
      • not recorded in the record stream, since it is the host machine's state, not a runtime fact;
      • nothing is signalled;
      • dispose() remains the only way to stop the process.
    • Tests:
      • a fake runtime that starts a child keeps it in the count;
      • one that re-parents a child out of its group is still counted while it is a descendant;
      • after exit the answer is null;
      • in-process runtimes have no member.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions