Skip to content

Thread caller context through dispatcher skill content fetch - #78596

Merged
pelikhan merged 3 commits into
mainfrom
sergo/thread-ctx-dispatcher-skill-r131-04846ff219bb8d92
Nov 17, 2026
Merged

pelikhan merged 3 commits into
mainfrom
sergo/thread-ctx-dispatcher-skill-r131-04846ff219bb8d92

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Evidence

buildAgenticWorkflowsSkillContent (pkg/cli/copilot_agents.go) called listAgenticWorkflowsMarkdownFiles(context.Background()), which performs an HTTP request to the GitHub API for the .github/aw markdown file list. Every caller already held a cancellable context (or a cobra command), so Ctrl-C / cancellation during init, upgrade, fix or add could not interrupt that network call.

Found by Serena-assisted trace of the remaining non-test context.Background() candidates listed in the previous run (copilot_agents.go:203).

Change

  • buildAgenticWorkflowsSkillContent(ctx) and ensureAgenticWorkflowsDispatcher(ctx, ...) now take a context.
  • Callers: upgrade passes opts.ctx; init passes its ctx; fix via new FixConfig.Ctx (nil falls back via ctxutil.OrBackground), set from cmd.Context() in the cobra fix command, compile --fix (cmd/gh-aw/main.go) and upgrade.
  • Bootstrap marker check: missingBootstrapInitMarkers / isBootstrapInitMarkerSatisfied take ctx; add passes cmd.Context() through ensureAddRepositoryInitialized[WithDetails] / initializeAddRepositoryFiles, which now also sets InitOptions.Ctx.
  • Test call sites and addMissingInitMarkers stubs updated (t.Context()).

No behaviour change when the context is never cancelled.

Not changed (out of scope)

applyAddRepositoryInitialization / ensureAddRepositoryInitializedFromPlan still build InitOptions without Ctx; compile_scanner_source.go:109 still uses context.Background() (no ctx on the scanner source loader chain).

Validation

  • Serena get_diagnostics_for_file returned 0 diagnostics for: copilot_agents.go, add_init.go, fix_command.go, bootstrap_shared.go, upgrade_command.go, add_command_test.go, copilot_agents_test.go, add_interactive_orchestrator_test.go.
  • Not run: go build, go test, make fmt, make agent-report-progress were denied by the sandbox in this run, so compilation, gofmt and tests were NOT executed. Please rely on CI; gofmt alignment of the new Ctx field in FixConfig and the fixConfig literal in upgrade_command.go should be checked.

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

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

  • expires on Nov 23, 2026, 7:54 PM UTC-08:00

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

github-actions Bot commented Nov 17, 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 #78596 · codex · routed: gpt61 medium · ~4 AIC · ⌖ ~1 AIC · ⊞ 185 · ◷

@github-actions

github-actions Bot commented Nov 17, 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

github-actions Bot commented Nov 17, 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 #78596 · copilot · gpt56 · ~3 AIC · ⌖ ~2 AIC · ⊞ 1.6K · ◷

@github-actions

github-actions Bot commented Nov 17, 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 · ~7 AIC · ⌖ ~2 AIC · ⊞ 6.6K · ◷

@github-actions

github-actions Bot commented Nov 17, 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 · ~4 AIC · ⌖ ~1 AIC · ⊞ 1.5K · ◷

@github-actions

Copy link
Copy Markdown
Contributor Author

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-17T04:43:08Z
review_event: REQUEST_CHANGES
top_themes: [cancellation semantics, context propagation]
files_reviewed: [cmd/gh-aw/main.go, pkg/cli/add_command.go, pkg/cli/add_init.go, pkg/cli/bootstrap_shared.go, pkg/cli/copilot_agents.go, pkg/cli/fix_command.go, pkg/cli/init.go, pkg/cli/upgrade_command.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 · ~4 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 cancellation correctness issues that should be fixed before merge.

Highlights
  • Cancelled dispatcher fetches are silently converted to fallback content and may still write files.
  • Interactive add still drops context on its actual initialization path.

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

Comment thread pkg/cli/copilot_agents.go
func buildAgenticWorkflowsSkillContent() (string, error) {
awFiles, err := listAgenticWorkflowsMarkdownFiles(context.Background())
func buildAgenticWorkflowsSkillContent(ctx context.Context) (string, error) {
awFiles, err := listAgenticWorkflowsMarkdownFiles(ctx)

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.

Passing the caller context here does not actually honor cancellation: buildAgenticWorkflowsSkillContent converts every fetch error, including context.Canceled/DeadlineExceeded, into embedded fallback content, so Ctrl-C can still report success and write a stale SKILL.md.

💡 Preserve cancellation semantics

Return cancellation errors instead of falling back (for example, check ctx.Err() before selecting the embedded list); only use the fallback for unrelated fetch failures. Add a cancelled-context test that verifies no generated artifact is written.

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.

The dispatcher now returns the caller’s context error before applying fallback content, and the regression test verifies cancellation leaves the skill file unwritten. Fixed in c025330.

Comment thread pkg/cli/add_init.go
}

func initializeAddRepositoryFiles(markers []string, engineOverride string, verbose bool, noGitattributes bool) ([]string, error) {
func initializeAddRepositoryFiles(ctx context.Context, markers []string, engineOverride string, verbose bool, noGitattributes bool) ([]string, error) {

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.

This context-aware init path is still bypassed by interactive add: applyAddRepositoryInitialization calls ensureAddRepositoryInitializedFromPlan, whose InitOptions does not carry the context used during confirmation, so the dispatcher fetch triggered by that real initialization remains on context.Background() and Ctrl-C cannot interrupt it.

💡 Thread context through the plan-application path

Add ctx to applyAddRepositoryInitialization and ensureAddRepositoryInitializedFromPlan, then set InitOptions.Ctx when invoking addInitRepository. This keeps both regular and interactive add cancellation behavior consistent.

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.

The interactive add plan path now carries its context into InitOptions; the regression test verifies cancellation propagates through initialization. Fixed in c025330.

@github-actions

Copy link
Copy Markdown
Contributor Author

Comment Memory

Peek at saved memory (spec-review-history)
{"id":"ldg-460315bd-b3db-404c-b0c5-d09784e7ed7e","parents":[],"payload":{"id":"ldg-8c0527bb-250a-47bf-816e-c121c6bf5545","operation":"append","value":{"finding_count":0,"head_sha":"7ebd1a783cc871b3119b3dc865d4a3cac7c0df85","outcome":"aligned"}},"sha":"sha256:5f088074ef064133e1739c43d31a70d7ce3b587cc55949b042737c68696b6e9b","timestamp":"2026-11-17T04:47:10.489Z","type":"ledger_append","version":1}
History

@github-actions

Copy link
Copy Markdown
Contributor Author

Comment Memory

Peek at saved memory (review-history)
{"id":"ldg-59ff71d1-33f6-4e52-a4b9-8eaa6b859641","parents":[],"payload":{"id":"ldg-326979ab-9a97-49f6-b996-1e65bb56e3a4","operation":"append","value":{"finding_count":2,"head_sha":"7ebd1a783cc871b3119b3dc865d4a3cac7c0df85","outcome":"findings"}},"sha":"sha256:b42f6c99826d77027162e4fd396f451155a5915dbb0e088377ceb2de0c689a9e","timestamp":"2026-11-17T04:47:53.646Z","type":"ledger_append","version":1}
History

Comment thread pkg/cli/copilot_agents.go
func buildAgenticWorkflowsSkillContent() (string, error) {
awFiles, err := listAgenticWorkflowsMarkdownFiles(context.Background())
func buildAgenticWorkflowsSkillContent(ctx context.Context) (string, error) {
awFiles, err := listAgenticWorkflowsMarkdownFiles(ctx)

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

Caller cancellation is swallowed by the embedded fallback, allowing init or upgrade to overwrite SKILL.md and continue after Ctrl-C instead of returning the context error.

1 open issue
What changed in this PR

This PR threads caller context through gh-aw’s dispatcher skill fetch so cancellation can interrupt the GitHub API request.

Changes:

  • Passes context through dispatcher generation and bootstrap marker checks.
  • Connects command contexts from init, upgrade, fix, compile --fix, and regular add, with a nil-context fallback for FixConfig.
  • Updates existing test calls and mocks for the new signatures.
File Description
pkg/​cli/​upgrade_command.go Passes upgrade context to fixes and dispatcher updates.
pkg/​cli/​init.go Passes initialization context to dispatcher generation.
pkg/​cli/​fix_command.go Adds context support to fix configuration and execution.
pkg/​cli/​copilot_agents.go Forwards caller context to the markdown-list fetch.
pkg/​cli/​copilot_agents_test.go Updates skill-generation tests to pass context.
pkg/​cli/​bootstrap_shared.go Threads context through bootstrap marker checks.
pkg/​cli/​add_interactive_orchestrator_test.go Updates marker-check mock signatures.
pkg/​cli/​add_init.go Propagates context through regular add initialization.
pkg/​cli/​add_command.go Supplies command context to repository initialization.
pkg/​cli/​add_command_test.go Updates initialization tests and mocks for context.
cmd/​gh-aw/​main.go Supplies command context to compile --fix.

Review effort: Balanced (adaptive)

Comment thread pkg/cli/copilot_agents.go
func buildAgenticWorkflowsSkillContent() (string, error) {
awFiles, err := listAgenticWorkflowsMarkdownFiles(context.Background())
func buildAgenticWorkflowsSkillContent(ctx context.Context) (string, error) {
awFiles, err := listAgenticWorkflowsMarkdownFiles(ctx)

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.

The dispatcher now returns the caller’s context error before applying fallback content, preventing cancelled init or upgrade from writing fallback SKILL.md. Fixed in c025330.

@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, /tdd and /codebase-design. Requesting changes because the new cancellation plumbing is silently swallowed.

📋 Key Themes & Highlights

Key Themes

  • Cancellation is swallowed: buildAgenticWorkflowsSkillContent falls back to the embedded list and returns nil when the context is cancelled. Ctrl-C aborts the HTTP call only, so init, upgrade, fix and add keep running (copilot_agents.go:203).
  • Missing ctx-propagation test: the mock ignores its context, so a regression that drops ctx would still pass (copilot_agents_test.go:330).
  • Partial add coverage: the plan and interactive paths still drop ctx (add_init.go:121).
  • Nil-context hardening: upgrade passes opts.ctx without ctxutil.OrBackground, unlike init and fix (upgrade_command.go:466). This is latent, not an active bug.

Verification

  • gofmt -l is clean on all 10 touched Go files.
  • go build ./cmd/gh-aw/ ./pkg/cli/ and go vet ./pkg/cli/ pass.
  • Targeted go test ./pkg/cli/ passes for the affected tests.
  • A throwaway red test asserting context.Canceled fails on the current code. The probe files were removed.
  • I did not run the full make test-unit suite.

Positive Highlights

  • ✅ The signature changes are consistent across all non-test callers and test call sites.
  • ✅ initializeAddRepositoryFiles correctly forwards Ctx into InitOptions.
  • ✅ init and fix normalise nil contexts with ctxutil.OrBackground.

@copilot please address the review comments above.

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

Comment thread pkg/cli/copilot_agents.go
func buildAgenticWorkflowsSkillContent() (string, error) {
awFiles, err := listAgenticWorkflowsMarkdownFiles(context.Background())
func buildAgenticWorkflowsSkillContent(ctx context.Context) (string, error) {
awFiles, err := listAgenticWorkflowsMarkdownFiles(ctx)

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 swallowed here. When ctx is cancelled, the fetch fails, this block logs a warning and falls back to the embedded list, and the function returns err == nil. Ctrl-C therefore only aborts the HTTP call; init, upgrade, fix and add keep running and write the fallback skill.

💡 Suggested fix

Return the cancellation before falling back:

awFiles, err := listAgenticWorkflowsMarkdownFiles(ctx)
if err != nil {
    if ctxErr := ctx.Err(); ctxErr != nil {
        return "", ctxErr
    }
    // existing warning and fallback
    awFiles = embeddedFallbackAWMarkdownFiles()
}

A regression test should assert that a cancelled context returns an error wrapping context.Canceled. I ran that test against this branch and it fails with Expected error with "context canceled" in chain but got nil.

@copilot please address this.

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.

Added a cancellation regression test and now return the caller’s context error before applying embedded fallback content. Fixed in c025330.

withMockAWMarkdownFileList(t, []string{"workflow-z.md", "workflow-a.md"}, nil)

content, err := buildAgenticWorkflowsSkillContent()
content, err := buildAgenticWorkflowsSkillContent(t.Context())

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] This call now passes t.Context(), but nothing checks that the context is actually threaded. withMockAWMarkdownFileList ignores its context argument, so a regression that drops ctx (for example passing context.Background() again) would still pass.

💡 Suggested test

Add a test that cancels the context, captures the context the mock receives, and fails if the cancellation is lost. Write it first so it fails on the current code, then fix the swallowed error.

func TestBuildAgenticWorkflowsSkillContentReturnsCancellation(t *testing.T) {
    ctx, cancel := context.WithCancel(t.Context())
    cancel()
    var seen context.Context
    previous := listAgenticWorkflowsMarkdownFiles
    listAgenticWorkflowsMarkdownFiles = func(c context.Context) ([]string, error) {
        seen = c
        return nil, c.Err()
    }
    t.Cleanup(func() { listAgenticWorkflowsMarkdownFiles = previous })

    _, err := buildAgenticWorkflowsSkillContent(ctx)
    require.ErrorIs(t, err, context.Canceled)
    assert.Equal(t, ctx, seen)
}

@copilot please address this.

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.

The regression test now verifies the cancelled caller context reaches the fetch and that cancellation is returned. Fixed in c025330.

Comment thread pkg/cli/add_init.go

func ensureAddRepositoryInitialized(engineOverride string, verbose bool, noGitattributes bool) error {
_, err := ensureAddRepositoryInitializedWithDetails(engineOverride, verbose, noGitattributes)
func ensureAddRepositoryInitialized(ctx context.Context, engineOverride string, verbose bool, noGitattributes bool) error {

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.

[/codebase-design] The add coverage is only partial. ensureAddRepositoryInitialized now takes ctx, but the plan path still drops it: add_init.go:110 calls addInitRepository without Ctx, and the interactive flow calls applyAddRepositoryInitialization without a context at add_interactive_orchestrator.go:254. Ctrl-C during interactive add therefore still cannot abort the init work.

💡 Suggestion

Thread ctx through applyAddRepositoryInitialization and ensureAddRepositoryInitializedFromPlan as well, and set Ctx: ctx in the InitOptions literal at add_init.go:110, matching the change already made in initializeAddRepositoryFiles. Either fix the coverage or narrow the PR description so it no longer claims add is covered.

@copilot please address this.

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.

The interactive plan-application path now forwards context to InitOptions; the test verifies the exact context and cancellation propagation. Fixed in c025330.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

@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/copilot_agents.go:203): 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": "7ebd1a783cc871b3119b3dc865d4a3cac7c0df85",
  "kind": "requested",
  "schema_version": "1",
  "state": "0af34f8a235bb102a2128e811f8dfef114837e50edda8d181cf4a8cd38a6cb5e",
  "work": [
    "71efdf047fdea86e14c92efec14411dbc48cb98fcaba30241e8a022e5206e0b3"
  ],
  "workflow": "pr-sous-chef"
}

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

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

Copilot AI commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

@copilot run pr-finisher skill

Ran the PR finisher pass and pushed the cancellation and interactive-add fixes in c025330. The review comments are answered; the threads still need resolution, and the final local gate remains blocked by pre-existing custom-linter findings.

@pelikhan
pelikhan merged commit 727e65e into main Nov 17, 2026
105 checks passed
@pelikhan
pelikhan deleted the sergo/thread-ctx-dispatcher-skill-r131-04846ff219bb8d92 branch November 17, 2026 06:10

Copilot AI commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

@copilot

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

Updated the branch with make merge-main and merged main through b594e8d in commit 708829e. The linked cancellation feedback is already fixed and replied to in c025330, with regression coverage. make merge-main completed its build and 368-workflow recompile; CI needs a maintainer re-trigger after this push.

@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

Labels

cookie Issue Monster Loves Cookies! sergo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants