Skip to content

feat(fleet): stream tenant cell logs through the supervisor - #104669

Merged
steipete merged 1 commit into
mainfrom
feat/fleet-logs
Jul 11, 2026
Merged

steipete merged 1 commit into
mainfrom
feat/fleet-logs

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fleet (#104527) manages cell lifecycle but gives operators no way to see why a cell is unhealthy — the first diagnostic step after a failed fleet status health probe is container logs, and today that means bypassing the supervisor and its ownership checks with a hand-crafted docker logs openclaw-cell-<tenant>. Closes #104644.

Why This Change Was Made

Adds openclaw fleet logs <tenant> [--follow] [--tail <n>] [--since <value>]:

  • Ownership is proven before any output: registry lookup, local-runtime assertion, container inspection, and the same fleet-label ownership check the other commands use — a foreign container squatting on the cell name is refused, never streamed.
  • Logs stream through a new narrow inherited-stdio seam (docker|podman logs via spawn, no capture cap, no timeout) rather than the existing captured executor, which is sized for short commands (4 MiB / 10 min). The seam carries no env or token argv, so no redaction machinery applies; commented at the seam.
  • Ctrl-C semantics: SIGINT is forwarded to the child; signal termination maps to exit 130, which is treated as operator-initiated success only under --follow — a non-follow logs exiting 130 remains an error.
  • Injection guards: --tail is a strict positive integer; --since must be non-empty, must not start with -, and must not contain whitespace/control characters (passed through verbatim otherwise, so both durations and timestamps work).
  • No --json mode by design: logs are a raw stream; documented alongside --tail guidance for scripting.

Implementation was Codex-built from a frozen spec and reviewed line-by-line; one review finding (SIGINT forwarding) was fixed before this PR.

User Impact

Operators diagnose cells without leaving the supervisor's ownership guarantees. Fleet remains experimental; no config surface changes, no new dependencies, no changes to existing commands.

Evidence

  • 138 focused tests green on Blacksmith Testbox (18 new: argv construction incl. injection rejections, ownership refusal before streaming, exit/SIGINT semantics, CLI parsing): https://github.com/openclaw/openclaw/actions/runs/29165510814
  • pnpm tsgo, pnpm check:test-types, oxlint, scoped format: clean.
  • Structured autoreview (Codex): the build pass fixed one SIGINT-forwarding finding; a fresh review then surfaced a real P2 — only SIGINT was forwarded, so a supervisor's SIGTERM/SIGHUP to the CLI PID could orphan a follow stream holding inherited descriptors. Fixed by adopting the repo's canonical attachChildProcessBridge (full termination-signal set, self-detaching) and an honest {code, signal} stream result. A further cycle narrowed follow-mode tolerance to deliberate-stop signals only (forwarded termination set + SIGPIPE + exit 130) so crash signals like SIGSEGV are never masked as operator stops, with regression coverage. Final review: clean, "no accepted/actionable findings" (0.93). One reviewer suggestion — editing CHANGELOG.md — was rejected per repo policy (changelog is release-only; release-note context lives in this PR body).
  • Live proof on Linux (Blacksmith Testbox, run https://github.com/openclaw/openclaw/actions/runs/29165538971): full fleet scenario on real Docker (rootful) and Podman (rootless) with the real image — create, hardening inspect (docker reports CapDrop=["ALL"]; podman equivalently enumerates the dropped default capability set), /healthz ok on first probe, fleet logs --tail 5 streaming real gateway boot lines from inside both cells, upgrade with token hash carry-over, rm --purge-data leaving zero containers/networks and purged data dirs. ALL_SCENARIOS_PASSED.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes fleet size: M maintainer Maintainer-authored PR labels Jul 11, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d63172f8ea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +459 to +460
if (!Number.isSafeInteger(options.tail) || options.tail < 1) {
throw new Error("Fleet logs --tail must be a positive integer.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Allow --tail 0 for log streaming

When users want to follow only new output (openclaw fleet logs acme --follow --tail 0), this validation rejects the standard container-log value before invoking Docker/Podman. Docker documents --tail as the number of lines and only calls negative or non-integer values invalid (https://docs.docker.com/reference/cli/docker/container/logs/), and Podman says --tail=LINES must be an integer with -1 meaning all logs (https://docs.podman.io/en/v5.0.1/markdown/podman-logs.1.html), so 0 should be allowed here and in the Commander parser rather than treated as an error.

Useful? React with 👍 / 👎.

Comment on lines +664 to +665
if (options.follow && (deliberateStop || result.code === 130)) {
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Treat SIGPIPE as a clean log pipe close

For non-following log reads used in scripts, e.g. openclaw fleet logs acme --tail 10000 | head, the inherited stdout can make the Docker/Podman child terminate with SIGPIPE once the downstream reader exits. The code comment classifies a closed downstream pipe as deliberate, but this branch only suppresses deliberate stops when options.follow is set, so the documented pipeline use can produce a spurious logs failed with signal SIGPIPE error for bounded reads.

Useful? React with 👍 / 👎.

@steipete
steipete merged commit ff1c29e into main Jul 11, 2026
137 of 140 checks passed
@steipete
steipete deleted the feat/fleet-logs branch July 11, 2026 19:59
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Jul 12, 2026
… cell diagnostics (#104828)

* feat(fleet): per-cell disk limits, egress policy, backup/restore, logs, and doctor

- fleet create --disk <size> caps the container writable layer via --storage-opt;
  unsupported storage backends fail create with an actionable support-matrix
  error, and the limit replays across upgrade/restore through a fleet-owned
  container label because Podman inspect has no HostConfig.StorageOpt.
- fleet create --network bridge|internal adds an opt-in no-egress mode on
  Podman (published loopback port keeps working, verified live); Docker
  internal cells are rejected fail-closed because Docker does not publish
  loopback ports on internal networks.
- fleet backup/restore: per-tenant 0600 tar archives with manifest tenant
  binding, symlink/hardlink rejection, byte and path-segment budgets,
  root-bounded extraction, atomic no-overwrite publish, lease fencing, and
  Gateway token rotation on restore; failures preserve displaced data and
  never leave a force-stopped or half-started cell serving silently.
- fleet logs: ownership-asserted, bounded, token-redacted on both streams,
  with a generation re-check so a concurrent restore cannot leak a rotated
  token.
- fleet doctor: read-only per-cell audit of ownership labels, health,
  hardening drift, loopback port binding, token presence, network egress
  mode, and 0700 state-dir permissions; any failed finding exits nonzero.
  Cross-runtime checks are grounded in live-verified Docker 28/Podman 4.9
  inspect shapes (CapDrop vs EffectiveCaps, missing StorageOpt, missing
  network containers map).

Related: #104436 (v1 shipped in #104527)

* fix(fleet): harden streamed log redaction and root restore ownership

- redacting stream writer honors target backpressure, retains secret-prefix
  overlap across forced long-line flushes, and never splits a token between
  emitted chunks
- root-invoked restores repair ownership for explicit non-root user mappings
  instead of leaving root-owned 0700 state trees
- fleet logs merges the shipped --follow streaming surface (#104669) with the
  v1.1 token-redaction contract

* fix(fleet): stream partial log lines live and report phase-accurate restore recovery paths

- the redacting log writer emits safe text on every chunk (retaining only a
  possible token prefix) so unterminated progress output streams immediately
- restore failure notes distinguish pre-swap, displaced, and swapped states so
  operators recover the correct tree, and an unavailable runtime inspection is
  reported as an unverified replacement instead of silence

* fix(fleet): reject backslash archive paths, guard stderr pipes, and validate disk-limit labels in doctor

- restore/backup path rules reject literal backslashes so a tampered entry
  cannot validate as one path and extract as another on POSIX
- fleet logs handles broken pipes on stderr as well as stdout
- fleet doctor fails malformed disk-limit labels that would break
  upgrade/restore replay instead of reporting them as passing
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 12, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 12, 2026
… cell diagnostics (openclaw#104828)

* feat(fleet): per-cell disk limits, egress policy, backup/restore, logs, and doctor

- fleet create --disk <size> caps the container writable layer via --storage-opt;
  unsupported storage backends fail create with an actionable support-matrix
  error, and the limit replays across upgrade/restore through a fleet-owned
  container label because Podman inspect has no HostConfig.StorageOpt.
- fleet create --network bridge|internal adds an opt-in no-egress mode on
  Podman (published loopback port keeps working, verified live); Docker
  internal cells are rejected fail-closed because Docker does not publish
  loopback ports on internal networks.
- fleet backup/restore: per-tenant 0600 tar archives with manifest tenant
  binding, symlink/hardlink rejection, byte and path-segment budgets,
  root-bounded extraction, atomic no-overwrite publish, lease fencing, and
  Gateway token rotation on restore; failures preserve displaced data and
  never leave a force-stopped or half-started cell serving silently.
- fleet logs: ownership-asserted, bounded, token-redacted on both streams,
  with a generation re-check so a concurrent restore cannot leak a rotated
  token.
- fleet doctor: read-only per-cell audit of ownership labels, health,
  hardening drift, loopback port binding, token presence, network egress
  mode, and 0700 state-dir permissions; any failed finding exits nonzero.
  Cross-runtime checks are grounded in live-verified Docker 28/Podman 4.9
  inspect shapes (CapDrop vs EffectiveCaps, missing StorageOpt, missing
  network containers map).

Related: openclaw#104436 (v1 shipped in openclaw#104527)

* fix(fleet): harden streamed log redaction and root restore ownership

- redacting stream writer honors target backpressure, retains secret-prefix
  overlap across forced long-line flushes, and never splits a token between
  emitted chunks
- root-invoked restores repair ownership for explicit non-root user mappings
  instead of leaving root-owned 0700 state trees
- fleet logs merges the shipped --follow streaming surface (openclaw#104669) with the
  v1.1 token-redaction contract

* fix(fleet): stream partial log lines live and report phase-accurate restore recovery paths

- the redacting log writer emits safe text on every chunk (retaining only a
  possible token prefix) so unterminated progress output streams immediately
- restore failure notes distinguish pre-swap, displaced, and swapped states so
  operators recover the correct tree, and an unavailable runtime inspection is
  reported as an unverified replacement instead of silence

* fix(fleet): reject backslash archive paths, guard stderr pipes, and validate disk-limit labels in doctor

- restore/backup path rules reject literal backslashes so a tampered entry
  cannot validate as one path and extract as another on POSIX
- fleet logs handles broken pipes on stderr as well as stdout
- fleet doctor fails malformed disk-limit labels that would break
  upgrade/restore replay instead of reporting them as passing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation fleet maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fleet logs: surface cell container logs through the supervisor

1 participant