fix(skill): resolve skill add persistence regression after PR #640 #1120

Merged
freemo merged 2 commits from bugfix/m3-skill-add-regression into master 2026-03-24 17:23:10 +00:00
Owner

Summary

Fixes the cross-process skill persistence regression reported in #980. Skills registered via agents skill add --config <file> in one CLI process are now correctly persisted to the database and visible in subsequent CLI invocations.

Root Cause

Two issues in the skill persistence layer:

  1. Missing table creation: _build_skill_service() in container.py created a SkillRepository pointing at the database but did not ensure the skills and skill_items tables existed. When the tables were missing, all repository operations failed silently (caught by SkillService._load_from_db and _persist_skill exception handlers), causing the service to operate in in-memory-only mode.

  2. Session mismatch: SkillRepository lacked auto_commit support. Each call to session_factory() returned a new session, so the flush() in create()/update()/delete() operated on a different session than the commit() in SkillService._commit(), meaning data was never actually persisted.

Fix

  1. Add targeted table creation in _build_skill_service (following the pattern in _build_session_service) — checks for missing skills and skill_items tables and creates them via Base.metadata.create_all.
  2. Add auto_commit parameter to SkillRepository (following the pattern in SessionRepository) so each mutating method commits and closes its own session.
  3. Pass auto_commit=True from the container builder.
  4. Remove @tdd_expected_fail from TDD test (leaving @tdd_bug and @tdd_bug_980 as permanent regression guards).

Quality Gates

  • nox -e lint — passed
  • nox -e typecheck — 0 errors
  • nox -e unit_tests — 462 features, 12232 scenarios passed
  • nox -e integration_tests — 1674 tests, 1674 passed, 0 failed
  • nox -e coverage_report — 98% coverage (threshold: 97%)

Note: This PR depends on PR #1110 (TDD test for #981) being merged first.

Closes #980

## Summary Fixes the cross-process skill persistence regression reported in #980. Skills registered via `agents skill add --config <file>` in one CLI process are now correctly persisted to the database and visible in subsequent CLI invocations. ### Root Cause Two issues in the skill persistence layer: 1. **Missing table creation**: `_build_skill_service()` in `container.py` created a `SkillRepository` pointing at the database but did not ensure the `skills` and `skill_items` tables existed. When the tables were missing, all repository operations failed silently (caught by `SkillService._load_from_db` and `_persist_skill` exception handlers), causing the service to operate in in-memory-only mode. 2. **Session mismatch**: `SkillRepository` lacked `auto_commit` support. Each call to `session_factory()` returned a new session, so the `flush()` in `create()`/`update()`/`delete()` operated on a different session than the `commit()` in `SkillService._commit()`, meaning data was never actually persisted. ### Fix 1. Add targeted table creation in `_build_skill_service` (following the pattern in `_build_session_service`) — checks for missing `skills` and `skill_items` tables and creates them via `Base.metadata.create_all`. 2. Add `auto_commit` parameter to `SkillRepository` (following the pattern in `SessionRepository`) so each mutating method commits and closes its own session. 3. Pass `auto_commit=True` from the container builder. 4. Remove `@tdd_expected_fail` from TDD test (leaving `@tdd_bug` and `@tdd_bug_980` as permanent regression guards). ### Quality Gates - ✅ `nox -e lint` — passed - ✅ `nox -e typecheck` — 0 errors - ✅ `nox -e unit_tests` — 462 features, 12232 scenarios passed - ✅ `nox -e integration_tests` — 1674 tests, 1674 passed, 0 failed - ✅ `nox -e coverage_report` — 98% coverage (threshold: 97%) **Note**: This PR depends on PR #1110 (TDD test for #981) being merged first. Closes #980
freemo added this to the v3.2.0 milestone 2026-03-23 02:39:42 +00:00
freemo added the
Type
Bug
label 2026-03-23 02:39:42 +00:00
freemo added the
MoSCoW
Must have
Priority
Critical
State
In Review
labels 2026-03-23 03:33:55 +00:00
freemo requested review from hamza.khyari 2026-03-23 03:38:55 +00:00
freemo requested review from brent.edwards 2026-03-23 03:38:55 +00:00
freemo reviewed 2026-03-23 03:41:12 +00:00
freemo left a comment
Author
Owner

Day 43 Review — PR #1120 fix(skill): resolve skill add persistence regression

Verdict: Review complete — meets all standards. Awaiting 2 peer approvals.

Review Findings

Category Status
Specification alignment PASS — Closes #980, all acceptance criteria addressed
Commit message format PASS — Conventional Changelog fix(skill): prefix
Code quality PASS — Defensive table check with sqlalchemy.inspect, backward-compatible auto_commit parameter
Testing (Behave) PASS — 2 cross-process scenarios
Testing (Robot) PASS — 2 integration test cases
@tdd_expected_fail removal PASS — Tag removed, @tdd_bug + @tdd_bug_980 remain as regression guards
Issue reference PASS — Closes #980 in body, ISSUES CLOSED: #980 in footer

@hamza.khyari @brent.edwards — please review and approve if findings are satisfactory.

## Day 43 Review — PR #1120 `fix(skill): resolve skill add persistence regression` **Verdict: Review complete — meets all standards. Awaiting 2 peer approvals.** ### Review Findings | Category | Status | |---|---| | Specification alignment | PASS — Closes #980, all acceptance criteria addressed | | Commit message format | PASS — Conventional Changelog `fix(skill):` prefix | | Code quality | PASS — Defensive table check with `sqlalchemy.inspect`, backward-compatible `auto_commit` parameter | | Testing (Behave) | PASS — 2 cross-process scenarios | | Testing (Robot) | PASS — 2 integration test cases | | `@tdd_expected_fail` removal | PASS — Tag removed, `@tdd_bug` + `@tdd_bug_980` remain as regression guards | | Issue reference | PASS — `Closes #980` in body, `ISSUES CLOSED: #980` in footer | @hamza.khyari @brent.edwards — please review and approve if findings are satisfactory.
freemo force-pushed bugfix/m3-skill-add-regression from 159cb7f730 to a652d6fb78 2026-03-23 11:51:20 +00:00 Compare
freemo force-pushed bugfix/m3-skill-add-regression from a652d6fb78 to 65d38e4759 2026-03-23 16:48:21 +00:00 Compare
freemo force-pushed bugfix/m3-skill-add-regression from 65d38e4759 to 312aa3d4f8 2026-03-23 22:49:29 +00:00 Compare
freemo force-pushed bugfix/m3-skill-add-regression from 312aa3d4f8 to 75161acf4b 2026-03-24 01:15:25 +00:00 Compare
freemo force-pushed bugfix/m3-skill-add-regression from 75161acf4b to fe8881b1c4 2026-03-24 14:26:15 +00:00 Compare
freemo reviewed 2026-03-24 15:26:26 +00:00
freemo left a comment
Author
Owner

Review: Looks Good (with Minor Notes)

Clean, well-documented bug fix that directly addresses both root causes of the cross-process skill persistence regression. The implementation follows established codebase patterns (SessionRepository auto_commit, _build_session_service table creation), maintains backward compatibility (auto_commit defaults to False), and includes thorough test coverage at BDD and Robot levels.

Minor Notes

  1. DRY opportunity. The if self._auto_commit: session.commit(); session.close() block is duplicated in create(), update(), and delete(). Consider extracting to a _finalize_session(session) helper or context manager. Not blocking — consistent with existing SessionRepository pattern.

  2. Session not closed on commit failure. If session.commit() raises (e.g., late IntegrityError), session.close() is skipped. The except block does session.rollback() but never closes. Minor resource hygiene issue — consider adding session.close() to a finally block when auto_commit=True.

  3. PR dependency. PR body states this depends on PR #1110 (TDD test). Ensure #1110 is merged first to avoid conflicts.

Overall this is solid work — the two-pronged fix (table creation + auto_commit) is the right approach.

Note: Cannot formally approve as PR author matches the authenticated API user.

## Review: Looks Good (with Minor Notes) Clean, well-documented bug fix that directly addresses both root causes of the cross-process skill persistence regression. The implementation follows established codebase patterns (`SessionRepository` auto_commit, `_build_session_service` table creation), maintains backward compatibility (`auto_commit` defaults to `False`), and includes thorough test coverage at BDD and Robot levels. ### Minor Notes 1. **DRY opportunity.** The `if self._auto_commit: session.commit(); session.close()` block is duplicated in `create()`, `update()`, and `delete()`. Consider extracting to a `_finalize_session(session)` helper or context manager. Not blocking — consistent with existing `SessionRepository` pattern. 2. **Session not closed on commit failure.** If `session.commit()` raises (e.g., late `IntegrityError`), `session.close()` is skipped. The `except` block does `session.rollback()` but never closes. Minor resource hygiene issue — consider adding `session.close()` to a `finally` block when `auto_commit=True`. 3. **PR dependency.** PR body states this depends on PR #1110 (TDD test). Ensure #1110 is merged first to avoid conflicts. Overall this is solid work — the two-pronged fix (table creation + auto_commit) is the right approach. *Note: Cannot formally approve as PR author matches the authenticated API user.*
freemo force-pushed bugfix/m3-skill-add-regression from fe8881b1c4 to 93da31e80f 2026-03-24 17:08:23 +00:00 Compare
freemo scheduled this pull request to auto merge when all checks succeed 2026-03-24 17:08:36 +00:00
freemo merged commit 93da31e80f into master 2026-03-24 17:23:10 +00:00
freemo deleted branch bugfix/m3-skill-add-regression 2026-03-24 17:23:11 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: cleveragents/cleveragents-core#1120