Skip to content

feat(session): Session.resources() reads a runtime's memory (#231) - #238

Merged
xxchan merged 3 commits into
mainfrom
lookout/session-resources
Oct 8, 2026
Merged

xxchan merged 3 commits into
mainfrom
lookout/session-resources

Conversation

@xxchan

@xxchan xxchan commented Oct 8, 2026

Copy link
Copy Markdown
Member

Closes #231, following the design in this comment: oar owns the process-table walk, and the pid stays inside oar.

What

Session.resources?(): Promise<SessionResources | null>, where SessionResources = { rss, processes }.

  • rss: resident bytes, summed over the runtime process, the process group it leads, and its descendants (including those that left the group). All of them come from one reading of the process table.
  • processes: how many processes were counted.
  • null: once the process has exited, before it has a pid, and on Windows (no reader yet; documented).
  • Readers (shared/executable/process-resources.ts, which reuses descendantsOf from process-tree.ts):
    • Linux: /proc/<pid>/stat, using its resident pages and the page size (getconf PAGESIZE, read once).
    • Other POSIX systems: ps -A -o pid=,ppid=,pgid=,rss=.
  • Observation only: it enters no record, nothing is signalled, and dispose() stays the only way to stop the process.
  • Who has it:
    • claude, codex and the ACP sessions get it through their line process. Codex's home-initialization client returns null until its process exists.
    • pi and cursor don't have the member, since their runtimes run in the host process. Absent means unsupported, as with steer and withdraw.

Docs:

  • record-stream.md: a new rule, "A runtime's memory is read, never recorded".
  • capabilities.md: resources added to the members that may be absent.
  • README.

Tests

  • tests/session-resources.test.ts:
    • For claude, codex and ACP stand-ins, the runtime and the tool it started are both counted (2 processes); this also holds when the tool runs in a session of its own. The answer is null after dispose().
    • On Linux both readers (procfs, and ps as used on macOS) count a process, its group, and a descendant that left it.
    • A pid that is gone and Windows both get null.
  • pi and cursor sessions don't have the member (tests/pi/pi-session-withdraw.test.ts, tests/cursor/cursor-session-withdraw.test.ts).
  • Real runtimes against aimock, checked locally: claude reported 1 process (71 MiB), codex 4 processes (145 MiB), and both returned null after dispose.

pnpm run check passes (1042 tests, mock 19/19).

🤖 Generated with Claude Code

xxchan pushed a commit that referenced this pull request Oct 8, 2026
…ree note

Review of #238: the Linux reader opened every /proc/<pid>/stat at once and
swallowed every error, so on a low ulimit -n (EMFILE) it could under-count or
answer null with nothing to tell the host. Reads now go 64 at a time; only
ENOENT and ESRCH (the process is gone) are skipped, any other failure makes
the reading null. Concurrent calls share the read in flight (forgotten once
it settles). The killTree option's comment is back to its full text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
exe.dev user and others added 3 commits October 8, 2026 09:26
A host (Ferry's device panel) wants to show how much memory the runtimes
of its sessions take, with everything they started, without a pid it could
signal behind oar's back. Session.resources?() answers { rss, processes }:
resident bytes summed over the runtime process, the process group it leads
and its descendants (those that left the group too), from one reading of
the process table (Linux /proc/<pid>/stat and the page size; elsewhere
ps -A -o pid=,ppid=,pgid=,rss=), and how many processes that was. null once
the process has exited, and on Windows (no reader yet).

Observation only: not recorded, nothing signalled, the pid stays inside oar.
claude, codex and the ACP sessions have it (through their line process);
pi and cursor, whose runtimes run in the host process, do not.

Tests: the runtime and its tool are counted, the tool in a session of its
own too, null after dispose, for claude, codex and ACP stand-ins; both
readers count a process, its group and a descendant that left it; a gone pid
and Windows have no reading; pi and cursor sessions lack the member.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ree note

Review of #238: the Linux reader opened every /proc/<pid>/stat at once and
swallowed every error, so on a low ulimit -n (EMFILE) it could under-count or
answer null with nothing to tell the host. Reads now go 64 at a time; only
ENOENT and ESRCH (the process is gone) are skipped, any other failure makes
the reading null. Concurrent calls share the read in flight (forgotten once
it settles). The killTree option's comment is back to its full text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@xxchan
xxchan force-pushed the lookout/session-resources branch from 5530bc4 to 3c60fd7 Compare October 8, 2026 09:26
@xxchan
xxchan merged commit e85bbcd into main Oct 8, 2026
13 checks passed
@xxchan
xxchan deleted the lookout/session-resources branch October 8, 2026 09:38
@xxchan xxchan mentioned this pull request Oct 8, 2026
xxchan added a commit that referenced this pull request Oct 8, 2026
Release OAR and CLI 0.42.0. This PR changes only the two package version
fields.

**Behavior changes**
- `FailureClass` has four new members: `model_unavailable`,
`input_too_large`, `rate_limited` and `billing` (#237). Host code with
an exhaustive `switch` over it needs the new cases.
- A 429 that names no quota or balance is now `rate_limited`; it was
`quota`. A 429 whose provider code names a quota or a balance is `quota`
or `billing`.
- `failureText("auth", name)` without a credential now reads "could not
authenticate". It used to read "is not signed in", which was wrong for a
refused key. Pass the outcome's `credential` to get "is not signed in"
(`missing`) or "credentials were rejected" (`rejected`).
- Some opens now reject with `RuntimeFailureError` (still an `Error`,
same message) where they rejected with a raw `RequestError` or a plain
`Error`: an ACP agent that requires auth, a -32602 answer to the model
call, a key cursor refuses, a pi model OAR does not find.
- A grok failure reason now includes its `data` text (the provider's
answer), not only "Internal error".
- An input with empty text and no images is now rejected `unsupported`
(`empty input: give text or images`) before anything reaches the runtime
(#239).

**New**
- Structured failure classification (#237, closes #227). Each adapter
reads the runtime's own category first, then the provider's error body
(`code`, then `type`), then the HTTP status; matching words is a
documented last resort. Fixed: claude's "Credit balance is too low" (now
`billing`) and oversized context (now `input_too_large`); codex
`serverOverloaded` (now `overloaded`) and `contextWindowExceeded` (now
`input_too_large`).
- A failed `TurnOutcome` may carry `credential` (`missing` | `rejected`)
and `status` (the provider's HTTP status), only where the runtime says
them.
- `RuntimeFailureError { failure, credential?, status?, reason }` for
opens that fail for one of these causes.
- `observe`: `failureAdvice(failure)` returns `{ retry: "now" | "later"
| "no", userAction }`.
- The per-runtime rules and known gaps are in runtime-matrix "Failure
evidence".
- `Session.resources?(): Promise<{ rss, processes } | null>` (#238,
closes #231): the host memory a session's runtime takes, in bytes, over
the runtime process, its process group and its descendants, from one
reading of the process table. Null once the process has exited, on
Windows, and when the table cannot be read whole. Absent on pi and
cursor, which run in the host process. Observation only: nothing is
recorded or signalled, and no pid leaves OAR. Concurrent calls share one
read.
- Image-only input (#239, closes #235): `prompt`, `steer` and `queue`
take `""` when `images` is non-empty. claude, codex and the ACP runtimes
no longer receive an empty text part; pi and cursor take the text as an
argument and receive `""`. grok drops images smaller than 8×8 without
saying so (its runtime page has the evidence).

Validation: all 13 checks passed on each PR's final head (#237
`772d337`, #238 `3c60fd7`, #239 `47d91ac`), and each merged tree equals
its CI tree. After this PR passes CI and merges, tag its exact squash
commit as `v0.42.0` to trigger npm trusted publishing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: exe.dev user <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant