Skip to content

Write HTML. Render video. Built for agents.

feat(studio): emit sdk_cutover_declined with reason + family

Vance Ingalls9ef37e5163d8
diff --git a/packages/studio/src/utils/sdkCutover.ts b/packages/studio/src/utils/sdkCutover.ts
index 4839bc083b..37e170112d 100644
--- a/packages/studio/src/utils/sdkCutover.ts
+++ b/packages/studio/src/utils/sdkCutover.ts
@@ -78,15 +78,16 @@ export async function sdkCutoverPersist(
options?: CutoverOptions,
): Promise<CutoverResult> {
if (!shouldUseSdkCutover(sdkFamilyEnabled("dom"), !!sdkSession, selection.hfId, ops))
- return declinedCutover("ineligible_operation");
- if (!sdkSession) return declinedCutover("session_unavailable");
+ return declinedCutover("ineligible_operation", "dom");
+ if (!sdkSession) return declinedCutover("session_unavailable", "dom");
const hfId = selection.hfId;
- if (!hfId) return declinedCutover("target_unaddressable");
+ if (!hfId) return declinedCutover("target_unaddressable", "dom");
const target = sdkSession.getElement(hfId);
- if (!target) return declinedCutover("target_not_found");
+ if (!target) return declinedCutover("target_not_found", "dom");
if (shouldDeclineTextCutoverForTarget(target, ops))
- return declinedCutover("unsupported_text_target");
- if (wrongCompositionFile(deps, targetPath)) return declinedCutover("wrong_composition_file");
+ return declinedCutover("unsupported_text_target", "dom");
+ if (wrongCompositionFile(deps, targetPath))
+ return declinedCutover("wrong_composition_file", "dom");
const result = await persistSdkCandidateMutation(
sdkSession,
targetPath,
@@ -122,10 +123,11 @@ export async function sdkTimingPersist(
// Dark-launch gate: without this, timing cutover runs whenever an SDK session
// exists (it always does, for shadow/selection) — flipping the flag OFF would
// NOT disable it. Gate here so flag-off routes back to the legacy server path.
- if (!sdkFamilyEnabled("timing")) return declinedCutover("feature_disabled");
- if (!sdkSession) return declinedCutover("session_unavailable");
- if (!sdkSession.getElement(hfId)) return declinedCutover("target_not_found");
- if (wrongCompositionFile(deps, targetPath)) return declinedCutover("wrong_composition_file");
+ if (!sdkFamilyEnabled("timing")) return declinedCutover("feature_disabled", "timing");
+ if (!sdkSession) return declinedCutover("session_unavailable", "timing");
+ if (!sdkSession.getElement(hfId)) return declinedCutover("target_not_found", "timing");
+ if (wrongCompositionFile(deps, targetPath))
+ return declinedCutover("wrong_composition_file", "timing");
try {
const serializedBefore = sdkSession.serialize();
const result = await persistSdkCandidateMutation(
@@ -166,11 +168,12 @@ export async function sdkTimingBatchPersist(
{ targetPath, compositionPath: deps.compositionPath },
);
}
- if (!sdkFamilyEnabled("timing")) return declinedCutover("feature_disabled");
- if (!sdkSession) return declinedCutover("session_unavailable");
- if (wrongCompositionFile(deps, targetPath)) return declinedCutover("wrong_composition_file");
+ if (!sdkFamilyEnabled("timing")) return declinedCutover("feature_disabled", "timing");
+ if (!sdkSession) return declinedCutover("session_unavailable", "timing");
+ if (wrongCompositionFile(deps, targetPath))
+ return declinedCutover("wrong_composition_file", "timing");
if (changes.some((change) => !sdkSession.getElement(change.hfId)))
- return declinedCutover("target_not_found");
+ return declinedCutover("target_not_found", "timing");
try {
const serializedBefore = sdkSession.serialize();
const result = await persistSdkCandidateMutation(
@@ -244,9 +247,9 @@ export function sdkGsapTweenPersist(
// Leading dark-launch gate so flag-off does no SDK touch (getElement) at all —
// matches the other three chokepoints' discipline.
if (!sdkFamilyEnabled("gsap-animation"))
- return Promise.resolve(declinedCutover("feature_disabled"));
+ return Promise.resolve(declinedCutover("feature_disabled", "gsap-animation"));
if (op.kind === "add" && sdkSession && !sdkSession.getElement(op.target))
- return Promise.resolve(declinedCutover("target_not_found"));
+ return Promise.resolve(declinedCutover("target_not_found", "gsap-animation"));
// dispatchGsapOpAndPersist declines on before===after — that catches stale
// animationIds and unsupported shapes (e.g. from-prop on a plain tween), falling
// back to the server path. This subsumes explicit existence guards for set/remove.
@@ -285,9 +288,10 @@ async function dispatchGsapOpAndPersist(
}
// Dark-launch gate (shared chokepoint for every GSAP-op cutover persist):
// flag OFF → explicit decline → caller falls back to the legacy server path.
- if (!sdkFamilyEnabled(family)) return declinedCutover("feature_disabled");
- if (!sdkSession) return declinedCutover("session_unavailable");
- if (wrongCompositionFile(deps, targetPath)) return declinedCutover("wrong_composition_file");
+ if (!sdkFamilyEnabled(family)) return declinedCutover("feature_disabled", family);
+ if (!sdkSession) return declinedCutover("session_unavailable", family);
+ if (wrongCompositionFile(deps, targetPath))
+ return declinedCutover("wrong_composition_file", family);
const session = sdkSession;
// persistSdkCandidateMutation owns the shared per-project/file transaction
// coordinator used by both SDK and legacy GSAP writes.
@@ -559,10 +563,11 @@ export async function sdkDeletePersist(
{ targetPath, compositionPath: deps.compositionPath },
);
// Dark-launch gate: flag OFF → legacy server delete path.
- if (!sdkFamilyEnabled("lifecycle")) return declinedCutover("feature_disabled");
- if (!sdkSession) return declinedCutover("session_unavailable");
- if (!sdkSession.getElement(hfId)) return declinedCutover("target_not_found");
- if (wrongCompositionFile(deps, targetPath)) return declinedCutover("wrong_composition_file");
+ if (!sdkFamilyEnabled("lifecycle")) return declinedCutover("feature_disabled", "lifecycle");
+ if (!sdkSession) return declinedCutover("session_unavailable", "lifecycle");
+ if (!sdkSession.getElement(hfId)) return declinedCutover("target_not_found", "lifecycle");
+ if (wrongCompositionFile(deps, targetPath))
+ return declinedCutover("wrong_composition_file", "lifecycle");
const result = await persistSdkCandidateMutation(
sdkSession,
targetPath,
diff --git a/packages/studio/src/utils/sdkEditTransaction.decline.test.ts b/packages/studio/src/utils/sdkEditTransaction.decline.test.ts
new file mode 100644
index 0000000000..a038b68fee
--- /dev/null
+++ b/packages/studio/src/utils/sdkEditTransaction.decline.test.ts
@@ -0,0 +1,25 @@
+import { describe, expect, it, vi } from "vitest";
+
+vi.mock("./studioTelemetry", () => ({ trackStudioEvent: vi.fn() }));
+
+import { trackStudioEvent } from "./studioTelemetry";
+import { declinedCutover } from "./sdkEditTransaction";
+
+describe("declinedCutover telemetry", () => {
+ it("emits sdk_cutover_declined with reason and family, and returns the declined result", () => {
+ const result = declinedCutover("target_not_found", "timing");
+ expect(result).toEqual({ status: "declined", reason: "target_not_found" });
+ expect(trackStudioEvent).toHaveBeenCalledWith("sdk_cutover_declined", {
+ reason: "target_not_found",
+ family: "timing",
+ });
+ });
+
+ it("emits family:null when the decline happens before a family is known", () => {
+ declinedCutover("no_change");
+ expect(trackStudioEvent).toHaveBeenCalledWith("sdk_cutover_declined", {
+ reason: "no_change",
+ family: null,
+ });
+ });
+});
diff --git a/packages/studio/src/utils/sdkEditTransaction.ts b/packages/studio/src/utils/sdkEditTransaction.ts
index 2ecf9df19b..a8acb2a1fd 100644
--- a/packages/studio/src/utils/sdkEditTransaction.ts
+++ b/packages/studio/src/utils/sdkEditTransaction.ts
@@ -3,6 +3,7 @@ import type { EditHistoryKind } from "./editHistory";
import { hashContent, markSelfWrite } from "../hooks/sdkSelfWriteRegistry";
import { trackStudioEvent } from "./studioTelemetry";
import { serializeStudioFileMutation } from "./studioFileMutationCoordinator";
+import type { StudioSdkOperationFamily } from "./sdkCutoverPolicy";
export type CutoverResult =
| { status: "declined"; reason: string }
@@ -66,7 +67,13 @@ interface CandidateEdit {
after: string;
}
-export function declinedCutover(reason: string): CutoverResult {
+/**
+ * Explicit fall-back to the legacy server path. Emits `sdk_cutover_declined` so
+ * post-flip we can distinguish "SDK took the edit" from "SDK bowed out"; payload
+ * is reason + family only (no hfId / path / content).
+ */
+export function declinedCutover(reason: string, family?: StudioSdkOperationFamily): CutoverResult {
+ trackStudioEvent("sdk_cutover_declined", { reason, family: family ?? null });
return { status: "declined", reason };
}