Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use corroborated routed endpoint in metadata
Co-authored-by: SivaKesava1 <11771739+SivaKesava1@users.noreply.github.com>
  • Loading branch information
Copilot and SivaKesava1 authored Oct 9, 2026
commit 721899ba864b2ef8ca8ca9afc02c8fb2f3d1e42b
14 changes: 14 additions & 0 deletions actions/setup/js/awf_model_routing.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,23 @@ function resolveAWFModelRoutingSelection(reflectData, routingRequired = false, a
const provider = typeof selection.provider === "string" ? selection.provider.trim().toLowerCase() : "";
const wireModel = typeof selection.wire_model === "string" ? selection.wire_model.trim() : "";
const endpoint = typeof selection.endpoint === "string" ? selection.endpoint.trim() : "";
const selectedEndpoint = typeof selection.selected_endpoint === "string" ? selection.selected_endpoint.trim() : endpoint;
if (!["copilot", "github-copilot", "github"].includes(provider) || !wireModel || !endpoint) {
return { selection: null, error: "AWF /reflect returned an incomplete or unsupported Copilot routing selection" };
}
if (endpoint !== selectedEndpoint && allowedEndpoints) {
if (!allowEndpointOverride) {
return { selection: null, error: `AWF /reflect selected endpoint ${endpoint}, which is not supported by this engine` };
}
const routingModel = getAWFRoutingModel(reflectData, wireModel);
const supportedEndpoints = routingModel?.supported_endpoints;
if (routingModel?.candidate_metadata_complete !== true || !Array.isArray(supportedEndpoints) || !supportedEndpoints.every(value => typeof value === "string")) {
return { selection: null, error: `AWF /reflect cannot verify endpoints for model ${wireModel}; candidate metadata is incomplete for engine API ${allowedEndpoints.join(", ")}` };
}
if (!supportedEndpoints.includes(endpoint)) {
return { selection: null, error: `AWF model ${wireModel} does not advertise endpoint ${endpoint}` };
}
}
if (!isModelAvailableInReflectData(wireModel, reflectData, REFLECT_PROVIDER_ALIASES.github)) {
return { selection: null, error: `AWF /reflect selected unavailable Copilot wire model ${wireModel}` };
}
Expand Down
13 changes: 10 additions & 3 deletions actions/setup/js/parse_token_usage.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function hasCorroboratedModelRoutingRequests(requestRecords, wireModel, endpoint
}

function getModelRoutingSelectionFailureCode(error) {
return /none compatible|not supported by this engine/.test(error) ? "unsupported_endpoint" : "invalid_selection";
return /none compatible|not supported by this engine|does not advertise endpoint/.test(error) ? "unsupported_endpoint" : "invalid_selection";
}

/** @returns {any|null} */
Expand Down Expand Up @@ -122,14 +122,21 @@ function resolveModelRoutingOutcome(env = process.env, ghAwDir = env.GH_AW_TMP_D
failure_code: wireModel ? "" : "invalid_selection",
};
const policy = getAWFModelRoutingPolicy(String(env.GH_AW_ENGINE_ID || ""));
const endpointOverride = !policy.endpoints.includes(routing.endpoint);
const selectedAdvisory = advisory?.status === "selected" && (advisory.endpoint !== undefined || advisory.selected_endpoint !== undefined);
const advisoryEndpointOverride = selectedAdvisory && ((typeof advisory.endpoint === "string" && advisory.endpoint !== routing.endpoint) || advisory.selected_endpoint !== routing.endpoint);
const endpointOverride = !policy.endpoints.includes(routing.endpoint) || advisoryEndpointOverride;
if (advisory?.status === "selected" && advisory.wire_model && advisory.wire_model !== wireModel) {
routing = { ...routing, status: "rejected", failure_code: "harness_selection_mismatch", detail: "Harness routing outcome did not match the proxy selection" };
} else if (["failed", "rejected", "pending", "unavailable"].includes(advisory?.status)) {
routing = { ...routing, status: advisory.status, failure_code: advisory.failure_code || routing.failure_code, detail: advisory.detail || routing.detail };
} else if (endpointOverride) {
const checked = resolveAWFModelRoutingSelection({ ...reflectData, routing: { status: "selected", selection: routing } }, true, policy.endpoints, policy.allowEndpointOverride);
const requestedEndpoint = selectedAdvisory && typeof advisory.endpoint === "string" ? advisory.endpoint : routing.endpoint;
const checked = resolveAWFModelRoutingSelection(
{ ...reflectData, routing: { status: "selected", selection: { ...routing, endpoint: requestedEndpoint, selected_endpoint: routing.endpoint } } },
true,
policy.endpoints,
policy.allowEndpointOverride
);
if (checked.error || !checked.selection) {
const detail = checked.error || "AWF /reflect did not return a compatible model-routing selection";
routing = { ...routing, status: "rejected", failure_code: getModelRoutingSelectionFailureCode(detail), detail };
Expand Down
12 changes: 12 additions & 0 deletions actions/setup/js/parse_token_usage.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,18 @@ describe("parse_token_usage", () => {
expect(getEffectiveModelLabel(path.join(tmpDir, "aw_info.json"), "agent", process.env)).toBe("routed: opus50 max");
});

test("records a corroborated pi effective endpoint even when AWF's endpoint is supported", async () => {
setupClaudeRoutingFixture({ engine: "pi" });

await main();

expect(JSON.parse(originalReadFileSync(path.join(tmpDir, "aw_info.json"), "utf8")).model_routing).toMatchObject({
status: "selected",
endpoint: "/v1/messages",
selected_endpoint: "/chat/completions",
});
});

test("attributes a corroborated Claude endpoint override from reflect when no harness outcome exists", async () => {
setupClaudeRoutingFixture({ withOutcome: false });

Expand Down
20 changes: 20 additions & 0 deletions pkg/cli/model_routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,26 @@ func TestApplyAwInfoModelRoutingAddsEndpointMetadata(t *testing.T) {
}
}

func TestApplyAwInfoModelRoutingPrefersAgentArtifactCopy(t *testing.T) {
runDir := t.TempDir()
if err := os.MkdirAll(filepath.Join(runDir, "agent"), 0o700); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(runDir, "aw_info.json"), []byte(`{"model":"agent"}`), 0o600); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(runDir, "agent", "aw_info.json"), []byte(
`{"model":"claude-opus-5","model_routing":{"status":"selected","endpoint":"/v1/messages","selected_endpoint":"/chat/completions"}}`,
), 0o600); err != nil {
t.Fatal(err)
}

result := applyAwInfoModelRouting(&ModelRoutingSummary{Status: "selected", Endpoint: "/chat/completions"}, runDir)
if result.EffectiveEndpoint != "/v1/messages" || result.SelectedEndpoint != "/chat/completions" {
t.Fatalf("agent artifact endpoint metadata was not preferred: %+v", result)
}
}

func TestBuildAuditComparisonCandidateFromLegacySummary(t *testing.T) {
runDir := t.TempDir()
routingDir := filepath.Join(runDir, "sandbox", "firewall", "logs", "api-proxy-logs")
Expand Down
Loading