Skip to content

feat(utils): CapabilityAutoGenerator — persist schedule state and YAML capability output (v1.8.0, #217) - #4275

Merged
makr-code merged 3 commits into
developfrom
copilot/v180-capability-auto-generator-persist-state
Mar 15, 2026
Merged

makr-code merged 3 commits into
developfrom
copilot/v180-capability-auto-generator-persist-state

Conversation

Copilot AI commented Mar 15, 2026 •

Copy link
Copy Markdown
Contributor

Resolves three no-op TODOs in capability_auto_generator.cpp that left schedule gating, document-count delta tracking, and capability file output entirely unimplemented.

Description

Core implementation (src/utils/capability_auto_generator.cpp, include/utils/capability_auto_generator.h)

  • Line 193 — schedule gate: processShard() now compares now − last_run_timestamps_[shard_id] against schedule.interval; returns early if within interval.
  • Line 373 — doc-count delta: shouldUpdate() reads last_document_counts_[shard_id]; short-circuits to true when delta >= min_document_change.
  • Line 435 — YAML output: saveCapability() serializes all DomainCapability fields via yaml-cpp, atomic write using tmp → fs::rename.

State persistence

  • Optional std::shared_ptr<RocksDBWrapper> state_db added to constructor (backward-compatible default nullptr).
  • loadPersistedState(): iterates utils_capgen_state:…utils_capgen_state; range on construction; corrupt-entry errors deferred outside mutex_ to avoid I/O under lock.
  • persistState(shard_id, timestamp, doc_count): public — updates in-memory maps + writes utils_capgen_state:<shard_id> JSON to RocksDB after each successful run. Public visibility allows migration/pre-seeding without exposing internals.
// After save succeeds in processShard():
persistState(shard_id, now_s, result.document_count);
// → state_db_->put("utils_capgen_state:my-shard",
//       {"last_run_timestamp": 1742067600, "last_document_count": 12450})

Tests & CI (tests/test_capabilityautogenerator_persist_state.cpp, tests/CMakeLists.txt, .github/workflows/capabilityautogenerator-persist-state-ci.yml)

13 focused tests covering:

  • Constructor load from pre-seeded RocksDB entries (AC-1)
  • PersistStateWritesNewEntryToRocksDB / PersistStateOverwritesExistingEntry — direct AC-5 coverage now that persistState() is public
  • ScheduleGateRespectsLastRunTimestamp — seeds a recent timestamp, verifies elapsed < interval and that saveCapability (which correctly bypasses the gate) still writes
  • Full YAML field fidelity, atomic write (no .tmp residue), directory auto-creation, null state_db safety, multi-shard independence

CI: ubuntu-22.04/gcc-12, ubuntu-22.04/clang-15, ubuntu-24.04/gcc-13.

Note on ConfigPathResolver::resolveWritable(): Referenced in the roadmap but does not exist in the codebase. Writing directly to config_.output_directory with fs::create_directories is the correct equivalent.

Type of Change

  • Bug fix
  • New feature
  • Refactoring
  • Documentation
  • Other:

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed

📚 Research & Knowledge (wenn applicable)

  • Diese PR basiert auf wissenschaftlichen Paper(s) oder Best Practices?
    • Falls JA: Research-Dateien in /docs/research/ angelegt?
    • Falls JA: Im Modul-README unter "Wissenschaftliche Grundlagen" verlinkt?
    • Falls JA: In /docs/research/implementation_influence/ eingetragen?

Relevante Quellen:

  • Paper:
  • Best Practice:
  • Architecture Decision:

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No new warnings introduced
Original prompt

This section details on the original issue you should resolve

<issue_title>CapabilityAutoGenerator: Persist Schedule and Document Count State</issue_title>
<issue_description>### Context

This issue implements the roadmap item 'CapabilityAutoGenerator: Persist Schedule and Document Count State' for the utils domain. It is sourced from the consolidated roadmap under 🟡 Medium Priority — Near-term (v1.5.0 – v1.8.0) and targets milestone v1.8.0.

Primary detail section: CapabilityAutoGenerator: Persist Schedule and Document Count State

Goal

Deliver the scoped changes for CapabilityAutoGenerator: Persist Schedule and Document Count State in src/utils/ and complete the linked detail section in a release-ready state for v1.8.0.

Detailed Scope

CapabilityAutoGenerator: Persist Schedule and Document Count State

Priority: Medium
Target Version: v1.8.0

capability_auto_generator.cpp has 3 TODOs:

  • Line 193: "Check last update time and compare with schedule interval" — schedule checking is a no-op; updates run every invocation regardless of interval.
  • Line 373: "Store previous document count somewhere" — document count delta cannot be computed without persistence.
  • Line 435: "Implement YAML serialization and file writing" — generated capabilities are not persisted to disk.

Implementation Notes:

  • [ ] Use a small RocksDB key (utils_capgen_state) to persist last_run_timestamp and last_document_count; load on construction.
  • [ ] At line 193: compare now - last_run_timestamp against config_.schedule_interval_s; skip regeneration if within interval.
  • [ ] At line 373: persist the current document_count to the state key after each successful run.
  • [ ] At line 435: serialize the generated CapabilitySet to YAML using yaml-cpp and atomically write via ConfigPathResolver::resolveWritable().

Acceptance Criteria

  • Line 193: "Check last update time and compare with schedule interval" — schedule checking is a no-op; updates run every invocation regardless of interval.
  • Line 373: "Store previous document count somewhere" — document count delta cannot be computed without persistence.
  • Line 435: "Implement YAML serialization and file writing" — generated capabilities are not persisted to disk.
  • Use a small RocksDB key (utils_capgen_state) to persist last_run_timestamp and last_document_count; load on construction.
  • At line 193: compare now - last_run_timestamp against config_.schedule_interval_s; skip regeneration if within interval.
  • At line 373: persist the current document_count to the state key after each successful run.
  • At line 435: serialize the generated CapabilitySet to YAML using yaml-cpp and atomically write via ConfigPathResolver::resolveWritable().

Relationships

References

  • src/ROADMAP.md
  • src/utils/FUTURE_ENHANCEMENTS.md#capabilityautogenerator-persist-schedule-and-document-count-state
  • Source key: roadmap:217:utils:v1.8.0:capabilityautogenerator-persist-schedule-and-document-count-state

Generated from the consolidated source roadmap. Keep the roadmap and issue in sync when scope changes.

</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

#217)

- Add optional state_db (RocksDBWrapper) parameter to constructor; load
  utils_capgen_state:<shard_id> entries on construction (AC-1)
- processShard: skip regeneration when within schedule.interval (AC-2)
- shouldUpdate: return true when doc-count delta >= min_document_change (AC-3)
- saveCapability: serialize DomainCapability to YAML, atomic tmp->rename write (AC-4)
- persistState: write timestamp + doc_count to utils_capgen_state:<shard_id> (AC-5)
- Add focused tests (test_capabilityautogenerator_persist_state.cpp)
- Register tests in tests/CMakeLists.txt
- Add CI workflow capabilityautogenerator-persist-state-ci.yml

Co-authored-by: makr-code <[email protected]>
Copilot AI changed the title [WIP] [CapabilityAutoGenerator] Persist schedule and document count state feat(utils): CapabilityAutoGenerator — persist schedule state and YAML capability output (v1.8.0, #217) Mar 15, 2026
Copilot AI requested a review from makr-code March 15, 2026 19:02
…w AC-5/AC-2 tests, stale banner

- Make persistState() public (was private) so AC-5 is directly testable
- Add PersistStateWritesNewEntryToRocksDB test (AC-5 direct DB write)
- Add PersistStateOverwritesExistingEntry test (AC-5b idempotent overwrite)
- Add PersistStateWithNullDbOnlyUpdatesMemory test (AC-5c null-safety)
- Add ScheduleGateRespectsLastRunTimestamp test (AC-2 gate data verified)
- Update stale file banner: TODOs: 3 -> 0, v0.0.34 -> v0.0.35

Co-authored-by: makr-code <[email protected]>
@makr-code
makr-code marked this pull request as ready for review March 15, 2026 19:26
@makr-code
makr-code merged commit 6b0f822 into develop Mar 15, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CapabilityAutoGenerator: Persist Schedule and Document Count State

2 participants