agent-native icon indicating copy to clipboard operation
agent-native copied to clipboard

`changeResource` reaches teammates only for shareable resources; org-only rows have no supported way to notify them

Open renansantos opened this issue 2 weeks ago • 1 comments

Environment: @agent-native/core 0.229.0, main at adfa32747f (2026-11-16).

Scenario

An internal app with one organization. Every domain record (programs, people, partner organizations) belongs to the organization, not to whoever created it, and every member can read all of it. Later, access may be narrowed by app role or by the person assigned to a record, but never by a per-user owner. In .agents/skills/build-an-app/references/data-and-access.md this is the "Organization-only rows" model: org_id only, filtered by the active org in each action.

We want to opt the program page into useDbSync({ realtime: { reason } }) so that a teammate sees a comment or an edit as it happens.

What happens today

  • An action's change event reaches only the actor: actionChangeTarget drops the org when there is a user (packages/core/src/server/action-change-marker-write.ts:35, orgId: owner ? undefined : ...).
  • The documented way to reach others is changeResource on the action (real-time-sync skill). The server then delivers the event to everyone resolveAccess lets read the resource.
  • resolveAccess only knows types registered with registerShareableResource; anything else throws Unknown shareable resource type ... Did you forget registerShareableResource()? (packages/core/src/sharing/registry.ts:242).
  • Registering means adopting the whole sharing model for data that has no owner: ownableColumns() (owner_email, org_id, visibility), a shares table, and the generic sharing actions (share-resource, set-resource-visibility, ...) applying to the type, so any member or the agent could make a record private. The "Team resource" row of data-and-access.md recommends exactly this, but it adds an owner the domain does not have.

The path that works today is the one the Analytics template uses for dashboards (templates/analytics/server/lib/dashboards-store.ts, recordScopedChange): call recordChange({ source: "programs", key: id, orgId }) from the action. It reaches every member of the org (poll.ts, if (event.orgId && orgId && event.orgId === orgId) return "visible"). But:

  • the skill says "Do not publish a parallel per-template event for the same purpose" right after describing changeResource, so it is unclear whether this is supported for action-driven changes;
  • a non-action event cannot use the resources narrowing: it invalidates every useActionQuery on the page unless the app passes actionInvalidatePredicate (packages/core/src/client/use-db-sync.ts, the !hasActionEvent branch);
  • it cannot express a later restriction by role or assignee.

Request

Let a resource type say who can read it without adopting the sharing model, so changeResource works for org-only rows. Two shapes, either would do:

  1. Per-type read resolver for non-shareable types. registerHostAccessResolver(type, resolver) (packages/core/src/sharing/access.ts:914) is already a per-type hook returning a role, null (deny) or undefined. Today it is only consulted inside accessToResource, after requireShareableResource (line 684) and the owner/visibility lookup. If resolveAccess consulted it for a type with no shareable registration (deny when it returns undefined), an org-only app could register canRead by org membership now, and by role or assignee later, and use changeResource as documented.
  2. Minimal: let changeResource return an explicit audience, e.g. { resourceType, resourceId, audience: "org" }, delivered like an org-scoped event while keeping resourceType on the event so resources narrowing still works on the client.

If recordChange({ source, key, orgId }) is the intended answer for org-only data, documenting it in real-time-sync and in the "Organization-only rows" row of data-and-access.md would settle it.

Related: #7892 (draft) reworks change visibility in poll.ts; this request may fit there.

renansantos avatar Nov 16 '26 21:11 renansantos

Thanks — the notification change needs access to the hosted gateway and an isolated session to verify that restricted updates stay private before it can ship.

builder-factory avatar Nov 16 '26 23:11 builder-factory