Skip to content

feat(remote-worker): opt-in per-Exec timing line in both sandbox workers (#576) - #666

Merged
pdettori merged 3 commits into
rossoctl:mainfrom
webchang:feat/576-exec-timing
Nov 3, 2026
Merged

pdettori merged 3 commits into
rossoctl:mainfrom
webchang:feat/576-exec-timing

Conversation

@webchang

Copy link
Copy Markdown
Member

Summary

Closes #576: an opt-in, cheap per-Exec timing line in both sandbox workers, SH_EXEC_TIMING=1, off by default. When off,
the cost is one boolean check per Exec; scheduling, admission and teardown are unchanged. No proto change.

exec-timing req=<req_id> workspace_key="<key>" start_ms=<epoch ms> dur_ms=<receipt to end> user_ms=<cpu> sys_ms=<cpu> exit=<code> err="<message>"
  • Container worker (internal/exec, cmd/worker): the line above, with the command process tree's CPU (rusage).
  • microVM worker (internal/vmpool, cmd/microvm-worker): the same fields in the same order, so one parser reads
    both tiers, then tier="microvm", the phases ExecPhased already computes (acquire_us resume_us mount_us run_us destroy_us), cold and the VM. user_ms/sys_ms are the VM's CPU over the Exec, from its pooled cgroup's
    cpu.stat read after the acquire and before the destroy (pooled cgroups are reused, so a difference), through an
    optional cpuReporter that firecrackerVM implements; -1 means not measured, never "no CPU".
  • Docs: docs/reference/configuration.md, both worker sections.

This code has run in a fork through a set of SWE-bench benchmarks on P6 (one c5.metal host, both tiers, several
thousand Execs per tier); every per-Exec figure there comes from this line, e.g. a microVM adding about 55–58 ms per
Exec over a container, and the phase breakdown of a microVM Exec. The commits here are the fork's two, rebased on
main unchanged (the same added and removed lines), with this repo's commit format and sign-off, plus the docs.

Checklist

  • Commits are signed off (git commit -s).
  • make lint and the tests for the touched packages pass: go vet ./... and go test ./... in remote-worker
    (and -race for internal/exec, internal/vmpool, cmd/worker, cmd/microvm-worker); new tests
    TestTimingLogsOneLinePerExec, TestTimingCountsChildCPU, TestTimingOffByDefault,
    TestRunnerTimingLogsOneLinePerExecWithTheVMsCPU, TestRunnerTimingIsOffByDefault,
    TestRunnerTimingMarksUnmeasuredCPUAsMinusOne, TestWorkspaceRunnerExecTiming.
  • Docs: the new environment variable is in docs/reference/configuration.md (both sandbox worker sections).
  • Docs: make check-links passes (212 files, 0 broken).
  • A new spec or ADR is registered: not applicable, no spec or ADR.

Assisted-By: Claude Code

…dbox worker (rossoctl#576)

SH_EXEC_TIMING=1 makes BashRunner log one exec-timing line per Exec:
req, workspace_key, start_ms, dur_ms (receipt to end), user_ms/sys_ms
(the process tree's rusage), exit and err. Off unless exactly 1, like
SH_DIAG_PHASES; when off the cost is one boolean check per Exec. No proto
change: a deployment joins the lines on workspace_key and req.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…er (rossoctl#576)

SH_EXEC_TIMING=1 makes vmpool.Runner log one exec-timing line per Exec in
the container worker's format (req, workspace_key, start_ms, dur_ms,
user_ms/sys_ms, exit, err), followed by tier="microvm", the phases
ExecPhased already computes (acquire_us, resume_us, mount_us, run_us,
destroy_us), cold and the VM. user_ms/sys_ms are the VM's CPU over the
Exec: its pooled cgroup's cpu.stat read after the acquire and before the
destroy (pooled cgroups are reused, so a difference), through an optional
cpuReporter that firecrackerVM implements; -1 when not measured, never
"no CPU". Off unless exactly 1. Scheduling, admission and teardown are
unchanged.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@webchang
webchang requested a review from pdettori as a code owner October 29, 2026 19:18
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 30, 2026

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, well-scoped change. It's off by default, gated on exactly 1, needs no proto change, and the CPU delta across a reused pooled cgroup is handled correctly (read after acquire, before destroy, -1 when not measured). The tests cover on/off, format, CPU and the cpu.stat parser, and CI is green.

Inline comments are non-blocking. The main one: in streaming mode, the container worker's dur_ms does include time spent in a slow sink, which contradicts its comment. There's also a small cross-tier inconsistency: the container worker reports 0 for unmeasured CPU, the microVM worker reports -1.

type BashRunner struct{}
type BashRunner struct {
// Timing, when set, logs one `exec-timing` line per Exec: its wall time from just before
// the child starts until Wait returns (so output still being delivered to a slow sink is

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This comment says output still going to a slow sink isn't counted, but in streaming mode it is. drain calls sink.Chunk inline, and wg.Wait() (which waits for both pumps) runs before cmd.Wait() and end. So dur_ms includes any back-pressure from a slow relay. Only the non-streaming emitBuffered at exit is left out. Either fix the comment (and the docs' "receipt to end") to say that streamed output is included, or take end from the child's exit if you want pure process time. As it stands, a benchmark could blame relay latency on the command.

if end.IsZero() {
end = time.Now()
}
var userMs, sysMs float64

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: When there's no ProcessState (a start or pipe error), this reports user_ms=0.0 sys_ms=0.0. The microVM line reports -1 for "not measured", and its docs say -1 "means not measured, never no CPU". The PR's goal is one parser for both tiers, so use -1.0 here too (and let timingLine in runner_test.go accept -?). Otherwise a failed container Exec reads as a measured zero.

return user, sys, gotU && gotS
}

// timingLog is nil unless the Runner was built with Timing (cmd/microvm-worker sets it from

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: timingLog is never nil. It's always log.Printf, and the gate is Runner.Timing. This wording was copied from phaseLog, which really is nil-gated. Suggest: "timingLog is log.Printf; a variable so tests capture the lines. Runner.Timing gates the call."

var timingLog = log.Printf

// logExecTiming emits the `exec-timing` line, the SAME format the container sandbox worker
// writes (internal/exec/runner.go logExecTiming, webchang 096a6df2), so a benchmark parses both

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: webchang 096a6df2 is the fork's commit and doesn't exist in this repo (here it's cd9d18a). Drop the SHA. The file/function reference is enough.

lines := captureTiming(t)
// No VM was acquired (an empty key is refused first), so no CPU was measured.
logExecTiming(7, "", time.UnixMilli(1000), 5*time.Millisecond, &Phases{}, 0, fmt.Errorf("refused"))
m := timingRe.FindStringSubmatch((*lines)[0])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: If no line is logged, (*lines)[0] panics instead of failing the test. Add a len(*lines) != 1 check first, as in the test above.

@pdettori
pdettori merged commit 68465f4 into rossoctl:main Nov 3, 2026
17 checks passed
webchang added a commit to webchang/moca that referenced this pull request Nov 3, 2026
Brings in upstream's 24 commits since the last merge: Valkey 9 in place of Redis (rossoctl#670), exec timing (rossoctl#666), both of
IBM Bob's MCP filenames (rossoctl#676), mocactl --show-tools and workloads
list, and the session turn counter.

Conflicts, both in docs on what `sbx up` writes: the SBX0 spec and
the sbx user guide. Resolved by keeping upstream's `.bob/mcp.json`
and `.bob/settings.json` and this branch's OpenCode `skill` deny
(98cc955). The merged code already does both.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

remote-worker: an opt-in per-Exec timing line (phases and sandbox CPU) for both sandbox workers

3 participants