chore: reconcile drop-backend-prefix into master (branch divergence) - #172
Conversation
…ng send path Fixes two related gaps: /handoff inbox listed via unscoped artifact_list (leaked across every project); fn handoff send path never touched an item. Now inbox uses item(action=list) (project-scoped), and handoff assigns/creates an item and attaches content as a versioned asset instead of publishing a flat-file artifact. Includes a CodeRabbit-flagged fix: asset filename (and version chain) is keyed on item.id, not the mutable brief/name.
📝 WalkthroughWalkthroughThe backend adds immutable asset versioning per entity and filename. MCP handoffs now assign or create backend items and attach content as versioned assets, with updated request fields, responses, prompts, and tests. ChangesVersioned asset handoffs
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Agent
participant HandoffTool
participant BackendDatabase
participant AssetStorage
Agent->>HandoffTool: Submit recipient, content, and optional item_id
HandoffTool->>BackendDatabase: Assign existing item or create new item
HandoffTool->>AssetStorage: Store content file when absent
HandoffTool->>BackendDatabase: Create versioned item_attachment asset
BackendDatabase-->>HandoffTool: Return item and asset identifiers
HandoffTool-->>Agent: Return item_id, asset_id, and asset_version
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/agentflare-backend/src/asset.rs`:
- Around line 133-138: Update the asset creation flow containing the version
lookup and subsequent INSERT to execute both statements within one SQLite
transaction, matching the transaction pattern used by item::create and
project::create. Ensure the transaction commits only after the versioned asset
insert succeeds and propagates failures without leaving partial state.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: c0c4caff-3bf5-45ee-a9e2-0dc18932dbec
📒 Files selected for processing (5)
crates/agentflare-backend/src/asset.rscrates/agentflare-backend/src/db.rscrates/agentflare-backend/src/migrations/0003_asset_versioning.sqlsrc/mcp_prompts.rssrc/mcp_server.rs
| let version: i64 = conn.query_row( | ||
| "SELECT COALESCE(MAX(version), 0) + 1 FROM assets | ||
| WHERE entity_type = ?1 AND entity_id = ?2 AND filename = ?3 AND deleted_at IS NULL", | ||
| rusqlite::params![input.entity_type, input.entity_id, input.filename], | ||
| |r| r.get(0), | ||
| )?; |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Look for concurrent/multi-connection usage of asset::create and any unique index on assets(version).
rg -nP 'asset::create|assets\s*\(.*version' --type=rust -C2
rg -nP 'CREATE\s+(UNIQUE\s+)?INDEX.*assets' -C2 crates/agentflare-backend/src/migrations
rg -nP 'open_db|Connection::open|open_in_memory' --type=rust crates/agentflare-backend/src -C1Repository: getappz/agentflare
Length of output: 156
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the asset create path and surrounding schema/migrations.
sed -n '1,240p' crates/agentflare-backend/src/asset.rs
printf '\n--- migrations mentioning assets ---\n'
fd -a . crates/agentflare-backend/src/migrations | sort | while read -r f; do
echo "### $f"
rg -n "assets|version|UNIQUE|CREATE INDEX|CREATE TABLE" "$f" || true
done
printf '\n--- DB connection / backend access paths ---\n'
rg -n "Connection::open|open_in_memory|with_backend_db|unchecked_transaction|transaction\(" crates/agentflare-backend/src -C 2Repository: getappz/agentflare
Length of output: 34998
Wrap the version lookup and insert in a transaction. SELECT COALESCE(MAX(version), 0) + 1 and the following INSERT are separate statements, so concurrent connections can assign the same version for the same (entity_type, entity_id, filename) chain. There’s no unique index on (entity_type, entity_id, filename, version) to catch duplicates, and item::create / project::create already use a transaction for this pattern.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/agentflare-backend/src/asset.rs` around lines 133 - 138, Update the
asset creation flow containing the version lookup and subsequent INSERT to
execute both statements within one SQLite transaction, matching the transaction
pattern used by item::create and project::create. Ensure the transaction commits
only after the versioned asset insert succeeds and propagates failures without
leaving partial state.
master gained its own independent squash-commit for the 4-tool consolidation (133b6dd), separate from the drop-backend-prefix branch line — so PR #169 (merged into drop-backend-prefix) never reached master, and master's later PRs (#170, #171) never reached drop-backend-prefix. The two lines diverged with unique work on each side.
This is a straightforward non-conflicting merge bringing drop-backend-prefix's unique commit (asset versioning + handoff-assigns-items rework) into master. No conflicts — different files/areas touched on each side.
Summary
asset.rs,db.rs, migration0003_asset_versioning.sql).mcp_prompts.rsand request/response handling + tests inmcp_server.rs.Test plan
cargo test— 365/365 passingcargo fmt --check— cleancargo clippy --workspace --all-targets -- -D warnings -A unsafe_code -A clippy::pedantic— cleanNotes for reviewers
mcp_server.rshandoff path now creates/attaches backend items instead of artifacts;/artifactremains available for standalone use but is deprecated for handoffs.assets.versioncolumn), no destructive schema changes.