fix(tracking): join feedback events with an opaque minted id (#674)

The feedback card asks the user to rate a render, and the four feedback events
could not be joined to the render that prompted them: `studioUsageProperties`
copies only the keys the event registry declares, and none of them declared an
identifier.

The first attempt registered `render_id: 'uuid'` and forwarded `job.id`. That
value is the server render job id, shaped `<project>_2026-11-10_10-00-00`, so
the `uuid` rule rejected every real value and the join stayed broken while the
test passed on a synthetic id. That id also embeds the project id and a
timestamp, which the tracking contract deliberately keeps in the browser, so
widening the rule to `code` was not an option.

`requestStudioFeedback` now mints an opaque uuid for each prompt and forwards
that, so `shown`, `dismissed`, `interview_click` and `feedback` for one render
share a join key that carries nothing about the project. `useRenderQueue` no
longer passes the server job id, the trigger ignores a caller-supplied id, and
`tracking/README.md` describes the retained value as a browser-minted
identifier rather than a render-job id.

Validation:
- `npx vitest run --config studio/vitest.config.ts studio/src/components/feedback/feedbackTrigger.test.ts`
  passes, including a new case asserting a caller-supplied job id is replaced.
- `tests/studio-tracking.test.ts` keeps the four-event uuid assertion green and
  adds the negative case that a `<project>_<timestamp>` id is dropped, which is
  why the rule stays `uuid`.
- `npm run typecheck:studio` and `npm run check` pass.

One pre-existing failure remains in `tests/studio-tracking.test.ts` on Windows
and is unrelated: the audio producer scan matches
`file.endsWith('/audioFxTelemetry.ts')` while the glob returns backslash
separators, so the `audio_fx_*` events are never collected. A clean checkout
gives the same six passing and one failing.
This commit is contained in:
Dery Ferdika
2026-11-23 10:20:19 +07:00
committed by GitHub
parent 19621e86e7
commit deca7fd805
8 changed files with 44 additions and 15 deletions

View File

@@ -233,7 +233,7 @@ export const StudioFeedbackCard = memo(function StudioFeedbackCard() {
rel="noopener noreferrer"
onClick={() => {
const req = stateRef.current.request;
if (req) trackStudioFeedbackInterviewClick({ reason: req.reason });
if (req) trackStudioFeedbackInterviewClick({ reason: req.reason, render_id: req.renderId });
close("sent");
}}
className="h-6 shrink-0 whitespace-nowrap rounded-full border border-border-strong bg-hover px-2.5 text-[11px] leading-6 text-neutral-100 transition-[background-color,border-color,transform] duration-150 ease-out hover:border-text-muted hover:bg-press active:scale-[0.97] motion-reduce:transition-none"

View File

@@ -42,16 +42,28 @@ afterEach(() => {
describe("requestStudioFeedback eligibility", () => {
it("asks on the first eligible request", () => {
const { seen, unsubscribe } = collect();
requestStudioFeedback({ reason: "render_complete", renderId: "r1" });
expect(seen).toEqual([{ reason: "render_complete", renderId: "r1" }]);
requestStudioFeedback({ reason: "render_complete" });
expect(seen).toHaveLength(1);
expect(seen[0].reason).toBe("render_complete");
// The join key is minted here: the server job id embeds the project id and a
// timestamp, so it must never leave the browser.
expect(seen[0].renderId).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
unsubscribe();
});
it("ignores a caller-supplied render id", () => {
const { seen, unsubscribe } = collect();
requestStudioFeedback({ reason: "render_complete", renderId: "demo_2026-11-10_10-00-00" });
expect(seen[0].renderId).not.toBe("demo_2026-11-10_10-00-00");
expect(seen[0].renderId).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/);
unsubscribe();
});
it("asks only once per tab session, however many renders finish", () => {
const { seen, unsubscribe } = collect();
requestStudioFeedback({ reason: "render_complete", renderId: "r1" });
requestStudioFeedback({ reason: "render_complete", renderId: "r2" });
requestStudioFeedback({ reason: "render_failed", renderId: "r3" });
requestStudioFeedback({ reason: "render_complete" });
requestStudioFeedback({ reason: "render_complete" });
requestStudioFeedback({ reason: "render_failed" });
expect(seen).toHaveLength(1);
unsubscribe();
});

View File

@@ -161,7 +161,11 @@ export interface FeedbackContext {
export interface FeedbackRequest {
reason: FeedbackReason;
/** Render job the prompt is about — joins the response to the render event. */
/**
* Opaque identifier for this prompt, minted by the trigger. It joins the feedback
* events for one render without exporting the render job id, which embeds the
* project id and a timestamp. Producers must not set it.
*/
renderId?: string;
/** Failure text shown to the user, sent verbatim so reports are actionable. */
detail?: string;
@@ -248,7 +252,10 @@ export function requestStudioFeedback(request: FeedbackRequest): void {
if (!listener) return;
if (!isEligible(Date.now())) return;
markAskedThisSession();
listener(request);
// Mint the join key here. The render job id is the server record id, which embeds
// the project id and a timestamp, so it must not leave the browser; this opaque id
// still ties the shown, dismissed, interview and rating events of one prompt together.
listener({ ...request, renderId: crypto.randomUUID() });
}
/** Subscribe the card. Single-subscriber by design — there is one card. */

View File

@@ -545,7 +545,6 @@ export function useRenderQueue(
promptedJobIds.current.add(job.id);
requestStudioFeedback({
reason: job.status === "complete" ? "render_complete" : "render_failed",
renderId: job.id,
detail: job.error,
context: {
...settings,

View File

@@ -139,9 +139,10 @@ export function trackStudioFeedbackDismissed(
* The booking link offered after a response. Its own event because the thing
* worth measuring is the click, and a link is otherwise invisible to us.
*/
export function trackStudioFeedbackInterviewClick(ctx: { reason: string }): void {
export function trackStudioFeedbackInterviewClick(ctx: { reason: string; render_id?: string }): void {
trackEvent("studio_feedback_interview_click", {
reason: ctx.reason,
render_id: ctx.render_id,
source: "studio",
});
}

View File

@@ -50,6 +50,16 @@ test('migration keeps signed/fractional measurements and only safe summaries', (
const shadow = studioUsageProperties('sdk_resolver_shadow', studioTrackingFixtures.sdk_resolver_shadow)!;
assert.equal(shadow.element_not_found_count, 1); assert.equal(shadow.value_mismatch_count, 1);
assert.equal(studioUsageProperties('studio_feedback', studioTrackingFixtures.studio_feedback)?.has_comment, true);
// The feedback card sends the render it is about; it must survive the boundary, and a non-uuid must not.
const renderId = '3f2b1c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d';
for (const event of ['studio_feedback_shown', 'studio_feedback_dismissed', 'studio_feedback_interview_click', 'studio_feedback']) {
const fixtureForEvent = studioTrackingFixtures[event as keyof typeof studioTrackingFixtures];
assert.equal(studioUsageProperties(event, { ...fixtureForEvent, render_id: renderId })?.render_id, renderId, event);
assert.equal(studioUsageProperties(event, { ...fixtureForEvent, render_id: 'not-a-render' })?.render_id, undefined, event);
}
// The server render job id embeds the project id and a timestamp, which is why the
// rule stays `uuid` and the prompt mints its own opaque identifier instead.
assert.equal(studioUsageProperties('studio_feedback_shown', { ...studioTrackingFixtures.studio_feedback_shown, render_id: 'demo_2026-11-10_10-00-00' })?.render_id, undefined);
assert.equal(studioUsageProperties('crash', studioTrackingFixtures.crash)?.error_name, 'OtherError');
assert.equal(studioUsageProperties('unknown', {}), null);
assert.equal(studioUsageProperties('playback', { action: 'PRIVATE' }), null);

View File

@@ -545,7 +545,7 @@ backend/data directory. Deterministic coverage lives in
The adapter preserves fixed actions, counts, booleans and safe catalog/control
identifiers. It drops messages/stacks, file paths, selectors, composition/block
names, free-text feedback, breadcrumb text and arbitrary error names. Feedback
retains `has_comment`, rating and fixed question/answer categories; resolver
retains `has_comment`, rating, an opaque browser-minted identifier for the prompt and fixed question/answer categories; resolver
mismatches become per-kind counts, and attempt rollups retain total attempts and
distinct-operation counts without raw JSON keys. Audio parameter numbers are
bounded; string parameters retain only a fixed engine-catalog `value_category` and

View File

@@ -60,11 +60,11 @@ export const studioUsageEvents = {
studio_keyframe_lane_expand: studio({ expanded: 'boolean' }, ['expanded']),
studio_segment_ease_edit: studio({ action: ['open', 'commit'], ease: 'code' }, ['action']),
studio_block_param_commit: studio({ tone: ['saved', 'error', 'confirm'] }, ['tone']),
studio_feedback_shown: studio({ reason: ['render_complete', 'render_failed', 'crash'], source: ['studio'] }, ['reason']),
studio_feedback_dismissed: studio({ reason: ['render_complete', 'render_failed', 'crash'], via: ['close', 'escape', 'timeout'], had_rating: 'boolean', source: ['studio'] }, ['reason', 'via']),
studio_feedback_interview_click: studio({ reason: ['render_complete', 'render_failed', 'crash'], source: ['studio'] }, ['reason']),
studio_feedback_shown: studio({ reason: ['render_complete', 'render_failed', 'crash'], source: ['studio'], render_id: 'uuid' }, ['reason']),
studio_feedback_dismissed: studio({ reason: ['render_complete', 'render_failed', 'crash'], via: ['close', 'escape', 'timeout'], had_rating: 'boolean', source: ['studio'], render_id: 'uuid' }, ['reason', 'via']),
studio_feedback_interview_click: studio({ reason: ['render_complete', 'render_failed', 'crash'], source: ['studio'], render_id: 'uuid' }, ['reason']),
studio_feedback: studio({ reason: ['render_complete', 'render_failed', 'crash'], rating: { min: 0, max: 10 }, rating_scale: { min: 10, max: 10 },
question: ['remove', 'borrow', 'fix', 'detractor', 'failure'], answer_kind: ['preset', 'typed'], has_comment: 'boolean', source: ['studio'] }, ['reason', 'question', 'answer_kind']),
question: ['remove', 'borrow', 'fix', 'detractor', 'failure'], answer_kind: ['preset', 'typed'], has_comment: 'boolean', source: ['studio'], render_id: 'uuid' }, ['reason', 'question', 'answer_kind']),
desktop_cta_eligibility: studio({ eligibility: ['open_in_app', 'download', 'no_app_for_platform'], ...desktop }, ['eligibility']),
desktop_cta_impression: studio({ eligibility: ['open_in_app', 'download', 'no_app_for_platform'], ...desktop }, ['eligibility']),
desktop_cta_guide: studio({ step: ['opened', 'closed', 'download_opened', 'install_detected'], ...desktop }, ['step']),