Repository navigation
Description
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
-
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 wrappedfindWorkflowFileerror). Each caller would add its own context prefix, so the existing messages ("approved worker", "worker profile", "profile pool/name") stay unchanged. -
Optionally add
workQueueProfileWorkflowPath(name string) string, returningconstants.WorkflowsDirSlash + name + ".lock.yml", to share the lock-file path construction withwork_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.
populateDefaultWorkQueueProfilesdeliberately skips non-workers, while the other two reject them. The helper must return a boolean and not decide the policy.validateWorkQueueProfileTargetshas a self-reference short-circuit (name == GetWorkflowIDFromPath(markdownPath) && isWorkQueueWorker(data)) that must stay at the call site, before resolution.- Map iteration in
validateWorkQueueProfileTargetsis 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 repeatedfmt.Sprintf("%q")patterns, but each use is short and the chunking logic is cohesive.applyRepositoryWorkQueueOptionsandwarnLegacyWorkQueueIssues: 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
github-actions commentedon Nov 8, 2026
🍪 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! 🍪