Skip to content

Commit fb6798e

Browse files
fix(push,pull): never take over same-named org resources without --adopt (#104)
* fix(push,pull): never take over same-named org resources without --adopt Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(adopt): delete the leftover alias file Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(push): plain-language stop messages with the fix for each file Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --------- Co-authored-by: dhruva <dhruva@vapi.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent a820577 commit fb6798e

35 files changed

Lines changed: 2189 additions & 1601 deletions

‎AGENTS.md‎

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ change, before running:
4242
| `npm run rollback -- <org> --to …` | Reverts live resources |
4343
| `npm run cleanup -- <org> --force --confirm <org>` | Deletes platform resources |
4444
| `npm run pull -- <org> --force` | Overwrites local edits |
45+
| `--adopt <id>[=<uuid>]` | Takes over an existing org resource; requires an explicit yes for that resource |
4546
| `--allow-new-files`, `--overwrite`, `--resolve=ours\|theirs` | Bypass a safety check (see rule 6) |
4647
| `npm run call`, `npm run sim`, live `npm run check` | Place calls or run simulations that cost minutes |
4748

@@ -147,7 +148,10 @@ precisely.
147148
`.vapi-org.json` to make a reference resolve: fix the name, or pull.
148149
4. **Build PR checks offline** if `vapi-checks.yml` exists:
149150
`npm run check -- --all --dry-run`. Fix anything it reports.
150-
5. **Deploy only with a yes** (safety rule 1): `npm run apply -- <org>`, or
151+
5. **Review the dry-run Name collisions list**, then **deploy only with a yes**
152+
(safety rule 1). Same-named org resources are never taken over automatically;
153+
`--adopt <id>[=<uuid>]` requires explicit human approval to take one over.
154+
Deploy: `npm run apply -- <org>`, or
151155
scoped to files: `npm run apply -- <org> resources/<org>/assistants/my-agent.md`.
152156
6. **Verify** with the human's agreement: `npm run call -- <org> -a <name>` or
153157
`npm run sim -- <org> --suite <name> --target <name>`.
@@ -161,11 +165,34 @@ the dashboard, `apply` asks about that resource alone in a terminal; in CI or
161165
piped runs it's blocked unless `--resolve=ours|theirs|fail` is passed — ask
162166
the human which.
163167

164-
**When a deploy stops at the new-file check** ("no state-file UUID mapping"),
165-
the engine can't tell whether each listed file is new, a rename, or stale.
166-
Show the list to the human and ask them to classify each file. Pass
168+
**When a deploy stops at the new-file check** ("Not linked to any resource
169+
in <org> yet"), the grouped report lists every blocking file with exact fix
170+
commands. The engine cannot tell new / renamed / stale files apart; pushing
171+
an unlinked file creates a new resource. Show the report and ask the human
172+
to choose per file. Pass
167173
`--allow-new-files` only once they confirm every file is genuinely new. For a
168174
rename, see [Renaming](#naming-and-renaming); delete stale files.
175+
Same-named org resources are NOT linked automatically. Preview with
176+
`npm run push -- <org> --dry-run --allow-new-files` only after approval for
177+
those new files, and check the **Name collisions** list (read-only dashboard
178+
GETs). To take over an existing resource instead, get an explicit yes for
179+
`--adopt <id>[=<uuid>]`; use the UUID form when candidates are ambiguous.
180+
Never auto-pass adoption or new-file approval to make a deploy succeed.
181+
Adoption removes unchanged alias files automatically using the last-synced
182+
baseline. Edited aliases or missing baselines require per-file y/N approval;
183+
headless runs stop before changing files/state or the platform. Merge edits
184+
into the adopted file or remove the alias manually, then rerun.
185+
186+
**Running in CI:** link/adoption preflight stops with exit code **1**, before
187+
file deletion, state writes or API mutations. It groups unlinked files, invalid
188+
adoptions and unsafe alias deletions once. `--json` prints one array of
189+
`{file, resourceType, problem, fix, command}` to stdout (other logs go to stderr);
190+
`[]` means this preflight found no blockers, not that deployment cannot fail.
191+
A combined command is suggested only when every file has an unambiguous
192+
suggestion; otherwise the report names files needing human choice. No flags
193+
are needed to remove a verified unchanged leftover of an already-adopted
194+
resource. The engine never auto-adopts, auto-allows new files or deletes edited
195+
files without approval.
169196

170197
If something goes wrong: `npm run rollback -- <org> --list`, then (with a yes)
171198
`--to <timestamp>`. Details for every workflow:

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ More detail: [How the engine works](docs/guides/how-it-works.md).
208208
| `npm run setup` | Connect an org: create `.env.<org>` and `resources/<org>/` |
209209
| `npm run validate -- <org>` | Check resource files offline before deploying |
210210
| `npm run apply -- <org>` | Deploy: pull, merge, then push (the default) |
211-
| `npm run pull -- <org>` | Sync platform changes down without overwriting local edits |
212-
| `npm run push -- <org>` | Push without pulling first (prefer `apply`) |
211+
| `npm run pull -- <org>` | Sync platform changes down without overwriting local edits; unknown UUIDs get separate files, never name-linked |
212+
| `npm run push -- <org>` | Push without pulling first (prefer `apply`); review `--dry-run` Name collisions, and use `--adopt <id>[=<uuid>]` only with explicit approval to take over a resource; unchanged alias files are removed, edited/unbaselined copies need review. Push/apply support `--json` for one grouped link-preflight report (exit 1 on blockers); see [Running in CI](docs/guides/commands.md#running-in-ci). |
213213
| `npm run rollback -- <org>` | Restore a pre-deploy snapshot |
214214
| `npm run cleanup -- <org>` | Find, and optionally delete, platform resources with no file |
215215
| `npm run audit -- <org>` | Report drift between files, state and the platform |

‎docs/guides/commands.md‎

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ The other commands are direct only.
1111
| --- | --- | --- |
1212
| `npm run setup` | `npm run setup [-- <org>]` | Connect an org: creates `.env.<org>` and `resources/<org>/`. |
1313
| `npm run validate` | `npm run validate -- <org>` | Check resource files offline: API shape rules, and that every reference names a file or a state entry. `apply` runs it first. On GitHub Actions, findings are also shown on the files in the pull request. |
14-
| `npm run apply` | `npm run apply -- <org> [types or paths]` | **The default deploy:** pull, merge, then push. See [workflows](workflows.md). |
14+
| `npm run apply` | `npm run apply -- <org> [types or paths] [--adopt <id>[=<uuid>]]` | **The default deploy:** pull, merge, then push. See [workflows](workflows.md). |
1515
| `npm run pull` | `npm run pull -- <org> [--force] [--bootstrap]` | Sync platform changes down; never overwrites local edits unless `--force`. |
16-
| `npm run push` | `npm run push -- <org> [--dry-run] [--strict]` | Push without pulling first. Prefer `apply`. `--strict` aborts before any API call if validation finds an error. |
16+
| `npm run push` | `npm run push -- <org> [--dry-run] [--json] [--strict] [--adopt <id>[=<uuid>]]` | Push without pulling first. Prefer `apply`. `--strict` aborts before any API call if validation finds an error. |
1717
| `npm run rollback` | `npm run rollback -- <org> --list` or `--to <ISO>` | Restore a pre-deploy snapshot from `.vapi-state.<org>.snapshots/`. |
1818
| `npm run cleanup` | `npm run cleanup -- <org> [--force --confirm <org>]` | List platform resources with no file; delete them only with both flags. |
1919
| `npm run audit` | `npm run audit -- <org> [--type <type>]` | Report drift between files, state and the platform. Exits 1 on any finding, so it can run in CI. |
@@ -24,6 +24,77 @@ The other commands are direct only.
2424
| `npm run build` | `npm run build` | Type-check the code and tests. |
2525
| `npm test` | `npm test` | Run the test suite. |
2626

27+
Pull and push never automatically rename UUID-suffixed state keys to match
28+
local files. A local file without a UUID mapping remains subject to the
29+
new-file gate even if the org has a same-name resource. The gate reports
30+
same-name candidates without linking them. Existing mappings, including
31+
legacy entries without provenance, remain linked. New pull mappings record
32+
`origin: pulled`; push-created resources record `origin: pushed`.
33+
34+
Dry-run push/apply ends with **Name collisions**, listing same-name state and
35+
live dashboard resources for every planned POST, including dependency creates.
36+
Read-only GETs run in dry-run. No matches prints `Name collisions: none`;
37+
unavailable inventories are reported as an incomplete check, not a clean result.
38+
Check this list before deploying; taking over a resource requires explicit
39+
human approval for `--adopt`, just as `--allow-new-files` requires approval.
40+
41+
### Running in CI
42+
43+
Push/apply link preflight reports all blocking files in one **Push stopped**
44+
block and exits **1**, before API mutations, state writes or alias deletion.
45+
"Not linked to any resource in <org> yet" means pushing would create a new
46+
resource; the engine cannot infer new versus renamed/stale intent.
47+
48+
Each file has exact commands: approve `--allow-new-files` for genuinely new
49+
resources, approve `--adopt <id>[=<uuid>]` for a takeover, or merge needed edits
50+
and remove a renamed/stale file. A single ready-to-run combined command appears
51+
only when every file has an unambiguous suggestion; otherwise the report lists
52+
which files need human choice. Suggestions are not authorization to execute.
53+
54+
`--json` on push or apply prints one stdout array of
55+
`{file, resourceType, problem, fix, command}`; ordinary logs go to stderr.
56+
The exit code stays 1 for blockers. `[]` means no link-preflight blockers,
57+
not a guarantee that later network/validation/deployment steps will succeed.
58+
Use `--dry-run --json` for a read-only preview. When invoking through npm,
59+
use `npm run -s push -- <org> --dry-run --json` to suppress npm's own
60+
command banner on stdout.
61+
62+
Safe, unchanged leftover alias files are removed automatically, including
63+
UUID-suffixed leftovers of an already-adopted mapping on a later plain push.
64+
Edited/unbaselined files need per-file y/N approval in a terminal and stop CI.
65+
The engine never auto-adopts, auto-passes the new-file flag or silently deletes
66+
edited files.
67+
68+
### Explicit resource adoption
69+
70+
`--adopt <resourceId>` opts a local file into taking over an existing org
71+
resource. It is repeatable; `--adopt=<resourceId>` also works. The file must
72+
exist and have no state mapping. Candidates are same-base-slug state entries
73+
and live resources of that type matching the file's name (or ID when unnamed).
74+
One distinct candidate is required. If several exist, use
75+
`--adopt <resourceId>=<uuid>`; that UUID must exist remotely for the file's type.
76+
Missing files, already-linked files, and zero/ambiguous candidates are errors.
77+
78+
Adoption records `origin: adopted`, removes other state keys for that UUID, and
79+
uses the normal PATCH path. Scoped saves include both sides of the re-key.
80+
`--dry-run --adopt <id>` performs live GET lookups and prints
81+
`would adopt <id> → <uuid>`, but does not write state or mutate the platform.
82+
`apply` forwards adoption to its push stage; its preceding pull remains a
83+
normal pull except in `--dry-run`, which skips pull to avoid local writes.
84+
Adoption deletes leftover alias files only when they match the last-synced
85+
baseline. Edited files or missing baselines need per-file y/N approval in a
86+
terminal; headless runs stop before changing files, state or the platform.
87+
Merge those edits into the adopted file or delete the alias manually and rerun.
88+
Dry-run reports would-delete/would-fail without deleting. Baselines are keyed
89+
by remote UUID, not alias; adoption drops the shared old baseline and the normal
90+
PATCH records a fresh one for the adopted resource.
91+
92+
Dependencies are automatically reused by name only when an existing state
93+
entry records `origin: pushed` or `origin: adopted`. Pulled and legacy entries,
94+
and dashboard-only name matches, are not authorization: a missing dependency
95+
is POST-created with a warning naming the existing resources. Use explicit
96+
adoption before dependency resolution to take one over instead.
97+
2798
## Interactive Mode
2899

29100
When you run a command without arguments, you get a fully interactive experience:

‎docs/guides/how-it-works.md‎

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Resources are scoped by organization, with names you choose (not fixed `dev`/`stg`/`prod`). Each org gets:
66

77
- `.env.<org>` — private API key and base URL
8-
- `.vapi-state.<org>.json` — resource name ↔ UUID mappings (nothing else — committed)
8+
- `.vapi-state.<org>.json` — resource ID ↔ UUID mappings and optional origin (committed)
99
- `.vapi-state-hash/<org>/<uuid>` — last-seen platform content hash per resource, used for drift detection (per-developer, gitignored)
1010
- `resources/<org>/` — all resource files
1111

@@ -42,7 +42,52 @@ files
4242

4343
**`push`** — reads local files and syncs them to the platform: creates and updates. It deletes platform resources whose files you removed only when you pass `--force`.
4444

45-
**`apply`** — runs `pull` then `push` in sequence.
45+
**`apply`** — runs `pull` then `push` in sequence. With `--dry-run`, it skips
46+
pull (which writes local files/state) and previews push with read-only GETs.
47+
48+
### Running in CI
49+
50+
Push/apply link preflight reports all blocking files in one **Push stopped**
51+
block and exits **1**, before API mutations, state writes or alias deletion.
52+
"Not linked to any resource in <org> yet" means pushing would create a new
53+
resource; the engine cannot infer new versus renamed/stale intent.
54+
55+
Each file has exact commands: approve `--allow-new-files` for genuinely new
56+
resources, approve `--adopt <id>[=<uuid>]` for a takeover, or merge needed edits
57+
and remove a renamed/stale file. A single ready-to-run combined command appears
58+
only when every file has an unambiguous suggestion; otherwise the report lists
59+
which files need human choice. Suggestions are not authorization to execute.
60+
61+
`--json` on push or apply prints one stdout array of
62+
`{file, resourceType, problem, fix, command}`; ordinary logs go to stderr.
63+
The exit code stays 1 for blockers. `[]` means no link-preflight blockers,
64+
not a guarantee that later network/validation/deployment steps will succeed.
65+
Use `--dry-run --json` for a read-only preview. With npm, use
66+
`npm run -s push -- <org> --dry-run --json` to suppress npm's banner.
67+
68+
Safe, unchanged leftover alias files are removed automatically, including
69+
UUID-suffixed leftovers of an already-adopted mapping on a later plain push.
70+
Edited/unbaselined files need per-file y/N approval in a terminal and stop CI.
71+
The engine never auto-adopts, auto-passes the new-file flag or silently deletes
72+
edited files.
73+
74+
### Names never authorize taking over org resources
75+
76+
Pull keeps existing UUID mappings and filenames stable. An unknown UUID always
77+
gets a separate `<name-slug>-<uuid8>` ID, even if a same-named local file exists.
78+
Neither pull nor push automatically collapses that key onto a local filename.
79+
80+
A file without a state mapping remains subject to the new-file gate. After
81+
confirming it is genuinely new, preview `--dry-run --allow-new-files` and review
82+
the final **Name collisions** list. It compares every planned POST, including
83+
auto-created dependencies, with state and live dashboard names. Matching names
84+
do not change the plan into a takeover. GETs run; platform mutations do not.
85+
86+
To take over a resource intentionally, obtain explicit human approval and use
87+
`--adopt <id>[=<uuid>]`. Adoption links an untracked local file before the gate
88+
and normal PATCH flow. Dependency alias reuse is restricted to state entries
89+
with `origin: pushed` or `origin: adopted`; pulled and legacy entries do not
90+
authorize new name-based links. Existing exact-key legacy links remain intact.
4691

4792
## Conflicts and the drift gate
4893

@@ -53,7 +98,7 @@ Before updating a resource, push GETs its current dashboard payload, hashes it,
5398
- **Hashes match** → your local edit is the natural next step in the change chain → pushed silently, and the baseline is refreshed from the PATCH **response** (what the platform actually stored).
5499
- **Hashes differ** → someone else published changes since your last sync. In a terminal, push asks **for that resource only**: ① push my local version (take ownership) ② keep the dashboard version (skip, local untouched) ③ save the dashboard version as `<name>.<TIMESTAMP>.bkp.<ext>` beside your file and skip, for a manual merge. In CI / piped runs the resource is blocked instead (use `--overwrite` to push unconditionally).
55100

56-
Backup copies (`*.bkp.*`, gitignored) are merge reference material only — invisible to the loader, the orphan gate, audit, the interactive picker, and explicit CLI paths.
101+
Backup copies (`*.bkp.*`, gitignored) are merge reference material only — invisible to the loader, the new-file check, audit, the interactive picker, and explicit CLI paths.
57102

58103
## Reading pull and push output
59104

@@ -77,7 +122,7 @@ Mental model: `⬆️` flows UP (push), `⬇️` flows DOWN (pull), `📝` is th
77122

78123
## Listing completeness
79124

80-
Vapi list endpoints cap a response at 100 items and expose no page cursor — only `createdAt` comparison filters. The engine pages backwards through `createdAt` until it gets a short page, so pull, push's invalid-mapping detection, `delete`'s orphan sweep, `audit`, and the credential reverse-map all see the whole type instead of the first hundred. When completeness cannot be proven — an endpoint that ignores the cursor params, a payload with no `createdAt`, or the page-count backstop — the engine says so on stderr. Treat that warning as "do not infer deletion from absence for this type".
125+
Vapi list endpoints cap a response at 100 items and expose no page cursor — only `createdAt` comparison filters. The engine pages backwards through `createdAt` until it gets a short page, so pull, push's invalid-mapping detection, `delete`'s missing-file sweep, `audit`, and the credential reverse-map all see the whole type instead of the first hundred. When completeness cannot be proven — an endpoint that ignores the cursor params, a payload with no `createdAt`, or the page-count backstop — the engine says so on stderr. Treat that warning as "do not infer deletion from absence for this type".
81126

82127
## Processing Order
83128

@@ -144,6 +189,8 @@ Tracks resource ID ↔ Vapi UUID mappings per org:
144189
```
145190

146191
Every resource type has a section. Keys are sorted, so diffs stay readable.
192+
New entries record `origin: pushed`, `pulled`, or `adopted`. Updates preserve
193+
that provenance, and legacy entries without an origin are not backfilled.
147194

148195
## What Vapi sees
149196

‎docs/guides/workflows.md‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,33 @@ When the files are genuinely new resources:
109109
npm run apply -- <org> --allow-new-files
110110
```
111111

112+
Before deploying, review the collision preview (the flag still needs approval
113+
for every genuinely new file):
114+
115+
```bash
116+
npm run push -- <org> --dry-run --allow-new-files
117+
```
118+
119+
The final **Name collisions** section includes same-name state and dashboard
120+
resources for every planned create, including dependencies. Names alone never
121+
take over an org resource. The plan POSTs a new one unless you explicitly adopt:
122+
123+
```bash
124+
npm run apply -- <org> --adopt my-agent assistants/my-agent.md
125+
# If multiple candidates exist:
126+
npm run apply -- <org> --adopt my-agent=<uuid> assistants/my-agent.md
127+
```
128+
129+
Adoption needs the human's explicit yes for that resource, just like new-file
130+
approval. It requires a local file with no state mapping. Pull never links
131+
unknown remote UUIDs to local files by name, and dependency aliases are reused
132+
only when state records pushed/adopted ownership. Adoption removes unchanged alias files automatically. Edited aliases or
133+
missing baselines require per-file approval in a terminal; headless runs stop
134+
so you can merge their edits into the adopted file or remove them manually.
135+
136+
Both `push --dry-run` and `apply --dry-run` perform read-only dashboard GETs
137+
for the collision preview; apply skips its pull stage to avoid local writes.
138+
112139
Check each listed file before you pass the flag: it confirms every one is
113140
new. If a coding agent runs your deploys, it should show you the list rather
114141
than pass the flag itself; [`AGENTS.md`](../../AGENTS.md) instructs it to.
@@ -202,7 +229,7 @@ npm run cleanup -- <org> --force --confirm <org>
202229
```
203230

204231
Cleanup treats every platform resource that isn't in
205-
`.vapi-state.<org>.json` as an orphan, except those matched by
232+
`.vapi-state.<org>.json` as unmanaged, except those matched by
206233
`resources/<org>/.vapi-ignore`: it lists those as retained and never deletes
207234
them. Still read the dry-run list before a destructive run.
208235

@@ -213,7 +240,7 @@ through the API, then refresh state:
213240

214241
```bash
215242
curl -X DELETE -H "Authorization: Bearer $VAPI_PRIVATE_API_KEY" \
216-
https://api.vapi.ai/assistant/<orphan-uuid>
243+
https://api.vapi.ai/assistant/<resource-uuid>
217244
npm run pull -- <org> --bootstrap
218245
```
219246

0 commit comments

Comments
 (0)