Skip to content

fix(skills): assigning a library skill delivers it, and every playbook list follows (#2703) - #2704

Merged
vybe merged 5 commits into
devfrom
feature/2703-skill-assign-delivery
Sep 11, 2026
Merged

vybe merged 5 commits into
devfrom
feature/2703-skill-assign-delivery

Conversation

@dolho

@dolho dolho commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary

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). 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 of remove_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_locked rewrites 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 guessed pending_start). Bounded by SKILL_DELIVERY_BUDGET_SECONDS (20 s) → in_progress with 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 is unassigned_meanwhile, never landed (mirror of removal's still_assigned guard). Start path / sweep / manual Sync unchanged.
  • Router: _deliver_assigned_skills on 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 from skill_service.broadcast_skills_changed on POST/PUT/DELETE/manual inject + background completion + the fleet sweep.

Frontend

  • stores/skills.js per-agent ticks (300 ms debounce) → ChatPanel / PlaybooksPanel refetch /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 flips briefing_state to pending), coalesces a mid-flight event, briefing_hydrated_at stamped. External-client Workspace has no /ws → the / popup open re-validates the active agent if older than 60 s.
  • Library control (AssignedAgents.vue) shows the outcome inline; assign/save carry a 45 s timeout.

MCP: delivery passed through verbatim; descriptions name the vocabulary.

Acceptance criteria

  • Assign on a running agent delivers with honest per-skill status; row never rolled back; 200 — deliver_assigned, test_post_row_survives_a_delivery_that_raises_and_still_answers_200
  • Stopped → pending_start; start path unchanged — test_stopped_agent_is_pending_start_and_never_injects
  • PUT symmetric — test_put_is_symmetric_added_delivered_dropped_removed
  • Surfaces refresh without reload via thin WS — platform sessions; external clients (no /ws) get the on-/-open re-validation as the AC's "equivalent invalidation"
  • Delivered library skill indistinguishable from native — every list reads ~/.claude/skills/, where packages land (verified, no per-surface code)
  • Library control surfaces the outcome inline — skill-delivery-note
  • MCP returns delivery status — skills.test.ts
  • 404/422 preserved and fire before any write — pinned
  • Tests: start-path call (not a fleet force=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 (delivery in the body, broadcast on all four, 404/422 before write), store ticks + debounce, the wording rule, the portal re-validation (no pending flip, mid-flight coalescing, maxAge), MCP passthrough. No source-text assertions.

Verification

pytest  test_2703 + ent183/ent236/ent386/ent237/ent346/183-compat/305/2163  → 321 passed
vitest  full suite                                                         → 121 files / 2668 passed (ratchets incl.)
node --test src/tools/skills.test.ts                                       → 3 passed
vite build                                                                 → ok
import main (test env)                                                     → ws manager wired
/review: 0 critical, 1 informational auto-fixed · /cso --diff: 0 findings (report in docs/security-reports/)

Pre-existing, not this PR: test_ent236_skills_lifecycle.py cannot collect standalone (its own utils.url_validation stub lacks scrub_url_credentials_in_text, since #2056); passes in the combined run.

Design notes (from /autoplan)

  • ent#385's opt-in ?deliver= is superseded — delivery is the default.
  • Deferred to DEBT_INBOX: MCP-layer {self} ∪ permitted gate 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

…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
@dolho dolho added the ui PR touches the frontend UI — triggers Playwright e2e tests label Sep 11, 2026
dolho and others added 3 commits September 11, 2026 13:45
…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
@vybe

vybe commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

merge-train 2026-09-11: on this train, with one mechanical push to your branch — f242e419.

What I pushed and why. The dev merge 5e53d372 auto-resolved tests/registry.json by running the new test_2703_skill_assign_delivery.py entry's keys straight into the test_2694_voice_delta_context.py object (lines 2896–2917): valid JSON, so nothing failed, but JSON's last-key-wins meant the #2694 entry was silently gone — 239 entries where 240 were expected. One },{ boundary restores it; test_2338_journey_catalog still passes (it only checks journeys/, which is why nothing caught it).

Non-blocking notes from validation, yours to take or leave:

  • tests/unit/test_2703_skill_assign_delivery.py router tests are order-sensitive: test_skill_service_user_agent.py:109 swaps sys.modules["services.skill_service"] at collection and the router fixture imports routers.skills lazily, so a subset run of the two files fails 5/25 while the full suite and a solo run pass. Importing routers.skills at module top (or patching mod.broadcast_skills_changed directly) pins it.
  • Two /playbooks readers don't subscribe to agent_skills_changed: ExposedToolsPanel.vue:110 and DashboardPanel.vue:510. The issue's AC names Workspace / chat / Playbooks tab, which all follow; the title's "every playbook list" overstates by two.
  • SkillsPanel.vue:270 renders only delivery; a drop-only PUT whose removal deferred reads as plain "Saved."

Everything else executes the changed path — the four route handlers, deliver_assigned through running/stopped/Docker-None/busy/over-budget, the WS trigger is {type, agent_name} only, MCP types match the backend.

…ign-delivery

# Conflicts:
#	docs/memory/learnings.md

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge-train: batch validated on train/20260911-1635 (#2729)

@vybe
vybe merged commit 639cd9d into dev Sep 11, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ui PR touches the frontend UI — triggers Playwright e2e tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants