Repository navigation
Conversation
A secret key without the Feature flags: Read scope gets 401 from /flags/definitions, so the poller logged an error on every poll. Warn once for 401 and 403 with the missing scope, log repeats at debug, and warn again only after definitions load from the API. Polling, flag state, the cache provider path and other statuses are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Note 🤖 Claude Opus 5.5 responding on behalf of Michael Decisions made while building this fix:
|
Contributor
posthog-go Compliance ReportDate: 2026-11-05 12:23:13 UTC ✅ All Tests Passed!111/111 tests passed Capture_V1 Tests✅ 94/94 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
When you set
SecretKey, the client turns on local evaluation and polls/flags/definitionswith it, every 5 minutes by default. Transactional email asks for a Project Secret API Key with only thetransactional_email:writescope. The flags service answers that key with401 authentication_failed("Secret API token is invalid."), the same answer as a wrong key, because its key lookup only finds keys with a flag scope. A personal API key without the scope gets403 permission_denied.So a client that only sends email logged
Unable to fetch feature flags, status: 401 Unauthorizedas an error on every poll, for as long as it ran, about feature flags it never uses.Merge Danger
Low, two-way door. Only the logging for 401 and 403 from
/flags/definitionschanges. Polling, flag state, the cache provider path, other statuses, network errors and remote evaluation are unchanged.What changes
SecretKeyis the only switch for local evaluation in this SDK. Adding one would change the public config, so it stays out of this fix.This PR is independent of the email PR #406. It touches only the flag poller and its tests, and applies cleanly on that PR's head.
💚 How did you test it?
featureflags_test.go: five polls answered with 401 or 403 log one warning and four debug lines, a 200 or a 304 between rejections warns again, and a load from the shared cache provider doesn't. They failed before the fix and pass now, and each fails when its reset or debug line is removed.definitionsSequenceServernow answers any numeric body as a status, which replaces its special cases for 304 and 402.go test ./...,go vet ./...andgofmt -l .pass.FeatureFlagsPoller.fetchFlagDefinitionsagainst anhttptestserver, read through a logger that records levels.NewWithConfigwithSecretKeyand a 1 s poll interval polled a local stub of/flags/definitionsthat sends the flags service's 401 and 403 bodies. Over 8 polls (three 401s, a 200, then 401s) it logged two warnings, one before and one after the load, and debug lines for the rest. Five 403s logged one warning. The same run onmainlogged 7 errors.rust/feature-flags/src/api/auth.rsanderrors.rsin PostHog/posthog.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code (Claude Opus 5.5) wrote the change test-first in a T3 Code thread, as a side fix from the transactional email work. GPT-6.1 Sol reviewed the diff before the push. The same fix is going to posthog-node, posthog-python and posthog-elixir.
Logger.Warnf, thenLogger.DebugfInvolvement: two cross-family review rounds (GPT-6.1 Sol), no grilling rounds, live-run proof against a local stub of the flags service.
🤖 Generated with Claude Code