Skip to content

Fix config-remote-sync failing on YAML anchors - #7950

Open
ilyakuz-db wants to merge 2 commits into
mainfrom
ilya/config-sync-unknown-anchor
Open

ilyakuz-db wants to merge 2 commits into
mainfrom
ilya/config-sync-unknown-anchor

Conversation

@ilyakuz-db

@ilyakuz-db ilyakuz-db commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Changes

config-remote-sync keeps YAML anchors working when it writes remote changes back. Before each patch, an alias on the changed path is expanded into a copy, and an anchored node that the change edits or removes hands its anchor to its first other alias, so the aliases after it still resolve.

Why

When a remote change removed or replaced a node holding an anchor (&name), the aliases (*name) elsewhere in the file were left dangling, and the next re-parse failed with unknown anchor 'name' referenced. An edit through an alias also went into the shared anchor and changed every alias.

An edit to an aliased field now changes only that field: its alias becomes an inline copy, so a file where every alias gets the same remote edit ends up with copies instead of one shared anchor. Fields inherited through merge keys (<<: *base) are out of scope here.

Tests

New unit cases in bundle/configsync/patch_test.go and a config-remote-sync/yaml_anchors acceptance test, which reproduced the error on main. Both pass locally, and lint is clean.

Status Check Revision Comments
✅ Local review ad1c97e (latest) Codex and auto review, no P0/P1 after 2 rounds; P2s noted: anchors become copies on shared edits, inline comment on the aliased key, retry and merge-key tests
✅ Design review ad1c97e (latest) RIGHT-SIZED: adds the anchor bookkeeping the patcher lacks, right before it runs
⚠️ E2E validation ad1c97e (latest) not run on a workspace; configsync unit tests and the yaml_anchors acceptance test pass locally
➖ Isaac review ad1c97e (latest) n/a on CLI PRs
⏳ Code owners review ad1c97e (latest) none yet
✅ CI / merge conflicts ad1c97e (latest) no conflicts; 20 checks pass, 10 skipped

✅ success · ⏳ pending · ⚠️ warning · ❌ failed · ➖ n/a

ilyakuz-db and others added 2 commits November 24, 2026 21:03
Co-authored-by: Isaac <no-reply@databricks.com>
Co-authored-by: Isaac <no-reply@databricks.com>
@ilyakuz-db
ilyakuz-db requested review from a team as code owners November 24, 2026 23:35
@ilyakuz-db ilyakuz-db self-assigned this Nov 24, 2026
@github-actions github-actions Bot added the DABs DABs related issues label Nov 24, 2026

@review-oss-bot review-oss-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review at ad1c97e. Each finding was verified against the code.

No blocking issues found. 4 non-blocking comment(s) below.

This PR makes config-remote-sync keep YAML anchors valid when it writes remote changes back. Before each patch, aliases on the changed path are expanded, and anchors on edited or removed nodes are handed to their next alias, so the unknown anchor failure on re-parse goes away. The main path holds up when traced through the patcher and the parent-path retry. One gap: the null-ancestor fallback still runs on the un-isolated content, so adds through an aliased or anchored null parent still fail. There is also no test for the retry path, and the changelog fragment and the acceptance script's jq usage need small fixes.

Comments outside the changed lines

  • [nice to have] .nextchanges/bundles: bundle config-remote-sync --save used to fail with unknown anchor 'name' referenced on files with anchors. It now writes the file, and it rewrites aliases that receive an edit into inline copies. Users can see both, and the PR adds no fragment. Can you add an entry under .nextchanges/bundles/, or say why this experimental command doesn't need one?

return nil, fmt.Errorf("failed to parse JSON Pointer %s: %w", jsonPointer, err)
}

source, err := isolateAnchors(content, fieldPathCandidate, fieldChange.Change.Operation)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] The isolated source goes to the patcher and the parent-path retry, but the fallback at line 151 still calls addThroughNullAncestor(content, ...) on the original content. That function bails on any anchored ancestor (line 215), and yamlChild can't follow an AliasNode. So other: &shared null\nparent: *shared with an add at parent.key still fails with scalar can not be a container, and so does parent: &shared {tags: null}\nother: *shared at parent.tags.key, even though after isolation both are plain nulls the fallback could fill in. Could the fallback run on the isolated source for each candidate? Then the anchor guard in addThroughNullAncestor could go, and those TestApplyChangeScalarParents cases would show the fix instead of pinning the error.


patcher := gopkgv3yamlpatcher.New(gopkgv3yamlpatcher.IndentSpaces(2))
modifiedContent, patchErr := patcher.Apply(content, yamlpatch.Patch{yamlpatch.Operation{
modifiedContent, patchErr := patcher.Apply(errInfo.source, yamlpatch.Patch{yamlpatch.Operation{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] Switching this retry from content to errInfo.source is part of the fix, but none of the TestApplyChangeKeepsAnchors cases reach it. For example, a: &x\n k: 1\nb: *x\n with an add at b.m.n fails first with a missing /b/m parent, so it goes through this retry. Can you add that case and assert that a stays {k: 1} and only b gains m: {n: 2}?

rm databricks.yml.backup

title "Only the changed tasks differ"
trace $CLI bundle validate -o json | jq -c '.resources.jobs.my_job.tasks[] | {task_key, job_cluster_key, libraries}'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] .agents/rules/testing.md asks for the acceptance/bin/ helpers instead of inline jq pipelines. Could this use gron.py | grep on the task fields (task_key, job_cluster_key, libraries) instead of the hand-written jq -c projection?

@github-actions

Copy link
Copy Markdown
Contributor

Commit: ad1c97ede | Workflow run

Regression test report

Selected 1 changed tests (limit=20, 0 not selected)

2 tests: regression=2 unreleased=0 coverage=0 failing=0
test branch main (c639f9d) latest (v1.28.0)
TestAccept/bundle/config-remote-sync/yaml_anchors/DMS= ✅ ❌ ❌
TestAccept/bundle/config-remote-sync/yaml_anchors/DMS=true ✅ ❌ ❌
TestAccept/bundle/config-remote-sync/yaml_anchors/DMS=: branch ✅ | main (c639f9d) ❌ | latest (v1.28.0) ❌

main (c639f9d):

acceptance_test.go:1402: Diff:
        --- bundle/config-remote-sync/yaml_anchors/output.txt
        +++ /tmp/TestAcceptbundleconfig-remote-syncyaml_anchorsDMS=3355443911/002/output.txt
        @@ -6,53 +6,8 @@
         === Remove the libraries of the task that defines the anchor, change the library of one aliased task and move another to the large cluster
         
         === Detect and save changes
        -Detected changes in 1 resource(s):
        +Error: failed to generate YAML files: failed to apply change to file [TEST_TMP_DIR]/databricks.yml for a field resources.jobs.my_job.tasks[2].job_cluster_key: failed to apply change: failed to convert YAML bytes to node: unmarshal original yaml bytes: yaml: unknown anchor 'common_libs' referenced
         
        -Resource: resources.jobs.my_job
        -  tasks[task_key='ingest'].libraries[0].pypi.package: replace
        -  tasks[task_key='setup'].libraries: remove
        -  tasks[task_key='transform'].job_cluster_key: replace
        -
        -
        -
        -=== Configuration changes
        -
        ->>> diff.py databricks.yml.backup databricks.yml
        ---- databricks.yml.backup
        -+++ databricks.yml
        -@@ -18,17 +18,18 @@
        -           notebook_task:
        -             notebook_path: /Users/{{workspace_user_name}}/setup
        --          libraries: &common_libs
        --            - pypi:
        --                package: requests
        -         - task_key: ingest
        -           job_cluster_key: main
        -           notebook_task:
        -             notebook_path: /Users/{{workspace_user_name}}/ingest
        --          libraries: *common_libs
        -+          libraries:
        -+            - pypi:
        -+                package: httpx
        -         - task_key: transform
        --          job_cluster_key: main
        -+          job_cluster_key: large
        -           notebook_task:
        -             notebook_path: /Users/{{workspace_user_name}}/transform
        --          libraries: *common_libs
        -+          libraries: &common_libs
        -+            - pypi:
        -+                package: requests
        -
        - targets:
        -
        -=== Only the changed tasks differ
        -
        ->>> [CLI] bundle validate -o json
        -{"task_key":"ingest","job_cluster_key":"main","libraries":[{"pypi":{"package":"httpx"}}]}
        -{"task_key":"setup","job_cluster_key":"main","libraries":null}
        -{"task_key":"transform","job_cluster_key":"large","libraries":[{"pypi":{"package":"requests"}}]}
        -
         >>> [CLI] bundle destroy --auto-approve
         The following resources will be deleted:
           delete resources.jobs.my_job
        @@ -60,3 +14,5 @@
         All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default
         
         Destroy: 1 deleted
        +
        +Exit code: 1
        
FAIL

latest (v1.28.0): same output as main (c639f9d)

TestAccept/bundle/config-remote-sync/yaml_anchors/DMS=true: branch ✅ | main (c639f9d) ❌ | latest (v1.28.0) ❌

main (c639f9d):

acceptance_test.go:1402: Diff:
        --- bundle/config-remote-sync/yaml_anchors/output.txt
        +++ /tmp/TestAcceptbundleconfig-remote-syncyaml_anchorsDMS=true3206606449/002/output.txt
        @@ -6,53 +6,8 @@
         === Remove the libraries of the task that defines the anchor, change the library of one aliased task and move another to the large cluster
         
         === Detect and save changes
        -Detected changes in 1 resource(s):
        +Error: failed to generate YAML files: failed to apply change to file [TEST_TMP_DIR]/databricks.yml for a field resources.jobs.my_job.tasks[2].job_cluster_key: failed to apply change: failed to convert YAML bytes to node: unmarshal original yaml bytes: yaml: unknown anchor 'common_libs' referenced
         
        -Resource: resources.jobs.my_job
        -  tasks[task_key='ingest'].libraries[0].pypi.package: replace
        -  tasks[task_key='setup'].libraries: remove
        -  tasks[task_key='transform'].job_cluster_key: replace
        -
        -
        -
        -=== Configuration changes
        -
        ->>> diff.py databricks.yml.backup databricks.yml
        ---- databricks.yml.backup
        -+++ databricks.yml
        -@@ -18,17 +18,18 @@
        -           notebook_task:
        -             notebook_path: /Users/{{workspace_user_name}}/setup
        --          libraries: &common_libs
        --            - pypi:
        --                package: requests
        -         - task_key: ingest
        -           job_cluster_key: main
        -           notebook_task:
        -             notebook_path: /Users/{{workspace_user_name}}/ingest
        --          libraries: *common_libs
        -+          libraries:
        -+            - pypi:
        -+                package: httpx
        -         - task_key: transform
        --          job_cluster_key: main
        -+          job_cluster_key: large
        -           notebook_task:
        -             notebook_path: /Users/{{workspace_user_name}}/transform
        --          libraries: *common_libs
        -+          libraries: &common_libs
        -+            - pypi:
        -+                package: requests
        -
        - targets:
        -
        -=== Only the changed tasks differ
        -
        ->>> [CLI] bundle validate -o json
        -{"task_key":"ingest","job_cluster_key":"main","libraries":[{"pypi":{"package":"httpx"}}]}
        -{"task_key":"setup","job_cluster_key":"main","libraries":null}
        -{"task_key":"transform","job_cluster_key":"large","libraries":[{"pypi":{"package":"requests"}}]}
        -
         >>> [CLI] bundle destroy --auto-approve
         The following resources will be deleted:
           delete resources.jobs.my_job
        @@ -60,3 +14,5 @@
         All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/test-bundle-[UNIQUE_NAME]/default
         
         Destroy: 1 deleted
        +
        +Exit code: 1

latest (v1.28.0): same output as main (c639f9d)

@eng-dev-ecosystem-bot

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: ad1c97e

Run: 45511440816

Env 💚​RECOVERED ✅​pass 🙈​skip Time
💚​ aws linux-2core-8gb 1 275 19 5:16
💚​ aws-windows-latest-4core-16gb 1 274 18 4:02
💚​ azure linux-2core-8gb 1 274 19 4:40
💚​ azure-windows-latest-4core-16gb 1 273 18 3:58
💚​ gcp linux-2core-8gb 1 275 19 4:56
💚​ gcp-windows-latest-4core-16gb 1 274 18 3:46
Test Name aws linux-2core-8gb aws-windows-latest-4core-16gb azure linux-2core-8gb azure-windows-latest-4core-16gb gcp linux-2core-8gb gcp-windows-latest-4core-16gb
💚​ TestAccept 💚​R 💚​R 💚​R 💚​R 💚​R 💚​R
Top 6 slowest tests (at least 2 minutes):
duration env testname
4:02 aws linux-2core-8gb TestAccept
3:59 aws-windows-latest-4core-16gb TestAccept
3:56 azure-windows-latest-4core-16gb TestAccept
3:44 gcp-windows-latest-4core-16gb TestAccept
3:26 gcp linux-2core-8gb TestAccept
3:24 azure linux-2core-8gb TestAccept

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DABs DABs related issues factory-generated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants