Skip to content

fix(analytics): token and publish events report with their commit - #698

Merged
allisonmahmood merged 1 commit into
mainfrom
fix/545-publish-events
Oct 15, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
fix/545-publish-events

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

token.minted, patch.created and patch.updated reported in a separate step after their transaction committed. A request interrupted in between, such as a client disconnecting during COMMIT, lost the event. The client's retry with the same publish key then replayed the stored answer and reported nothing, so that publish was never counted.

Fix

These now report the way the lifecycle events already do, with their commit: the report runs in the same uninterruptible span as COMMIT, the work before it stays cancellable, and a refused or rolled-back change reports nothing. No new mechanism:

  • DeviceLogins.poll runs its transaction through withReportedCommit.
  • The publish report moves out of the handler into Patches.record, the step that commits the version, which already runs in withLifecycleTransaction. The event's properties are unchanged, and the handler no longer needs Analytics.
  • @patchy/sql/testing gains interruptDuringCommit(table, change). A deferred trigger makes the commit sleep, and the interrupt lands only once a COMMIT is sleeping in that trigger. One test per emitter (DeviceLogins.test.ts, PatchesApi.test.ts) interrupts there and sees exactly one event; the publish test also checks that the retry with the same key reports nothing. Both tests fail on main.
  • The Patches and Portal suites' lifecycle-event helpers now skip publishes, since direct record calls report them. The API suite's lost-reply test injects its fault into the reporting step, which moved.

Tested by hand

A pnpm dev up team instance, its server pointed at a local PostHog collector (a temporary, uncommitted change to the dev runner's closed env), with a 4-second slow-commit trigger on patch_versions:

  • curl POSTed a publish and was SIGKILLed while the COMMIT slept. The server recorded the request as 499 interrupted, and the collector still received one patch.created for the new patch. Retrying the same payload got the stored 201 and reported no new business event.
  • Killing the patchy CLI the same way did not interrupt the server: the request ran on to 201, so the CLI path never reached this window. It still reported one patch.created.
  • token.minted is covered by its vitest case only.

Hit every surface

  • Vocabulary and product shape: docs/OPERATIONS.md now says when token.minted and publishes report, and that a replay reports nothing. The glossaries already define a patch event as a committed publish.
  • Wire contract, CLI, dev loop, migrations, company resources, served pages, reverse states, repo layout: not touched.

Closes #545

Made by Claude Opus 5.5 in Claude Code, running in T3 Code.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Sol review (GPT 6.1 Sol, xhigh), round 1 on 8256039...fa9362d: one finding, fixed.

  • medium, packages/sql/src/testing.ts: interruptDuringCommit waited for any active COMMIT. A publish commits smaller transactions before recording its version, so the interrupt could land on one of those, and the retry would then be a first publish that passes without proving anything. Fixed in 3f72644: the helper now waits for a COMMIT that is sleeping in its trigger (wait_event = 'PgSleep'). The publish test asserts that the version and its patch.created exist before the retry, and that the retry adds nothing. Both interrupt tests still fail against main's sources.

No correctness, mirrored-surface or over-engineering findings otherwise.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Sol review, round 2 on 8256039...3f72644: the round-1 finding is resolved, and there are no new correctness, mirrored-surface, scope or Effect-convention findings.

@github-actions github-actions Bot added area:server Touches the server area area:docs Touches the docs area area:ui Portal and first-party browser pages, shared rendering and styles size:m 100-500 changed lines labels Oct 15, 2026
token.minted, patch.created and patch.updated reported in a separate step after
their transaction, so an interrupt between the commit and the report lost the
event, and a publish retried with the same key replayed and never counted.

DeviceLogins.poll now runs through withReportedCommit, and Patches.record
reports the publish through withLifecycleTransaction, the step that commits
the version. A test per emitter interrupts during COMMIT and sees one event.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood merged commit 3c1b9df into main Oct 15, 2026
13 checks passed
@allisonmahmood
allisonmahmood deleted the fix/545-publish-events branch October 15, 2026 21:23
allisonmahmood added a commit that referenced this pull request Oct 15, 2026
…699)

Stacked on #698

A patch's sharing changes through the share action, which reports
`patch.shared`, or through an update publish that passes another scope,
which reported only `patch.updated`. A dashboard counting sharing
changes from `patch.shared` missed the second kind.

## Fix

`Patches.record` reports the publish with its commit since #698. It now
also reports `patch.shared` there when an update's scope differs from
the locked row's: `scope`, `previousScope`, `byAdmin: false`, principal
the publisher. A create, whose `patch.created` already carries `scope`,
a same-scope update and a replay report none.

The API suite's publish walk (create as company, then public, the same
scope again, then company) now expects exactly two `patch.shared`
events. The interrupt test's update changes the scope and sees one
`patch.shared`, and its replay adds nothing. Both fail on #698's branch.

## Tested by hand

On the same `pnpm dev up team` instance and local collector as #698,
through the environment's CLI on a patch that started company-scoped:

- `patchy publish launch-plan.html --patch <id> --share public` reported
`patch.updated` (v2) and one `patch.shared` (`company` → `public`,
`byAdmin: false`, principal Ada).
- A publish without `--share` (v3) and one with `--share public` again
(v4) each reported `patch.updated` only.

## Hit every surface

- Vocabulary and product shape: `docs/OPERATIONS.md`'s lifecycle bullet
now says an update publish that passes another scope reports
`patch.shared` too. The catalogue's `patch.shared` shape is unchanged.
- Wire contract, CLI, dev loop, migrations, company resources, served
pages, reverse states, repo layout: not touched.

Closes #544

Made by Claude Opus 5.5 in Claude Code, running in T3 Code.
allisonmahmood added a commit that referenced this pull request Oct 15, 2026
Stacked on #699

`patch.created` and `patch.updated` report the SDK entry points a patch
imports, from the manifest's client-supplied `sdkImports`. The server
filtered them with a pattern, so any `patchy/…` path, such as
`patchy/customer-jane-doe/private-project`, still reached PostHog.

## Fix

`SDK_ENTRY_POINTS` in `@patchy/api`, beside `Manifest`, is now the one
closed list: the page entries, the server entries and `patchy/client`,
which only the generated client imports. The CLI's import check
(`pageImports.ts`) builds from it instead of keeping its own two arrays,
so what the CLI accepts is unchanged. The publish event keeps only
listed entries. Anything else is dropped from analytics only: the
publish is never rejected and the manifest is stored as sent.

The tier 2 publish test's manifest now carries
`patchy/customer-jane-doe/private-project` next to the existing junk
entry, and the event still reports only `patchy/server`. The test fails
under the old pattern.

## Tested by hand

On the same instance and collector as #698, I POSTed a tier 0 publish
whose `sdkImports` was `["patchy/customer-jane-doe/private-project",
"patchy/csv", "patchy/internal/secret-roadmap", "Jane
<[email protected]>", "patchy/preact"]`. It answered `201`, its
`patch.created` carried `sdkImports: ["patchy/csv", "patchy/preact"]`,
and none of the three bogus strings appeared anywhere in what the
collector received.

## Hit every surface

- Wire contract: `packages/api` is the source, and the CLI's import
check and the server's event filter both read it. No request or response
shape or description changed, so `docs/API.md` is unchanged; the api
suite, which checks it is current, passes.
- CLI: no command, flag or exit code changed. The README's list of
allowed imports is still accurate; ADR-0004 and the skills are
unaffected.
- Vocabulary: the analytics catalogue's `sdkImports` and
`docs/OPERATIONS.md`'s business-events section name the list.
- Dev loop, migrations, company resources, served pages, reverse states,
repo layout: not touched.

Closes #542

Made by Claude Opus 5.5 in Claude Code, running in T3 Code.
allisonmahmood added a commit that referenced this pull request Oct 16, 2026
…u when they fail (#720)

Release 13's What's new entry, written from `c9b8fc4`, ahead of
deploying it. `patchy` and `CURRENT_RELEASE` move to `0.13.0`, so CLIs
and patch repos installed before this deploy are told to upgrade.

| Change | PRs |
| --- | --- |
| New: Home puts the patches you use first | #713, #716, #719 |
| New: Every patch in one list | #715 |
| Improved: Each patch's page leads with Open | #717 |
| New: See when your tools are failing | #718 |
| Fixed: Everyone has a name | #687 |
| Improved: Your company's look is easier to get right | #697, #696,
#703, #688 |
| Improved: Forms follow your look's error states | #691, #692 |
| Improved: Clearer answers when a publish goes wrong | #686, #685, #689
|
| Fixed: Your agent's Patchy commands are steadier | #695, #704, #680,
#681 |
| Behind the scenes: stricter checks on static pages and tools' database
requests; malformed requests are logged | #682, #693, #683 |
| Behind the scenes: usage numbers count every publish, sharing change
and restore | #698, #699, #700, #690 |
| Test and tooling only, no line | #705, #702, #701, #694, #684, #607 |

Made by Claude Opus 5.5 in Claude Code, running in T3 Code.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Touches the docs area area:server Touches the server area area:ui Portal and first-party browser pages, shared rendering and styles size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant