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

`useActionQuery({ resources })` narrows refetches by resource type only, not by resource id as the changelog says

Open renansantos opened this issue 2 weeks ago • 1 comments

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

What the changelog says: the entry for d7da131 (#7314) in packages/core/CHANGELOG.md: "useActionQuery takes resources and useActionMutation takes resources, so a query tagged for a resource refetches only when a change to that resource lands".

What happens: the match is by type only. changedActionResourceTypes (packages/core/src/client/use-db-sync.ts:578) collects the resourceType of the incoming action events, and actionQueryAffectedByResources (packages/core/src/client/action-query-scope.ts:16) compares query tags against those types. resourceId is never consulted. So with changeResource on an action, an edit to program A refetches the open page of program B in every tab that can read programs. With org-wide visibility, that is every open tab of the organization.

Tagging a query with "program:<id>" does not work around it: the tag never equals the event's resourceType, so the query stops refetching at all.

What apps do instead: filter by id by hand through useDbSync({ actionInvalidatePredicate }), whose second argument carries the events with their resourceId. Content does it with eventChangesOnlyAnotherPage (templates/content/app/hooks/content-action-refresh.ts:343); Design passes its own predicate, shouldInvalidateDesignQueryForSync (templates/design/app/root.tsx:353, #6983).

Request:

  1. Let a query declare the record, not only the type, e.g. resources: ["program:<id>"] next to resources: ["program"]. An event refetches a type:id query when both its resourceType and its resourceId match, and type-only tags keep today's behavior (lists). Should useActionMutation({ resources }) accept the same form for local invalidation?
  2. Whatever is decided for 1, the docs are out of date: packages/core/docs/content/client-data.mdx documents actionInvalidatePredicate as (query: Query) => boolean and "Rarely needed"; the hook passes (query, events), and that second argument is what Content and Design rely on. The page also does not mention resources.

The server side does not need to change: the event is small and only reaches people who can read the record anyway; the cost is in the refetch.

renansantos avatar Nov 16 '26 21:11 renansantos

Thanks — once this fix merges, record-specific changes will refresh matching queries without refreshing unrelated records; it’s in review now.

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