Skip to content

feat(bin): prefer a configured provider family in dispatch resolution - #7876

Merged
kunchenguid merged 3 commits into
kunchenguid:mainfrom
tiago-peixoto:fm/upstream-7863
Oct 28, 2026
Merged

kunchenguid merged 3 commits into
kunchenguid:mainfrom
tiago-peixoto:fm/upstream-7863

Conversation

@tiago-peixoto

Copy link
Copy Markdown
Contributor

Intent

Fixes #7863.

Open the upstream pull request for #7863, "Dispatch resolver has no way to prefer one provider family in mixed-provider arrays", now that Kun's side has labelled it ready-for-pr with contract class opt-in.

The problem: bin/fm-dispatch-resolve.sh ranks the eligible candidates of a matched profile array only by the spendPriority argmax (docs/configuration.md, "Checks performed after the answer"). An operator who pays for more than one provider subscription has no way to say "spend this provider family first". Array order is deliberately ignored for ranking, and removing the other family's candidates also removes the fallback when the preferred family cannot run. Example: one array holds a Codex-family candidate at 82% remaining and a Claude-family candidate at 26%. The Claude candidate still wins because its spendPriority is higher, which spends the wrong subscription for an operator whose policy is to use one subscription first.

Expected:

  • An operator can state a preferred provider family for mixed-provider arrays.
  • The resolver keeps every existing gate: rule match, explicit override, approval, model support, authentication, reasoning class and runway.
  • Among the candidates that pass those gates, it prefers the stated family and ranks within that family as it ranks today.
  • It picks another family only when evidence shows that no preferred candidate can run. Unknown quota for a preferred candidate is uncertainty, not proof that it cannot run.
  • A rule whose array names only one family, an explicit per-task override, and a configuration without the setting all behave exactly as today.

How to verify:

  • In the example, with the preference set to the Codex family, the resolver picks the Codex candidate and prints why.
  • With the preferred candidate exhausted, the resolver picks the other family and says so.
  • With the preferred candidate's quota unknown, the resolver still prefers it and discloses the uncertainty.
  • With two preferred-family candidates, the resolver ranks them by spendPriority as today.
  • An invalid preference value is reported as a configuration error, never silently ignored.

Quality criteria: the output names the preferred-family decision for every resolution where the setting applied, and changing prose-only fields of the dispatch configuration does not change routing.
Kun's side added: keep the decision in code, not in the model question, and print the preferred-family reason on every resolution where it applied.

What Changed

  • bin/fm-dispatch-resolve.sh reads an optional top-level preferred_provider from config/crew-dispatch.json. After the existing eligibility gates, it restricts spendPriority ranking to eligible candidates of that family, falls back to other families only when every matched preferred candidate is proven ineligible, escalates when preferred candidates are eligible but unrankable, and prints a preferred_provider: decision line on every resolution where the setting applied. Absent setting, single-family arrays, and explicit overrides route as before.
  • bin/fm-bootstrap.sh and the resolver both reject a malformed preferred_provider (null, empty, uppercase, whitespace) as a CREW_DISPATCH: invalid config/crew-dispatch.json error. Bootstrap validates this field even without a typesafe key.
  • docs/configuration.md, docs/verification/dispatch-resolve.md, AGENTS.md, and the quota-array-dispatch skill document the new field, its fallback and uncertainty rules, and its position in the ranking order. Tests in tests/fm-dispatch-resolve.test.sh and tests/fm-bootstrap.test.sh cover the preference, fallback, unknown-quota escalation, same-family ranking, and invalid-value scenarios.

Risk Assessment

✅ Low: The routing change is a few jq bindings that only narrow the ranking pool when a validated preferred_provider is set and an eligible candidate of that family exists; every intent scenario traced to the expected pool and decision text, the absent-setting path is byte-identical to before, validation runs in both bootstrap and the resolver before any network or quota read, and the new tests drive the public interface rather than source text.

Testing

The Test agent exceeded its invocation budget before live validation completed; no evidence was gathered for this head.

  • Outcome: ⚠️ 1 warning across 1 run (30m2s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ⚠️ docs/configuration.md:1666 - Simplification: the change introduces a new documented top-level field policy_why (docs/configuration.md:1666, header comment bin/fm-dispatch-resolve.sh:34, test scenario tests/fm-dispatch-resolve.test.sh:234 and :268). Neither issue Dispatch resolver has no way to prefer one provider family in mixed-provider arrays #7863 nor the intent asks for a second prose field; the intent's criterion 'changing prose-only fields of the dispatch configuration does not change routing' is already satisfied by the existing rule why, which the resolver never sends (only .rules[].when is placed in the request). No code reads policy_why, so documenting it adds schema vocabulary with no behavior behind it and a second definition of the prose-only concept. Recommended remedy: remove the policy_why sentence from docs/configuration.md and the header comment, and if a top-level prose case is wanted in the test, flip the existing rule why text instead (the fixture already carries SECRET-WHY-TEXT for this purpose).
  • ℹ️ tests/fm-dispatch-resolve.test.sh:253 - tests/fm-dispatch-resolve.test.sh:206-208 writes preferred-auth.json and :253 passes it as QUOTA_AUTH_FIXTURE, but nothing consumes it: the fake quota-axi only serves --json from QUOTA_AXI_FIXTURE, and the resolver never calls quota-axi auth. The section comment at :188 ('with separate account evidence') overstates what the test proves; account separation is actually exercised through the schema-6 accountKey rows. Also the same-family scenario shares the exact case branch and expectations of work-account (:211), so it runs the identical test twice. Remedy: drop the auth fixture, the env var, and the duplicate scenario name.
  • ℹ️ bin/fm-dispatch-resolve.sh:541 - Interpretation note on 'With the preferred candidate's quota unknown, the resolver still prefers it and discloses the uncertainty.' The implementation keeps the pool on the preferred family and, because an unrankable candidate can never produce clear under the existing contract, escalates with reason 'no rankable eligible candidate in preferred provider <p>; uncertainty does not authorize fallback' plus the preferred_provider: line. Operator-visible effect: an intake that before this change got a clear other-family pick (with an unranked note) now returns to the manual intake whenever the preferred family is unmeasured. This matches the issue's 'picks another family only when evidence shows that no preferred candidate can run' and SKILL.md's new sentence, so no contradiction; recorded so the human can confirm escalate is the intended reading of 'still prefers it'.

🔧 Fix applied.
1 info still open:

  • ℹ️ bin/fm-dispatch-resolve.sh:541 - Interpretation note on 'With the preferred candidate's quota unknown, the resolver still prefers it and discloses the uncertainty.' The implementation keeps the pool on the preferred family and, because an unrankable candidate can never produce clear under the existing contract, escalates with reason 'no rankable eligible candidate in preferred provider <p>; uncertainty does not authorize fallback' plus the preferred_provider: line. Operator-visible effect: an intake that before this change got a clear other-family pick (with an unranked note) now returns to the manual intake whenever the preferred family is unmeasured. This matches the issue's 'picks another family only when evidence shows that no preferred candidate can run' and SKILL.md's new sentence, so no contradiction; recorded so the human can confirm escalate is the intended reading of 'still prefers it'.
⚠️ **Test** - 1 warning
  • ⚠️ The Test agent did not finish within its invocation budget. Reported: agent run tests timed out after 30m0s: agent last produced output 560ms ago (96 observed); agent reported: claude parse events: context deadline exceeded. This is a budget or provider-slowness cut, not a code failure. Re-running the same request costs another full budget, so no further attempt is made automatically. If this repository's targeted tests or evidence gathering routinely approach the default 30m0s, raise test_agent_timeout in global config. Respond with fix to spend another budget: a repair turn runs only for selected findings other than this budget cut, then validation re-runs. Or abort and retry after raising the budget.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Reviews (3) · Last reviewed commit: "no-mistakes(document): docs: record pref..." · Reviewed by Greptile

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @tiago-peixoto, this is a careful take on #7863. I read the tip 00afa298 against main. After the existing gates, the resolver narrows the spendPriority pool to eligible candidates of preferred_provider. It falls back only when every matched candidate of that family is ineligible, escalates when they're eligible but unrankable, and prints the decision line. Bootstrap and the resolver both reject malformed values. With the field absent, the pool is the same $cands as before. Candidates without a provider are already ineligible, so the null comparison can't narrow anything. There are no workflow, network or credential changes. The no-mistakes attestation binds this head.

contract-class: opt-in. Nothing changes unless a home sets preferred_provider.

One thing on you, gently: live validation. The PR body says the pipeline's Test agent ran out of budget before driving any live scenario for this head. When you can, could you drive the issue's checks against a real resolver run and post the evidence here? The checks are: prefer the Codex family in the 82%/26% example, fall back when it's exhausted, keep preferring it when its quota is unknown, rank two same-family candidates by spendPriority, and reject an invalid value. Or you could re-raise through git push no-mistakes so the attestation carries it.

The only CI red is Behavior portable serial 1 in run 40601139325. That run is on a merge base from before main's 2ba4c455 shard fix, failing in the known inherited class, so it isn't yours to fix. A re-raise would also give a fresh run. FYI, issue #7879 asks for a credential-source declaration in the same bin/fm-dispatch-resolve.sh. It's a separate concern and doesn't overlap this one.

@tiago-peixoto

Copy link
Copy Markdown
Contributor Author

Live evidence against commit 00afa2981d9f4a74e8ec998ecd086a812f4a4fdd:

Checks 1-4 used this command shape with the named quota snapshot:

FM_HOME=<fixture-home> TYPESAFE_API_KEY=fixture-key LIVE_RESPONSE=<fixture-response> LIVE_QUOTA=<quota-snapshot> PATH=<fixture-tools> bash <commit-snapshot>/bin/fm-dispatch-resolve.sh <fixture-home>/brief.md
  1. The 82% Codex / 26% Claude case used quota-1.json and returned status: clear, preferred_provider: codex: prefer eligible family candidates, and profile: --harness 'pi' --model 'openai-codex/gpt-6-astra'.
  2. The exhausted Codex case used quota-2.json and returned preferred_provider: codex: fall back; every matched family candidate is ineligible and profile: --harness 'claude' --model 'opus'.
  3. The unknown Codex quota case used quota-3.json and returned status: escalate, reason: no rankable eligible candidate in preferred provider codex; uncertainty does not authorize fallback, and preferred_provider: codex: prefer eligible family candidates.
  4. The same-family ranking case used quota-4.json and returned preferred_provider: codex: prefer eligible family candidates and profile: --harness 'pi' --model 'openai-codex-work/gpt-6-astra' when that candidate had the higher spendPriority.
  5. The invalid setting case set preferred_provider to Codex and ran FM_HOME=<fixture-home> TYPESAFE_API_KEY=fixture-key PATH=<fixture-tools> bash <commit-snapshot>/bin/fm-dispatch-resolve.sh <fixture-home>/brief.md. It returned exit code 2 and error: malformed rules file: <fixture-home>/config/crew-dispatch.json - preferred_provider must be a lowercase provider ID (for example codex).

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @tiago-peixoto, that evidence covers it. You ran the resolver from 00afa298 against all five of the issue's checks. Codex is preferred in the 82%/26% case. It falls back to Claude when Codex is exhausted. It escalates rather than falling back when Codex quota is unknown. It ranks the two Codex candidates by spendPriority. And it rejects Codex as a malformed value. The quota and model replies were fixtures, which is fine for a routing decision whose inputs are exactly those. I re-read the resolver diff against main. With preferred_provider absent, the pool is still $cands, so the class stays opt-in. The no-mistakes attestation binds this head.

The only red left is Behavior portable serial 1 in run 40601139325. That run sits on a merge base from before main's shard fix, so it's on our side. I'm closing and reopening this PR once to get a fresh CI run on current main. That changes no code and keeps your attestation. If it comes back green and CLEAN, I'll merge it on a later pass. Nothing more is needed from you.

@kunchenguid kunchenguid reopened this Oct 28, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: quick CI note, @tiago-peixoto. Nothing is needed from you.

My close+reopen last pass didn't get a run on current main. GitHub's merge ref for run 40643677061 was still 00afa298 merged into the old 7da4c362, from before main's runner fixes. Its only red is Behavior portable serial 1 ("the watcher's downtime resurface did not reach main"). That's a watcher/supervision case your dispatch-resolver change doesn't touch, and the other 19 checks passed. The merge ref now sits on a current main, so I'm closing and reopening once more for a fresh run. Your head and the no-mistakes attestation stay as they are, so please don't push or rebase for this.

I re-checked the diff: with preferred_provider unset, the pool is still the full candidate list, so contract-class stays opt-in. If the fresh run is green and the PR is CLEAN, I'll merge it on a later pass.

@kunchenguid kunchenguid reopened this Oct 28, 2026
@kunchenguid
kunchenguid merged commit df9e6ce into kunchenguid:main Oct 28, 2026
57 of 59 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @tiago-peixoto — really appreciate you taking the time on this.