Repository navigation
feat(ticket): snapshot the owning organization on client tickets and scope Fae reads by it CU-17tkuw60wmg - #2857
Conversation
🦩 Flamingo Code Review✅ Tests and checks passed on this commit (2 lanes). ✅ No findings on the current head. Advisory: findings do not block the merge.
✅ What this change does well
10 possible problems checked and ruled out, 1 after reading more of the repository
Review again. New commits are not reviewed until you ask:
Or comment 🧪 Tests and mutationTests per lane
Mutation testingThis build has no PIT plugin, so each module is mutated from the command line with pit-adhoc.sh, changing nothing in the repository; no production class changed in openframe-external-api-service-core: nothing there to mutate.
New code, its covering tests and the result
The covering tests by name (32 methods)
17 mutants on lines this change added are not caught (4 survived, 13 with no test reaching them): each is annotated on its line in the 1 gap (not tested here):
Started 2026-11-13 12:06 UTC · updated 2026-11-13 12:09 UTC · workflow run |
…nt tickets and scope Fae reads by it A device re-enrolled under another customer keeps its machineId, and every Fae read was scoped by owner.machineId alone, so the new customer saw the previous customer's tickets. ClientTicketOwner now records the organization the machine belonged to at creation; ClientOwnerScope (machine + current organization) decides what an AGENT may see and is applied to the ticket list query and the single ticket reads. A snapshot that is still missing stays visible until the new Mongock unit backfills it from the ticket's organization or the machine's current one.
…neId for deliveries without a principal
… previous customer through the machines cascade MachineEvent now carries the machine's organization, so a reinstall under another customer publishes the change. MachineOnClientTicketsProjection, registered on the machines spec and run by the shared stream like its siblings, moves every client ticket of the machine whose owner snapshot names another customer to the tenant's ARCHIVED status; a machine without an organization or a tenant without an ARCHIVED status archives nothing. MachineWriter publishes organizationId writes like the other event fields. The ticket owner backfill moves to openframe-saas-tenant with the other change units.
…e, scope as a class, reconcile skips unarchivable tenants Review follow-ups: an AGENT token without a machineId is refused instead of matching every owner without one; ClientOwnerScope is a Lombok class and the resolver exposes isOwnerScoped/scopeOf instead of an Optional; MachineOnClientTicketsProjection.reconcile ignores tenants without an ARCHIVED status, which apply could never repair; TicketProjectionRepository gets its query tests.
9ad350c to
0979803
Compare
…ent enrollment A reinstall under another customer stamps Machine.organizationAssignedAt; the owner scope then hides client tickets created before it, so a device that comes back to a customer starts clean.
…-organization # Conflicts: # openframe-api-lib/src/main/java/com/openframe/api/service/ticket/TicketService.java
…-organization # Conflicts: # openframe-data-mongo-sync/src/main/java/com/openframe/data/repository/device/publishing/MachineEvent.java
ClickUp task: CU-17tkuw60wmg BE: hide a device's earlier tickets and chats from Fae after it moves to another customer
Why
A device moves to another customer by re-running the install command with the new
--orgId. The agent calls/reinstallwith its saved machineId and the backend only rewritesmachine.organizationId. Every Fae (AGENT token) read of tickets was scoped byowner.machineIdalone, so the device under customer B kept listing the tickets it opened under customer A.What
Owner organization snapshot (hide).
ClientTicketOwner.organizationId: the organization the machine belonged to when the ticket was created. Written once, never updated, so admin changes toticket.organizationIdcannot hide a ticket from its own device.ClientOwnerScope(machine + its current organization) is the single rule: an AGENT sees an item when the owner machine matches and the owner's organization snapshot equals the machine's current organization. A missing snapshot (pre-backfill) stays visible, and so does everything when the machine has no organization.ClientOwnerScopeResolver(api-lib) builds the scope for AGENT principals, and by machineId for deliveries without a principal, fromMachineRepositoryon every call: a cached organization would keep leaking for the cache's lifetime after the move.TicketService: the list query getsowner.organizationId $in [current, null];ticket(id)and ticket-by-number apply the predicate after the lookup, so a hidden ticket is not found. Client-created tickets stamp the owner from the loaded machine.Machines cascade (archive).
MachineEvent.organizationId: a reinstall under another customer publishes the change (andMachineWriterpublishesorganizationIdwrites like the other event fields).MachineOnClientTicketsProjection(machine-on-client-tickets), registered onMachineAggregateSpecand run by the shared stream like its siblings: moves every client ticket of the machine whose owner snapshot names another customer to the tenant's ARCHIVED status (TicketProjectionRepository,$nin [null, current], tenant-scoped). A machine without an organization or a tenant without an ARCHIVED status archives nothing. Reconcile reports open client tickets whose snapshot differs from the machine's current organization.Moving the device back to customer A makes A's tickets visible again (the rule is equality with the current organization, not a time cut-off); tickets archived by the projection stay archived.
The ticket owner backfill lives in
openframe-saas-tenantwith the other change units. Dialogs follow inopenframe-saas-lib(owner snapshot +machine-on-client-dialogsprojection) andopenframe-saas-tenant(every AGENT access point in the AI agent, the client notification gate, both backfills).Tests
ClientOwnerScopeTest,ClientOwnerScopeResolverTest,TicketServiceClientOwnerScopeTest, owner-scope cases inCustomTicketRepositoryFilterTest,MachineOnClientTicketsProjectionTest,MachineAggregateSpecTest,MachineWriterTest(event paths); existingTicketService*Testadjusted for the new dependency.Enrollment cut-off
A device that comes back to a customer it belonged to before must look like a new device, so the customer snapshot alone is not enough.
Machine.organizationAssignedAtis set on registration and on a reinstall under another customer (same-customer reinstalls keep it; one field-level write together with the other reinstall fields).ClientOwnerScopecarries it andallows(owner, createdAt)hides every client item created before it; the ticket list query merges it with the caller'screatedAtFrominto onecreatedAtbound. Null cut-off (legacy machines) keeps the old behaviour; an item withoutcreatedAtis hidden when a cut-off exists. The field is not part ofMachineEvent, so the archive projections still react to the organization change only.Change-Set: feat-fae-client-owner-organization
Change set
flamingo-stack/openframe-oss-lib#2857: these pull requests are one change, reviewed together.Linked work
Linked by the
Depends-On/Change-Setlines in these descriptions; this block is maintained by the hub.