Skip to content

fix(cli): thread command context through experiments analyze loaders - #78246

Merged
pelikhan merged 3 commits into
mainfrom
sergo/thread-ctx-experiments-analyze-r130-e7729dba7305afb0
Nov 16, 2026
Merged

pelikhan merged 3 commits into
mainfrom
sergo/thread-ctx-experiments-analyze-r130-e7729dba7305afb0

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

gh aw experiments analyze loads grader and outcome artifacts from GitHub, but loadGraderObservationSetsForAnalysis and loadOutcomeObservationSetsForAnalysis passed context.Background() to loadGraderRunData / loadOutcomeRunData. Those helpers already accept a ctx and run bounded-concurrency downloads (pool.New().WithContext(ctx)), so cancelling the command (Ctrl-C) did not stop in-flight downloads.

Evidence

  • pkg/cli/experiments_command.go (loadGraderObservationSetsForAnalysis): loadGraderRunData(context.Background(), ...)
  • pkg/cli/experiments_outcome_observations.go (loadOutcomeObservationSetsForAnalysis): loadOutcomeRunData(context.Background(), ...)
  • The only call chain is cobra RunE -> RunExperimentsAnalyze -> loadMetricObservationSetsForAnalysis -> the two loaders. RunExperimentsAnalyze has no other callers, and RunE holds cmd.Context().

Change

  • RunExperimentsAnalyze now takes ctx context.Context; RunE passes cmd.Context().
  • ctx is threaded through loadMetricObservationSetsForAnalysis, loadGraderObservationSetsForAnalysis, and loadOutcomeObservationSetsForAnalysis.
  • The 3 existing test call sites pass t.Context().

No behaviour change when the context is not cancelled.

Validation

  • Serena (gopls) diagnostics on the 3 changed files: 0 errors. The test file shows 2 existing embedlit hints on lines this PR does not touch.
  • go build, go test, make fmt and make agent-report-progress were not run: the sandbox denied go and make commands in this run. CI should run them. The edits were made by hand and match gofmt style, but gofmt was not run.
  • Grep confirms no other callers of the changed signatures.

🤖 Generated with [Claude Code]((claude.com/redacted)

Generated by 🤖 Sergo - Serena Go Expert · claude · routed: sonnet55 high · ~51 AIC · ⌖ ~2 AIC · ⊞ 4.7K · ◷

  • expires on Nov 22, 2026, 7:53 PM UTC-08:00

@github-actions github-actions Bot added cookie Issue Monster Loves Cookies! sergo labels Nov 16, 2026
@pelikhan
pelikhan marked this pull request as ready for review November 16, 2026 04:08
Copilot AI adaptive review requested due to automatic review settings November 16, 2026 04:09
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ PR Code Quality Reviewer completed the code quality review.

PR Code Quality Reviewer

Outcome: reported_action

The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt56 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.5K · ◷

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ PR Specification Reviewer completed successfully!

PR Specification Reviewer

Outcome: reported_action

The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated by PR Specification Reviewer for #78246 · copilot · gpt56 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.6K · ◷

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated by Ponytail Reviewer for #78246 · codex · routed: gpt61 medium · ~4 AIC · ⌖ ~1 AIC · ⊞ 185 · ◷

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

Design Decision Gate 🏗️

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: sonnet55 high · ~6 AIC · ⌖ ~2 AIC · ⊞ 8.6K · ◷

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~6 AIC · ⌖ ~2 AIC · ⊞ 6.6K · ◷

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

🧪 Test quality analysis by Test Quality Sentinel · copilot · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ⊞ 7.2K · ◷

@github-actions

Copy link
Copy Markdown
Contributor Author

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-16T04:11:45Z
review_event: COMMENT
top_themes:
  - cancellation errors are discarded, allowing partial analyses after Ctrl-C
files_reviewed:
  - pkg/cli/experiments_command.go
  - pkg/cli/experiments_outcome_observations.go
  - pkg/cli/experiments_outcome_observations_test.go
comment_count: 2
History

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.5K · ◷
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Found two related correctness issues in cancellation handling. The context is now threaded into both download paths, but pool cancellation errors are still discarded, so Ctrl-C can produce a successful-looking analysis from partial artifact data. Inline comments explain the required propagation/abort behavior.

Validation

Static review only; repository tests/builds were not run per the review constraints.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.5K
Comment /review to run again

}
source := newGitHubGraderRunArtifactSource(tempDir, repoOverride)
runData := loadGraderRunData(context.Background(), details.Runs, runRefs, source)
runData := loadGraderRunData(ctx, details.Runs, runRefs, source)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When the command context is cancelled, this loader still turns cancelled artifact fetches into exclusion reasons and continues building an analysis from partial data, because loadGraderRunData discards p.Wait() errors; Ctrl-C can therefore produce a normal-looking, incomplete report with exit status 0.

💡 Propagate cancellation instead of analyzing partial data

Check ctx.Err() after the load and return it before building observation sets, and propagate the pool wait error from loadGraderRunData so cancellation aborts the command rather than being treated as an unavailable artifact.

now := time.Now()
source := &githubOutcomeRunSource{artifacts: newGitHubGraderRunArtifactSource(cacheDir, repoOverride)}
data := loadOutcomeRunData(context.Background(), details.Runs, windows, automatic, now, source)
data := loadOutcomeRunData(ctx, details.Runs, windows, automatic, now, source)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The outcome path has the same cancellation behavior: a cancelled context can leave loadOutcomeRunData with partial data, and this code immediately computes windows and observations without surfacing the cancellation because p.Wait() errors are ignored. That can return a misleading successful report after Ctrl-C.

💡 Abort outcome analysis on cancellation

Propagate the pool wait error (or check ctx.Err() immediately after the load) and return before estimating windows or building observation sets. Cancellation should be distinguishable from an unavailable artifact.

@github-actions

Copy link
Copy Markdown
Contributor Author

Comment Memory

Peek at saved memory (spec-review-history)
{"id":"ldg-b0500835-2cee-4008-95e6-a806affb41a6","parents":[],"payload":{"id":"ldg-a15a4d07-73b7-4808-a8d9-79f1f0949dac","operation":"append","value":{"finding_count":0,"head_sha":"da051bcb7b1cfe016eb8935140a0072418384b5a","outcome":"aligned"}},"sha":"sha256:aa4e677d920f230cd8d1f22afd91809f3c18de48658402d90f8aaaa2bcf8ea02","timestamp":"2026-11-16T04:15:32.330Z","type":"ledger_append","version":1}
History

@github-actions

Copy link
Copy Markdown
Contributor Author

Comment Memory

Peek at saved memory (review-history)
{"id":"ldg-9f0f93ce-2290-4f49-b5fd-a585dfa66f89","parents":[],"payload":{"id":"ldg-3ebfcf8b-821f-439b-a4b7-b4a8e794a529","operation":"append","value":{"finding_count":2,"head_sha":"da051bcb7b1cfe016eb8935140a0072418384b5a","outcome":"findings"}},"sha":"sha256:1a5ba034f347c4c19dcf806bb3bafeba577ebfcee13ce5b5ca190b0d0e02705f","timestamp":"2026-11-16T04:16:13.853Z","type":"ledger_append","version":1}
History

Copilot AI 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.

🟡 Changes recommended

The change introduces a source-incompatible exported API signature without corresponding compatibility or migration updates, and its cancellation behavior is not verified by a test that actually cancels the context.

2 open issues
What changed in this PR

This PR propagates the Cobra command context through gh aw experiments analyze so cancellation can reach concurrent grader and outcome artifact downloads.

Changes:

  • Passes cmd.Context() through the analysis and observation-loading call chain.
  • Replaces context.Background() with the caller-provided context for grader and outcome run-data loading.
  • Updates existing test call sites to provide a test context.
File Description
pkg/​cli/​experiments_outcome_observations.go Uses the propagated context when loading outcome observation artifacts.
pkg/​cli/​experiments_outcome_observations_test.go Updates observation-loader test call sites for the context-aware API.
pkg/​cli/​experiments_command.go Threads the command context through experiment analysis and grader observation loading.

Review effort: Lite (dynamic)

Comment thread pkg/cli/experiments_command.go Outdated

// RunExperimentsAnalyze analyzes a specific experiment branch.
func RunExperimentsAnalyze(config ExperimentsAnalyzeConfig) error {
func RunExperimentsAnalyze(ctx context.Context, config ExperimentsAnalyzeConfig) error {

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.

Preserved the documented RunExperimentsAnalyze(config) API; the Cobra command now uses a private context-aware helper. Commit 1cd166f.

Comment thread pkg/cli/experiments_command.go Resolved

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd. The context threading is correct, but cancellation is still not reported to the user, so requesting changes.

📋 Key Themes & Highlights

Key Themes

  • Silent cancellation: the loaders map a cancelled ctx to unavailable exclusion reasons and return err == nil, so Ctrl-C prints a partial analysis and exits 0.
  • Missing regression test: nothing exercises the cancelled path.

Positive Highlights

  • ✅ ctx is threaded correctly through RunE, RunExperimentsAnalyze, and both loaders. Cobra defaults cmd.Context() to Background(), so there is no nil-context risk.
  • ✅ The pool.WithContext(ctx) and source.Load(ctx, ...) paths already honour cancellation, so the fix reaches the downloads.
  • ✅ gofmt is clean and go vet ./pkg/cli/ passes.
  • ✅ Targeted tests (TestOutcome|TestLoadOutcome|TestExperiments|TestRunExperiments) pass.

Validation Notes

The PR notes that go build and go test were not run. I ran go vet and the targeted tests, and both pass. I also verified the cancellation behaviour with a temporary probe test, which I removed afterwards.

@copilot please address the review comments above.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~6 AIC · ⌖ ~2 AIC · ⊞ 6.6K
Comment /matt to run again

@@ -201,6 +201,7 @@ func RunExperimentsAnalyze(config ExperimentsAnalyzeConfig) error {
}

metricObservationSets, cleanup, err := loadMetricObservationSetsForAnalysis(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[/diagnosing-bugs] Cancellation is silently swallowed. The loaders turn a cancelled ctx into exclusionRunUnavailable / exclusionArtifactUnavailable instead of returning an error, so Ctrl-C prints a partial analysis and exits 0. A temporary probe with a pre-cancelled context returned err == nil and marked both runs as unavailable.

💡 Suggested fix

After the loadMetricObservationSetsForAnalysis error check, surface cancellation before computing or printing results:

if err := ctx.Err(); err != nil {
    return err
}

This way RunE reports the interruption instead of a misleading table.

@copilot please address this.

},
}}
bundle, cleanup, err := loadMetricObservationSetsForAnalysis(details, frontmatter, "acme/repo", true)
bundle, cleanup, err := loadMetricObservationSetsForAnalysis(t.Context(), details, frontmatter, "acme/repo", true)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[/tdd] No test covers the new cancellation path, which is why the silent-success behaviour above went unnoticed. Add a case with an already-cancelled context that asserts RunExperimentsAnalyze returns context.Canceled and that no per-run gh calls appear in the fixture call log.

Write this test first and watch it fail on the current code (it currently gets err == nil), then add the ctx.Err() check.

@copilot please address this.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/cli/experiments_command.go:186): address unresolved feedback - Review comment
  3. Review (pkg/cli/experiments_command.go:204): address unresolved feedback - Review comment

Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering.

Structured data
{
  "completed_task": 0,
  "head": "da051bcb7b1cfe016eb8935140a0072418384b5a",
  "kind": "requested",
  "schema_version": "1",
  "state": "c17c0d3497e46965620023d5253cc97cc20b800dec3b59e4b5207039cbb65df4",
  "work": [
    "0bfc5090f7765c93c8fc4faf2a92b2c7dc9634bf7d2d63956849a6449474237f",
    "3814782545529f61f87ae3dd96c59aa2d6703a7231d3f073fc967252ba594f43"
  ],
  "workflow": "pr-sous-chef"
}

Generated by 👨🍳 PR Sous Chef · pi · routed: haiku55 xhigh · ~2 AIC · ⌖ ~2 AIC · ⊞ 7K · ◷
Comment /souschef to run again

gh-aw-bot and others added 2 commits November 16, 2026 04:48
…riments-analyze-r130-e7729dba7305afb0

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Copilot AI commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:...

Merged the latest main, preserved API compatibility, and added both cancellation tests in 1cd166f. The changes are published; build/tests passed, but the final custom lint reported pre-existing findings and CodeQL timed out.

@github-actions

Copy link
Copy Markdown
Contributor Author

Triage

  • Category: bug
  • Risk: medium
  • Score: 71/100 (impact 33 + urgency 20 + quality 18)
  • Recommended action: fast_track
  • Notes: CLI bug fix with direct user impact; keep in fast queue.

Generated by 🔧 PR Triage Agent · copilot · mai11 · ~9 AIC · ⌖ ~2 AIC · ⊞ 15.3K · ◷

@github-actions

Copy link
Copy Markdown
Contributor Author

Category: bug
Risk: medium
Total score: 71/100
Score breakdown: impact 39 + urgency 22 + quality 10 = 71
Recommended action: fast_track
Batch: none

Generated by 🔧 PR Triage Agent · copilot · mai11 · ~6 AIC · ⌖ ~2 AIC · ⊞ 15.3K · ◷

@pelikhan
pelikhan merged commit 3ba8106 into main Nov 16, 2026
67 checks passed
@pelikhan
pelikhan deleted the sergo/thread-ctx-experiments-analyze-r130-e7729dba7305afb0 branch November 16, 2026 15:09
@github-actions

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v1.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants