|
| 1 | +#!/usr/bin/env node |
| 2 | +/** |
| 3 | + * Live repro for PR #91373: cron sessions with string agent model configs |
| 4 | + * should inherit agents.defaults.model.fallbacks. |
| 5 | + * |
| 6 | + * Run: pnpm exec tsx scripts/repro/91373-cron-fallback-proof.mjs |
| 7 | + */ |
| 8 | +import { |
| 9 | + resolveCronPreflightCandidates, |
| 10 | + resolveCronFallbacksOverride, |
| 11 | +} from "../../src/cron/isolated-agent/run-fallback-policy.ts"; |
| 12 | + |
| 13 | +function makeJob(payload) { |
| 14 | + return { |
| 15 | + id: "91373-proof", |
| 16 | + name: "Cron fallback inheritance proof", |
| 17 | + schedule: { kind: "cron", expr: "0 9 * * *", tz: "UTC" }, |
| 18 | + sessionTarget: "isolated", |
| 19 | + payload, |
| 20 | + state: {}, |
| 21 | + }; |
| 22 | +} |
| 23 | + |
| 24 | +const cfg = { |
| 25 | + agents: { |
| 26 | + defaults: { |
| 27 | + model: { |
| 28 | + primary: "openai/gpt-5.4", |
| 29 | + fallbacks: ["anthropic/claude-sonnet-4-6", "google/gemini-3-pro"], |
| 30 | + }, |
| 31 | + }, |
| 32 | + list: [ |
| 33 | + { |
| 34 | + id: "main", |
| 35 | + // This is the bug-triggering shape: a plain string model config |
| 36 | + // instead of an object with explicit fallbacks. |
| 37 | + model: "openai/gpt-5.4", |
| 38 | + }, |
| 39 | + ], |
| 40 | + }, |
| 41 | +}; |
| 42 | + |
| 43 | +console.log("=== PR #91373 Cron fallback inheritance proof ===\n"); |
| 44 | + |
| 45 | +console.log("Config shape:"); |
| 46 | +console.log( |
| 47 | + ' agents.defaults.model.fallbacks: ["anthropic/claude-sonnet-4-6", "google/gemini-3-pro"]', |
| 48 | +); |
| 49 | +console.log(' agents.list[0].model: "openai/gpt-5.4" (string, no explicit fallbacks)\n'); |
| 50 | + |
| 51 | +const fallbacksOverride = resolveCronFallbacksOverride({ |
| 52 | + cfg, |
| 53 | + agentId: "main", |
| 54 | + job: makeJob({ kind: "agentTurn", message: "summarize" }), |
| 55 | +}); |
| 56 | + |
| 57 | +console.log( |
| 58 | + "resolveCronFallbacksOverride result:", |
| 59 | + fallbacksOverride === undefined |
| 60 | + ? "undefined (will fall through to defaults)" |
| 61 | + : JSON.stringify(fallbacksOverride), |
| 62 | +); |
| 63 | + |
| 64 | +const candidates = resolveCronPreflightCandidates({ |
| 65 | + cfg, |
| 66 | + agentId: "main", |
| 67 | + provider: "openai", |
| 68 | + model: "gpt-5.4", |
| 69 | + job: makeJob({ kind: "agentTurn", message: "summarize" }), |
| 70 | +}); |
| 71 | + |
| 72 | +console.log("\nresolveCronPreflightCandidates result:"); |
| 73 | +for (const candidate of candidates) { |
| 74 | + console.log(` - ${candidate.provider}/${candidate.model}`); |
| 75 | +} |
| 76 | + |
| 77 | +// The exact resolved model may vary due to alias normalization; the |
| 78 | +// critical behavior is that the candidate chain walks the configured |
| 79 | +// default fallbacks instead of stopping at the primary. |
| 80 | +const hasPrimary = candidates.some((c) => c.provider === "openai" && c.model === "gpt-5.4"); |
| 81 | +const hasAnthropicFallback = candidates.some((c) => c.provider === "anthropic"); |
| 82 | +const hasGoogleFallback = candidates.some((c) => c.provider === "google"); |
| 83 | +const matches = hasPrimary && hasAnthropicFallback && hasGoogleFallback && candidates.length >= 3; |
| 84 | + |
| 85 | +console.log("\nVerification:"); |
| 86 | +console.log(` Primary present: ${hasPrimary}`); |
| 87 | +console.log(` Anthropic fallback present: ${hasAnthropicFallback}`); |
| 88 | +console.log(` Google fallback present: ${hasGoogleFallback}`); |
| 89 | +console.log(` Total candidates: ${candidates.length}`); |
| 90 | +console.log( |
| 91 | + matches ? "\nPASS: fallback chain inherits defaults." : "\nFAIL: fallback chain mismatch.", |
| 92 | +); |
| 93 | +process.exit(matches ? 0 : 1); |
0 commit comments