Skip to content

Commit af53508

Browse files
vanceingallsclaude
andcommitted
fix(cli): keep a set-but-empty router env var breaker-managed (review)
Ownership detection classified ANY defined HF_DE_PARALLEL_ROUTER as a user choice, but both parsers read empty/whitespace as "unset -> default ON". Launching with `HF_DE_PARALLEL_ROUTER=` therefore routed the render (empty parses as ON) while exempting the install from its circuit breaker: after a verified fallback applyDeParallelRouterBreaker() no-op'd, so the install kept retrying the failing router instead of latching off. That is the exact first-fallback protection this PR exists to provide, lost on a documented default path. Ownership now uses the same normalization as the parsers. Also: only announce a trip the breaker could act on. With an explicit user opt-in the breaker is deliberately a no-op, so "now off for this install" was factually wrong — and reprinted on every later revert, since the user's value keeps the router active. Tests: set-but-empty and whitespace both latch off and persist the fired flag (fault-injection verified — restoring the old check fails both); explicit "true" survives a fallback. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent c6df112 commit af53508

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

‎packages/cli/src/commands/render.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,51 @@ describe("renderLocal — DE parallel-router circuit breaker", () => {
815815
expect(process.env.HF_DE_PARALLEL_ROUTER).toBe("false");
816816
});
817817

818+
for (const emptyish of ["", " "]) {
819+
it(`treats a set-but-empty env var (${JSON.stringify(emptyish)}) as default, not a user choice`, async () => {
820+
// Both parsers read empty/whitespace as "unset → default ON", so the
821+
// producer routes. If ownership instead treated any defined value as a
822+
// user choice, the breaker would no-op and this install would keep
823+
// retrying a failing router forever — losing the first-fallback
824+
// protection that is the point of the breaker.
825+
configState.disk = {
826+
telemetryEnabled: true,
827+
deParallelRouterTrialFired: false,
828+
telemetryNoticeShown: true,
829+
};
830+
process.env.HF_DE_PARALLEL_ROUTER = emptyish;
831+
producerState.executeImpl = async (job) => {
832+
job.perfSummary = {
833+
resolution: { width: 100, height: 100 },
834+
drawElement: { parallelRouter: "reverted" },
835+
};
836+
};
837+
await renderLocal("/tmp/project", "/tmp/out.mp4", baseOptions);
838+
expect(process.env.HF_DE_PARALLEL_ROUTER).toBe("false");
839+
expect(configState.writeConfigCalls).toContainEqual(
840+
expect.objectContaining({ deParallelRouterTrialFired: true }),
841+
);
842+
});
843+
}
844+
845+
it("does not override an explicit user opt-in even after a fallback", async () => {
846+
// "Explicit user choice wins in both directions" — the opt-in half.
847+
configState.disk = {
848+
telemetryEnabled: true,
849+
deParallelRouterTrialFired: false,
850+
telemetryNoticeShown: true,
851+
};
852+
process.env.HF_DE_PARALLEL_ROUTER = "true";
853+
producerState.executeImpl = async (job) => {
854+
job.perfSummary = {
855+
resolution: { width: 100, height: 100 },
856+
drawElement: { parallelRouter: "reverted" },
857+
};
858+
};
859+
await renderLocal("/tmp/project", "/tmp/out.mp4", baseOptions);
860+
expect(process.env.HF_DE_PARALLEL_ROUTER).toBe("true");
861+
});
862+
818863
it("keeps the router on for a telemetry opt-out — analytics choice must not cost performance", async () => {
819864
// The old trial refused to arm without recordable telemetry (no point
820865
// running an experiment you can't measure). Now that the router is a

‎packages/cli/src/commands/render.ts‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ import {
6969
writeConfigWithResult,
7070
type HyperframesConfig,
7171
} from "../telemetry/config.js";
72-
import { shouldTrack } from "../telemetry/client.js";
7372
import { renderJobObservabilityTelemetryPayload } from "../telemetry/renderObservability.js";
7473
import { bytesToMb } from "../telemetry/system.js";
7574
import { VERSION } from "../version.js";
@@ -1185,8 +1184,16 @@ function applyDeParallelRouterBreaker(): void {
11851184
function applyDeParallelRouterCircuitBreaker(quiet: boolean): boolean {
11861185
// Latch the user's own choice on first observation, BEFORE the breaker can
11871186
// write the var itself and make the two indistinguishable.
1187+
//
1188+
// Ownership uses the SAME normalization as the two parsers: a set-but-empty
1189+
// (or whitespace) value means "unset / default ON", so it is NOT a user
1190+
// choice and must stay breaker-managed. Treating any defined value as
1191+
// user-managed would let `HF_DE_PARALLEL_ROUTER=` route the render (empty
1192+
// parses as ON) while exempting that install from the breaker — it would
1193+
// keep retrying a failing router forever, losing exactly the first-fallback
1194+
// protection this PR exists to provide (review finding).
11881195
if (!deParallelRouterUserManagedResolved) {
1189-
deParallelRouterUserManaged = process.env.HF_DE_PARALLEL_ROUTER !== undefined;
1196+
deParallelRouterUserManaged = (process.env.HF_DE_PARALLEL_ROUTER ?? "").trim() !== "";
11901197
deParallelRouterUserManagedResolved = true;
11911198
}
11921199
if (deParallelRouterUserManaged) {
@@ -1326,7 +1333,11 @@ function maybeConsumeDeParallelRouterTrial(
13261333
applyDeParallelRouterBreaker();
13271334
}
13281335
writeConfig(config);
1329-
if (fired) reportDeParallelRouterBreakerTrip(quiet);
1336+
// Only announce a trip the breaker could actually act on. With an explicit
1337+
// user opt-in the breaker is a no-op, so "now off for this install" would
1338+
// be false — and would reprint on every subsequent revert, since the user's
1339+
// value keeps the router active (review finding).
1340+
if (fired && !deParallelRouterUserManaged) reportDeParallelRouterBreakerTrip(quiet);
13301341
}
13311342

13321343
/**

0 commit comments

Comments
 (0)