Repository navigation
Description
Overview
Sampled refactor review of pkg/workflow, slices 685/695 and 686/695, run 2026-11-18. Reviewed 2 files, 16 functions and 353 source lines from the AST-selected packet. No excerpt was truncated. Full rotation coverage for this unchanged inventory is 904 days. This is a sample, not coverage of the package or repository. Callers and the parser were not read.
One finding: the two "prefer parsed frontmatter, else raw models section" helpers in pkg/workflow/workflow_builder_model_overlays.go use different fallback rules, and one comment does not describe its code.
Key findings
| # | Location | Observation |
|---|---|---|
| 1 | extractMainModelCostsOverlay, L15–21 |
If parsed ModelCosts is non-empty but has no usable providers map, it returns nil at L21 and never consults raw models. |
| 2 | extractMainModelPolicyOverlay, L134–137 |
It falls back to raw models whenever parsed allowed and blocked are both empty. A non-empty parsed policy is returned directly. |
| 3 | extractMainModelCostsOverlay, L13–15 |
The comment says fallback happens "when ParseFrontmatterConfig failed". The code also falls back when parsing succeeds but ModelCosts is empty. |
Observed code
extractMainModelCostsOverlay, L13–22:
// Fall back to raw frontmatter when ParseFrontmatterConfig failed (e.g. due to unrecognized
// tool config shapes like bash: ["*"]).
if toolsResult.parsedFrontmatter != nil && len(toolsResult.parsedFrontmatter.ModelCosts) > 0 {
if providers, hasProviders := toolsResult.parsedFrontmatter.ModelCosts["providers"]; hasProviders {
if providersMap, ok := providers.(map[string]any); ok && len(providersMap) > 0 {
return map[string]any{"providers": providersMap}
}
}
return nil
}extractMainModelPolicyOverlay, L129–137:
if toolsResult.parsedFrontmatter != nil {
mainPolicy := map[string][]string{
"allowed": toolsResult.parsedFrontmatter.ModelPolicyAllowed,
"blocked": toolsResult.parsedFrontmatter.ModelPolicyBlocked,
}
if len(mainPolicy["allowed"]) > 0 || len(mainPolicy["blocked"]) > 0 {
return mainPolicy
}
}
// otherwise falls through to frontmatter["models"]The raw models lookup is also repeated at L24–26, L138 and L189 (extractDefaultAiCreditsPricingFromModels).
Proposed refactoring
- Decide the intended rule for a non-empty parsed
ModelCostswith no usable providers. Either make the costs path fall back to rawmodelslike the policy path, or keepreturn niland rewrite the L13–14 comment to say so. - Add one helper for the raw
modelssection lookup and use it at L24–26, L138 and L189. - Give both overlay extractors the same parsed-then-raw shape. Keep a per-field predicate, since costs checks
ModelCostsand policy checksallowedandblocked.
Preservation risks
- Changing L21 or L134–137 changes output when parsed and raw sources disagree. Before refactoring, pin current behavior with table tests for: non-empty parsed
ModelCostswithout providers (raw providers present); empty parsedModelCostswith raw providers; empty parsed policy with raw allowed and blocked lists; and nilparsedFrontmatter. - From the packet alone I cannot tell whether
ParseFrontmatterConfigcan fillModelCostsfrom anything other than rawmodels. If it cannot, the costs-onlyreturn nilmay be unreachable and the change is low-risk. This is unverified.
Open question (unverified)
resolveDefaultAiCreditsPricing (L179–184) reads main pricing from frontmatter["models"]["default-ai-credits-pricing"], but passes imported directly to extractDefaultAiCreditsPricingFromObject, which treats its argument as the pricing object. If a caller passes an imported models section, the result is a non-nil config with zero input and output rates, not the imported pricing. Callers are outside the packet and were not checked.
Scope and functions compared but not reported
- Compared: costs vs policy overlay extractors; concurrency extractors; pricing resolution chain.
extractConcurrencySectionandextractConcurrencyJobDiscriminatorboth assertfrontmatter["concurrency"]as a map. This is a routine idiom, so not reported.extractYAMLSectionsis a list of independent field assignments with no duplicated logic.mergeExcludedEnvVarNamesandmergeModelCostOverlaysare distinct merge helpers; their logic reads as correct.
References: §44222810359
Generated by 🔧 Semantic Function Refactoring · claude · routed: haiku55 xhigh · ~3 AIC · ⌖ ~1 AIC · ⊞ 4.1K · ◷
- expires on Nov 19, 2026, 6:31 PM UTC-08:00
Activity
github-actions commentedon Nov 18, 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! 🍪