Repository navigation
Conversation
In multi-gateway deployments every replica kept its own log buffer, so openshell logs returned different lines depending on which replica served the request. The supervisor now pushes logs to the gateway that accepted its session, and gateways forward gateway lines and platform events to that parent. GetSandboxLogs and log/event WatchSandbox are proxied to the parent. When the parent changes, the old replica drops its buffer, which ends open watch streams. Closes #5462 Signed-off-by: divesh <dgude@nvidia.com>
|
🌿 Preview your docs: https://nvidia-preview-pr-6153.docs.buildwithfern.com/openshell |
EmilienM
left a comment
There was a problem hiding this comment.
Another iteration needed: 5 major (inline)
The parent-resolution design holds up; the problems are in the new log_routing.rs mechanics. The two that decide it for me: lines are deterministically lost around home moves (#5462 asks for the opposite), and the router couples every sandbox's log path to serial store reads with silent drops behind a 16k queue.
How this was reviewed
- Commit
30b6c449b, round 1 - Deep review, because the change crosses the gateway peer/auth boundary (auth/method_authz.rs, auth/peer.rs) and adds new peer RPCs to the multi-replica routing path
- Passes: architecture, performance, security, scalability, rust, kubernetes, correctness, a defensive review
- Independent skeptics checked each candidate finding (3 per code-lens finding, 2 for architecture and scalability, 1 per minor); 11 of 12 held up
- Repo rules read from
main: AGENTS.md, CLAUDE.md, CONTRIBUTING.md, docs/CONTRIBUTING.mdx - Not covered: the multi-replica E2E lanes have not run on this head yet (CI approval pending), so the manual k3s verification in the description is the only end-to-end evidence
| let home = if let Some(home) = homes.get(&sandbox_id) { | ||
| home.clone() | ||
| } else { | ||
| let home = log_home_peer(&state, &sandbox_id).await; |
There was a problem hiding this comment.
Major: route_events is the single consumer of ROUTER_QUEUE, and on a cache miss it awaits log_home_peer inline, so one sandbox's home resolution (a store read, re-paid for every remote-home sandbox after the homes.clear() every 2s) stalls routing for every sandbox on this replica. Once the 16k queue fills, route() in tracing_bus.rs drops events with no signal, losing lines that main always buffered. Move home resolution off the event path (a background-refreshed cache, or per-sandbox ordering tasks) and make the drop observable.
There was a problem hiding this comment.
Good catch. Home lookups now run in a background task per sandbox, so a slow read only holds back that sandbox (its events wait in order). It also checks the local session before trusting the cache, and drops show up in openshell_server_sandbox_log_events_dropped_total. Fixed in 80311a0.
| } | ||
| } | ||
| _ = timer.tick() => { | ||
| for sandbox_id in state.tracing_log_bus.idle_sandbox_ids(Duration::ZERO) { |
There was a problem hiding this comment.
Major: drop_moved_buffers scans every buffered sandbox every 5s and does awaited, unbatched store reads for each one without a local session (owner record, then sandbox_log_home), forever for disconnected supervisors and retained buffers. bus_sweeper already solves this job shape the intended way: batched primary-key lookups, a 30s interval, and a 2-minute idle gate.
There was a problem hiding this comment.
Agreed, switched it to the bus_sweeper shape: every 30s, only idle buffers with no local session, one batched get_many on the home records. It drops a buffer only when another live replica has recorded itself as the home.
| _ = timer.tick() => { | ||
| for sandbox_id in state.tracing_log_bus.idle_sandbox_ids(Duration::ZERO) { | ||
| if log_home_peer(&state, &sandbox_id).await.is_some() { | ||
| state.tracing_log_bus.remove(&sandbox_id); |
There was a problem hiding this comment.
Major: Lines are lost on every home move. While a session is in flight the old home still resolves itself (fresh owner record or its own last_home) and buffers the supervisor's push locally; once the record flips, drop_moved_buffers deletes that buffer instead of forwarding it. The 2s homes cache also misroutes on both sides of a move. That breaks #5462's "without losing lines" criterion and the claim in the log_push.rs comment. Forward the tail to the new home before remove(), and re-check has_session before trusting a cached entry.
There was a problem hiding this comment.
This one is on purpose. A move only happens when the parent changes, and we already lose the in-memory buffer when a gateway crashes, so handing the old buffer over felt like more machinery than this fix needs. The new home starts fresh and open tails end. I updated #5462 to say that.
| /// Events waiting to be sent to one peer; more are dropped. | ||
| const PEER_QUEUE: usize = 8 * 1024; | ||
| /// Most events per forwarded batch. | ||
| const MAX_BATCH: usize = 512; |
There was a problem hiding this comment.
Major: Batches are capped at 512 events but not by size, and the gateway decodes at most 1 MiB (MAX_GRPC_DECODE_SIZE in multiplex.rs). A sandbox with KiB-scale lines (JSON, stack traces) makes every full batch fail the RPC; the batch is then dropped at debug level and the healthy peer channel is evicted. The supervisor push path sizes its batches for this on purpose (LOG_PUSH_BATCH_LINES = 50, "below the gateway's ingest cap"). Budget by encoded_len() (flushing around 256 KiB), and don't evict the channel on ResourceExhausted.
There was a problem hiding this comment.
Yep, that was a real bug. Batches are now capped at 256 KiB encoded as well as 512 events, and a ResourceExhausted/OutOfRange reply no longer evicts the channel. Failed batches get counted too.
| "", | ||
| state.replica_id.as_bytes(), | ||
| None, | ||
| WriteCondition::Unconditional, |
There was a problem hiding this comment.
Major: record_home does a read-then-unconditional-write, so if another replica accepts a reconnect between the GET and the PUT, this write clobbers its record. Once the real owner's record expires, resolution falls back to the stale home, and that replica's sweep then deletes the current history within 5s. The store already has WriteCondition::MatchResourceVersion; condition the write on the version the GET returns.
There was a problem hiding this comment.
Fixed. The write now uses MatchResourceVersion (or MustCreate) from the read, and checks we still hold the session first. A conflict means a newer home won, so it just backs off.
Resolve log homes in background tasks so a slow store read holds back only that sandbox's events, and count dropped events in openshell_server_sandbox_log_events_dropped_total. Check for moved log homes every 30 seconds with one batched read of the log home records, and drop a buffer only when another live replica recorded itself as the home. Record the home with a version-conditioned write. Cap forwarded batches at 256 KiB and keep the peer channel when a batch is rejected for size. Signed-off-by: divesh <dgude@nvidia.com>
|
/ok to test 80311a0 |
Summary
With several gateway replicas, each kept its own sandbox log buffer, so
openshell logsshowed different lines depending on which replica answered. Now each sandbox's logs live on one replica, its parent: the one holding the supervisor session.Related Issue
Closes #5462
Changes
PeerPublishSandboxEvents), in batches of at most 256 KiB. Home lookups run in the background, so a slow one holds back only that sandbox.GetSandboxLogsand log/eventWatchSandboxare proxied to the parent (PeerGetSandboxLogs,PeerWatchSandbox), falling back to the local buffer on error.openshell_server_sandbox_log_events_dropped_total{reason}.accessing-logs.mdxandgateway-metrics.mdx.Testing
cargo testand clippy-D warningsforopenshell-server,openshell-supervisor,openshell-supervisor-process,openshell-sdk--tailmatched from both gateways (35/13 split before). After deleting the parent gateway or the hosting supervisor, the session moved, open tails ended, and logs matched again. No events dropped.Checklist