Commit 630e4fc
authored
The bundler's import path used to claim an agent_id, mutate pipelines/flows/agent_config across
multiple unwrapped wpdb writes, and only check sub-step results for the agent insert. Under SQLite
contention on Studio that produced "success: true" responses with a populated agent_id summary while
the underlying rows were silently rolled back, leaving operators with a `Agent "..." not found` on
the very next CLI call.
This change wraps the post-claim work in a transaction with try/catch + manual rollback, throws on
any sub-step write failure, re-fetches the agent row after the final update_agent and verifies the
artifact registry actually persisted, and surfaces typed errors (`install_post_claim_failure`,
`install_invalid_bundle`, `install_slug_collision`, `install_bundle_slug_mismatch`) instead of bare
strings. The manual_rollback() path is the safety net for engines that silently no-op ROLLBACK; it
deletes only rows this call inserted, never pre-existing ones.
`agent upgrade` now passes `is_upgrade => true` so an existing agent row is treated as the upgrade
target instead of returning "Agent slug already exists. Use --slug=<new-slug> to rename on import."
when a bundle's artifacts lack `portable_slug` and the live pipelines/flows have been edited
(`local_modified`). Conflicts come back through `result.conflicts` and the CLI hands them to the
existing PendingActions staging path, matching what `agent diff` already reports.
Defensive cleanup: `InstalledBundleArtifacts::register()` listens on `datamachine_agent_deleted`
and wipes any tracked rows for the deleted agent_id. The importer does not write to that table
today, but extensions can — and a stale row would mis-classify a fresh install as an upgrade
against a non-existent agent.
Also adds two test seam actions, `datamachine_bundle_import_post_claim_started` and
`datamachine_bundle_import_pre_commit`, so tests can throw inside the critical section without
needing a live SQLite race to reproduce the bug.
Tests: tests/Unit/Core/Agents/AgentBundlerImportTest.php covers all three regression shapes:
silent partial success → rollback + typed error, upgrade-against-local-modified → success with
conflicts, agent delete → bundle artifact registry cleared.
1 parent a8bc102 commit 630e4fc
5 files changed
Lines changed: 520 additions & 74 deletions
File tree
- inc
- Cli/Commands
- Core
- Agents
- Database/BundleArtifacts
- tests/Unit/Core/Agents
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
224 | 224 | | |
225 | 225 | | |
226 | 226 | | |
227 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
228 | 241 | | |
229 | 242 | | |
230 | 243 | | |
| |||
0 commit comments