Repository navigation
feat(patches): every patch lifecycle change is a business event, from every path - #541
Conversation
Codex review (GPT 6.1 Sol, high)Round 1 verdict: not safe to merge. All three findings are addressed in 291e373.
|
Codex review (GPT 6.1 Sol, high), round 2Verdict: safe to merge. No remaining findings.
Sol also ran an isolated Effect transaction and interruption check, which passed. |
Codex review (GPT 6.1 Sol, high), round 3CI fix and verdict. 6de716a marks the injected stall Verdict: safe to merge. Sol reports no findings:
Locally, Content.test passes (21/21) and |
#541's lifecycle transaction already queues patch events, runs only the work interruptibly and reports them with the commit. Deactivation and reactivation now queue their user event there through Patches.reportOnCommit, replacing the page's own mask and flag and the explicit cancellable advisory wait, which its restore already covers. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… every path The Patches service reports patch.shared, patch.retired, patch.restored, patch.rolled_back, patch.reassigned and patch.deleted itself, so the CLI, the portal and member deactivation or reactivation all report them. Events queue beside the wake notices and leave only after the outermost lifecycle transaction commits; a refused, rolled-back or no-op change reports nothing. PatchesApi no longer reports patch.deleted on its own. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… is interrupted Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ge to report Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…s a transaction body is Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
6de716a to
0d4d6fa
Compare
#541's lifecycle transaction already queues patch events, runs only the work interruptibly and reports them with the commit. Deactivation and reactivation now queue their user event there through Patches.reportOnCommit, replacing the page's own mask and flag and the explicit cancellable advisory wait, which its restore already covers. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The product dashboard can't see onboarding. Creating or joining a company, invitations, role changes, deactivation and connections sent no business event. The only trace of `POST /join` was an anonymous request event that couldn't tell creating a company from accepting an invitation. Each of those actions now reports one business event from the catalogue, after its change commits. A refused or rolled-back action reports nothing. | Event | Emitted by | Principal | | --- | --- | --- | | `company.created`, `user.joined` (`via`, `role`, `inviteId` for invitations) | `Join.ts` (Companies) | the new user's own id | | `invite.sent` (`role`, `emailed`), `invite.resent` (`emailed`), `invite.revoked` | `CompanyPage.ts` (Companies) | the admin | | `user.role_changed` (`userId`, `role`) | `CompanyPage.ts` | the admin | | `user.deactivated`, `user.reactivated` (`userId`) | `UserLifecyclePage.ts` (Portal), queued with #541's patch events and reported when the `withDependencyLock` transaction commits | the admin | | `connection.connected`, `connection.deleted` (`connectionId`, `integration`) | `ConnectionPage.ts` (Integrations) | the admin | - **Where events fire.** The page modules that call the services emit, not the services themselves. `Companies.create`, `consumeInvite` and `Invitations.*` each commit their own transaction before returning, so the page emits after commit. The only dependency change is `@patchy/companies → @patchy/analytics`. A browser disconnect can't drop the event of a change that committed, even one that lands during COMMIT. Invitations already deliver uninterruptibly, so each one and its event share one uninterruptible region. Join, role changes and connection connect/delete use a new `withReportedCommit` in `@patchy/sql`. It opens the outermost transaction with only the change cancellable, lock waits included, and runs the report with the commit. Connections pass their report to `ConnectionStore.connect`/`delete`, which apply it around their own transaction, so discovery's audit rows stay outside it. Deactivation and reactivation use #541's mechanism instead. `withLifecycleTransaction` queues lifecycle events, runs only the work interruptibly, and reports the events with its commit. The page queues its user event in the same batch through a new `Patches.reportOnCommit`, so a committed deactivation reports `user.deactivated` and each `patch.retired` once, and a rolled-back or cancelled one reports none of them. The dependency lock serializes these commits, so a repeated action is refused and reports nothing. - **`Users.setRole`** now returns `{ user, changed }`. A stale form asking for a role the user already has changes nothing and reports nothing. - **`ConnectionStore.delete`** now returns the connection it deleted, read under its row lock, so the event can name the integration. - **Properties.** Only ids, roles, booleans and the integration kind (`postgres`). - **Mail failures.** `emailed` is false whenever no email went out. That includes a resend where Clerk wouldn't revoke the old link, so the invitation is unchanged; the event then reads as a resend attempt that didn't email. A revoke whose Clerk link couldn't be revoked still reports `invite.revoked`, because Patchy revoked it. - **Tests.** The existing page tests now record events. They assert one event per success, the new user as principal on join, and nothing on refusal: member, origin, foreign company, invalid form, duplicate invite, last admin, a stale same-role change, a repeated deactivation, a concurrent change, a deletion refused because a patch uses the connection, and the injected rollback. One test interrupts an invitation request during delivery and checks that the committed invitation is still reported. Another disconnects a deactivation blocked on a held company lock and checks that the server stops waiting, rolls back and reports nothing. A third pauses wake publication after a deactivation commits, disconnects, and checks that `user.deactivated` and the `patch.retired` each follow once. A Patches test covers `reportOnCommit`: rolled back reports nothing, committed reports once, outside the lock dies. SQL tests cover `withReportedCommit`: a deferred trigger makes COMMIT slow, an interrupt during it still reports, a change cancelled before commit reports nothing, and inside a caller's transaction it leaves reporting to that caller. Hit every surface: vocabulary applied. `packages/sql/CONTEXT.md` gains **Reported commit**. `CONTEXT-MAP.md`'s Analytics relationship now names Companies and Integrations, and says Portal's lifecycle events report through Patches; and `docs/OPERATIONS.md` lists the new events. I also made one minimal edit outside this ticket's files: the intro line of `packages/analytics/CONTEXT.md` (owned by #534) listed only Patches and Auth as the contexts that decide business moments, so I added the three new ones. In #536's area I added one method to the Patches service, `reportOnCommit`, which pushes onto #541's pending-events queue. The wire contract, CLI, dev loop, migrations, company resources, served pages and repo layout are untouched. Privacy page (#537): the new events carry company, user, invitation and connection ids, roles, whether an invitation email went out, and the integration kind. They never carry names, email addresses or connection strings. Closes #535 Made by Claude Opus 5.5 via Claude Code in T3 Code. --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
…ease (#556) What's new for this deploy, plus the history since the first production deploy. The thin entries #555 seeded by hand are rewritten from what each deploy actually shipped. This is the first run of `AGENTS.md` › Deploying: a fresh subagent gathered and wrote these releases, and I checked them against the PRs. **Release 4 (this deploy, `4a928f7..8697463`)** - New: **See what's new in Patchy** (#555) **Release 3 (2026-10-06, `aed1454..4a928f7`)** - Fixed: **Creating a company explains a handle it can't use** (#553) **Release 2 (2026-10-05, `48153dc..aed1454`)** - Behind the scenes: key moments are recorded, identifying people by id, never by name or email address (#538, #539, #541) - Behind the scenes: the patchy command reports its version, command and coding agent (#540) **Release 1 (2026-10-05, first production deploy, `48153dc`)** - Behind the scenes: Patchy Cloud's first release went live Made by Claude Opus 5.5 via Claude Code in T3 Code. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Only a CLI delete reported
patch.deleted. A portal delete made the same change and reported nothing, so deletions were undercounted. Sharing, retiring, restoring, rolling back and reassigning reported nothing from any path, and retiring or restoring a member's patches during deactivation or reactivation left no trace.The Patches service now reports every lifecycle change itself, so each path that makes a change reports it: the CLI's API, the portal's patch actions and the deactivation and reactivation bulk path.
patch.shared(scope,previousScope),patch.retired,patch.restored,patch.rolled_back(versionNumber,fromVersionNumber) andpatch.reassigned(fromUserId;ownerUserIdis the new owner) joinpatch.deletedin the catalogue. Every event exceptpatch.reassignedcarriesbyAdmin, which comes from the actor. Only admins reassign, so that event needs nobyAdmin. All properties are ids, version numbers and states.withDependencyLockaround a deactivation, which is what makes a rolled-back deactivation report nothing. Events are reported when the transaction exits, so a caller interrupted just after commit still reports them.PatchesApi's ownpatch.deletedcall is gone, so an API delete reports once.Patches.layernow needsAnalytics. The server provides it below the services, and the test layers that build Patches providelayerNoopor a recording layer.@patchy/sdkgains@patchy/analyticsas a dev dependency for its tests.Tests cover each event on the service, the API path (share, retire, restore, rollback, delete, plus owner refusals) and the portal (scope, rollback, restore, retire and delete as owner and as admin, reassign, a refused delete). The deactivation retire and reactivation restore are tested in bulk. Rollbacks are tested two ways: a nested
withDependencyLockthat fails, and a deactivation whose second patch refuses after the first was retired. Makingreportfire immediately fails both.Hit every surface:
Analytics.ts, and thedocs/OPERATIONS.md"Business events" list gains a "Patch lifecycle" line.Touches outside #536's area, kept minimal:
Analytics.test.ts(feat(analytics): every business event names its company #534) addsbyAdminto itspatch.deletedfixture.PortalPages.test.tsgains a recording analytics layer, which feat(analytics): onboarding moments are business events #535's user events may also want.Closes #536
Made by Claude Opus 5.5 via Claude Code in T3 Code.