Skip to content

Propagate compile context into remote workflowspec resolution to make fetch/SHA calls cancellable - #48481

Closed
pelikhan with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-context-background-issue
Closed

pelikhan with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-context-background-issue

Conversation

Copilot AI commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Compilation could continue through remote workflowspec network calls after cancellation because the parser path used context.Background() for ref resolution and file download. This change threads the active compile context through those code paths so Ctrl+C can stop in-flight remote fetches.

  • Parser: context-aware workflowspec resolution

    • Updated downloadIncludeFromWorkflowSpec and resolveWorkflowSpecSHAForCache to accept context.Context.
    • Replaced internal context.Background() usage with propagated context for:
      • ref → SHA resolution
      • remote file download (default and host-specific paths)
  • Parser APIs: backward-compatible context threading

    • Added context-aware entry points:
      • ResolveIncludePathWithContext
      • ProcessImportsFromFrontmatterWithSourceWithContext
      • ExpandIncludesForEnginesWithContext
      • ExpandIncludesForSafeOutputsWithContext
    • Kept existing non-context APIs as wrappers to preserve current callers.
  • Import/include pipelines: end-to-end propagation

    • Threaded context through import BFS/topological resolution and include field expansion so nested workflowspec imports also honor cancellation.
  • Compiler integration

    • Updated compiler orchestrator call sites to pass c.ctx into parser import/include resolution, removing uncancellable network hops during compile.
// before
importsResult, err := parser.ProcessImportsFromFrontmatterWithSource(...)

// after
importsResult, err := parser.ProcessImportsFromFrontmatterWithSourceWithContext(
    c.ctx, result.Frontmatter, markdownDir, importCache, cleanPath, string(content),
)

Copilot AI changed the title [WIP] Fix context.Background() to honour compile cancellation Propagate compile context into remote workflowspec resolution to make fetch/SHA calls cancellable Jul 28, 2026
Copilot AI requested a review from pelikhan July 28, 2026 02:34
@pelikhan
pelikhan marked this pull request as ready for review July 28, 2026 02:35
Copilot AI review requested due to automatic review settings July 28, 2026 02:35
@github-actions

github-actions Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

@github-actions

github-actions Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ PR Code Quality Reviewer failed during code quality review.

@github-actions

github-actions Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

✅ Design Decision Gate 🏗️ completed the design decision gate check.

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.

Pull request overview

Threads compile context through remote workflowspec resolution to support cancellation for issue #48469.

Changes:

  • Adds context-aware parser APIs while preserving existing wrappers.
  • Propagates compiler context through imports and selected include paths.
  • Adds cancellation propagation tests and WASM API parity.
Show a summary per file
File Description
pkg/workflow/compiler_orchestrator_workflow.go Passes context to safe-output includes.
pkg/workflow/compiler_orchestrator_engine.go Passes context through import and engine resolution.
pkg/parser/remote_workflow_spec.go Uses propagated context for remote calls.
pkg/parser/remote_resolve_path.go Adds context-aware path resolution.
pkg/parser/remote_fetch_wasm.go Mirrors the new API for WASM.
pkg/parser/remote_fetch_test.go Tests low-level context propagation.
pkg/parser/remote_fetch_integration_test.go Updates integration calls with test context.
pkg/parser/include_expander.go Threads context through field expansion.
pkg/parser/import_topological.go Threads context through dependency resolution.
pkg/parser/import_processor.go Adds a context-aware import entry point.
pkg/parser/import_bfs.go Propagates context throughout import traversal.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (1)

pkg/workflow/compiler_orchestrator_engine.go:238

  • Cancellation from this resolution is treated as an unresolvable import by the warning/continue branch, so Ctrl+C merely skips the security scan and compilation proceeds. Return ctx.Err() before applying the fail-open behavior intended for ordinary resolution failures.
		fullPath, resolveErr := parser.ResolveIncludePathWithContext(ctx, importFilePath, markdownDir, importCache)
		if resolveErr != nil {
			orchestratorEngineLog.Printf("Skipping security scan for unresolvable import: %s: %v", importedFile, resolveErr)
			fmt.Fprintf(os.Stderr, "WARNING: Skipping security scan for unresolvable import '%s': %v\n", importedFile, resolveErr)
			continue
  • Files reviewed: 11/11 changed files
  • Comments generated: 3
  • Review effort level: Medium


// ResolveIncludePath resolves include path based on workflowspec format or relative path
func ResolveIncludePath(filePath, baseDir string, cache *ImportCache) (string, error) {
return ResolveIncludePathWithContext(context.Background(), filePath, baseDir, cache)
dependencies := make(map[string][]string, len(imports))
for _, importPath := range imports {
nestedImports, err := resolveNestedImportPaths(importPath, baseDir, cache)
nestedImports, err := resolveNestedImportPaths(ctx, importPath, baseDir, cache)
Comment on lines +323 to 326
fullPath, err := ResolveIncludePathWithContext(ctx, filePath, baseDir, nil)
if err != nil {
if directive.IsOptional {
return "", true, nil
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.

[Code Quality] Fix context.Background() in pkg/parser/remote_workflow_spec.go to honour compile cancellation

3 participants