Skip to content

Extend plan x logs: list, download, and bulk export captured logs - #319

Merged
daniel-de-vera merged 5 commits into
feature-planfrom
feature-plan-step-logs
Apr 16, 2026
Merged

daniel-de-vera merged 5 commits into
feature-planfrom
feature-plan-step-logs

Conversation

@daniel-de-vera

@daniel-de-vera daniel-de-vera commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Unifies plan execution log access under a single plan x logs command. Previously the command only streamed live logs — now it also lists captured log streams, downloads captured stdout/stderr for a step, and bulk-exports all captured logs to a directory.

Also bumps go-sdk to pick up the new DownloadStepLog endpoint added server-side in signadot/signadot#6885.

Command surface

Single command, intent driven by flags:

Invocation Behavior
plan x logs EXEC_ID List captured log streams (table)
plan x logs EXEC_ID STEP_ID Print captured stdout (default)
plan x logs EXEC_ID STEP_ID -s stderr Print captured stderr
plan x logs EXEC_ID -f Stream live aggregated logs
plan x logs EXEC_ID STEP_ID -f Stream live step logs
plan x logs EXEC_ID --all --dir ./logs/ Bulk export captured logs

Follows the kubectl logs convention: the default action is to print what's captured, -f follows the live stream.

Edge-case messages

Instead of passing raw API errors through, the command pre-checks where it helps and produces actionable messages:

  • plan x logs EXEC_ID on a running execution — table shows whatever has been captured so far, with a hint above: "Execution is still running. Captured logs appear as steps complete. Use -f to stream live."
  • plan x logs EXEC_ID -f on a terminal execution — blocked before hitting the server (the runner is gone and live streaming can't work): "execution is failed; live logs are unavailable. Omit -f to read captured logs"
  • plan x logs EXEC_ID STEP_ID when the requested stream isn't present — on a 404 we fetch the execution and diagnose: "step "check_response" has no stdout log (available: stderr)"
  • Similar diagnoses for nonexistent step IDs and still-running steps.

Flag validation:

  • --all requires --dir
  • --all rejects a STEP_ID argument
  • --all cannot be combined with -f

Tests performed

Automated (unit tests, logs_test.go)

  • renderCapturedLogs prints the "still running" hint when phase is running
  • No hint when phase is completed / failed / cancelled
  • The hint is suppressed in -o json output (machine-readable stays clean)
  • For a running execution, completed steps' captured logs still appear in the table while still-running steps without logs are omitted

Manual (against local apiserver)

  • List captured logs — completed execution with one stderr entry → correct table
  • List captured logs — execution with no logs → empty table
  • Download stderr from a terminal step → inline content printed
  • Download stdout when only stderr was captured → helpful "available: stderr" message
  • Download for a nonexistent step → "step not found in execution" message
  • Bulk export with --all --dir → files written to <dir>/<step-id>/<stream>
  • All three --all flag-combination errors
  • -o json listing
  • -f on a terminal execution → blocked by pre-check with actionable message
  • -f on a running execution → kicked off via a freshly-compiled 15-second shell plan; streams and exits cleanly with code 0 on completion
  • plan x logs EXEC_ID against that same running execution → the "still running" hint was observed in real output (not just the unit test)

Test plan (reviewer)

  • go build ./... passes
  • go test ./internal/command/planexec/... passes
  • plan x logs --help describes all four modes
  • Against a completed execution: plan x logs <id> lists captured streams; plan x logs <id> <step> prints stdout
  • Against a running execution: plan x logs <id> shows the hint; plan x logs <id> -f streams and exits on completion
  • plan x logs <id> -f on a terminal execution returns the pre-check error rather than a 500

🤖 Generated with Claude Code

Unifies plan execution log access under a single command: list
captured log streams, download captured stdout/stderr for a step,
stream live logs with -f, or bulk export all captured logs to a
directory. Bumps go-sdk to pick up the new DownloadStepLog endpoint.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@scott-cotton

Copy link
Copy Markdown
Member

Review: #319 + signadot/actions#11

1. UX consistency — the real issue

There's a live, top-level signadot logs --plan EXEC_ID command (internal/command/logs/command.go:63) that still streams by default, uses --step instead of a positional step arg, and has no captured-log / -f distinction. After this PR:

Command Default on a plan Follow Step
signadot logs --plan <id> streams live (implicit, always) --step <id>
signadot plan x logs <id> lists captured -f positional

Two commands do the same thing with opposite defaults and different flag conventions. This is the kind of split that bakes itself into muscle memory and doesn't come out. Options, in rough order of preference:

  • Deprecate signadot logs --plan and point users at plan x logs. The job case is signadot logs --job; the plan case can be its own verb.
  • Alternatively, make signadot logs --plan adopt the same default-list-plus--f shape. But that's a breaking change for anyone scripting the old command.

Either way, the PR should pick one — shipping as-is means both exist forever.

2. Live-vs-not-live races

  • Pre-check → SSE gap in -f. runLogs calls execTerminalPhase (logs.go:86), gets "running", then subscribes to SSE. If termination happens in between, the SSE either returns tail+EOF or closes immediately. Functionally OK; server-side handles cleanly. Worth confirming the SSE endpoint tails recently-terminated executions (within some window) rather than 404-ing — otherwise a race loses the last 0–2s of output.
  • 404 → diagnose second-GET is lying-prone. diagnoseMissingLog (logs.go:173) issues a second GetPlanExecution and categorizes based on current state. A step that was still-running at the download time may have completed by the diagnose call — user gets "has no captured logs" when a retry would succeed. Not broken; misleading. One fix: add a ; retry in a moment suffix when the state is freshly terminal.
  • --all --dir on a running execution is silently partial. bulkExportLogs (logs.go:205) snapshots step logs from GetPlanExecution and exports only what's in the snapshot. Steps that complete after the GET are invisible. No warning that the export is incomplete. Recommend: reuse isTerminalPhase and print a stderr warning when the execution is non-terminal.
  • --all ignores ready: false. The list shows a READY column, but bulk export iterates everything and calls DownloadStepLog even for non-ready artifacts — server will 404 and the whole export aborts mid-stream, leaving a partial tree. Recommend: skip and warn on non-ready artifacts, or retry with backoff.

3. Other issues

Bugs / defensive gaps

  • collectAllLogs (logs.go:372) panics on ex == nil — renderCapturedLogs guards running but still calls through. Nil-check at the top.
  • bulkExportLogs: stepID is joined via filepath.Join(cfg.Dir, stepID) without sanitization (logs.go:253). If a server-side stepID ever contained .. or an absolute path, export escapes --dir. Realistically the server doesn't emit such IDs, but this is the easy kind of defense to add (filepath.Clean + reject ..).
  • cfg.Dir is silently ignored when --all=false — --dir ./foo without --all does nothing and doesn't tell the user.
  • On download error mid---all, a zero-length or partial file is left on disk with no cleanup. Worth os.Remove(outPath) on failure, or writing to outPath.tmp + rename.

Smaller UX nits

  • Running-hint on the list is written to stdout (logs.go:126), so plan x logs <id> | grep step1 will also match the hint line. JSON output is guarded; text isn't. Move to log (stderr).
  • -f help says "stream live logs (SSE)" — "(SSE)" leaks an implementation detail; drop it.
  • --stream help: "only used with a step ID" is no longer accurate; it's also ignored under --all (both streams exported regardless). Either respect -s under --all or document that it's ignored.
  • printLogsTable renders Size = 0 as an empty cell rather than 0 B or —. Minor.

daniel-de-vera and others added 3 commits April 16, 2026 09:00
The plan x logs command now covers listing, downloading, streaming,
and bulk-exporting plan execution logs. Remove the duplicate --plan
and --step flags from the top-level signadot logs command to avoid
two commands with opposite defaults for the same functionality.
signadot logs is now job-only.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- diagnoseMissingLog: when a step is terminal but has no captured logs
  yet, hint that a retry may succeed ("if it just completed, retry in
  a moment") instead of a flat "has no captured logs".
- --all --dir on a non-terminal execution: print a warning that the
  export may be incomplete since only a snapshot of current logs is
  exported.
- --all --dir skips logs with ready=false (artifact still uploading)
  and prints a "Skipped ... (artifact not ready)" message instead of
  attempting the download and aborting the whole export on 503.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Bugs / defensive gaps:
- collectAllLogs: nil-guard on ex to prevent panic.
- bulkExportLogs: sanitize stepID and stream via validatePathComponent
  to reject path traversal (../, slashes, absolute paths).
- --dir without --all now returns an error instead of silently ignoring.
- On download error during --all, remove the partial file (os.Remove).

UX fixes:
- Running-execution hint goes to stderr, not stdout, so piped output
  stays clean (plan x logs <id> | grep ... won't match the hint).
- -f help: drop "(SSE)" implementation detail.
- --stream help: clarify that it's ignored under --all.
- printLogsTable: Size=0 renders as "—" instead of blank.

Tests:
- New TestRenderCapturedLogs_NilExecution for nil-guard.
- New TestValidatePathComponent for path sanitization.
- Existing tests updated for stderr-separated hint.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@daniel-de-vera

Copy link
Copy Markdown
Contributor Author

@scott-cotton, feedback was implemented in the three prev commits.

@scott-cotton scott-cotton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@daniel-de-vera
daniel-de-vera merged commit ee304a2 into feature-plan Apr 16, 2026
@daniel-de-vera
daniel-de-vera deleted the feature-plan-step-logs branch April 16, 2026 12:32
daniel-de-vera added a commit that referenced this pull request Apr 22, 2026
* Add plan CRUD commands (compile, create, list, get, delete) (#306)

* Add plan CRUD commands (compile, create, list, get, delete)

Phase 1 of the plan CLI: basic plan management against the API.

Commands:
  signadot plan compile -f <prompt-file> [--tag <name>]
  signadot plan create -f <spec.yaml> [--set var=val]
  signadot plan list
  signadot plan get <plan-id>
  signadot plan delete <plan-id>

All commands support -o json and -o yaml output formats.
Compile supports -f - for stdin. Create supports --set template
substitution via the existing LoadUnstructuredTemplate path.
Compile --tag compiles then tags the plan via PutPlanTag.

Depends on go-sdk with plan CRUD client (signadot/signadot#6825).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Add plan tag commands (list, get, apply, delete) (#307)

* Add plan tag commands (list, get, apply, delete)

Phase 2 of the plan CLI: named references to plans.

Commands:
  signadot plan tag list
  signadot plan tag get <tag-name>
  signadot plan tag apply <tag-name> --plan <plan-id>
  signadot plan tag delete <tag-name>

Alias: signadot plan t <subcommand>

ApplyTag is exported from the plantag package so compile --tag
can reuse it. The local plan/tag.go wrapper is removed.

Also extracts print.FirstLine as a shared helper, and improves
command help text for agent discoverability.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Add plan execution commands and plan run (#308)

* Add plan execution commands and plan run

Plan execution management (signadot plan x / plan execution):
  - get <exec-id>: show execution details with step status table
  - cancel <exec-id>: cancel a running execution
  - outputs <exec-id>: list output metadata (inline/artifact, size, ready)
  - get-output <exec-id> <name>: download output to stdout
  - get-output <exec-id> <step>/<name>: download step-level output

Plan run (signadot plan run):
  - Creates execution, polls until terminal phase, prints results
  - Resolve by plan ID or --tag
  - --param key=value for execution parameters
  - --wait=false for fire-and-forget
  - --timeout for poll timeout
  - --output-dir to export all outputs on completion
  - Exit codes: 0=completed, 1=failed, 2=cancelled
  - Ctrl+C cancels the execution via API

Also adds --tag flag to plan create (matching compile --tag).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Remove plan list and add tag history rendering

- Remove plan list command — tags are now the sole discovery
  mechanism per the plan lifecycle redesign.
- Remove printPlanTable and PlanList config (dead code after removal).
- Render tag-to-plan mapping history in plan tag get detail view.
  History table shows PLAN ID, TAGGED, UNTAGGED columns. Only
  displayed when there are previous mappings (len > 1).
- 409 on plan delete (tagged plans) passes through as a clear
  API error message — no special handling needed.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Add plan recompile command

signadot plan recompile <plan-id> [--tag <name>]

Recompiles a plan from its original prompt, producing a new plan.
Supports --tag to tag the result in one command. Shows the
Compiled From field linking back to the source plan.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Update go-sdk and adapt to param renames

Update go-sdk to latest feature-plan branch which normalises
swagger parameter names:
  - WithPlanExecutionID → WithExecutionID
  - WithStepOutputName → WithOutputName

Also adds PlanExecutionLogs client for streaming log endpoints.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Add plan execution log streaming (#309)

* Add plan execution log streaming

Two ways to stream plan execution logs:

  signadot plan x logs <exec-id> [step-id]
  signadot logs --plan <exec-id> [--step <step-id>]

Without a step ID, streams aggregated logs for all steps.
With a step ID, streams stdout or stderr (--stream flag) for that step.

Extracts ParseSSEStream from the logs package into internal/print/sse.go
to avoid an import cycle between logs and planexec packages.

Also adds --plan and --step flags to the existing signadot logs command
(previously job-only), making --job and --plan mutually exclusive.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Add plan execution list command (#310)

* Add plan execution list command

signadot plan x list [--plan <id>] [--tag <name>] [--phase <phase>]

Lists plan executions with pagination support. Filters:
  --plan: filter by plan ID
  --tag: filter by tag name (resolved server-side)
  --phase: filter by execution phase

Also unexports ShowPlanLogs (unused cross-package after import cycle fix).

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Add plan run --attach for structured event streaming (#311)

* Add plan run --attach for structured event streaming

Streams execution events (logs, outputs, result) to stdout in real-time.

Text mode (default):
  time=12:08:18 type=log step=greet stream=stdout msg="step starting"
  time=12:08:23 type=output name=greeting value="hello world"
  time=12:08:23 type=result id=abc123 phase=completed

JSON mode (-o json):
  {"time":"...","type":"log","step":"greet","stream":"stdout","msg":"step starting\n"}

Pipe-friendly: plan run --attach | grep type=output
stderr reserved for CLI messages (Created execution...).

Also fixes non-attach mode to write failure/cancellation details to
stderr so stdout stays clean, and rejects -o yaml with --attach.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Plan outputs list fixes (#312)

- Show both plan-level and step-level outputs in plan x outputs
  (previously only plan-level, which was often empty)
- Add SCOPE column (plan/step) and rename TYPE to STORAGE
- Compute inline output size from value length
- Show READY as true for inline outputs (always available)
- Deduplicate: step outputs already shown as plan outputs are skipped

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>

* Fix get-output --all --dir to include step-scoped outputs (#315)

The getAllOutputs() function only iterated over plan-level outputs
(resp.Payload.Status.Outputs), causing "No outputs." when only
step-scoped outputs existed. Now also collects outputs from
resp.Payload.Status.Steps[*].Outputs, downloads them via the
GetStepOutput API, and writes them into <dir>/<stepID>/<name>
subdirectories to avoid name collisions.

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>

* Add --cluster, --sandbox, and --route-group flags to plan run (#316)

* Add --cluster flag to `signadot plan run`

Plans without cluster affinity now require an explicit cluster in the
execution request. This adds a --cluster flag that maps to the Cluster
field in PlanExecutionSpec.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Update go-sdk to v0.3.8-0.20260407201055-78b3ac589bac

Picks up the latest SDK with cluster field support in PlanExecutionSpec.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Add --sandbox and --route-group flags to plan run, update go-sdk

- Add --sandbox and --route-group mutually exclusive flags that translate
  to the correct plan param based on cluster affinity (FromAnyTarget for
  polymorphic JSON, FromSandbox/FromRouteGroup for plain strings)
- Consolidate resolvePlanID + fetchPlanSpec into resolvePlan, which
  returns the full RunnablePlan (avoiding double fetch when using --tag)
- Update go-sdk to v0.3.8-0.20260409131400-73b58199c972 for
  FromAnyTarget and RoutingTarget types

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>

* Suppress human-readable status messages when using -o json/yaml (#314)

When structured output formats (JSON/YAML) are requested, skip printing
"Tagged plan..." and "Created execution..." messages that would pollute
stdout and break machine parsing. Also silence the spinner during
polling in non-default output modes.

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>

* Update go-sdk to include drill down and extraOutputs

Show steps and prompt columns in plan tag list

The ListPlanTags API returns inlined plan details but the table
printer was not using them.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Add hidden planrunnergroup CLI command (#317)

Add apply/get/list/delete subcommands for plan runner groups,
modeled after the existing jobrunnergroup command. Hidden from
top-level help; accessible via `signadot planrunnergroup` or
alias `signadot prg`. Needed for e2e test infrastructure.

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>

* Emit get-output sidecars by default with server-supplied Content-Type (#318)

Previously --metadata was opt-in and only wrote a sidecar when the
output carried explicit metadata, so silent shell outputs (stdout,
stderr, exitCode) exported with no sidecar — the user had no way to
tell what the file was without opening it.

Make --metadata default true and always emit a sidecar per exported
output. The sidecar carries the derived allOutput fields (name,
scope, step, type, size, ready) plus the Content-Type the apiserver
returned (now exposed on GetStepOutputOK / GetPlanExecutionOutputOK
after the go-sdk regen) and any explicit Metadata.

Drop omitempty on Size so 0-byte outputs show size:0 rather than
eliding the field, which would be ambiguous with "size not reported".

Bump go-sdk to 170febfc to pick up the Content-Type header binding.

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>

* Extend plan x logs: list, download, and bulk export captured logs (#319)

* Extend plan x logs to list, download, and bulk export captured logs

Unifies plan execution log access under a single command: list
captured log streams, download captured stdout/stderr for a step,
stream live logs with -f, or bulk export all captured logs to a
directory. Bumps go-sdk to pick up the new DownloadStepLog endpoint.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Remove plan execution path from signadot logs command

The plan x logs command now covers listing, downloading, streaming,
and bulk-exporting plan execution logs. Remove the duplicate --plan
and --step flags from the top-level signadot logs command to avoid
two commands with opposite defaults for the same functionality.
signadot logs is now job-only.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Handle race conditions in logs command edge cases

- diagnoseMissingLog: when a step is terminal but has no captured logs
  yet, hint that a retry may succeed ("if it just completed, retry in
  a moment") instead of a flat "has no captured logs".
- --all --dir on a non-terminal execution: print a warning that the
  export may be incomplete since only a snapshot of current logs is
  exported.
- --all --dir skips logs with ready=false (artifact still uploading)
  and prints a "Skipped ... (artifact not ready)" message instead of
  attempting the download and aborting the whole export on 503.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Harden logs command: defensive checks, UX fixes, path safety

Bugs / defensive gaps:
- collectAllLogs: nil-guard on ex to prevent panic.
- bulkExportLogs: sanitize stepID and stream via validatePathComponent
  to reject path traversal (../, slashes, absolute paths).
- --dir without --all now returns an error instead of silently ignoring.
- On download error during --all, remove the partial file (os.Remove).

UX fixes:
- Running-execution hint goes to stderr, not stdout, so piped output
  stays clean (plan x logs <id> | grep ... won't match the hint).
- -f help: drop "(SSE)" implementation detail.
- --stream help: clarify that it's ignored under --all.
- printLogsTable: Size=0 renders as "—" instead of blank.

Tests:
- New TestRenderCapturedLogs_NilExecution for nil-guard.
- New TestValidatePathComponent for path sanitization.
- Existing tests updated for stderr-separated hint.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Scott Cotton <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Co-authored-by: David Orozco <[email protected]>
Co-authored-by: Scott Cotton <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants