Skip to content

An open-source, faster Devin alternative

TypeScript

feat(logship): tee ExecSession too (closes the user-visible exec gap)

Igor Zalutskifa1ef1aa51cc
diff --git a/.agents/work/sandbox-session-logs-impl.md b/.agents/work/sandbox-session-logs-impl.md
index b84f096d..738df644 100644
--- a/.agents/work/sandbox-session-logs-impl.md
+++ b/.agents/work/sandbox-session-logs-impl.md
@@ -1032,3 +1032,40 @@ phase-4 turn-on watch.
- **Native search-input clear button** swapped for a custom thin
SVG X — macOS default has a heavy blue gradient that clashes
with the dashboard palette.
+- *2026-05-05* — ExecSession tee shipped. Phase 1 originally
+ covered `Exec` and `ExecStream` only, leaving the most-used path
+ uncovered: every command run via `POST /api/sandboxes/:id/exec`
+ goes through `ExecSession{Create,Attach}`, so users couldn't see
+ their own command output. Added a per-session pair of
+ `LineWriter`s (`stdoutTee`/`stderrTee`) created in
+ `ExecSessionCreate` via the existing `newExecLineWriters` helper;
+ the two pipe-pumping goroutines write to the LineWriter alongside
+ the existing scrollback; on cmd.Wait() + pipeWg.Wait(),
+ `closeExecLineWriters` flushes any partial trailing line and
+ emits the synthesised EOF event with exit_code. Verified on the
+ EC2 dev host: bash exec via the API now produces visible content
+ rows in the dashboard. PTY content stays excluded.
+- *2026-05-05* — three deploy-side gotchas caught during the e2e:
+ 1. `deploy/ec2/deploy-qemu-dev.sh` writes `worker.env` /
+ `server.env` but doesn't `systemctl daemon-reload`. New env
+ entries (we added `AXIOM_*`) silently don't propagate to the
+ running service env until daemon-reload — confirmed by reading
+ `/proc/$pid/environ` and seeing AXIOM_* missing despite the
+ file having them. The diagnostic log in
+ `configureLogshipForSandbox` now reports
+ "ConfigureLogship skipped … no axiom ingest token set on
+ worker" so this misconfiguration is loud, not silent.
+ 2. The deploy script only builds the rootfs ext4 image when it
+ doesn't exist on disk (`if [ ! -f .../default.ext4 ]`). After
+ the first deploy, freshly-built `osb-agent` binaries land at
+ `/usr/local/bin/` but the rootfs keeps the old one. Need
+ either an explicit `delete + redeploy` or a manual splice
+ (mount loop, cp, umount). Worth either re-baking on every
+ deploy or surfacing a `--rebuild-rootfs` flag.
+ 3. Even with a fresh rootfs, the `golden` snapshot under
+ `/data/sandboxes/golden/` caches a memory snapshot of the
+ agent process from the *initial* boot. New sandboxes restore
+ from that snapshot, so they keep running the snapshotted
+ agent rather than the on-disk one. Invalidate by `rm -rf
+ /data/sandboxes/golden && systemctl restart opensandbox-
+ worker` — worker rebuilds it on first sandbox create.
diff --git a/internal/agent/exec_session.go b/internal/agent/exec_session.go
index 320891d3..f08f4baa 100644
--- a/internal/agent/exec_session.go
+++ b/internal/agent/exec_session.go
@@ -11,6 +11,7 @@ import (
"time"
"github.com/google/uuid"
+ "github.com/opensandbox/opensandbox/internal/logship"
"github.com/opensandbox/opensandbox/internal/sandbox"
pb "github.com/opensandbox/opensandbox/proto/agent"
)
@@ -28,6 +29,13 @@ type execSession struct {
exitCode *int32
exited chan struct{}
+ // Logship tees: shadow each pipe's bytes into a per-session
+ // LineWriter that ships line-by-line to Axiom alongside the
+ // existing scrollback. Both nil if logship isn't wired (Shipper
+ // not set on Server) — LineWriter is nil-safe.
+ stdoutTee *logship.LineWriter
+ stderrTee *logship.LineWriter
+
mu sync.Mutex
attachedClients int
lastDisconnect time.Time
@@ -82,6 +90,8 @@ func (s *Server) ExecSessionCreate(ctx context.Context, req *pb.ExecSessionCreat
maxScrollback := int(req.ScrollbackMaxBytes)
scrollback := sandbox.NewScrollbackBuffer(maxScrollback)
+ stdoutTee, stderrTee := s.newExecLineWriters(req.Command, req.Args)
+
sess := &execSession{
id: sessionID,
cmd: cmd,
@@ -91,6 +101,8 @@ func (s *Server) ExecSessionCreate(ctx context.Context, req *pb.ExecSessionCreat
started: time.Now(),
scrollback: scrollback,
stdinPipe: stdinPipe,
+ stdoutTee: stdoutTee,
+ stderrTee: stderrTee,
exited: make(chan struct{}),
}
@@ -121,6 +133,9 @@ func (s *Server) ExecSessionCreate(ctx context.Context, req *pb.ExecSessionCreat
n, err := stdoutPipe.Read(buf)
if n > 0 {
scrollback.Write(1, buf[:n])
+ if stdoutTee != nil {
+ stdoutTee.Write(buf[:n])
+ }
}
if err != nil {
return
@@ -135,6 +150,9 @@ func (s *Server) ExecSessionCreate(ctx context.Context, req *pb.ExecSessionCreat
n, err := stderrPipe.Read(buf)
if n > 0 {
scrollback.Write(2, buf[:n])
+ if stderrTee != nil {
+ stderrTee.Write(buf[:n])
+ }
}
if err != nil {
return
@@ -151,6 +169,10 @@ func (s *Server) ExecSessionCreate(ctx context.Context, req *pb.ExecSessionCreat
sess.mu.Lock()
sess.exitCode = &code
sess.mu.Unlock()
+ // Flush any trailing partial line and emit the synthesised
+ // EOF event with exit_code so the UI can render the row.
+ // Same shape as one-shot Exec / streaming ExecStream.
+ closeExecLineWriters(stdoutTee, stderrTee, int(code))
close(sess.exited)
// Schedule cleanup after 5 minutes
diff --git a/internal/worker/grpc_server.go b/internal/worker/grpc_server.go
index 02fbb303..10f16f6f 100644
--- a/internal/worker/grpc_server.go
+++ b/internal/worker/grpc_server.go
@@ -157,10 +157,12 @@ func (s *GRPCServer) Stop() {
// implement LogshipConfigurator.
func (s *GRPCServer) configureLogshipForSandbox(ctx context.Context, sandboxID string) {
if s.axiomIngestToken == "" {
+ log.Printf("grpc: ConfigureLogship skipped for %s: no axiom ingest token set on worker", sandboxID)
return
}
cfger, ok := s.manager.(LogshipConfigurator)
if !ok {
+ log.Printf("grpc: ConfigureLogship skipped for %s: manager %T does not implement LogshipConfigurator", sandboxID, s.manager)
return
}
var orgID string
@@ -169,7 +171,9 @@ func (s *GRPCServer) configureLogshipForSandbox(ctx context.Context, sandboxID s
}
if err := cfger.ConfigureLogship(ctx, sandboxID, s.axiomIngestToken, s.axiomDataset, orgID); err != nil {
log.Printf("grpc: ConfigureLogship for %s failed: %v (logs disabled for this sandbox)", sandboxID, err)
+ return
}
+ log.Printf("grpc: ConfigureLogship sent for %s (org=%s, dataset=%s)", sandboxID, orgID, s.axiomDataset)
}
// parseSecretAllowedHosts converts the proto map (env var → comma-separated hosts)