Repository navigation
Description
User Story
I use OpenShell in single-host and distributed deployments, including Kubernetes with shared supervisors. I need recent sandbox logs and events through the CLI, TUI, and SDKs without log volume becoming a gateway scaling cost. I also need a persistent filesystem directory or optional object storage for deployments that retain logs beyond a supervisor's lifetime.
Problem Statement
The gateway currently buffers sandbox logs and platform events in memory and serves user reads from those local buffers. Supervisor log pushes continue even when nobody is reading. Log ownership and cursor state are tied to a gateway replica rather than the supervisor responsible for the sandbox.
Impact / Why This Matters
Gateway restarts clear buffered history. Multi-replica reads can return partial histories, while log traffic and memory costs grow with the sandbox fleet. External collection does not remove the existing supervisor-to-gateway ingestion path. Operators need consistent built-in access, explicit recovery behavior, and storage choices that do not depend on the compute driver.
Proposed Design
The supervisor becomes the source of truth for sandbox logs and events, and the gateway stops buffering either. Logs live on the data plane; the gateway only routes requests to the right supervisor and streams the answer back.
Principles:
- No log state in the gateway. Remove the per-sandbox tail buffers and broadcast channels the gateway holds today.
- Supervisor owns the record. It keeps an in-memory buffer for fast reads and writes every line to disk, where log shippers can pull from it.
- Reads route through the gateway to the supervisor. WatchSandbox and GetSandboxLogs become proxied requests instead of local lookups.
- Handoff is a read-through cache. When a sandbox moves to a new supervisor, the new supervisor pulls the previous buffer from the sandbox.
- Assume the sandbox is compromised. Anything stored inside the sandbox can be altered, so it is never the authoritative copy.
- Full telemetry is the operator's job. Operators who need complete, durable logs run their own shipper or enable our persistent storage option.
Non-goals
- Guaranteed lossless, tamper-proof log retention. That is the job of an operator's own shipper or the persistent storage option.
- A new query language or search index. Reads stay tail, follow and cursor-based resume.
- Changing what gets logged. OCSF event classes and the OCSF versus plain tracing rules stay as they are.
Threat model
We assume the workload inside the sandbox can be fully compromised, including everything stored in sandbox memory or on its filesystem. Any log data that has been inside the sandbox is therefore untrusted when it comes back out.
| Component | Trust for log integrity | Notes |
|---|---|---|
| Supervisor | Trusted | Writes the authoritative record, on disk and in memory, outside the workload's reach. |
| Gateway | Trusted, but stateless for logs | Routes requests and enforces auth. Holds no log data. |
| Sandbox buffer | Untrusted | A convenience copy for handoff. The workload can read, edit, truncate or fill it. |
| Log shipper and storage | Operator-controlled | Trusted as far as the operator trusts their own pipeline. |
What this implies:
- The sandbox copy is never authoritative. While a supervisor is alive, reads come from its own buffer and disk, never from the sandbox.
- Recovered entries are labeled. Lines a new supervisor pulls from the sandbox are marked as recovered and unverified in every API response and in shipped output.
- The supervisor parses recovered data defensively. It enforces size and count limits, rejects malformed entries, and strips or escapes control characters so a forged line cannot attack a terminal or a downstream parser.
- Tampering must be detectable where possible. Each supervisor-written line carries a sequence number and a chain value keyed with a secret the workload never sees. Detection covers edits, reordering and mid-stream deletion. Truncating the newest entries cannot be detected by this alone; see open questions.
- Log content is data, not instructions. A compromised workload can emit log text that looks like an OCSF event. Consumers must not treat sandbox-influenced fields as trusted.
Architecture
The supervisor writes each log line and event to its memory buffers and to disk, and serves reads from them. The gateway authorizes a client request, forwards it to that sandbox's supervisor over the existing ConnectSupervisor stream, and relays the answer. The sandbox holds only a mirror copy for handoff, and shippers read the disk files directly.
flowchart TB
User["CLI, TUI, SDK"] <-->|"Authorized reads and opaque cursors"| Gateway["Gateway: route and proxy"]
Gateway <-->|"ConnectSupervisor request and response relay"| Read
subgraph Supervisor["Owning supervisor: trusted log owner"]
Records["Log lines and platform events"] --> Memory["Recent memory buffer"]
Records --> Disk["Per-sandbox NDJSON files"]
Memory --> Read["History, follow and resume"]
Disk --> Read
Memory --> Mirror["Sequence and keyed integrity chain"]
end
Mirror --> Cache["Sandbox: untrusted handoff mirror"]
Cache -.->|"Bounded recovery and chain verification"| Replacement["Replacement supervisor"]
Disk --> Shipper["Operator-managed shipper"]
Disk -.->|"Optional segment shipping"| Durable["Persistent storage backend"]
Supervisor handoff
The sandbox behaves as a read-through cache for the supervisor's recent buffer. It lets a replacement supervisor recover history it never saw.
- Mirror. While running, the supervisor periodically writes its recent tail into a buffer held by the sandbox, as sequence-numbered entries with the chain value described in the threat model.
- Rebalance. The sandbox is reattached to a new supervisor, for example after a node failure or a reschedule.
- Establish identity. The new supervisor connects to the gateway and receives the per-sandbox integrity secret over its authenticated session. The workload never has this secret.
- Pull. The new supervisor reads the sandbox buffer, applies size and count limits, and verifies each entry against the chain.
- Merge. Verified entries are imported and labeled recovered. Entries that fail verification are dropped and counted, and the supervisor records one event stating how many were rejected and why.
- Resume. The new supervisor appends its own lines after the recovered tail, writes everything to its own disk, and continues the cursor space so watchers can resume.
The handoff is best-effort. If the sandbox buffer is missing, empty or corrupt, the new supervisor starts with an empty history and logs that fact. Operators who need continuity across a lost supervisor must ship logs off the supervisor, since its local disk may go with it.
Persistence and shipping
The supervisor writes every log line to disk, and shippers pull from there. We do not build a full telemetry pipeline into OpenShell.
- On-disk format. Newline-delimited JSON, one file set per sandbox, rotated by size and age with a bounded total footprint. The existing OCSF JSONL output is the starting point, extended with the sequence number, chain value and recovered flag.
- Pull model. Operators run a standard shipper (a sidecar or node agent) against the log directory. The supervisor never needs credentials for the destination in this mode.
- Built-in persistent storage. An optional backend where the supervisor ships rotated segments to object or other durable storage. It is off by default and configured per gateway or per sandbox policy. Backends are pluggable behind one narrow trait.
- Retention. Local disk is a bounded window, not an archive. Rotation drops the oldest segments, and the supervisor emits an event when it does.
- Backpressure. Logging never blocks the workload. When disk or shipping falls behind, the supervisor drops with a counter and surfaces the drop count in the stream, as it does for the push channel today.
- Full telemetry. If an operator wants complete history, they run their own shipper or enable the persistent storage option. The in-memory buffer and local disk are not a compliance record.
Storage configuration
Provide explicit support for a local filesystem directory and optional object storage. A persistent directory enables history retention for single-host deployments; object storage enables shipping and retention across supervisor ownership changes. Select storage through configuration and capabilities, not Kubernetes versus non-Kubernetes behavior. Either backend can be used wherever the selected storage is accessible. Exact configuration fields and scope remain to be settled below.
API and proto changes
Client-facing calls keep their shape. The change is behind the gateway.
| Surface | Change |
|---|---|
| GetSandboxLogs, WatchSandbox | Same request and response. The gateway authorizes, finds the sandbox's supervisor session, forwards the request over ConnectSupervisor, and streams results back. |
| ConnectSupervisor messages | New gateway-to-supervisor request and supervisor-to-gateway response messages for log and event reads, including tail, follow and resume. |
| PushSandboxLogs | Deprecated, then removed once the read-path proxy ships. |
| Cursors | The supervisor issues the epoch and sequence. The gateway passes cursors through opaquely and no longer allocates them. |
| New field on log lines and events | A provenance marker (live or recovered), so clients can tell verified lines from entries pulled out of a sandbox. |
| Errors | A sandbox with no live supervisor session returns UNAVAILABLE with a message naming that state, instead of serving stale buffered data. |
Gateway replicas already track which replica owns a supervisor session (supervisor_owner.rs). A read that lands on another replica is forwarded to the owner, so no replica needs a local log copy.
CLI, TUI and the Rust, Go and TypeScript SDKs only need to render the provenance marker and handle the new UNAVAILABLE case. Public protobuf changes follow proto/README.md.
Suggested UX
Existing commands continue to provide recent history and live follow through the gateway:
openshell logs demo
openshell logs demo --tailLog and event responses identify recovered entries. A sandbox without a live supervisor returns the stated UNAVAILABLE response. Persistent filesystem and object-storage configuration is explicit and independent of compute-driver identity; exact configuration fields remain an open question.
Migration and rollout
Each phase ships on its own and leaves the system working.
Phase 1: Move log and event buffers down to the supervisor
Both logs and events are held in the supervisor, and the gateway holds neither.
- Add in-memory buffers and on-disk NDJSON files in the supervisor for log lines and for events, with rotation and a supervisor-issued cursor space.
- Add the ConnectSupervisor log and event messages and route GetSandboxLogs and WatchSandbox to the supervisor, including follow and resume.
- Delete the TracingLogBus buffering, the platform event tail and PushSandboxLogs. Roll out behind a gateway flag first, with the old buffers as a fallback until mixed-version upgrades are done.
- Update the gateway configuration docs, the logging docs and the debug-openshell-cluster skill in the same branch.
Phase 2: Add a sandbox buffer and read-through cache
The supervisor mirrors its recent tail of logs and events into a buffer held by the sandbox. A replacement supervisor pulls it, verifies it against the integrity chain, and labels entries recovered.
Phase 3: Add persistent storage from the supervisor
Ship rotated segments to NFS, object storage and similar backends behind one narrow trait. Off by default, and the first backend ships once the trait settles.
Step 1 is the riskiest for compatibility, because older supervisors and newer gateways must interoperate during an upgrade. The proxy must fall back cleanly when a supervisor does not support the new messages. Steps 2 and 3 are independent of each other and both build on step 1.
Open questions
- Pre-supervisor and driver events. Compute drivers publish platform events (scheduling, image pull) into the gateway today, often before a supervisor exists. With no gateway buffer, do these come from the driver's native source on demand, from sandbox status conditions, or from a small supervisor-adjacent store?
- Gateway's own correlated logs. follow_logs also streams gateway process logs about a sandbox. Do we drop that, or fetch it from the gateway's normal log output?
- Post-mortem reads. Logs of a crashed or stopped sandbox are the main debugging case. Where do they live once the supervisor is gone, if the operator has no shipper?
- Tail truncation. A chain detects edits and deletions in the middle, not removal of the newest entries. Do we anchor a checkpoint somewhere the workload cannot reach, such as the gateway holding only a counter and head hash?
- Integrity secret. Is a per-sandbox secret delivered over the supervisor session the right mechanism, and how is it rotated across handoffs?
- Disk location per driver. Where does the supervisor's log directory live for Kubernetes, Docker, Podman, VM and MXC, and who cleans it up on sandbox delete?
- Sizing defaults. Memory buffer size, on-disk cap and rotation policy per sandbox, and whether operators can tune them.
- Persistent storage scope. Which backend ships first, and is it configured per gateway, per sandbox, or in policy?
- Mixed-version upgrades. How long do we keep the gateway fallback buffer before removing it?
Acceptance Criteria
- The gateway holds zero log or event buffers and no per-sandbox log cursor state.
- Log and event reads work the same for the CLI, TUI and SDKs, with the gateway as a pass-through.
- Supervisor logs survive a supervisor restart and are readable by an external shipper without gateway involvement.
- A sandbox moving to a new supervisor keeps its recent history on a best-effort basis.
- A compromised sandbox cannot forge, erase or reorder the supervisor's authoritative record.
Alternatives Considered
- Keep gateway buffering and optimize its memory use. This retains the existing access path but leaves history and ingestion costs in the control plane.
- Use driver-owned retrieval from runtime logs. This was the earlier proposal; this plan instead makes the supervisor the owner of the structured log and event record.
- Require external collection alone. Operators can use their own shipper, but the plan also preserves built-in tail, follow, and cursor-based access.
- Add only a disable-push switch (feat(observability): allow disabling supervisor log pushes to the gateway #5418). This removes forwarding when disabled but does not provide the replacement supervisor-owned read path.
Agent Investigation
Current state
The gateway buffers logs and events in memory today, and the supervisor pushes lines to it.
- Push path. The supervisor's LogPushLayer (
crates/openshell-supervisor-process/src/log_push.rs) batches tracing and OCSF events and streams them to the gateway over the PushSandboxLogs client-streaming RPC. It drops lines when its channel is full. - Gateway buffers. TracingLogBus (
crates/openshell-server/src/tracing_bus.rs) keeps a per-sandbox tail of 2000 log lines and a PlatformEventBus tail of 50 events, plus a broadcast channel per sandbox. - Cursors. A shared per-sandbox sequence allocator stamps events with an epoch and sequence number so WatchSandbox can resume. Resume gaps are judged by what the gateway trimmed.
- Read path. GetSandboxLogs (
crates/openshell-server/src/grpc/policy.rs) and WatchSandbox (crates/openshell-server/src/grpc/sandbox.rs) read from those buses. Platform events also come from the compute drivers, which publish into the gateway's bus. - Routing primitive. The supervisor already holds a persistent ConnectSupervisor stream to the gateway and opens RelayStream calls for byte relays, so there is a channel to route requests down.
Consequences: log history is lost when the gateway restarts, every gateway replica needs the same sandbox's logs to answer a read, and log volume scales with sandbox count on the control plane.
Related issues and prior work
These reports and improvements provide evidence and coordination points; inclusion does not establish a shared root cause or make every adjacent runtime issue a prerequisite.
| Issue | Relationship |
|---|---|
| #6246 | Gateway OOMs with a stable 3,000-sandbox fleet. Allocation profiling and rebuilt-image reproduction remain necessary; logging has not been established as the cause. |
| #5400 | Per-sandbox gateway log-tail memory and byte budgeting for the existing path and compatibility period. |
| #5404 | Allocator retention evaluation, separate from live-allocation leaks. |
| #5462 | Multi-replica log/watch ownership, incomplete histories, and buffer fan-out. Coordinate the proxy routing transition with PR #6153. |
| #5752 | Restore HA sandbox-log conformance coverage when the supported log path is fixed. |
| #5505 | Shared-supervisor trace/OCSF OTLP export and trusted attribution; coordinate with the supervisor record owner while keeping export independently configured. |
| #5660 | Shared-supervisor thread, socket, and memory overhead; log transport is one overlapping cost. |
| #5956 | Repeatable shared-supervisor resource measurement. |
| #5957 | Shared-runtime identity and teardown; separate work that must preserve log attribution. |
| #5399 | Completed idle log/event buffer preallocation fix, via PR #5408; retain regression coverage. |
| #5401 | Completed cross-replica buffer cleanup fix; retain regression coverage. |
| #5402 | Completed protection against recreating buffers after deletion; retain regression coverage. |
| #5418 | Earlier disable-push proposal, closed in favor of redesigning retrieval. |
| #1922 | Earlier portable log collection investigation. |
| #1055 | Enterprise Observability umbrella. |
The 2026-12-04 issue map retains the earlier status snapshot. Existing issue backlinks continue to point to this umbrella.
Audit and update the existing Accessing Logs documentation, gateway configuration documentation, and relevant contributor/public skills with implementation. Follow current SDK repository ownership and cryptography rules when implementing public protocol changes and the integrity chain.
Checklist
- I've reviewed existing issues and the published docs.
- This is a design proposal, not a "please build this" request.
Activity
TaylorMutch commentedon Nov 24, 2026
TaylorMutch commentedon Dec 4, 2026
Related memory and logging issues
Snapshot as of 2026-12-04. These are related work and evidence, not a claim that all reports share one cause or are blocked by this redesign.
Gateway memory
Logging architecture, correctness, and coverage
This redesign (#5948) remains open. Its Docker prototype demonstrates limited history/live retrieval with pushes absent, not fleet-scale performance or completed cross-driver/distributed support. Gateway-source history, cursor semantics, a stable driver extension, remaining drivers, and enterprise collector validation remain work.
Shared-supervisor resource costs
Completed buffer fixes to retain as baseline
For #6246, keep control-plane availability separate from application data-plane continuity. Verify the current image/source versions and profile before attributing its OOMs to any of these mechanisms. Compare the redesign under fixed fleet sizes and log rates with zero, one, and multiple readers, measuring gateway CPU/memory, log traffic/streams, and control-plane latency.
[-]feat(observability): rearchitect logging UX to remove continuous gateway log ingestion[/-][+]OpenShell Logging Improvements[/+][-]OpenShell Logging Improvements[/-][+]Move Sandbox Logging to the Supervisor (Data Plane)[/+]TaylorMutch commentedon Dec 5, 2026
Related supervisor metrics work: #6211. Include supervisor-owned logging measurements when coordinating that metrics surface: ingestion/drop counts, queue and retained-storage bytes, persistence failures, rotation/eviction, active readers, lag, and read latency/outcomes. Finalize names and counting rules with the implementation; use bounded, process-level labels and consistent Prometheus/OTLP measurements. Performance-suite integration remains separate from the initial local logging cutover.