Skip to content

Record when Magic Compose asks questions, and how they were answered - #575

Merged
richshaw merged 13 commits into
claude/pensive-thompson-quytut-2-serverfrom
claude/pensive-thompson-quytut-3-telemetry
Oct 27, 2026
Merged

richshaw merged 13 commits into
claude/pensive-thompson-quytut-2-serverfrom
claude/pensive-thompson-quytut-3-telemetry

Conversation

@richshaw

@richshaw richshaw commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

Part of #570, the third of five stacked PRs. It's based on #573 (the questions reply and the follow-up request). Dormant until #577 makes the prompt ask.

The problem

Nothing records how Magic Compose's questions round goes. Without that, nobody can tell whether asking helps, or how often organizers leave at the questions screen.

The fix

Two activity events, both written by POST /api/signups/magic-compose.

event payload when
magic_compose.asked { topics, options } A first request the model answered with questions, unless the organizer had already left.
magic_compose.answered { answered, skipped, picked, added, limits, placeholders, retried, gaveUp } Once a request carrying the organizer's answers has ended, however it ended: a draft, a refusal, an error or asked_again. One row per request the quota was charged for.

In magic_compose.answered:

  • answered and skipped list which of what and when were answered or left blank, for the ones asked. "How many" has no blank state, since an empty box means no limit.
  • picked and added count the model's options picked and the organizer's own items. The browser reports these, and the server can't check them; docs/telemetry.md says so.
  • limits is how many items got a number of people.
  • placeholders is true when the organizer pressed Draft with placeholders with nothing answered. (From Show Magic Compose's questions, and say what a draft needs #576 on, the button sends the answers when there are any, so those requests read false.)
  • retried is true when the model asked again and the route made its one retry (one more call to the AI).
  • gaveUp is true when the retry asked too, or there was no time for one. An organizer who had already left isn't counted as given up on.

How the rows are written:

  • Both rows have no signup, and the organizer's default workspace. They're written best effort, outside any transaction, as signup.draft_started is.
  • Payloads hold codes and counts only. They never hold the description, the options or the answers, and a unit test checks that.
  • The answered write runs after the handler has its response. Every ending, including a thrown error, writes exactly one row.
  • event_type is plain text, so there's no migration.
  • "Asked, then left at the questions screen" is an asked with no answered after it. There's no event for leaving.
  • Record link copies, failed AI drafts and refused publishes #525's magic_compose.failed (now on main) still counts failed drafts, with asked_again added in Let Magic Compose answer with questions, and draft from the answers #573. The two events here count the questions round. docs/telemetry.md points one section at the other.

Docs

Tests

  • telemetry.test.ts: the payload for each kind of answer, and that no text gets into it.

  • route.questions.db.test.ts checks the row written by each path:

    • a draft, a refusal, an AI error;
    • questions and then a draft;
    • questions twice;
    • no time for the retry (retried: false, gaveUp: true);
    • an organizer who had left (gaveUp: false, and no asked row);
    • placeholders.

    It also checks that a first-call draft, answers rejected before the quota, and a follow-up over the hourly limit write nothing.

  • pnpm lint && pnpm typecheck && pnpm knip && pnpm test (1897) and pnpm test:db src/app/api/signups/magic-compose pass.

Tophat

This branch on its own, against a local fake OpenAI-compatible endpoint, through the API. Six requests wrote exactly these rows:

  • an asked for "Bake sale";
  • one answered each for:
    • answers that drafted;
    • a model that asked twice (retried and gaveUp);
    • Draft with placeholders.
  • nothing for bad answers;
  • nothing for an organizer who left mid-request.

Reviews

A second review (/code-review), fixed in f8b6857:

  • an organizer who had left still got an asked row, inflating the "left at the questions screen" count;
  • a disconnect counted as gaveUp;
  • a stale comment.

Left as is:

  • writing the answered row after the handler (it can't throw there: activityActor only refuses non-organizers, whom the route has already turned away);
  • telemetry using the default workspace with no policy guard (the same as signup.draft_started and Record link copies, failed AI drafts and refused publishes #525's events);
  • no signupId on answered (it would put telemetry into the signup's own activity history).

main (through #683) is merged in.

Before merging

The separate analytics reader's allow-list needs the two event names and their payload keys: topics, options, answered, skipped, picked, added, limits, placeholders, retried and gaveUp.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UW9ZpEu4MWkeqTv2Qe14ks

So an operator can see whether the questions help: how often drafting
asks, how often organizers answer instead of leaving, and how often the
AI asks again anyway. Two activity events, written with
recordActivityBestEffort outside any transaction, with no signup and the
organizer's default workspace, as the other organizer telemetry is:

- magic_compose.asked { topics, options }: a first call the model
  answered with questions.
- magic_compose.answered { answered, skipped, picked, added, limits,
  placeholders, retried, gaveUp }: one row per follow-up the quota was
  charged for, written once the request has ended, however it ended. The
  route sets the write up once the quota is charged and runs it after
  the handler has its response, so a draft, a refusal, asked_again, an AI
  error and a thrown error each leave exactly one row, without moving the
  route's existing code.

Payloads hold codes and counts only, never the description, the options
or the answers; answeredPayload is a pure function with tests that say
so. The helpers take (db, actor, workspaceId, ...) like recordFailed on
the open funnel-telemetry PR, so the two merge without reshaping.

event_type is plain text, so there is nothing to migrate. The privacy
page's activity-log line now says the log records whether AI drafting
asked questions and how they were answered, in counts only;
docs/telemetry.md lists both events and notes that picked and added are
the browser's claim.

Part of #570.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UW9ZpEu4MWkeqTv2Qe14ks
retried now means the route made its one retry: a retry skipped for time
or because the organizer left records retried: false, gaveUp: true, so
counting retried counts extra calls to the AI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UW9ZpEu4MWkeqTv2Qe14ks
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UW9ZpEu4MWkeqTv2Qe14ks
Second review of this PR:

- A first call the organizer had already left (closed the tab while the
  model worked) still wrote magic_compose.asked, though nobody saw the
  questions. Those rows read as "asked, then left the questions
  screen", the very drop-off this event is for. A request that's been
  aborted now records no asked row.
- gaveUp meant "the organizer was told the AI couldn't draft from their
  answers", but a follow-up that asked again after the organizer had
  left set it too. It's now false then; running out of time for the
  retry still sets it.
- A comment on the refusal branch said it writes no activity; a
  follow-up's answered row is still written there.

docs/telemetry.md says both.

Part of #570.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UW9ZpEu4MWkeqTv2Qe14ks
Brings in #525 and #526 (through the server branch). The two
questions-round events sit after #525's in ACTIVITY_EVENTS; the privacy
page's activity-log line names both sets; docs/telemetry.md points the
Magic Compose section at #525's failed event. The tests of each read only
their own rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UW9ZpEu4MWkeqTv2Qe14ks
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UW9ZpEu4MWkeqTv2Qe14ks
@richshaw
richshaw added this pull request to stack #618 October 25, 2026 17:21
Through the server branch, which resolved the route's import conflict.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UW9ZpEu4MWkeqTv2Qe14ks
…he 3-telemetry branch

Through the server branch. The privacy page's activity-log line now
names both the share panel's events (from main) and the questions
round's counts (this branch). CHANGELOG keeps both new lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UW9ZpEu4MWkeqTv2Qe14ks
Through the server branch. No conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UW9ZpEu4MWkeqTv2Qe14ks
Through the server branch. CHANGELOG keeps this branch's line and
main's updated share-panel line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UW9ZpEu4MWkeqTv2Qe14ks
Brings in the first call's retry for questions of the wrong shape, the
new asked-again wording and the privacy page's date. The follow-up's
retry check is now the shared worthRetrying, with this branch's
outcome.gaveUp kept inside it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UW9ZpEu4MWkeqTv2Qe14ks
Through the server branch. No conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UW9ZpEu4MWkeqTv2Qe14ks
@richshaw
richshaw merged commit e79d264 into main Oct 27, 2026
7 checks passed
@richshaw
richshaw deleted the claude/pensive-thompson-quytut-3-telemetry branch October 27, 2026 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants