From 91ba36df1aab671e140c5899782695611861b739 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 30 Nov 2026 13:29:41 +0000 Subject: [PATCH 1/7] Record deployment history for bundle deployment unbind Unbind now records a version with one UPDATE operation per removed state entry (the resource and its permissions/grants), each carrying no state, which is how the service learns the resource left the deployment. Recording is best effort and runs after the state commit, as bind's does; a failed history upload warns and fails the version, not the unbind. The workspace resources are untouched, and an already-unbound resource records no version. direct.Unbind returns the removed entries and the serial so the phase can record them, mirroring Bind's DMSBindMetadata. Co-authored-by: Isaac --- .../bind/feature_spec/out.unbind.recorded.txt | 1 + acceptance/bundle/dms/bind-unbind/output.txt | 28 ++++++-- acceptance/bundle/dms/bind-unbind/script | 10 +++ .../bundle/dms/bind-upload-failure/output.txt | 19 +++++ .../bundle/dms/bind-upload-failure/script | 10 +++ .../dms_fault/complete_version/output.txt | 2 + .../dms_fault/create_deployment/output.txt | 2 + .../dms_fault/create_version/output.txt | 2 + .../dms_fault/get_deployment/output.txt | 6 ++ .../dms_fault/update_operation/output.txt | 2 + bundle/direct/bind.go | 70 +++++++++++++------ bundle/phases/bind.go | 35 +++++++++- 12 files changed, 157 insertions(+), 30 deletions(-) diff --git a/acceptance/bundle/deployment/bind/feature_spec/out.unbind.recorded.txt b/acceptance/bundle/deployment/bind/feature_spec/out.unbind.recorded.txt index aa9e81e6253..31696588f39 100644 --- a/acceptance/bundle/deployment/bind/feature_spec/out.unbind.recorded.txt +++ b/acceptance/bundle/deployment/bind/feature_spec/out.unbind.recorded.txt @@ -1,2 +1,3 @@ >>> [CLI] bundle deployment unbind spec1 +Warn: Failed to record deployment history for unbind: failed to create deployment version: operations.resource_key must have a known resource type prefix (e.g. 'jobs.', 'pipelines.'): feature_specs.spec1 diff --git a/acceptance/bundle/dms/bind-unbind/output.txt b/acceptance/bundle/dms/bind-unbind/output.txt index c9475205cad..41fe009c44a 100644 --- a/acceptance/bundle/dms/bind-unbind/output.txt +++ b/acceptance/bundle/dms/bind-unbind/output.txt @@ -83,6 +83,22 @@ Resources: 0 created, 1 changed, 0 deleted, 0 unchanged "job_id": [JOB_ID] } +=== Unbind records a version whose operation carries no state, so the service drops the resource + +>>> print_requests.py --dms //versions --oneline +{"method": "POST", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions", "q": {"version_id": "4"}, "body": {"cli_version": "[CLI_VERSION]", "operations": [{"action_type": "OPERATION_ACTION_TYPE_UPDATE", "resource_key": "jobs.foo"}], "previous_version_id": "3", "version_type": "VERSION_TYPE_DEPLOY"}} +{"method": "PATCH", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/4/operations/jobs.foo", "q": {"update_mask": "state,error_message,status"}, "body": {"error_message": "", "sequence_id": 0, "status": "OPERATION_STATUS_SUCCEEDED"}} +{"method": "POST", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/4/complete", "body": {"completion_reason": "VERSION_COMPLETE_SUCCESS"}} + +>>> MSYS_NO_PATHCONV=1 [CLI] bundle-deployments list-resources deployments/[DEPLOYMENT_ID] -o json +[] + +=== Unbinding an already unbound resource records no version + +>>> [CLI] bundle deployment unbind foo + +>>> print_requests.py --dms //versions + === Rebind preserves the existing shadow history marker without configuration >>> DATABRICKS_BUNDLE_DEPLOYMENT_HISTORY= [CLI] bundle deployment bind foo [JOB_ID] --auto-approve @@ -98,9 +114,9 @@ Run 'bundle deploy' to deploy changes to your workspace } >>> print_requests.py --dms //versions --oneline -{"method": "POST", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions", "q": {"version_id": "6"}, "body": {"cli_version": "[CLI_VERSION]", "operations": [{"action_type": "OPERATION_ACTION_TYPE_UPDATE", "resource_key": "jobs.foo"}], "previous_version_id": "3", "version_type": "VERSION_TYPE_DEPLOY"}} -{"method": "PATCH", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/6/operations/jobs.foo", "q": {"update_mask": "state,error_message,resource_id,status"}, "body": {"error_message": "", "resource_id": "[JOB_ID]", "sequence_id": 0, "state": "{\"state\":{\"deployment\":{\"kind\":\"BUNDLE\",\"metadata_file_path\":\"/Workspace/Users/[USERNAME]/.bundle/dms-bind-unbind-[UNIQUE_NAME]/default/state/metadata.json\"},\"edit_mode\":\"UI_LOCKED\",\"format\":\"MULTI_TASK\",\"max_concurrent_runs\":1,\"name\":\"foo\",\"queue\":{\"enabled\":true}}}", "status": "OPERATION_STATUS_SUCCEEDED"}} -{"method": "POST", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/6/complete", "body": {"completion_reason": "VERSION_COMPLETE_SUCCESS"}} +{"method": "POST", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions", "q": {"version_id": "7"}, "body": {"cli_version": "[CLI_VERSION]", "operations": [{"action_type": "OPERATION_ACTION_TYPE_UPDATE", "resource_key": "jobs.foo"}], "previous_version_id": "4", "version_type": "VERSION_TYPE_DEPLOY"}} +{"method": "PATCH", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/7/operations/jobs.foo", "q": {"update_mask": "state,error_message,resource_id,status"}, "body": {"error_message": "", "resource_id": "[JOB_ID]", "sequence_id": 0, "state": "{\"state\":{\"deployment\":{\"kind\":\"BUNDLE\",\"metadata_file_path\":\"/Workspace/Users/[USERNAME]/.bundle/dms-bind-unbind-[UNIQUE_NAME]/default/state/metadata.json\"},\"edit_mode\":\"UI_LOCKED\",\"format\":\"MULTI_TASK\",\"max_concurrent_runs\":1,\"name\":\"foo\",\"queue\":{\"enabled\":true}}}", "status": "OPERATION_STATUS_SUCCEEDED"}} +{"method": "POST", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/7/complete", "body": {"completion_reason": "VERSION_COMPLETE_SUCCESS"}} === An explicit false drops the marker, so this bind records no history @@ -135,9 +151,9 @@ Run 'bundle deploy' to deploy changes to your workspace } >>> print_requests.py --dms //versions --oneline -{"method": "POST", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions", "q": {"version_id": "12"}, "body": {"cli_version": "[CLI_VERSION]", "operations": [{"action_type": "OPERATION_ACTION_TYPE_UPDATE", "resource_key": "jobs.foo"}], "previous_version_id": "6", "version_type": "VERSION_TYPE_DEPLOY"}} -{"method": "PATCH", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/12/operations/jobs.foo", "q": {"update_mask": "state,error_message,resource_id,status"}, "body": {"error_message": "", "resource_id": "[JOB_ID]", "sequence_id": 0, "state": "{\"state\":{\"deployment\":{\"kind\":\"BUNDLE\",\"metadata_file_path\":\"/Workspace/Users/[USERNAME]/.bundle/dms-bind-unbind-[UNIQUE_NAME]/default/state/metadata.json\"},\"edit_mode\":\"UI_LOCKED\",\"format\":\"MULTI_TASK\",\"max_concurrent_runs\":1,\"name\":\"foo\",\"queue\":{\"enabled\":true}}}", "status": "OPERATION_STATUS_SUCCEEDED"}} -{"method": "POST", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/12/complete", "body": {"completion_reason": "VERSION_COMPLETE_SUCCESS"}} +{"method": "POST", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions", "q": {"version_id": "13"}, "body": {"cli_version": "[CLI_VERSION]", "operations": [{"action_type": "OPERATION_ACTION_TYPE_UPDATE", "resource_key": "jobs.foo"}], "previous_version_id": "8", "version_type": "VERSION_TYPE_DEPLOY"}} +{"method": "PATCH", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/13/operations/jobs.foo", "q": {"update_mask": "state,error_message,resource_id,status"}, "body": {"error_message": "", "resource_id": "[JOB_ID]", "sequence_id": 0, "state": "{\"state\":{\"deployment\":{\"kind\":\"BUNDLE\",\"metadata_file_path\":\"/Workspace/Users/[USERNAME]/.bundle/dms-bind-unbind-[UNIQUE_NAME]/default/state/metadata.json\"},\"edit_mode\":\"UI_LOCKED\",\"format\":\"MULTI_TASK\",\"max_concurrent_runs\":1,\"name\":\"foo\",\"queue\":{\"enabled\":true}}}", "status": "OPERATION_STATUS_SUCCEEDED"}} +{"method": "POST", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/13/complete", "body": {"completion_reason": "VERSION_COMPLETE_SUCCESS"}} === A subsequent deploy continues managing the same job diff --git a/acceptance/bundle/dms/bind-unbind/script b/acceptance/bundle/dms/bind-unbind/script index e27035b9413..d2985e3f648 100644 --- a/acceptance/bundle/dms/bind-unbind/script +++ b/acceptance/bundle/dms/bind-unbind/script @@ -25,10 +25,20 @@ trace $CLI bundle deploy trace jq '{features, resource_id: .state["resources.jobs.foo"].__id__}' .databricks/bundle/default/resources.json title "Unbind preserves the shadow history marker and leaves the job intact" +rm -f "$OUT_REQUESTS" trace $CLI bundle deployment unbind foo trace jq '{features, state}' .databricks/bundle/default/resources.json trace $CLI jobs get "$job_id" | jq '{job_id}' +title "Unbind records a version whose operation carries no state, so the service drops the resource" +trace print_requests.py --dms //versions --oneline +trace MSYS_NO_PATHCONV=1 $CLI bundle-deployments list-resources "deployments/${deployment_id}" -o json | jq -S 'map({resource_key, resource_id, last_action_type})' + +title "Unbinding an already unbound resource records no version" +rm -f "$OUT_REQUESTS" +trace $CLI bundle deployment unbind foo +trace print_requests.py --dms //versions + rm -f "$OUT_REQUESTS" title "Rebind preserves the existing shadow history marker without configuration" diff --git a/acceptance/bundle/dms/bind-upload-failure/output.txt b/acceptance/bundle/dms/bind-upload-failure/output.txt index 332a578b2d6..2e21db70ab7 100644 --- a/acceptance/bundle/dms/bind-upload-failure/output.txt +++ b/acceptance/bundle/dms/bind-upload-failure/output.txt @@ -44,3 +44,22 @@ Run 'bundle deploy' to deploy changes to your workspace "kept": "[JOB_ID]", "upload_failed": null } + +=== A history upload failure only warns the unbind, but fails its version + +>>> fault.py PATCH /api/2.0/bundle/deployments/*/versions/*/operations/* 500 0 1 + +>>> [CLI] bundle deployment unbind kept +Warn: Failed to record deployment history for unbind: recording operation for resources.jobs.kept: Fault injected by test. + +>>> print_requests.py --dms //complete --oneline +{"method": "POST", "path": "/api/2.0/bundle/deployments/[DEPLOYMENT_ID]/versions/6/complete", "body": {"completion_reason": "VERSION_COMPLETE_FAILURE"}} + +=== Remote state no longer contains the unbound resource + +>>> [CLI] bundle summary -o json +{ + "history_failed": "[JOB_ID]", + "kept": null, + "upload_failed": null +} diff --git a/acceptance/bundle/dms/bind-upload-failure/script b/acceptance/bundle/dms/bind-upload-failure/script index f1bc835915f..0958c2f7a3b 100644 --- a/acceptance/bundle/dms/bind-upload-failure/script +++ b/acceptance/bundle/dms/bind-upload-failure/script @@ -23,3 +23,13 @@ rm -rf .databricks title "Remote state contains the binding whose history upload failed" trace $CLI bundle summary -o json | jq '.resources.jobs | map_values(.id // null)' rm -f "$OUT_REQUESTS" + +title "A history upload failure only warns the unbind, but fails its version" +trace fault.py "PATCH /api/2.0/bundle/deployments/*/versions/*/operations/*" 500 0 1 +trace $CLI bundle deployment unbind kept +trace print_requests.py --dms //complete --oneline + +rm -rf .databricks +title "Remote state no longer contains the unbound resource" +trace $CLI bundle summary -o json | jq '.resources.jobs | map_values(.id // null)' +rm -f "$OUT_REQUESTS" diff --git a/acceptance/bundle/dms_fault/complete_version/output.txt b/acceptance/bundle/dms_fault/complete_version/output.txt index 269f73a6721..5b2911a608c 100644 --- a/acceptance/bundle/dms_fault/complete_version/output.txt +++ b/acceptance/bundle/dms_fault/complete_version/output.txt @@ -48,6 +48,7 @@ >>> bundle deployment unbind foo + Warn: Failed to complete deployment history version: Fault injected by test. >>> bundle generate job --existing-job-id [FOO_ID] --key foo --config-dir resources --source-dir src --force --bind Job configuration successfully saved to resources/foo.job.yml @@ -67,6 +68,7 @@ >>> bundle deployment unbind bar + Warn: Failed to complete deployment history version: Fault injected by test. >>> bundle generate pipeline --existing-pipeline-id [BAR_ID] --key bar --config-dir resources --source-dir src --force --bind File successfully saved to src/pipeline.sql diff --git a/acceptance/bundle/dms_fault/create_deployment/output.txt b/acceptance/bundle/dms_fault/create_deployment/output.txt index 7f7b781fd79..4ae0acb41f6 100644 --- a/acceptance/bundle/dms_fault/create_deployment/output.txt +++ b/acceptance/bundle/dms_fault/create_deployment/output.txt @@ -39,6 +39,7 @@ >>> bundle deployment unbind foo + Warn: Failed to record deployment history for unbind: failed to create deployment: Fault injected by test. >>> bundle generate job --existing-job-id [FOO_ID] --key foo --config-dir resources --source-dir src --force --bind Job configuration successfully saved to resources/foo.job.yml @@ -58,6 +59,7 @@ >>> bundle deployment unbind bar + Warn: Failed to record deployment history for unbind: failed to create deployment: Fault injected by test. >>> bundle generate pipeline --existing-pipeline-id [BAR_ID] --key bar --config-dir resources --source-dir src --force --bind File successfully saved to src/pipeline.sql diff --git a/acceptance/bundle/dms_fault/create_version/output.txt b/acceptance/bundle/dms_fault/create_version/output.txt index 20eb577bf16..0ef6a35c36a 100644 --- a/acceptance/bundle/dms_fault/create_version/output.txt +++ b/acceptance/bundle/dms_fault/create_version/output.txt @@ -47,6 +47,7 @@ >>> bundle deployment unbind foo + Warn: Failed to record deployment history for unbind: failed to create deployment version: Fault injected by test. >>> bundle generate job --existing-job-id [FOO_ID] --key foo --config-dir resources --source-dir src --force --bind Job configuration successfully saved to resources/foo.job.yml @@ -66,6 +67,7 @@ >>> bundle deployment unbind bar + Warn: Failed to record deployment history for unbind: failed to create deployment version: Fault injected by test. >>> bundle generate pipeline --existing-pipeline-id [BAR_ID] --key bar --config-dir resources --source-dir src --force --bind File successfully saved to src/pipeline.sql diff --git a/acceptance/bundle/dms_fault/get_deployment/output.txt b/acceptance/bundle/dms_fault/get_deployment/output.txt index 2d35346e952..44689cefc28 100644 --- a/acceptance/bundle/dms_fault/get_deployment/output.txt +++ b/acceptance/bundle/dms_fault/get_deployment/output.txt @@ -55,6 +55,9 @@ >>> bundle deployment unbind foo + Warn: retrying after 500 Internal Server Error from GET /api/2.0/bundle/deployments/[DEPLOYMENT_ID] + Warn: retrying after 500 Internal Server Error from GET /api/2.0/bundle/deployments/[DEPLOYMENT_ID] + Warn: Failed to record deployment history for unbind: Fault injected by test. >>> bundle generate job --existing-job-id [FOO_ID] --key foo --config-dir resources --source-dir src --force --bind Job configuration successfully saved to resources/foo.job.yml @@ -76,6 +79,9 @@ >>> bundle deployment unbind bar + Warn: retrying after 500 Internal Server Error from GET /api/2.0/bundle/deployments/[DEPLOYMENT_ID] + Warn: retrying after 500 Internal Server Error from GET /api/2.0/bundle/deployments/[DEPLOYMENT_ID] + Warn: Failed to record deployment history for unbind: Fault injected by test. >>> bundle generate pipeline --existing-pipeline-id [BAR_ID] --key bar --config-dir resources --source-dir src --force --bind File successfully saved to src/pipeline.sql diff --git a/acceptance/bundle/dms_fault/update_operation/output.txt b/acceptance/bundle/dms_fault/update_operation/output.txt index 3aeeb3dc84a..6aad0f0fa2b 100644 --- a/acceptance/bundle/dms_fault/update_operation/output.txt +++ b/acceptance/bundle/dms_fault/update_operation/output.txt @@ -48,6 +48,7 @@ >>> bundle deployment unbind foo + Warn: Failed to record deployment history for unbind: recording operation for [RESOURCE_KEY]: Fault injected by test. >>> bundle generate job --existing-job-id [FOO_ID] --key foo --config-dir resources --source-dir src --force --bind Job configuration successfully saved to resources/foo.job.yml @@ -67,6 +68,7 @@ >>> bundle deployment unbind bar + Warn: Failed to record deployment history for unbind: recording operation for [RESOURCE_KEY]: Fault injected by test. >>> bundle generate pipeline --existing-pipeline-id [BAR_ID] --key bar --config-dir resources --source-dir src --force --bind File successfully saved to src/pipeline.sql diff --git a/bundle/direct/bind.go b/bundle/direct/bind.go index 5551985c3e6..d9f4930b87d 100644 --- a/bundle/direct/bind.go +++ b/bundle/direct/bind.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "slices" "strings" "github.com/databricks/cli/bundle/config" @@ -279,37 +280,60 @@ func (result *BindResult) Cancel() { // Unbind removes a resource from direct engine state without deleting // the workspace resource. Also removes associated permissions/grants entries. -func (b *DeploymentBundle) Unbind(ctx context.Context, statePath, resourceKey string) error { +func (b *DeploymentBundle) Unbind(ctx context.Context, statePath, resourceKey string) (*DMSUnbindMetadata, error) { if err := b.StateDB.Open(ctx, statePath, dstate.ReadingFile, dstate.WithRecovery(true), dstate.OpenDmsArgs{}); err != nil { - return err + return nil, err } if err := b.StateDB.UpgradeToWrite(); err != nil { - return err + return nil, err } - // Delete the main resource - err := b.StateDB.DeleteState(ctx, resourceKey, false) - if err != nil { - return err + // The resource and its permissions/grants entries, which are stored as + // "resources.jobs.foo.permissions" or "resources.schemas.bar.grants". Sorted so the + // recorded operations come out in a stable order. + var keys []string + for key := range b.StateDB.Data.State { + if key == resourceKey || strings.HasPrefix(key, resourceKey+".") { + keys = append(keys, key) + } } + slices.Sort(keys) - log.Infof(ctx, "Unbound %s", resourceKey) - - // Also delete associated permissions/grants if they exist - // These are stored as "resources.jobs.foo.permissions" or "resources.schemas.bar.grants" - permissionsKey := resourceKey + ".permissions" - grantsKey := resourceKey + ".grants" - - for key := range b.StateDB.Data.State { - if key == permissionsKey || key == grantsKey || strings.HasPrefix(key, resourceKey+".") { - err = b.StateDB.DeleteState(ctx, key, false) - if err != nil { - return err - } - log.Infof(ctx, "Unbound %s", key) + var removed []RemovedResource + for _, key := range keys { + removed = append(removed, RemovedResource{Key: key, ID: b.StateDB.GetResourceID(key)}) + if err := b.StateDB.DeleteState(ctx, key, false); err != nil { + return nil, err + } + log.Infof(ctx, "Unbound %s", key) + } + if len(keys) == 0 { + // Nothing to remove; still write the state so the serial moves, as it always has. + if err := b.StateDB.DeleteState(ctx, resourceKey, false); err != nil { + return nil, err } + log.Infof(ctx, "Unbound %s", resourceKey) } - _, err = b.StateDB.Finalize(ctx) - return err + var dmsMetadata *DMSUnbindMetadata + if b.StateDB.RecordsHistory() && len(removed) > 0 { + dmsMetadata = &DMSUnbindMetadata{Serial: b.StateDB.Data.Serial, Removed: removed} + } + if _, err := b.StateDB.Finalize(ctx); err != nil { + return nil, err + } + return dmsMetadata, nil +} + +// RemovedResource is a state entry an unbind dropped, by key and workspace id. +type RemovedResource struct { + Key string + ID string +} + +// DMSUnbindMetadata holds unbinding data to publish after the unbind commits. It is nil when +// deployment history is disabled or nothing was removed. +type DMSUnbindMetadata struct { + Serial int + Removed []RemovedResource } diff --git a/bundle/phases/bind.go b/bundle/phases/bind.go index 7de8730e4d8..607913100ba 100644 --- a/bundle/phases/bind.go +++ b/bundle/phases/bind.go @@ -175,7 +175,11 @@ func Unbind(ctx context.Context, b *bundle.Bundle, group, resourceKey string, en return } + var history *bindingHistory + var historyErr error defer func() { + // Same rule as bind: a failed history upload fails the version, not the unbind. + completeBindingHistory(ctx, b, history, historyErr == nil && !logdiag.HasError(ctx)) bundle.ApplyContext(ctx, b, lock.Release(lock.GoalUnbind)) }() @@ -188,15 +192,44 @@ func Unbind(ctx context.Context, b *bundle.Bundle, group, resourceKey string, en fullResourceKey := fmt.Sprintf("resources.%s.%s", group, resourceKey) _, statePath := b.StateFilenameDirect(ctx) - err := b.DeploymentBundle.Unbind(ctx, statePath, fullResourceKey) + metadata, err := b.DeploymentBundle.Unbind(ctx, statePath, fullResourceKey) if err != nil { logdiag.LogError(ctx, err) return } + history, historyErr = recordUnbindHistory(ctx, b, metadata) + if historyErr != nil { + log.Warnf(ctx, "Failed to record deployment history for unbind: %s", historyErr) + } + statemgmt.PushResourcesState(ctx, b) } +// recordUnbindHistory publishes a committed unbinding when DMS metadata was requested: one +// operation per removed entry, recorded without state, which is how the service learns the +// resource left the deployment. The workspace resources themselves are untouched. +func recordUnbindHistory(ctx context.Context, b *bundle.Bundle, metadata *direct.DMSUnbindMetadata) (*bindingHistory, error) { + if metadata == nil { + return nil, nil + } + staged := make([]bundledeployments.StagedOperation, 0, len(metadata.Removed)) + for _, r := range metadata.Removed { + staged = append(staged, bundledeployments.StagedOperation{ + ResourceKey: strings.TrimPrefix(r.Key, dms.StatePrefix), + ActionType: bundledeployments.OperationActionTypeOperationActionTypeUpdate, + }) + } + history, err := createBindingVersion(ctx, b, metadata.Serial, staged) + if err != nil { + return nil, err + } + for _, r := range metadata.Removed { + history.buffer.RecordOperation(ctx, r.Key, false, r.ID, nil) + } + return history, history.buffer.Drain(ctx) +} + // recordBindHistory publishes a committed binding when DMS metadata was requested. func recordBindHistory(ctx context.Context, b *bundle.Bundle, resourceKey string, metadata *direct.DMSBindMetadata) (*bindingHistory, error) { if metadata == nil { From 509b83f585ace82d5e411eeabd9e2b914daf6821 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 30 Nov 2026 13:32:54 +0000 Subject: [PATCH 2/7] Add changelog fragment for unbind history Co-authored-by: Isaac --- .nextchanges/bundles/record-unbind-history.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .nextchanges/bundles/record-unbind-history.md diff --git a/.nextchanges/bundles/record-unbind-history.md b/.nextchanges/bundles/record-unbind-history.md new file mode 100644 index 00000000000..a23a128a520 --- /dev/null +++ b/.nextchanges/bundles/record-unbind-history.md @@ -0,0 +1 @@ +- Record `bundle deployment unbind` in deployment history when it is enabled, so the service no longer lists the unbound resource ([#8204](https://github.com/databricks/cli/pull/8204)). From fb7d17633bbd685b47a67aa49f1b5d80efd8c076 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 30 Nov 2026 13:33:41 +0000 Subject: [PATCH 3/7] Match the fragment bullet style Co-authored-by: Isaac --- .nextchanges/bundles/record-unbind-history.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/bundles/record-unbind-history.md b/.nextchanges/bundles/record-unbind-history.md index a23a128a520..40ff8cb0608 100644 --- a/.nextchanges/bundles/record-unbind-history.md +++ b/.nextchanges/bundles/record-unbind-history.md @@ -1 +1 @@ -- Record `bundle deployment unbind` in deployment history when it is enabled, so the service no longer lists the unbound resource ([#8204](https://github.com/databricks/cli/pull/8204)). +* Record `bundle deployment unbind` in deployment history when it is enabled, so the service no longer lists the unbound resource ([#8204](https://github.com/databricks/cli/pull/8204)). From 60047e9fcdbf2fb28695bf688411d7272d6801f5 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 30 Nov 2026 13:53:02 +0000 Subject: [PATCH 4/7] Capture the unbind serial after the commit Finalize is what bumps the serial, so reading it beforehand numbered the version one below the serial the state file carries. Bind already reads it after its commit. Co-authored-by: Isaac --- bundle/direct/bind.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bundle/direct/bind.go b/bundle/direct/bind.go index d9f4930b87d..31bfe977ad0 100644 --- a/bundle/direct/bind.go +++ b/bundle/direct/bind.go @@ -315,14 +315,14 @@ func (b *DeploymentBundle) Unbind(ctx context.Context, statePath, resourceKey st log.Infof(ctx, "Unbound %s", resourceKey) } - var dmsMetadata *DMSUnbindMetadata - if b.StateDB.RecordsHistory() && len(removed) > 0 { - dmsMetadata = &DMSUnbindMetadata{Serial: b.StateDB.Data.Serial, Removed: removed} - } if _, err := b.StateDB.Finalize(ctx); err != nil { return nil, err } - return dmsMetadata, nil + if !b.StateDB.RecordsHistory() || len(removed) == 0 { + return nil, nil + } + // Finalize bumps the serial, so this is the one the state file now carries. + return &DMSUnbindMetadata{Serial: b.StateDB.Data.Serial, Removed: removed}, nil } // RemovedResource is a state entry an unbind dropped, by key and workspace id. From d6839ea6b5c261e075162ba2d8e83ad3ac930a57 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 30 Nov 2026 14:16:55 +0000 Subject: [PATCH 5/7] End the changelog fragment with the PR link Co-authored-by: Isaac --- .nextchanges/bundles/record-unbind-history.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/bundles/record-unbind-history.md b/.nextchanges/bundles/record-unbind-history.md index 40ff8cb0608..9d1a14184a5 100644 --- a/.nextchanges/bundles/record-unbind-history.md +++ b/.nextchanges/bundles/record-unbind-history.md @@ -1 +1 @@ -* Record `bundle deployment unbind` in deployment history when it is enabled, so the service no longer lists the unbound resource ([#8204](https://github.com/databricks/cli/pull/8204)). +* Record `bundle deployment unbind` in deployment history when it is enabled, so the service no longer lists the unbound resource. ([#8204](https://github.com/databricks/cli/pull/8204)) From fcdb0876fa52f2be82f8b075fcf87206935a6fc2 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Tue, 1 Dec 2026 14:40:52 +0000 Subject: [PATCH 6/7] Take the unbind serial before Finalize clears it Finalize resets the in-memory data after committing, so reading the serial afterwards always gave 0 and the version fell back to last+1, which can sit below the file serial. The WAL commits under serial+1, so take that before the commit. Co-authored-by: Isaac --- bundle/direct/bind.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bundle/direct/bind.go b/bundle/direct/bind.go index 31bfe977ad0..58ca5edd4d0 100644 --- a/bundle/direct/bind.go +++ b/bundle/direct/bind.go @@ -315,14 +315,15 @@ func (b *DeploymentBundle) Unbind(ctx context.Context, statePath, resourceKey st log.Infof(ctx, "Unbound %s", resourceKey) } + // Finalize commits the WAL under the next serial and then clears Data, so take it now. + serial := b.StateDB.Data.Serial + 1 if _, err := b.StateDB.Finalize(ctx); err != nil { return nil, err } if !b.StateDB.RecordsHistory() || len(removed) == 0 { return nil, nil } - // Finalize bumps the serial, so this is the one the state file now carries. - return &DMSUnbindMetadata{Serial: b.StateDB.Data.Serial, Removed: removed}, nil + return &DMSUnbindMetadata{Serial: serial, Removed: removed}, nil } // RemovedResource is a state entry an unbind dropped, by key and workspace id. From e1760039cb1137c29825268e4210ea867242ab73 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Tue, 1 Dec 2026 16:09:56 +0000 Subject: [PATCH 7/7] Drop the removed-resource id from the unbind metadata An update without state clears the resource, and NewStateUpdate sends no resource_id with it, so the id was collected for nothing. Co-authored-by: Isaac --- bundle/direct/bind.go | 14 ++++---------- bundle/phases/bind.go | 9 +++++---- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/bundle/direct/bind.go b/bundle/direct/bind.go index 58ca5edd4d0..411a6a31c56 100644 --- a/bundle/direct/bind.go +++ b/bundle/direct/bind.go @@ -299,9 +299,9 @@ func (b *DeploymentBundle) Unbind(ctx context.Context, statePath, resourceKey st } slices.Sort(keys) - var removed []RemovedResource + var removed []string for _, key := range keys { - removed = append(removed, RemovedResource{Key: key, ID: b.StateDB.GetResourceID(key)}) + removed = append(removed, key) if err := b.StateDB.DeleteState(ctx, key, false); err != nil { return nil, err } @@ -326,15 +326,9 @@ func (b *DeploymentBundle) Unbind(ctx context.Context, statePath, resourceKey st return &DMSUnbindMetadata{Serial: serial, Removed: removed}, nil } -// RemovedResource is a state entry an unbind dropped, by key and workspace id. -type RemovedResource struct { - Key string - ID string -} - // DMSUnbindMetadata holds unbinding data to publish after the unbind commits. It is nil when -// deployment history is disabled or nothing was removed. +// deployment history is disabled or nothing was removed. Removed lists the dropped state keys. type DMSUnbindMetadata struct { Serial int - Removed []RemovedResource + Removed []string } diff --git a/bundle/phases/bind.go b/bundle/phases/bind.go index 607913100ba..ef975b7cdc5 100644 --- a/bundle/phases/bind.go +++ b/bundle/phases/bind.go @@ -214,9 +214,9 @@ func recordUnbindHistory(ctx context.Context, b *bundle.Bundle, metadata *direct return nil, nil } staged := make([]bundledeployments.StagedOperation, 0, len(metadata.Removed)) - for _, r := range metadata.Removed { + for _, key := range metadata.Removed { staged = append(staged, bundledeployments.StagedOperation{ - ResourceKey: strings.TrimPrefix(r.Key, dms.StatePrefix), + ResourceKey: strings.TrimPrefix(key, dms.StatePrefix), ActionType: bundledeployments.OperationActionTypeOperationActionTypeUpdate, }) } @@ -224,8 +224,9 @@ func recordUnbindHistory(ctx context.Context, b *bundle.Bundle, metadata *direct if err != nil { return nil, err } - for _, r := range metadata.Removed { - history.buffer.RecordOperation(ctx, r.Key, false, r.ID, nil) + // No state means the resource left the deployment, and the update then carries no id. + for _, key := range metadata.Removed { + history.buffer.RecordOperation(ctx, key, false, "", nil) } return history, history.buffer.Drain(ctx) }