Skip to content

fix(gateway-registry): adopt agentflare-db-kit migrations preventively - #573

Merged
getappz merged 2 commits into
masterfrom
task/520-fix-gateway-registry-adopt-agentflare-db
Aug 21, 2026
Merged

getappz merged 2 commits into
masterfrom
task/520-fix-gateway-registry-adopt-agentflare-db

Conversation

@getappz

@getappz getappz commented Aug 20, 2026 •

Copy link
Copy Markdown
Owner

Preventive follow-up to item #519 (PR #572). gateway-registry's db.rs explicitly mirrors skill-registry's pre-migration apply_schema() pattern. Audited its git history (#104 -> #158 -> #347): the tools table's columns have never changed since creation, so there's no live bug today -- but it carries the identical architectural gap (no user_version, hand-rolled schema) and would hit the same class of bug the first time a column is added.

Migrates to agentflare-db-kit's open_file/open_memory with a real migration list:

Added GatewayError::DbInit for db_kit::open::Error plus its error_kind match arm.

Test plan

  • cargo test -p agentflare-gateway-registry --lib (60/60, including the existing legacy-standalone-FTS conversion test)
  • cargo clippy -p agentflare-gateway-registry --all-targets --all-features -- -D warnings -A unsafe_code -A clippy::pedantic (clean)
  • cargo fmt -p agentflare-gateway-registry -- --check (clean)
  • cargo check -p agentflare --bin agentflare (full binary compiles)

Summary by CodeRabbit

  • New Features

    • Added full-text search support for registered tools.
    • Added automatic synchronization of search data when tools are added, updated, or removed.
  • Improvements

    • Database setup now uses versioned migrations for more reliable upgrades.
    • Added clearer database initialization error reporting and audit logging.

Same architectural gap as skill-registry (#519/PR #572), which
gateway-registry's own doc comments say it mirrors: hand-rolled
apply_schema() with no user_version tracking. Audited the git history
(#104 -> #158 -> #347) -- the tools table's columns have never changed
since creation, so there's no live "no such column" bug today, but the
next column addition would hit the identical class of bug.

Migrates to agentflare-db-kit's open_file/open_memory with a real
migration list: 0001_initial replays the original (#104) narrow schema,
0002_fts_triggers unconditionally drops and recreates tools_fts as the
external-content shape with sync triggers plus a backfill. No ALTER
TABLE/migration hook needed here (unlike #519) since tools's columns
are stable -- DROP ... IF EXISTS before a fresh CREATE is correct
regardless of which pre-migration shape existed.

Added GatewayError::DbInit for db_kit::open::Error and its error_kind
match arm. All 60 gateway-registry unit tests pass, including the
existing legacy-standalone-FTS conversion test; clippy (with the CI
gate flags) and fmt are clean; the full agentflare binary compiles.

Agentflare-Agent: claude-code_2-1-237_agent
Agentflare-Branch: task/520-fix-gateway-registry-adopt-agentflare-db
Agentflare-Item: 520
@coderabbitai

coderabbitai Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b4de00a7-1823-487b-ba6e-e366214a073c

📥 Commits

Reviewing files that changed from the base of the PR and between 24803b0 and b687cb9.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • crates/gateway-registry/Cargo.toml
  • crates/gateway-registry/src/db.rs
  • crates/gateway-registry/src/error.rs
  • crates/gateway-registry/src/migrations/0001_initial.sql
  • crates/gateway-registry/src/migrations/0002_fts_triggers.sql
  • crates/gateway-registry/src/registry.rs

Included review availability: 0 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.


📝 Walkthrough

Walkthrough

The gateway registry now uses versioned SQLite migrations for the tools schema and FTS synchronization. Database opening delegates to db_kit, and initialization failures use a dedicated gateway error and audit classification.

Changes

Gateway registry database

Layer / File(s) Summary
Schema and FTS migrations
crates/gateway-registry/src/migrations/*
The migrations create the tools and tools_fts tables, add synchronization triggers, and populate the FTS index.
Migration-backed database opening
crates/gateway-registry/Cargo.toml, crates/gateway-registry/src/db.rs
The crate adds database dependencies. open_db and open_in_memory use db_kit with ordered migrations.
Initialization error reporting
crates/gateway-registry/src/error.rs, crates/gateway-registry/src/registry.rs
GatewayError::DbInit wraps database initialization errors and maps to the DbInit audit classification.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to b687c

This PR adopts versioned database migrations without any supplied current-head merge-blocking risk; it is merge-ready after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant GatewayRegistry
  participant DbKit
  participant SQLite
  GatewayRegistry->>DbKit: open database with migrations
  DbKit->>SQLite: create or open connection
  DbKit->>SQLite: execute 0001_initial and 0002_fts_triggers
  SQLite-->>GatewayRegistry: connection or DbInit error
``

</details>

<!-- walkthrough_end -->
<!-- pre_merge_checks_walkthrough_start -->

<details>
<summary>🚥 Pre-merge checks | ✅ 5</summary>

<details>
<summary>✅ Passed checks (5 passed)</summary>

|         Check name         | Status   | Explanation                                                                                                                          |
| :------------------------: | :------- | :----------------------------------------------------------------------------------------------------------------------------------- |
|         Title check        | ✅ Passed | The title clearly identifies the gateway-registry migration change and its preventive purpose.                                       |
|      Description check     | ✅ Passed | The description explains the change and rationale and provides completed test results, but it omits the Notes for reviewers section. |
|     Docstring Coverage     | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.                                                 |
|     Linked Issues check    | ✅ Passed | Check skipped because no linked issues were found for this pull request.                                                             |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request.                                                             |

</details>

</details>

<!-- pre_merge_checks_walkthrough_end -->
<!-- finishing_touch_checkbox_start -->

<details>
<summary>✨ Finishing Touches</summary>

<details>
<summary>📝 Generate docstrings</summary>

- [ ] <!-- {"checkboxId":"7962f53c-55bc-4827-bfbf-6a18da830691"} --> Create stacked PR
- [ ] <!-- {"checkboxId":"3e1879ae-f29b-4d0d-8e06-d12b7ba33d98"} --> Commit on current branch

</details>
<details>
<summary>🧪 Generate unit tests (beta)</summary>

- [ ] <!-- {"checkboxId": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} -->   Create PR with unit tests
- [ ] <!-- {"checkboxId": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} -->   Commit unit tests in branch `task/520-fix-gateway-registry-adopt-agentflare-db`

</details>

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---




<sub>Comment `@coderabbitai help` to get the list of available commands.</sub>

<!-- tips_end -->
Loading

@getappz
getappz merged commit 9ec8d37 into master Aug 21, 2026
17 checks passed
@getappz
getappz deleted the task/520-fix-gateway-registry-adopt-agentflare-db branch August 21, 2026 03:55
getappz added a commit that referenced this pull request Sep 16, 2026
* feat(item): add plan-gate pure logic module (item #573)

Agentflare-Agent: claude-code_2-1-272_agent
Agentflare-Branch: task/573-feat-plan-mode-style-approval-gate-befor
Agentflare-Item: 573
Agentflare-Session: b2a9a8b7-a892-4ace-bc24-64c355019547

* feat(item): block claim() on an unapproved plan gate (item #573)

Agentflare-Agent: claude-code_2-1-272_agent
Agentflare-Branch: task/573-feat-plan-mode-style-approval-gate-befor
Agentflare-Item: 573
Agentflare-Session: b2a9a8b7-a892-4ace-bc24-64c355019547

* feat(supervisor): skip plan-gated items in automatic dispatch (item #573)

Agentflare-Agent: claude-code_2-1-272_agent
Agentflare-Branch: task/573-feat-plan-mode-style-approval-gate-befor
Agentflare-Item: 573
Agentflare-Session: b2a9a8b7-a892-4ace-bc24-64c355019547

* test(supervisor): assert dispatched job belongs to the approved item (item #573)

Agentflare-Agent: claude-code_2-1-272_agent
Agentflare-Branch: task/573-feat-plan-mode-style-approval-gate-befor
Agentflare-Item: 573
Agentflare-Session: b2a9a8b7-a892-4ace-bc24-64c355019547

* feat(item): add plan_asset_id/plan_approver/reason fields and dispatch entries (item #573)

Agentflare-Agent: claude-code_2-1-272_agent
Agentflare-Branch: task/573-feat-plan-mode-style-approval-gate-befor
Agentflare-Item: 573
Agentflare-Session: b2a9a8b7-a892-4ace-bc24-64c355019547

* feat(item): implement submit_plan/approve_plan/reject_plan (item #573)

Agentflare-Agent: claude-code_2-1-272_agent
Agentflare-Branch: task/573-feat-plan-mode-style-approval-gate-befor
Agentflare-Item: 573
Agentflare-Session: b2a9a8b7-a892-4ace-bc24-64c355019547

* feat(supervisor): generalize Telegram approval flow for plan approval (item #573)

Agentflare-Agent: claude-code_2-1-272_agent
Agentflare-Branch: task/573-feat-plan-mode-style-approval-gate-befor
Agentflare-Item: 573
Agentflare-Session: b2a9a8b7-a892-4ace-bc24-64c355019547

* feat(item): apply default plan-gate policy at create/update (item #573)

Agentflare-Agent: claude-code_2-1-272_agent
Agentflare-Branch: task/573-feat-plan-mode-style-approval-gate-befor
Agentflare-Item: 573
Agentflare-Session: b2a9a8b7-a892-4ace-bc24-64c355019547

* fix: enforce human plan-approval, surface stalled auto-gated items, and other final-review fixes (item #573)

Agentflare-Agent: claude-code_2-1-272_harness
Agentflare-Branch: task/573-feat-plan-mode-style-approval-gate-befor
Agentflare-Item: 573
Agentflare-Session: 5c8c7535-39a4-4662-9251-0f3295609583

* fix: namespace the plan-gate ping dedup key, fix a stray fmt violation (item #573)

Agentflare-Agent: claude-code_2-1-272_harness
Agentflare-Branch: task/573-feat-plan-mode-style-approval-gate-befor
Agentflare-Item: 573
Agentflare-Session: 5c8c7535-39a4-4662-9251-0f3295609583

* Fix CodeRabbit findings on the plan-approval gate: self-approval bypass, malformed-metadata gate bypass, and metadata smuggling

- item_submit_plan could not be downgraded from a stored plan_approver="human"
  by a caller-supplied plan_approver, closing a self-approval bypass where an
  agent could submit_plan(plan_approver="agent") then approve_plan itself on
  a human-gated item (Critical).
- read_plan_gate now extracts each plan-gate field independently instead of
  one whole-struct deserialize, so a malformed unrelated field (e.g. a
  string plan_approved_at) can no longer fall back to
  PlanGateMeta::default() and silently open a plan_required=true gate
  (Major).
- item_create/item_update now strip the server-authoritative plan-transition
  fields (plan_status, plan_approved_by, plan_approved_at,
  plan_rejection_reason) from caller metadata, so a caller can no longer
  create/update an item straight into plan_status="approved" (Major).
- Corrected the plan_approver field's schemars description: it is read by
  submit_plan only, not create/update (Minor).

Agentflare-Agent: claude-code_2-1-273_agent
Agentflare-Branch: task/573-feat-plan-mode-style-approval-gate-befor
Agentflare-Item: 573
Agentflare-Session: 61cf1e19-60fe-45bf-bcf6-8e9a434e297b

* Fix CodeRabbit finding: keep the plan-approval Telegram button on a failed approval so a human can retry

Agentflare-Agent: claude-code_2-1-273_agent
Agentflare-Branch: task/573-feat-plan-mode-style-approval-gate-befor
Agentflare-Item: 573
Agentflare-Session: 61cf1e19-60fe-45bf-bcf6-8e9a434e297b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant