From 582510c78735c995cc8dc2e18d3b9c7491cf6593 Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Sun, 15 Nov 2026 09:25:26 +0000 Subject: [PATCH 1/4] acc: deploy and destroy fail on a legacy empty-ID state entry Records current behavior: bundle plan tolerates a state entry whose __id__ is empty (written by CLIs before #5173) when the resource is still in config, but deploying with the resource removed from config, or destroying, fails with 'internal error, missing in state'. Co-authored-by: Isaac --- .../destroy/empty-id-in-state/databricks.yml | 11 +++++ .../empty-id-in-state/databricks_no_bar.yml | 9 ++++ .../destroy/empty-id-in-state/out.test.toml | 2 + .../destroy/empty-id-in-state/output.txt | 45 +++++++++++++++++++ .../bundle/destroy/empty-id-in-state/script | 27 +++++++++++ .../destroy/empty-id-in-state/test.toml | 6 +++ 6 files changed, 100 insertions(+) create mode 100644 acceptance/bundle/destroy/empty-id-in-state/databricks.yml create mode 100644 acceptance/bundle/destroy/empty-id-in-state/databricks_no_bar.yml create mode 100644 acceptance/bundle/destroy/empty-id-in-state/out.test.toml create mode 100644 acceptance/bundle/destroy/empty-id-in-state/output.txt create mode 100644 acceptance/bundle/destroy/empty-id-in-state/script create mode 100644 acceptance/bundle/destroy/empty-id-in-state/test.toml diff --git a/acceptance/bundle/destroy/empty-id-in-state/databricks.yml b/acceptance/bundle/destroy/empty-id-in-state/databricks.yml new file mode 100644 index 00000000000..4ed04bdfd08 --- /dev/null +++ b/acceptance/bundle/destroy/empty-id-in-state/databricks.yml @@ -0,0 +1,11 @@ +bundle: + name: empty-id-in-state + +resources: + jobs: + foo: + name: foo + bar: + name: bar + baz: + name: baz diff --git a/acceptance/bundle/destroy/empty-id-in-state/databricks_no_bar.yml b/acceptance/bundle/destroy/empty-id-in-state/databricks_no_bar.yml new file mode 100644 index 00000000000..05907956684 --- /dev/null +++ b/acceptance/bundle/destroy/empty-id-in-state/databricks_no_bar.yml @@ -0,0 +1,9 @@ +bundle: + name: empty-id-in-state + +resources: + jobs: + foo: + name: foo + baz: + name: baz diff --git a/acceptance/bundle/destroy/empty-id-in-state/out.test.toml b/acceptance/bundle/destroy/empty-id-in-state/out.test.toml new file mode 100644 index 00000000000..a927a5fbc06 --- /dev/null +++ b/acceptance/bundle/destroy/empty-id-in-state/out.test.toml @@ -0,0 +1,2 @@ +Cloud = false +EnvMatrix.DMS = ["", "true"] diff --git a/acceptance/bundle/destroy/empty-id-in-state/output.txt b/acceptance/bundle/destroy/empty-id-in-state/output.txt new file mode 100644 index 00000000000..7657e4746eb --- /dev/null +++ b/acceptance/bundle/destroy/empty-id-in-state/output.txt @@ -0,0 +1,45 @@ + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/empty-id-in-state/default/files... +Created jobs.bar +Created jobs.baz +Created jobs.foo +Files: 2 uploaded, 0 deleted +Resources: 3 created, 0 changed, 0 deleted, 0 unchanged + +=== An empty-ID entry for a resource in config is planned as a create + +>>> [CLI] bundle plan +create jobs.foo + +Plan: 1 to add, 0 to change, 0 to delete, 2 unchanged + +=== An empty-ID entry for a resource removed from config + +>>> cp databricks_no_bar.yml databricks.yml + +>>> [CLI] bundle deploy +Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/empty-id-in-state/default/files... +Error: cannot plan resources.jobs.bar: internal error, missing in state + +Error: planning failed + +Files: 1 uploaded, 0 deleted + +Exit code: 1 +["resources.jobs.bar","resources.jobs.baz","resources.jobs.foo"] + +=== An empty-ID entry on destroy + +>>> [CLI] bundle destroy --auto-approve +Error: cannot plan resources.jobs.bar: internal error, missing in state + +Error: cannot plan resources.jobs.baz: internal error, missing in state + +Error: cannot plan resources.jobs.foo: internal error, missing in state + +Error: planning failed + + +Exit code: 1 +["resources.jobs.bar","resources.jobs.baz","resources.jobs.foo"] diff --git a/acceptance/bundle/destroy/empty-id-in-state/script b/acceptance/bundle/destroy/empty-id-in-state/script new file mode 100644 index 00000000000..f27b36c3c28 --- /dev/null +++ b/acceptance/bundle/destroy/empty-id-in-state/script @@ -0,0 +1,27 @@ +state_file=".databricks/bundle/default/resources.json" + +# CLIs before #5173 recorded an empty-ID entry when the create step of a recreate failed. +blank_id() { + jq ".state[\"resources.jobs.$1\"].__id__ = \"\"" "$state_file" > state.tmp && mv state.tmp "$state_file" +} + +show_state() { + if [ -f "$state_file" ]; then jq -c '.state | keys' "$state_file"; else echo "no state file"; fi +} + +trace $CLI bundle deploy + +title "An empty-ID entry for a resource in config is planned as a create" +blank_id foo +trace $CLI bundle plan + +title "An empty-ID entry for a resource removed from config" +blank_id bar +trace cp databricks_no_bar.yml databricks.yml +errcode trace $CLI bundle deploy +show_state + +title "An empty-ID entry on destroy" +blank_id baz +errcode trace $CLI bundle destroy --auto-approve +show_state diff --git a/acceptance/bundle/destroy/empty-id-in-state/test.toml b/acceptance/bundle/destroy/empty-id-in-state/test.toml new file mode 100644 index 00000000000..dc8e63be949 --- /dev/null +++ b/acceptance/bundle/destroy/empty-id-in-state/test.toml @@ -0,0 +1,6 @@ +Cloud = false + +Ignore = [ + "databricks_no_bar.yml", + ".databricks/" +] From de137212f32ad4b2edc1a3123ce7980cc01a8fc2 Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Sun, 15 Nov 2026 09:28:58 +0000 Subject: [PATCH 2/4] direct: drop legacy empty-ID state entries on delete instead of failing CLIs before #5173 left a state entry with an empty __id__ when the create step of a recreate failed. #5173 made plan treat such an entry as missing when the resource is still in config, but the Delete path (resource removed from config, or bundle destroy) still failed with 'internal error, missing in state', so the bundle could not be destroyed without hand-editing resources.json. The resource behind such an entry was already deleted, so mark the Delete as Gone: apply drops the state entry without calling the delete API. Co-authored-by: Isaac --- .../bundles/destroy-empty-id-state.md | 1 + .../destroy/empty-id-in-state/output.txt | 24 +++++++------------ bundle/direct/bundle_plan.go | 7 ++++-- 3 files changed, 14 insertions(+), 18 deletions(-) create mode 100644 .nextchanges/bundles/destroy-empty-id-state.md diff --git a/.nextchanges/bundles/destroy-empty-id-state.md b/.nextchanges/bundles/destroy-empty-id-state.md new file mode 100644 index 00000000000..f42c28d542d --- /dev/null +++ b/.nextchanges/bundles/destroy-empty-id-state.md @@ -0,0 +1 @@ +* `bundle destroy` and `bundle deploy` no longer fail with "internal error, missing in state" when the state holds an empty-ID entry left by an interrupted recreate in an older CLI. diff --git a/acceptance/bundle/destroy/empty-id-in-state/output.txt b/acceptance/bundle/destroy/empty-id-in-state/output.txt index 7657e4746eb..917e51c7f33 100644 --- a/acceptance/bundle/destroy/empty-id-in-state/output.txt +++ b/acceptance/bundle/destroy/empty-id-in-state/output.txt @@ -20,26 +20,18 @@ Plan: 1 to add, 0 to change, 0 to delete, 2 unchanged >>> [CLI] bundle deploy Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/empty-id-in-state/default/files... -Error: cannot plan resources.jobs.bar: internal error, missing in state - -Error: planning failed - +Created jobs.foo Files: 1 uploaded, 0 deleted - -Exit code: 1 -["resources.jobs.bar","resources.jobs.baz","resources.jobs.foo"] +Resources: 1 created, 0 changed, 0 deleted, 1 unchanged +["resources.jobs.baz","resources.jobs.foo"] === An empty-ID entry on destroy >>> [CLI] bundle destroy --auto-approve -Error: cannot plan resources.jobs.bar: internal error, missing in state - -Error: cannot plan resources.jobs.baz: internal error, missing in state - -Error: cannot plan resources.jobs.foo: internal error, missing in state - -Error: planning failed +The following resources will be deleted: + delete resources.jobs.foo +All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/empty-id-in-state/default -Exit code: 1 -["resources.jobs.bar","resources.jobs.baz","resources.jobs.foo"] +Destroy: 1 deleted +no state file diff --git a/bundle/direct/bundle_plan.go b/bundle/direct/bundle_plan.go index 43a58291ab2..0c10f067ce0 100644 --- a/bundle/direct/bundle_plan.go +++ b/bundle/direct/bundle_plan.go @@ -225,8 +225,11 @@ func (b *DeploymentBundle) CalculatePlan(ctx context.Context, client *databricks if entry.Action == deployplan.Delete { id := b.StateDB.GetResourceID(resourceKey) if id == "" { - logdiag.LogError(ctx, fmt.Errorf("%s: internal error, missing in state", errorPrefix)) - return false + // An empty-ID entry from an older partial-recreate failure (see the + // Create path below): its resource was deleted and never re-created, + // so there is nothing to delete remotely; applying only drops the entry. + entry.Gone = true + return true } if !adapter.HasDoDelete() { From 0d0b993e3accae264da7c09ff933f9362dfdda2e Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Mon, 16 Nov 2026 10:30:08 +0000 Subject: [PATCH 3/4] Add PR link to changelog fragment Co-authored-by: Isaac --- .nextchanges/bundles/destroy-empty-id-state.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/bundles/destroy-empty-id-state.md b/.nextchanges/bundles/destroy-empty-id-state.md index f42c28d542d..ac56f5563ef 100644 --- a/.nextchanges/bundles/destroy-empty-id-state.md +++ b/.nextchanges/bundles/destroy-empty-id-state.md @@ -1 +1 @@ -* `bundle destroy` and `bundle deploy` no longer fail with "internal error, missing in state" when the state holds an empty-ID entry left by an interrupted recreate in an older CLI. +* `bundle destroy` and `bundle deploy` no longer fail with "internal error, missing in state" when the state holds an empty-ID entry left by an interrupted recreate in an older CLI. ([#7676](https://github.com/databricks/cli/pull/7676)) From 49b2f0366072fc60f43128da260ad5f9190963e2 Mon Sep 17 00:00:00 2001 From: "denis.bilenko" Date: Mon, 16 Nov 2026 14:13:06 +0000 Subject: [PATCH 4/4] direct: document empty-ID state entries in the Gone comments Also run the deploy and destroy in the test without errcode: with the fix both must succeed. Co-authored-by: Isaac --- acceptance/bundle/destroy/empty-id-in-state/script | 4 ++-- bundle/deployplan/action.go | 2 +- bundle/deployplan/plan.go | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/acceptance/bundle/destroy/empty-id-in-state/script b/acceptance/bundle/destroy/empty-id-in-state/script index f27b36c3c28..70396e347dd 100644 --- a/acceptance/bundle/destroy/empty-id-in-state/script +++ b/acceptance/bundle/destroy/empty-id-in-state/script @@ -18,10 +18,10 @@ trace $CLI bundle plan title "An empty-ID entry for a resource removed from config" blank_id bar trace cp databricks_no_bar.yml databricks.yml -errcode trace $CLI bundle deploy +trace $CLI bundle deploy show_state title "An empty-ID entry on destroy" blank_id baz -errcode trace $CLI bundle destroy --auto-approve +trace $CLI bundle destroy --auto-approve show_state diff --git a/bundle/deployplan/action.go b/bundle/deployplan/action.go index 408e2a143f5..698c11e56b1 100644 --- a/bundle/deployplan/action.go +++ b/bundle/deployplan/action.go @@ -10,7 +10,7 @@ type Action struct { ResourceKey string ActionType ActionType // Gone mirrors PlanEntry.Gone: the delete is a state-only cleanup because the - // resource no longer exists remotely. + // resource no longer exists remotely (confirmed by a read, or an empty-ID state entry). Gone bool // StateOnly mirrors PlanEntry.StateOnly: applying the action only changes the state // (a delete of a resource without DoDelete, or a re-key). diff --git a/bundle/deployplan/plan.go b/bundle/deployplan/plan.go index 44d6e9f0f12..6fcaa333e08 100644 --- a/bundle/deployplan/plan.go +++ b/bundle/deployplan/plan.go @@ -130,9 +130,11 @@ type PlanEntry struct { ID string `json:"id,omitempty"` DependsOn []DependsOnEntry `json:"depends_on,omitempty"` Action ActionType `json:"action,omitempty"` - // Gone is set on Delete entries when planning confirmed the resource no longer - // exists remotely. Applying such an entry only removes it from the state, without - // calling the delete API, and approval prompts do not list it as a deletion. + // Gone is set on Delete entries when the resource no longer exists remotely: planning + // confirmed it with a read, or the state entry has an empty ID (left by a recreate in + // an older CLI whose create step failed after the delete). Applying such an entry only + // removes it from the state, without calling the delete API, and approval prompts do + // not list it as a deletion. Gone bool `json:"gone,omitempty"` // StateOnly marks an entry whose apply has no backend effect and only changes the state: // - a Delete of a resource that implements no DoDelete. Like Gone, applying it only