fix(skill): persist skill registration to database after add #640

Merged
freemo merged 1 commit from fix/skill-add-not-registering into master 2026-03-08 22:06:15 +00:00
Owner

Summary

Fixes #620agents skill add followed by agents skill list now correctly shows the added skill.

Closes #620

Root Cause

The CLI skill.py used SkillService which stored skills in a pure in-memory OrderedDict. Each CLI process created a new empty SkillService, so data added during skill add was lost when the process exited.

Meanwhile, the codebase already had:

  • SkillModel — full SQLAlchemy model for the skills table (with SkillItemModel children)
  • SkillRepository — database-backed CRUD with session-factory pattern
  • SkillRegistryService — service layer wrapping the repository
  • Alembic migrations (c0_001, c0_002, m4_002) for the skills tables

The wiring between the CLI and the database layer was simply missing.

Changes

src/cleveragents/application/services/skill_service.py

  • Added optional skill_repo and session_factory parameters to __init__
  • When skill_repo is provided, the constructor pre-loads existing skills from DB
  • add_skill() now persists to DB via skill_repo.create() / update() + session.commit()
  • remove_skill() now persists deletion via skill_repo.delete() + session.commit()
  • Fallback to pure in-memory mode when no repo is provided (backwards compatible)

src/cleveragents/cli/commands/skill.py

  • _get_skill_service() now creates a DB-backed service following the same engine -> sessionmaker -> repository pattern used by tool.py
  • _reset_skill_service() now installs a fresh in-memory SkillService (instead of None)

Tests

  • Behave BDD: features/skill_add_persist.feature — 4 scenarios (round-trip, multiple, duplicates, remove)
  • Robot Framework: robot/skill_add_persist.robot — 3 integration smoke tests
  • ASV Benchmark: benchmarks/skill_add_persist_bench.py — add + list performance

Quality Gates

  • nox -s lint — PASSED
  • nox -s typecheck — 0 errors, 0 warnings
  • nox -s unit_tests — 9,110 scenarios, 0 failures
  • nox -s coverage_report — 97%

ISSUES CLOSED: #620

## Summary Fixes #620 — `agents skill add` followed by `agents skill list` now correctly shows the added skill. Closes #620 ## Root Cause The CLI `skill.py` used `SkillService` which stored skills in a pure in-memory `OrderedDict`. Each CLI process created a new empty `SkillService`, so data added during `skill add` was lost when the process exited. Meanwhile, the codebase already had: - `SkillModel` — full SQLAlchemy model for the `skills` table (with `SkillItemModel` children) - `SkillRepository` — database-backed CRUD with session-factory pattern - `SkillRegistryService` — service layer wrapping the repository - Alembic migrations (`c0_001`, `c0_002`, `m4_002`) for the skills tables The wiring between the CLI and the database layer was simply missing. ## Changes ### `src/cleveragents/application/services/skill_service.py` - Added optional `skill_repo` and `session_factory` parameters to `__init__` - When `skill_repo` is provided, the constructor pre-loads existing skills from DB - `add_skill()` now persists to DB via `skill_repo.create()` / `update()` + `session.commit()` - `remove_skill()` now persists deletion via `skill_repo.delete()` + `session.commit()` - Fallback to pure in-memory mode when no repo is provided (backwards compatible) ### `src/cleveragents/cli/commands/skill.py` - `_get_skill_service()` now creates a DB-backed service following the same `engine -> sessionmaker -> repository` pattern used by `tool.py` - `_reset_skill_service()` now installs a fresh in-memory `SkillService` (instead of `None`) ## Tests - **Behave BDD**: `features/skill_add_persist.feature` — 4 scenarios (round-trip, multiple, duplicates, remove) - **Robot Framework**: `robot/skill_add_persist.robot` — 3 integration smoke tests - **ASV Benchmark**: `benchmarks/skill_add_persist_bench.py` — add + list performance ## Quality Gates - `nox -s lint` — PASSED - `nox -s typecheck` — 0 errors, 0 warnings - `nox -s unit_tests` — 9,110 scenarios, 0 failures - `nox -s coverage_report` — 97% ISSUES CLOSED: #620
fix(skill): persist skill registration to database after add
Some checks failed
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 15s
CI / quality (pull_request) Successful in 19s
CI / build (pull_request) Successful in 19s
CI / security (pull_request) Successful in 36s
CI / typecheck (pull_request) Successful in 39s
CI / unit_tests (pull_request) Successful in 2m29s
CI / docker (pull_request) Successful in 41s
CI / integration_tests (pull_request) Successful in 3m14s
CI / coverage (pull_request) Successful in 4m26s
CI / benchmark-regression (pull_request) Successful in 30m9s
CI / lint (push) Successful in 14s
CI / build (push) Successful in 16s
CI / quality (push) Successful in 17s
CI / security (push) Successful in 33s
CI / typecheck (push) Successful in 34s
CI / benchmark-regression (push) Has been skipped
CI / unit_tests (push) Successful in 2m18s
CI / docker (push) Successful in 39s
CI / integration_tests (push) Successful in 3m7s
CI / coverage (push) Successful in 4m29s
CI / benchmark-publish (push) Has been cancelled
9704281bdd
Wire SkillService to use SkillRepository for database persistence,
fixing the bug where `agents skill add` stored skills only in an
in-memory OrderedDict that was lost when the CLI process exited.

Changes:
- SkillService now accepts optional skill_repo and session_factory
  parameters.  When provided, add_skill() persists to the database
  and the constructor pre-loads existing skills from DB rows.
- _get_skill_service() in the CLI now creates a DB-backed service
  following the same engine/sessionmaker/repository pattern used by
  the tool CLI (tool.py).
- _reset_skill_service() now installs a fresh in-memory SkillService
  (instead of setting None) to avoid DB side-effects during unit
  testing with parallel runners.
- remove_skill() also persists the deletion to the database.

Test coverage:
- Behave BDD: features/skill_add_persist.feature (4 scenarios)
- Robot Framework: robot/skill_add_persist.robot (3 smoke tests)
- ASV benchmark: benchmarks/skill_add_persist_bench.py

ISSUES CLOSED: #620
freemo added this to the v3.2.0 milestone 2026-03-08 03:17:56 +00:00
freemo merged commit 9704281bdd into master 2026-03-08 22:06:15 +00:00
freemo deleted branch fix/skill-add-not-registering 2026-03-08 22:06:15 +00:00
Author
Owner

Also Closes #637

Also Closes #637
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core!640
No description provided.