Repository navigation
fix(cli): thread command context through experiments analyze loaders - #78246
Conversation
|
✅ PR Code Quality Reviewer completed the code quality review. PR Code Quality ReviewerOutcome: 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.
|
|
✅ PR Specification Reviewer completed successfully! PR Specification ReviewerOutcome: 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.
|
|
✅ Ponytail Reviewer completed successfully! Ponytail ReviewerOutcome: 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.
|
|
✅ 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: 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.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: 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.
|
Comment MemoryPeek at saved memory (pr-code-quality-reviewer)Note This comment is managed by comment memory.Expand the saved memory block to view or edit the persistent context for this thread.
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
Comment MemoryPeek at saved memory (spec-review-history)History |
Comment MemoryPeek at saved memory (review-history)History |
There was a problem hiding this comment.
🟡 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)
|
|
||
| // RunExperimentsAnalyze analyzes a specific experiment branch. | ||
| func RunExperimentsAnalyze(config ExperimentsAnalyzeConfig) error { | ||
| func RunExperimentsAnalyze(ctx context.Context, config ExperimentsAnalyzeConfig) error { |
There was a problem hiding this comment.
Preserved the documented RunExperimentsAnalyze(config) API; the Cobra command now uses a private context-aware helper. Commit 1cd166f.
There was a problem hiding this comment.
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
ctxtounavailableexclusion reasons and returnerr == nil, so Ctrl-C prints a partial analysis and exits 0. - Missing regression test: nothing exercises the cancelled path.
Positive Highlights
- ✅
ctxis threaded correctly throughRunE,RunExperimentsAnalyze, and both loaders. Cobra defaultscmd.Context()toBackground(), so there is no nil-context risk. - ✅ The
pool.WithContext(ctx)andsource.Load(ctx, ...)paths already honour cancellation, so the fix reaches the downloads. - ✅
gofmtis clean andgo 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( | |||
There was a problem hiding this comment.
[/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) |
There was a problem hiding this comment.
[/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.
|
🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:
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"
}
|
…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>
Merged the latest |
Triage
|
|
Category: bug
|
|
🎉 This pull request is included in a new release. Release: |


Summary
gh aw experiments analyzeloads grader and outcome artifacts from GitHub, butloadGraderObservationSetsForAnalysisandloadOutcomeObservationSetsForAnalysispassedcontext.Background()toloadGraderRunData/loadOutcomeRunData. Those helpers already accept actxand 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(), ...)RunE->RunExperimentsAnalyze->loadMetricObservationSetsForAnalysis-> the two loaders.RunExperimentsAnalyzehas no other callers, andRunEholdscmd.Context().Change
RunExperimentsAnalyzenow takesctx context.Context;RunEpassescmd.Context().ctxis threaded throughloadMetricObservationSetsForAnalysis,loadGraderObservationSetsForAnalysis, andloadOutcomeObservationSetsForAnalysis.t.Context().No behaviour change when the context is not cancelled.
Validation
embedlithints on lines this PR does not touch.go build,go test,make fmtandmake agent-report-progresswere not run: the sandbox deniedgoandmakecommands in this run. CI should run them. The edits were made by hand and match gofmt style, but gofmt was not run.🤖 Generated with [Claude Code]((claude.com/redacted)