Repository navigation
fix(skills): assigning a library skill delivers it, and every playbook list follows (#2703) - #2704
Conversation
…k list follows (#2703) Every assign path — `POST /agents/{n}/skills/{s}`, the bulk `PUT`, the Library control (ent#386), MCP `assign_skill_to_agent` / `set_agent_skills` — wrote the `agent_skills` row and stopped. The package reached the agent only on a manual Sync, the next start or the fleet sweep, while unassigning already REMOVED it (ent#236): the write path was asymmetric, and the natural flow — assign from the Library, open the Workspace, type `/` — showed nothing. Once it did land, no open surface refreshed. Backend - `skill_service.deliver_assigned(agent, requested)` — the write-side twin of `remove_skills`. Container state via the tri-state executor read (`docker_utils.agent_container_state_async`, #2196): running → the START-PATH injection (every assigned name, `force=False`) — NOT a named subset, because `_inject_skills_locked` rewrites CLAUDE.md's Platform Skills section to the names of the run it is in, and a subset call on a ten-skill agent would leave it advertising one; stopped/missing → `pending_start`; `None` (Docker could not be asked) → `not_delivered/docker_unavailable`, never a guessed `pending_start`. Bounded by `SKILL_DELIVERY_BUDGET_SECONDS` (20 s): past it the injection continues as a strong-ref background task and the caller gets `in_progress`; the WS trigger fires on completion. Busy is retried once (2 s) — an assign landing while the start path holds the lock would otherwise never be delivered. The report is projected onto the requested names; the row is never rolled back and the HTTP status stays 200. - `_inject_skills_locked(assigned_only=True)` re-reads the rows under the lock and skips names no longer assigned (`unassigned_meanwhile`) — the mirror of removal's `still_assigned` guard, so a PUT-inject on one worker cannot land a package a concurrent DELETE just removed. Opt-in: start path, sweep and manual Sync keep their explicit lists verbatim. - Router: `_deliver_assigned_skills` (twin of `_remove_unassigned_skills`) on POST — both branches, since the Library control's only retry is a re-click — and on the PUT's added names; the PUT is now symmetric. Every listing change fires the thin `agent_skills_changed` WS trigger `{type, agent_name}` (identifiers only — `/ws` is SCOPE_ALL, the #918/ent#305 rule) from `skill_service.broadcast_skills_changed`, which lives in the service so the fleet sweep and the background completion can fire it too (Invariant #1). Frontend - `stores/skills.js` ticks the agent (300 ms debounce); `ChatPanel` and `PlaybooksPanel` watch their agent's tick and refetch `/playbooks` (`ChatInput` takes its list from `ChatPanel`, #2198). `saveAssignments` keeps the PUT's `delivery` report; the Skills tab's Save note says what happened and arms the Sync nudge only when delivery did NOT land (`utils/skillDelivery.js`, one pure wording rule). - `stores/clientPortal.js::revalidateBriefing` — stale-while-revalidate: the card's hint cards and `/` entries stay until the new answer lands; `briefing_state` is never flipped back to `pending` (that re-enters the loading skeleton on a zone with data). An event landing mid-flight marks the agent dirty and re-runs once. `applyBriefings` stamps `briefing_hydrated_at`. - An external client's Workspace has no `/ws` (portal token; the ticket mint is JWT-only), so opening the `/` popup re-validates the active agent's briefing if older than 60 s — the equivalent invalidation, bounded. - The Library control (`AssignedAgents.vue`) renders the delivery outcome inline; assign/save requests carry a 45 s timeout above the server budget. MCP: `assign_skill_to_agent` / `set_agent_skills` pass `delivery` through verbatim and their descriptions name the vocabulary (Invariant #13). Tests execute every path — the service (running/stopped/None/busy/over-budget/ partial), the under-lock re-read, the routes (200 + `delivery`, broadcast on all four, 404/422 before any write), the store ticks and debounce, the wording rule, the portal re-validation (no pending flip, mid-flight coalescing, maxAge), and the MCP passthrough. /cso --diff: 0 findings. Fixes #2703 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015owqMKD5QDjzZrUTF2Joht
…v read (#2703) `SKILL_DELIVERY_BUDGET_SECONDS` read `os.environ` but no compose file forwarded it — an inert knob that read as configurable (the #1056 packaging-gap class /validate-pr §4.9 catches). The #1644 rule applies: a value neither compose forwards is a constant, literally. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015owqMKD5QDjzZrUTF2Joht
Resolve docs/memory/learnings.md (append-only, both kept) and tests/registry.json (both new entries kept). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015owqMKD5QDjzZrUTF2Joht
…to (#2704) — mechanical, per the merge-train note on the PR The dev merge 5e53d37 auto-resolved tests/registry.json by running the new test_2703 entry's keys straight into the test_2694 object: valid JSON, so nothing failed, but last-key-wins meant the #2694 entry was silently gone (239 entries where 240 were expected). One object boundary restores it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_018h3Ku8HFzwPfNR75kf1Gxe
|
merge-train 2026-09-11: on this train, with one mechanical push to your branch — What I pushed and why. The dev merge Non-blocking notes from validation, yours to take or leave:
Everything else executes the changed path — the four route handlers, |
…ign-delivery # Conflicts: # docs/memory/learnings.md
Summary
Every assign path —
POST /agents/{n}/skills/{s}, the bulkPUT, the Library control (ent#386), MCPassign_skill_to_agent/set_agent_skills— wrote theagent_skillsrow and stopped; the package reached the agent only on a manual Sync, the next start, or the fleet sweep, while unassigning already removed it (ent#236). Once it landed, no open surface refreshed. This PR makes assignment deliver, reports honestly, and tells every list.What changes
Backend
skill_service.deliver_assigned— write-side twin ofremove_skills. Tri-state container read (agent_container_state_async, bug: Workspace roster lists agents with no container (DB-sourced roster vs Docker-as-truth) #2196): running → the start-path injection (every assigned name,force=False) — not a named subset, because_inject_skills_lockedrewrites CLAUDE.md's Platform Skills section to the names of the run it is in (a subset call on a 10-skill agent would leave it advertising one); stopped →pending_start;None→not_delivered/docker_unavailable(never a guessedpending_start). Bounded bySKILL_DELIVERY_BUDGET_SECONDS(20 s) →in_progresswith the work kept alive and the WS trigger on completion. Busy → one 2 s retry (the assign-during-start race). Report projected onto the requested names; row never rolled back; HTTP stays 200._inject_skills_locked(assigned_only=True)— opt-in under-lock re-read; a name unassigned between commit and lock isunassigned_meanwhile, never landed (mirror of removal'sstill_assignedguard). Start path / sweep / manual Sync unchanged._deliver_assigned_skillson POST (both branches — the Library control's only retry is a re-click) and on the PUT's added names; PUT is symmetric.agent_skills_changed{type, agent_name}fired fromskill_service.broadcast_skills_changedon POST/PUT/DELETE/manual inject + background completion + the fleet sweep.Frontend
stores/skills.jsper-agent ticks (300 ms debounce) →ChatPanel/PlaybooksPanelrefetch/playbooks. Skills-tab Save note renders the delivery outcome (utils/skillDelivery.js) and arms the Sync nudge only when delivery did NOT land.stores/clientPortal.js::revalidateBriefing— stale-while-revalidate (never flipsbriefing_statetopending), coalesces a mid-flight event,briefing_hydrated_atstamped. External-client Workspace has no/ws→ the/popup open re-validates the active agent if older than 60 s.AssignedAgents.vue) shows the outcome inline; assign/save carry a 45 s timeout.MCP:
deliverypassed through verbatim; descriptions name the vocabulary.Acceptance criteria
deliver_assigned,test_post_row_survives_a_delivery_that_raises_and_still_answers_200pending_start; start path unchanged —test_stopped_agent_is_pending_start_and_never_injectstest_put_is_symmetric_added_delivered_dropped_removed/ws) get the on-/-open re-validation as the AC's "equivalent invalidation"~/.claude/skills/, where packages land (verified, no per-surface code)skill-delivery-noteskills.test.tsforce=True),pending_start, WS on assign+unassign, listener refetch (store tick + portal re-validation)Coverage
Every test executes the changed path — service branches (running / stopped / Docker-
None/ busy-retry / over-budget with the work kept / partial / transport), the under-lock re-read, the routes (deliveryin the body, broadcast on all four, 404/422 before write), store ticks + debounce, the wording rule, the portal re-validation (nopendingflip, mid-flight coalescing,maxAge), MCP passthrough. No source-text assertions.Verification
Pre-existing, not this PR:
test_ent236_skills_lifecycle.pycannot collect standalone (its ownutils.url_validationstub lacksscrub_url_credentials_in_text, since #2056); passes in the combined run.Design notes (from /autoplan)
?deliver=is superseded — delivery is the default.{self} ∪ permittedgate on the skill assign tools (pre-existing reach; this PR removes the Sync step from it).Docs:
feature-flows/skill-injection.md(new Delivery on assign section),skill-assignment.md,architecture/backend.md,learnings.md.Fixes #2703
🤖 Generated with Claude Code
https://claude.ai/code/session_015owqMKD5QDjzZrUTF2Joht