Files
multica/server/pkg
8d7e6f6a0a perf(server): resolve only the requested skill bundles (#7810)
The daemon resolves one skill bundle per request -- deliberately, so each
download gets its own size-scaled deadline and is cached independently
(GH #4505). ResolveTaskSkillBundles answered each of those by calling
LoadAgentSkillBundles, which reads and hashes EVERY skill the agent has,
then picks the single requested bundle out of the result and discards the
rest.

So the per-request cost scaled with the agent's skill count, and the
number of requests did too. A cold dispatch for an agent with N skills
read the whole skill set N+1 times and computed N*(N+1) bundle hashes to
deliver N bundles. #7689 cut each of those loads from N+1 queries to 2,
which fixed the round-trip count but not the multiplier: the bytes read
from Postgres and the SHA-256 work stayed quadratic, and because the
daemon issues these requests serially, that work lands directly in
prepare latency.

Load only what was asked for:

- ListAgentSkillsByIDs is ListAgentSkills narrowed to a set of ids. The
  junction predicate is unchanged, so it is still the authorization: an
  id the agent does not have enabled returns no row, which the caller
  reports as not-found. It is deliberately NOT workspace-scoped, because
  ListAgentSkills is not either -- a stricter resolve could 404 a ref
  that claim had just advertised, breaking prepare instead of protecting
  it.
- Files come from ListSkillFilesBySkillIDs, the batch query #7689 added,
  for those skills only.
- Builtins resolve by name from the embedded FS and touch no query.
- Only the requested skills are hashed.

For 15 skills / 600KB that takes a cold dispatch from ~9.6MB read and 240
hashes to ~1.2MB and 30, with no schema change, no new index, and no
change to the wire contract: stale-hash still returns the current bundle,
plugin hash pinning still conflicts, response order still follows the
request, and a read failure still fails closed with a 500 rather than a
404 the daemon would treat as permanent.

LoadAgentSkills and the new loader share one assembly helper, so claim
and resolve cannot drift on skill order, per-skill file order, or the nil
file list of a skill with no files.

Tests: an agent with three skills resolving one must issue one scoped
query for one id and never the full ListAgentSkills; a builtin ref must
touch no query at all; request order and ref dedup; and the denials the
old full-set lookup used to provide -- unassigned skill, disabled
assignment, another workspace's skill, unparseable id, a source with no
server-side producer -- plus a scoped-read failure returning 500. Both
the scoped load and the enabled predicate are mutation-verified.

Co-authored-by: J <[email protected]>
Co-authored-by: multica-agent <[email protected]>
2026-08-31 15:14:18 +08:00
..