Skip to content

fix(analytics): token and publish events survive a disconnect after commit #545

Closed

Description

@allisonmahmood

Problem

The lifecycle and onboarding events report with their commit: an interrupt that arrives during or right after COMMIT still reports a committed change (withLifecycleTransaction in Patches.ts, withReportedCommit in @patchy/sql, from #541 and #539). Three older emitters don't. They report in a separate step after their transaction, so a request interrupted between the commit and the report, such as a client disconnecting at that moment, loses the event:

  • token.minted, in DeviceLogins.poll (packages/auth/src/DeviceLogins.ts);
  • patch.created and patch.updated, in the publish handler (packages/patches/src/PatchesApi.ts). A retry with the same publish key replays the stored response and reports nothing, so that publish is never counted.

The window is small and costs one analytics event, never a wrong one.

Do

  • Give these emitters the same guarantee: the report runs with the commit, the work before it stays cancellable, and a refused or rolled-back change reports nothing. Reuse withReportedCommit or the existing mask pattern rather than adding a third mechanism. Publish records across more than one step, so put the report at the step that commits the version.
  • A test per emitter that interrupts during COMMIT and still sees exactly one event, modelled on packages/sql/src/sql.test.ts's slow-commit trigger.

Done when

Every business event's report survives an interrupt that arrives after its change committed.

Filed by Claude Opus 5.5 via Claude Code for Allison.

Activity

  1. added
    enhancement
    ready-for-agent
    area:server
    on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:serverenhancementready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions