Skip to content

fix: make job logs failed_only a modifier#2482

Open
he-yufeng wants to merge 1 commit into
github:mainfrom
he-yufeng:fix/actions-job-logs-run-modifier
Open

fix: make job logs failed_only a modifier#2482
he-yufeng wants to merge 1 commit into
github:mainfrom
he-yufeng:fix/actions-job-logs-run-modifier

Conversation

@he-yufeng
Copy link
Copy Markdown

Summary

  • allow get_job_logs to fetch all jobs in a run when run_id is provided without failed_only
  • make failed_only a modifier for both run_id and job_id
  • reject ambiguous calls that provide both job_id and run_id

Fixes #2389.

To verify

  • go test ./pkg/github -run 'Test_ActionsGetJobLogs' -count=1
  • go test ./pkg/github -count=1
  • go test ./... -count=1
  • git diff --check

@he-yufeng he-yufeng requested a review from a team as a code owner May 15, 2026 20:34
@FuzzysTodd
Copy link
Copy Markdown

FuzzysTodd commented May 15, 2026 via email

Copy link
Copy Markdown

@jluocsa jluocsa left a comment

Choose a reason for hiding this comment

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

Nice cleanup of the get_job_logs parameter semantics — making failed_only a true modifier (instead of a mode selector implicitly tied to run_id) reads much more naturally from the agent side, and the validation error messages are now actually helpful. The new tests for the failed-only-on-job_id path and the both-ids/neither-id validation cases are exactly the right coverage.

A few things worth a look before merge:

1. The tool schema snapshot doesn't appear to be updated

Three things changed in the tool definition:

  • Top-level Description string
  • job_id parameter description
  • run_id parameter description
  • failed_only parameter description

…but the changed-files list (pkg/github/actions.go, pkg/github/actions_test.go, pkg/github/helper_test.go) doesn't include anything under pkg/github/__toolsnaps__/. Per the repo's snapshot-validation system, that should fail go test ./pkg/github with a diff against __toolsnaps__/get_job_logs.snap (or whatever the file is named for this tool).

The fix is just:

UPDATE_TOOLSNAPS=true go test ./pkg/github -run Test_ActionsGetJobLogs -count=1

…and committing the resulting .snap change. That also serves as a nice reviewable record of the public-surface change.

2. Subtle behavior change for result["failed_jobs"] clients

Before this PR, the run_id path always returned failed_jobs in the response map. After the PR, failed_jobs is only present when failed_only=true:

if failedOnly {
    result["failed_jobs"] = len(selectedJobs)
}

That's a sensible shape change (it'd be weird to report failed_jobs when the user didn't ask to filter by failure), but it's still an output-schema break for any caller that was unconditionally reading that key on the run-level result. Worth a one-liner in the PR body / changelog so downstream users notice.

If you'd prefer to keep the key for backwards compatibility, you could always emit it and just compute it independently:

failedJobsCount := 0
for _, job := range jobs.Jobs {
    if job.GetConclusion() == "failure" {
        failedJobsCount++
    }
}
result["failed_jobs"] = failedJobsCount

…but I don't feel strongly — the "only when asked" shape is arguably cleaner.

3. Previously-tolerated combination now errors

Before: passing both job_id and run_id with failed_only=true silently went down the failed-jobs-in-run path (because the old branch checked failedOnly && runID > 0 first). After: that combination now returns a hard error ("provide either job_id or run_id, not both").

This is the right behavior — that input was always ambiguous — but it is a strict-mode change for any agent that was passing extra fields and relying on the old precedence rule. Probably worth one bullet in the PR description acknowledging it. (Not a blocker.)

4. Tiny nit on handleSingleJobLogs resource handling

if failedOnly {
    workflowJob, resp, err := client.Actions.GetWorkflowJobByID(ctx, owner, repo, jobID)
    if err != nil {
        return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to get workflow job", resp, err), nil, nil
    }
    defer func() { _ = resp.Body.Close() }()
    ...
}

The defer is inside the if failedOnly block, so it only schedules the close when we entered that branch — good. But the second getJobLogData call below also returns a resp; if we made it through the failed-only check, we still close that body via defer later in the function. Just double-check the existing close on the lower resp in handleSingleJobLogs still fires for the non-failedOnly path. The diff didn't touch it, so this is probably fine, but it'd be reassuring to confirm via go vet / a quick read.

5. Test for failed_only=true with run_id returning an empty selection

There's "no failed jobs found" coverage for the run-level branch, and the new test exercises the job_id+failed_only=true+success-conclusion error path. Consider one more test: run_id + failed_only=true where all jobs failed (currently only the partial-failure case is exercised in the existing test). Small, but exercises the message construction that was reshuffled.


Overall the change is straightforward and the API ergonomics improvement is well worth it. Mostly just want to make sure the toolsnap file is regenerated so the schema change is captured in the diff.

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.

get_job_logs: run_id with failed_only=false should return all job logs; failed_only should be a consistent modifier

4 participants