Skip to content

feat(sync): send the repository source in an LD-Sync-Source header (AIC-3974) - #1043

Merged
ctawiah merged 1 commit into
mainfrom
ctawiah/sync-source-header
Nov 18, 2026
Merged

ctawiah merged 1 commit into
mainfrom
ctawiah/sync-source-header

Conversation

@ctawiah

@ctawiah ctawiah commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Human

Every request that ldcli sync makes now carries an LD-Sync-Source header with the manifest source of the repository, for example git:acme/support-agent. The User-Agent does not change. This is the ldcli half of the ownership lock in launchdarkly/gonfalon#79442 and its stack.

Why

LaunchDarkly must tell a sync write from a UI or plain API write, and it must know which repository sends the write. Today ldcli identifies itself only with the launchdarkly-cli/<version> User-Agent. Any script can copy that header, and it does not name the repository. Since launchdarkly/gonfalon#79268 the sync settings return the sources that sync a resource in syncedSources, so the server can accept a write to a code owned resource when the header value is one of those sources, and reject the rest.

What changes

  • internal/resources: ResourcesClient gets MakeRequestWithHeaders, and a HeaderClient interface names it. The extra headers are added after the headers that every request sends, so a caller cannot replace the User-Agent or the API version. MakeRequest calls it with no extra headers.
  • internal/sync/api: the client gets WithSource. With a source, every read and write sends LD-Sync-Source when the transport is a HeaderClient. Without a source, or with a transport that only has MakeRequest, the request goes out as before.
  • internal/sync/prompt: the runner keeps the source that it resolves from the Git origin and gives it to every API client it builds.

Other ldcli commands do not send the header.

Testing

go test ./... passes, and golangci-lint run reports 0 issues on the changed packages.

  • TestMakeRequestWithHeaders: the header goes out and the User-Agent, API version, and token stay.
  • TestClientWithSourceSendsTheSyncSourceHeader, TestClientWithoutSourceSendsNoSyncSourceHeader, TestClientWithSourceFallsBackToAPlainTransport.
  • TestSyncSendsTheRepositorySourceWithEveryRequest: a push sends git:example/repo with every request.

A manual run against staging waits for the gonfalon lock to check the header.

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

Related issues

  • Jira: AIC-3974
  • gonfalon lock: launchdarkly/gonfalon#79442

🤖 Generated with Claude Code


Note

Overview
ldcli sync now tags every API call with LD-Sync-Source (e.g. git:acme/support-agent) so LaunchDarkly can distinguish repo sync writes from UI or generic API writes and enforce ownership against syncedSources.

The HTTP stack gains HeaderClient / MakeRequestWithHeaders on ResourcesClient, with extra headers applied after the standard User-Agent and LD-API-Version so callers cannot override them. The sync API client adds WithSource and routes reads/writes through a shared send path that sets LD-Sync-Source when a source is configured and the transport supports headers; otherwise behavior is unchanged. The prompt sync runner resolves the Git manifest source at startup and attaches it to every API client it builds—other CLI commands are unaffected.

Coverage includes unit tests for header merging, source on/off, plain-transport fallback, and end-to-end sync runs asserting the header on every request.

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


Related Jira issue: AIC-3974: [ldcli] Send the sync source in an LD-Sync-Source header on every sync request

…IC-3974)

LaunchDarkly needs to tell a sync write from a UI or API write, and to know
which repository sends it. The User-Agent names ldcli but not the
repository, and any script can copy it.

Every request from the sync commands now carries LD-Sync-Source with the
manifest source of the repository, for example git:acme/support-agent. The
runner keeps the source that it resolves from the Git origin and gives it
to every API client. The User-Agent does not change, and other ldcli
commands send no header.

The HTTP client gets MakeRequestWithHeaders, which adds extra headers after
the headers that every request sends. The sync client uses it when the
transport supports it, and falls back to MakeRequest otherwise, so the
test fakes that only implement MakeRequest keep working.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@ctawiah
ctawiah marked this pull request as ready for review November 18, 2026 19:02
@ctawiah
ctawiah requested a review from a team as a code owner November 18, 2026 19:02
@ctawiah
ctawiah requested review from apucacao and nkester-ld and removed request for a team November 18, 2026 19:02
@ctawiah
ctawiah merged commit 6d2aaeb into main Nov 18, 2026
17 checks passed
@ctawiah
ctawiah deleted the ctawiah/sync-source-header branch November 18, 2026 19:04
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