Skip to content

[refactor] Align model overlay fallback rules in workflow_builder_model_overlays.go #78890

Done

Description

@github-actions

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

  1. Decide the intended rule for a non-empty parsed ModelCosts with no usable providers. Either make the costs path fall back to raw models like the policy path, or keep return nil and rewrite the L13–14 comment to say so.
  2. Add one helper for the raw models section lookup and use it at L24–26, L138 and L189.
  3. Give both overlay extractors the same parsed-then-raw shape. Keep a per-field predicate, since costs checks ModelCosts and policy checks allowed and blocked.

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 ModelCosts without providers (raw providers present); empty parsed ModelCosts with raw providers; empty parsed policy with raw allowed and blocked lists; and nil parsedFrontmatter.
  • From the packet alone I cannot tell whether ParseFrontmatterConfig can fill ModelCosts from anything other than raw models. If it cannot, the costs-only return nil may 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.
  • extractConcurrencySection and extractConcurrencyJobDiscriminator both assert frontmatter["concurrency"] as a map. This is a routine idiom, so not reported.
  • extractYAMLSections is a list of independent field assignments with no duplicated logic.
  • mergeExcludedEnvVarNames and mergeModelCostOverlays are 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

  1. github-actions commented on Nov 18, 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 · ⌖ ~1 AIC · ⊞ 11.4K · ◷

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