Skip to content

feat(sync): skip variations that LaunchDarkly owns (AIC-3901) - #1032

Open
nkester-ld wants to merge 3 commits into
mainfrom
AIC-3901/nkester/code-ownership-1-foundation
Open

nkester-ld wants to merge 3 commits into
mainfrom
AIC-3901/nkester/code-ownership-1-foundation

Conversation

@nkester-ld

@nkester-ld nkester-ld commented Nov 16, 2026 •

Copy link
Copy Markdown

Human

LaunchDarkly works out ownership from the synced manifest, so ldcli doesn't write ownership rules. It only reads them, so that it never pushes over a variation someone kept in LaunchDarkly.

tldr of changes:

  1. Ownership applies to every variation, not just linked ones. Without this, a variation that has an explicit "managed in LaunchDarkly" rule still gets pushed and overwrites UI edits. The lock doesn't stop that. This is the substance of AC3, and it's what applyVariationOwnership and enforceOwnership in state.go do.
  2. A message when a push is skipped: " is managed in LaunchDarkly; pulled, not pushed. To manage it in code, switch it to Code in LaunchDarkly." It appears in the text output and as notes in the JSON, and only on rows that would otherwise have pushed.
  3. A clearer error when the lock rejects a write (403 managed_in_code). It now says the variation is managed in code and to run sync from its source repo. Before, it wrongly told the user to ask for the syncAIConfigVariation permission.

Why

LaunchDarkly now treats a variation in a synced manifest as owned by code, unless someone has set it to LaunchDarkly in the UI. ldcli still reads the setting literally. A variation with no rule reads as "LaunchDarkly", so a linked variation gets pulled when it should be pushed. A variation someone deliberately kept in LaunchDarkly still gets pushed.

Related: launchdarkly/gonfalon#75851 (the server lock) · AIC-3901

Open questions

  • Should the lock accept ldcli's User-Agent, or should ldcli send LD-Sync-Source? Until one of these happens, pushes to code-owned variations fail while the lock is on, now with a clear "managed in code" error.

What changes

Before, for a variation set to LaunchDarkly in the UI:

$ ldcli sync prompts --yes
Pushed 1 variation.

After:

$ ldcli sync prompts --yes
Note: support/default is managed in LaunchDarkly; pulled, not pushed. To manage it in code, switch it to Code in LaunchDarkly.
  • A variation with no rule pushes and pulls as before. ldcli writes no ownership rules and needs no updateSyncSettings permission.
  • --output json carries the same message under notes. A row that ends up as an error or conflict gets no note.
  • When LaunchDarkly leaves a variation out of its settings answer, the run stops before writing anything.
  • When the server rejects a variation write with 403, the error names the missing syncAIConfigVariation action. If the lock rejected it, the error says the variation is managed in code instead.

Review focus

  • A variation with no rule must not turn into pull-only → enforceOwnership in prompt/state.go
  • ldcli must never write ownership rules → requireNoSettingsWrite in prompt/ownership_test.go

Testing

go test ./... passes, and golangci-lint reports 0 issues. The skip and linked-push tests fail when the old literal handling is put back. All five acceptance criteria are covered on the ldcli side; three of them also need gonfalon#75851 to land. A staging check with the lock on is still to do.

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Note

Overview
ldcli now reads sync ownership from LaunchDarkly (direction plus matched rule pattern) and uses that to decide whether variations can be pushed, without writing any ownership rules itself.

Variations with an explicit LaunchDarkly rule are treated as server-canonical: planned pushes become pulls/skips, and users see a note (stderr / --output json notes) explaining the variation is managed in LaunchDarkly. Variations without a matching rule still push and pull as before—the default server_canonical direction alone does not block push.

The settings client gains ResolveOwnership, batches requests beyond 100 resources, and SyncDirections is implemented on top of it. 403 variation writes are classified: managed_in_code becomes variation_managed_in_code; other forbidden responses name the missing syncAIConfigVariation permission. Sync fails closed when settings are missing or unreadable (except 404, which preserves legacy behavior).

Reviewed by Cursor Bugbot for commit 162272e. Bugbot is set up for automated code reviews on this repo. Configure here.


Related Jira issue: AIC-3901: [ldcli] Pushing, linking or first-pulling a variation makes it code-owned; detach returns it to LaunchDarkly

@nkester-ld nkester-ld changed the title feat(sync): (AIC-3901, 1/5) feat(sync): read and write variation ownership rules (AIC-3901, 1/5) Nov 16, 2026
@nkester-ld
nkester-ld force-pushed the AIC-3901/nkester/code-ownership-1-foundation branch from e93b237 to 4e53436 Compare November 17, 2026 15:03
@nkester-ld
nkester-ld requested a review from ctawiah November 17, 2026 16:00
@nkester-ld
nkester-ld marked this pull request as ready for review November 17, 2026 16:13
@nkester-ld
nkester-ld requested a review from a team as a code owner November 17, 2026 16:14
@nkester-ld
nkester-ld requested review from ld-ahartmann and removed request for a team November 17, 2026 16:14
Comment thread internal/sync/api/settings_write.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we can avoid having the ldcli write to the sync settings API entirely, since the sync settings can be inferred automatically.

For example, the sync settings API can determine whether a variation is code canonical or server canonical by checking whether the resource belongs to a synced manifest. Since only code-synced resources can be part of a manifest, the presence of the resource in a synced manifest tells us it's code canonical.

This allows sync to continue working as it does today without requiring ldcli to explicitly update the sync settings API.

This is also better from a permissions standpoint. The sync settings API requires specific permissions, and we shouldn't need to grant those permissions to every API token, especially since engineers will typically be the ones running sync commands.

With this, ldcli never needs to write to the sync settings API. Gonfalon can automatically determine and resolve the appropriate sync settings internally, keeping the CLI simpler and avoiding additional permission requirements.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This does simplify things quite a bit. I will update the stack and lyk when it's ready.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

commented on the ticket what we removed from the ticket's responsibilities 👍

nkester-ld and others added 3 commits November 17, 2026 15:46
Read each variation's ownership together with the rule that produced it.
A variation with an explicit server_canonical rule is pulled and never
pushed, with a note that says how to move it to code. A variation without
a rule may push: the server_canonical default does not make it pull, and
gonfalon records code as the owner once the variation is in a synced
manifest, so ldcli writes no sync settings and needs no updateSyncSettings
permission.

Also: read sync settings 100 at a time, fail closed when the settings read
leaves out a variation, and name syncAIConfigVariation when the server
rejects a variation write with 403.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A 403 with code managed_in_code comes from the sync lock, not a missing
permission, so it reports LaunchDarkly's message instead of asking for
syncAIConfigVariation. A create that an explicit LaunchDarkly rule turns
into an error no longer gets the "pulled, not pushed" note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A row that later planning turns into a conflict no longer says "pulled,
not pushed". A lock rejection now names the variation it is about and uses
ldcli's own message, since the client always rewrites LaunchDarkly's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nkester-ld
nkester-ld marked this pull request as draft November 17, 2026 23:26
@nkester-ld
nkester-ld force-pushed the AIC-3901/nkester/code-ownership-1-foundation branch from 4e53436 to 162272e Compare November 17, 2026 23:26
@nkester-ld nkester-ld changed the title feat(sync): read and write variation ownership rules (AIC-3901, 1/5) feat(sync): skip variations that LaunchDarkly owns (AIC-3901) Nov 17, 2026
@nkester-ld
nkester-ld marked this pull request as ready for review November 18, 2026 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants