Skip to content

[refactor] Extract shared work-queue worker-target resolution in work_queue_policy.go #75798

Done

Description

@github-actions

Summary

Three functions in pkg/workflow/work_queue_policy.go repeat the same four-step "resolve workflow name → require compiler-managed .md source → check tools.work-queue.worker: true" sequence, differing only in error-message wording and what happens when the target is not a worker.

Scope: sampled analysis, pkg/workflow slices 660/673 and 661/673 (2026-11-08). 5 files, 14 functions reviewed. One excerpt (buildInitialWorkflowData) was truncated and was not analyzed. This is not a claim of whole-package coverage.

Observed duplication

Function Lines Loop input On !worker
validateApprovedWorkQueueTargets work_queue_policy.go:570-590 SafeOutputs.DispatchWorkflow.Workflows names return error
populateDefaultWorkQueueProfiles work_queue_policy.go:592-631 (loop at ~598-617) same dispatch-workflow names continue (skip)
validateWorkQueueProfileTargets work_queue_policy.go:633-658 name derived from filepath.Base(profile.Workflow) with .lock.yml/.yml/.yaml trimmed return error

Each one executes this same sequence:

target, err := findWorkflowFile(name, markdownPath)
if err != nil { return fmt.Errorf("work-queue: ...%q: %w", ..., err) }
if !target.mdExists { return fmt.Errorf("work-queue: ... requires compiler-managed ... source") }
worker, err := mdHasWorkQueueWorker(target.mdPath)
if err != nil { return err }
if !worker { /* error or continue */ }

The first two also share the same outer guard, data.SafeOutputs != nil && data.SafeOutputs.DispatchWorkflow != nil, and the same iteration over DispatchWorkflow.Workflows.

A second, smaller overlap: populateDefaultWorkQueueProfiles and approvedAWQueueProfiles (work_queue_repo_config.go:153-191) both build a worker profile from a template by setting Ref = "${{ github.sha }}" and Workflow = constants.WorkflowsDirSlash + name + ".lock.yml".

Proposed refactoring

  1. Add a helper in work_queue_policy.go, for example:

    // resolveWorkQueueWorkerTarget returns whether `name` resolves to a compiler-managed
    // workflow source and whether it declares tools.work-queue.worker: true.
    func resolveWorkQueueWorkerTarget(name, markdownPath string) (isWorker bool, err error)

    The helper would return typed or sentinel errors (errNotCompilerManaged, or the wrapped findWorkflowFile error). Each caller would add its own context prefix, so the existing messages ("approved worker", "worker profile", "profile pool/name") stay unchanged.

  2. Optionally add workQueueProfileWorkflowPath(name string) string, returning constants.WorkflowsDirSlash + name + ".lock.yml", to share the lock-file path construction with work_queue_repo_config.go.

Preservation risks

  • Error text is probably asserted in tests (for example the long "ordinary delegated workflows have no Claim-scoped delivery adapter" message). Keep per-caller wrapping so the strings are byte-identical.
  • populateDefaultWorkQueueProfiles deliberately skips non-workers, while the other two reject them. The helper must return a boolean and not decide the policy.
  • validateWorkQueueProfileTargets has a self-reference short-circuit (name == GetWorkflowIDFromPath(markdownPath) && isWorkQueueWorker(data)) that must stay at the call site, before resolution.
  • Map iteration in validateWorkQueueProfileTargets is unordered, so the first error reported is nondeterministic. The refactor should not change that, but it could be sorted separately.
Other candidates reviewed and not flagged
  • workQueuePolicyEnvironment / workQueuePolicyJSONEnvironment / splitWorkQueuePolicyJSON: environment line construction with repeated fmt.Sprintf("%q") patterns, but each use is short and the chunking logic is cohesive.
  • applyRepositoryWorkQueueOptions and warnLegacyWorkQueueIssues: separate concerns. The warning helper is shared by two call sites.
  • buildInitialWorkflowData: truncated in the packet, so no whole-function claims were made.

Generated by 🔧 Semantic Function Refactoring · claude · routed: sonnet55 high · ~16 AIC · ⌖ ~1 AIC · ⊞ 3.2K · ◷

  • expires on Nov 9, 2026, 6:27 PM UTC-08:00

Activity

  1. github-actions commented on Nov 8, 2026

    @github-actions
    ContributorAuthor

    🍪 Issue Monster selected this for Copilot

    I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.

    If assignment succeeds, Copilot will analyze the issue and create a pull request with the fix.

    Om nom nom! 🍪

    🍪 Om nom nom by Issue Monster · pi · gpt50 · ~1 AIC · ⌖ ~2 AIC · ⊞ 12.3K · ◷

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions