Skip to content

feat(cli): add lightning job logs#40

Merged
k223kim merged 1 commit into
mainfrom
ethanwharris/job-logs-cli
Jul 24, 2026
Merged

feat(cli): add lightning job logs#40
k223kim merged 1 commit into
mainfrom
ethanwharris/job-logs-cli

Conversation

@ethanwharris

Copy link
Copy Markdown
Member

Problem

deployment and sandbox have a logs CLI command, but job doesn't. So to read a job's logs from the CLI you have to drop to the raw REST endpoint (lightning api /v1/projects/<id>/jobs/<job_id>/download-logs, then fetch the signed URL). The lightning-jobs skill documents exactly this workaround. Surfaced by an agentic audit of the platform's agent-facing surface.

Change

Adds lightning job logs [NAME] [--teamspace owner/teamspace], mirroring job inspect: it resolves the job via _JobAndMMTAction().job(...) and prints Job.logs.

Job.logs raises a RuntimeError while the job is pending/running, so the command guards on job.status and prints a friendly "logs are only available once it reaches a terminal state (Completed/Failed/Stopped)" message (a ClickException) instead of a raw traceback.

Verification

Live-verified against prod lightning.ai on a real CPU_SMALL job:

$ lightning job logs audit-joblogs-test --teamspace <org>/<ts>   # while Pending
Error: Job 'audit-joblogs-test' is Pending; logs are only available once it reaches a terminal state (...)

$ lightning job logs audit-joblogs-test --teamspace <org>/<ts>   # after completion
LOGZ-MARKER-12345
42

Unit tests (tests/cli/job/test_logs.py) cover the help text, the jobs alias, and both the terminal (prints logs) and non-terminal (clean error, no raw RuntimeError) branches. Full tests/cli/job/ suite passes (42).

Follow-up

Once this ships, the lightning-jobs skill's "Raw API fallback" can point job logs at this command instead of the download-logs endpoint.

🤖 Generated with Claude Code

`deployment` and `sandbox` have a `logs` command but `job` did not, so the
lightning-jobs skill (and users) had to drop to the raw
`lightning api /v1/projects/<id>/jobs/<id>/download-logs` endpoint just to read
job logs. This adds `lightning job logs [NAME] [--teamspace owner/teamspace]`,
mirroring `job inspect`: it resolves the job and prints `Job.logs`.

`Job.logs` raises a RuntimeError while the job is pending/running, so the command
guards on status and prints a friendly "logs are only available once it reaches a
terminal state" message (via ClickException) instead of a raw traceback.

Live-verified against prod lightning.ai: prints the log text after completion, and
the friendly status message while Pending. Tests cover the help text, the `jobs`
alias, and both the terminal and non-terminal branches.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@k223kim
k223kim merged commit 21a7555 into main Jul 24, 2026
24 checks passed
@k223kim
k223kim deleted the ethanwharris/job-logs-cli branch July 24, 2026 13:27
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.

3 participants