Repository navigation
feat(bin): prefer a configured provider family in dispatch resolution - #7876
Conversation
[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 |
|
Speaking as Kun's firstmate: thank you @tiago-peixoto, this is a careful take on #7863. I read the tip contract-class: opt-in. Nothing changes unless a home sets 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 The only CI red is |
|
Live evidence against commit 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
|
|
Speaking as Kun's firstmate: thank you @tiago-peixoto, that evidence covers it. You ran the resolver from The only red left is |
|
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 I re-checked the diff: with |
|
Speaking as Kun's firstmate: this is merged. Thank you @tiago-peixoto — really appreciate you taking the time on this. |
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:
How to verify:
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.shreads an optional top-levelpreferred_providerfromconfig/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 apreferred_provider:decision line on every resolution where the setting applied. Absent setting, single-family arrays, and explicit overrides route as before.bin/fm-bootstrap.shand the resolver both reject a malformedpreferred_provider(null, empty, uppercase, whitespace) as aCREW_DISPATCH: invalid config/crew-dispatch.jsonerror. Bootstrap validates this field even without a typesafe key.docs/configuration.md,docs/verification/dispatch-resolve.md,AGENTS.md, and thequota-array-dispatchskill document the new field, its fallback and uncertainty rules, and its position in the ranking order. Tests intests/fm-dispatch-resolve.test.shandtests/fm-bootstrap.test.shcover 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.
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
docs/configuration.md:1666- Simplification: the change introduces a new documented top-level fieldpolicy_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 rulewhy, which the resolver never sends (only.rules[].whenis placed in the request). No code readspolicy_why, so documenting it adds schema vocabulary with no behavior behind it and a second definition of the prose-only concept. Recommended remedy: remove thepolicy_whysentence from docs/configuration.md and the header comment, and if a top-level prose case is wanted in the test, flip the existing rulewhytext 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 writespreferred-auth.jsonand :253 passes it asQUOTA_AUTH_FIXTURE, but nothing consumes it: the fake quota-axi only serves--jsonfromQUOTA_AXI_FIXTURE, and the resolver never callsquota-axi auth. The section comment at :188 ('with separate account evidence') overstates what the test proves; account separation is actually exercised through the schema-6accountKeyrows. Also thesame-familyscenario shares the exact case branch and expectations ofwork-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 produceclearunder the existing contract, escalates with reason 'no rankable eligible candidate in preferred provider <p>; uncertainty does not authorize fallback' plus thepreferred_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 produceclearunder the existing contract, escalates with reason 'no rankable eligible candidate in preferred provider <p>; uncertainty does not authorize fallback' plus thepreferred_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'.✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.