feat: persist last PTY output timestamp - #168
Merged
Merged
Conversation
The daemon already parses every PTY output byte (that is how the terminal buffer exists), so recording WHEN output last happened is O(1) in the existing onData path — no new observation machinery. The stamp persists to the session metadata the daemon already maintains, through the locked metadata mutation, debounced to at most one write per second per busy session. Consumers (st2's observed harness state) derive session activity from the persisted field instead of observing output streams themselves: one field, one writer that already sees everything, one reader. Activity is an activity signal only — deliberately not liveness or delivery.
Use lastOutputAtMs rather than RFC3339 text: st2's freshness and wire contracts already use unix milliseconds, so the numeric scalar avoids a time-parser dependency and is cheaper for every cross-language reader.
Add the user-confirmed R14 contract, exact daemon/debounce/exit-flush mechanism, and validation-matrix ownership. Extend the integration proof with immediate-output-then-exit durability.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
st2 needs launcher-agnostic coarse session activity for every managed PTY. Existing PTY surfaces are unsuitable:
scrollbackUsedis bounded and saturates, so deltas fail on long sessions;pty eventsis sparse and semantic, not an output stream;pty stats --jsonmeasured 520ms/60 sessions (~5.5s projected at 627) and includes resource probes the consumer does not need.The PTY daemon already processes every output byte to maintain terminal state. It is the unique lowest-cost observer.
Goal
Persist when each session last emitted output, with bounded write amplification and no launcher/harness coupling, so readers can derive activity directly from session metadata.
Decisions
lastOutputAtMsin the existingptyProcess.onDatapath: O(1), no new observer.Verification
npm run typecheck— green.npx vitest run tests/output-activity.test.ts tests/disk-layout-docs.test.ts— 9/9 green, including immediate output followed by exit carrying the final stamp.nix build .#pty --no-link— green:/nix/store/y4c3pnafcpmgsa289znrx15qf45vljzf-pty-0.1.0.VRS
With explicit user authorization,
docs/vrs/requirements.mdadds R14 (protected requirement): optional unix-ms evidence, absence-before-output, ≤1 metadata write/s during output, final exit persistence, and no activity/liveness interpretation.spec.mddefines the exact algorithm and validation matrix;docs/disk-layout.mdcarries the public record contract.axe vrs check --profile strict docs/vrsis green.Complexity
One optional metadata field and one per-session debounce flag. No new process, event vocabulary, stream, or background loop.
Concerns
A continuously chatty session performs one small locked metadata write per second. The bound is explicit; st2 consumes the file directly and never asks PTY to classify state.
Friction & bottlenecks
branchy new --carry-changesfailed against unrelated dirt in the canonical main worktree; created a clean worktree instead.Follow-ups
lastOutputAtMs, compose session/driver fidelity, benchmark 627-seat roster.References
Posted on behalf of @schickling
agent_identityagent_personaagent_supervisoragent_toolagent_tool_versionagent_runtimetooling_profile