Skip to content

feat: fetch project remote config at startup and periodically - #972

Draft
marandaneto wants to merge 4 commits into
mainfrom
feat/remote-config
Draft

marandaneto wants to merge 4 commits into
mainfrom
feat/remote-config

Conversation

@marandaneto

@marandaneto marandaneto commented Sep 21, 2026

Copy link
Copy Markdown
Member

💡 Motivation and Context

Add project remote-config fetching based on the HTTP contract in PostHog/sdk-specs#70. Also read sdkDiagnosticsEnabled from PostHog/posthog#103683. The new local sdk_diagnostics_enabled option defaults to True. Effective diagnostics permission requires both the local option and the remote value to be true. Missing or invalid remote values mean false. This is experimental and does not collect or report diagnostics yet. Other fetched settings do not change SDK behavior.

Clients fetch asynchronously at startup and refresh after each configured interval. remote_config_poll_interval_seconds defaults to 300 seconds. None disables both startup and periodic fetches. Disabled clients keep an idle poller without making requests and resume fetching on the next interval after re-enabling. send=False and empty project tokens do not start a poller.

Requests use the public project token, map US/EU ingestion hosts to their asset hosts, and preserve custom proxy paths. Failed fetches keep the last successful response in memory. Shutdown stops the worker, and forked clients recreate it unless already shut down. Sync-mode clients also register non-blocking poller cleanup at interpreter exit. A private subclass reuses the existing Poller loop and cleanup, adding only the immediate startup fetch and remote-config response handling.

💚 How did you test it?

  • Added 62 unit and local mock HTTP-server tests covering routing, request shape, invalid responses, refresh failures, disabled fetching, startup, shutdown, and fork lifecycle behavior. Diagnostics coverage checks local/remote combinations, missing and invalid values, module-level configuration, and HTTP refresh transitions.
  • Full test suite: 3,504 passed, 16 skipped, and 38 subtests passed. One Python warning concerns an existing test that forks a multithreaded process.
  • Reproduced both review concerns with three failing cases for direct/module-level re-enabling and sync exit cleanup. All three pass after the fixes. Both fixes retain their regression tests.
  • Ruff lint and formatting, mypy baseline, public API snapshot, warnings-as-errors import, and git diff --check passed.
  • Branch autoreview against origin/main passed at 06332f2 with no actionable findings.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran sampo add to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented with Pi using file editing, shell, GitHub CLI, and the isolated autoreview helper. The human-directed scope includes startup and periodic fetching, with a five-minute default and None as the opt-out, plus experimental diagnostics permission. The local permission defaults to enabled but cannot override a remote disable. Code comments explicitly state that no diagnostics are collected yet. Human review is required.

@marandaneto marandaneto self-assigned this Sep 21, 2026
@github-actions

github-actions Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

posthog-python Compliance Report

Date: 2026-09-21 12:09:04 UTC
Duration: 255880ms

✅ All Tests Passed!

111/111 tests passed


Capture_V1 Tests

94/94 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint 512ms
Endpoint And Method.Does Not Use Legacy Endpoints 507ms
Required Headers.Has Authorization Bearer Header 508ms
Required Headers.Has Content Type Json 506ms
Required Headers.Has Posthog Sdk Info Format 507ms
Required Headers.Has Posthog Attempt Header 506ms
Required Headers.Has Posthog Request Id 507ms
Required Headers.Has Posthog Request Timestamp 506ms
Required Headers.Has User Agent 507ms
Body Format.Body Has Created At And Batch 507ms
Body Format.No Api Key In Body 508ms
Body Format.No Sent At In Body 506ms
Event Format.Event Has Required Root Fields 507ms
Event Format.Event Uuid Is Valid 506ms
Event Format.Event Timestamp Is Rfc3339 507ms
Event Format.Distinct Id Is String 507ms
Event Format.Distinct Id At Root Not Properties 506ms
Event Format.Custom Properties Preserved 507ms
Event Format.Set Properties Preserved 506ms
Event Format.Set Once Properties Preserved 507ms
Event Format.Groups Properties Preserved 506ms
Event Format.Sdk Generates Uuid If Not Provided 506ms
Event Format.Event Has Required Root Fields Batch 510ms
Event Format.Event Uuid Is Valid Batch 508ms
Event Format.Event Timestamp Is Rfc3339 Batch 509ms
Event Format.Distinct Id Is String Batch 509ms
Event Format.Distinct Id At Root Not Properties Batch 509ms
Event Format.Custom Properties Preserved Batch 509ms
Event Format.Set Properties Preserved Batch 509ms
Event Format.Set Once Properties Preserved Batch 508ms
Event Format.Groups Properties Preserved Batch 509ms
Event Format.Sdk Generates Uuid If Not Provided Batch 509ms
Batch Behavior.Multiple Events In Single Batch 512ms
Batch Behavior.Batch Envelope Smoke 509ms
Batch Behavior.Flush With No Events Sends Nothing 505ms
Batch Behavior.Flush At Triggers Batch 1008ms
Batch Behavior.Created At Reflects Batch Creation Time 506ms
Deduplication.Generates Unique Uuids 512ms
Deduplication.Different Events Same Content Different Uuids 508ms
Deduplication.Preserves Uuid On Retry 6513ms
Deduplication.Preserves Timestamp On Retry 6515ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 6519ms
Deduplication.No Duplicate Events In Batch 513ms
Header Behavior On Retry.Attempt Header Starts At One 507ms
Header Behavior On Retry.Attempt Header Increments On Retry 13520ms
Header Behavior On Retry.Request Id Preserved On Retry 6514ms
Header Behavior On Retry.Different Requests Have Different Request Ids 3014ms
Header Behavior On Retry.Request Timestamp Changes On Retry 6513ms
Response Format Validation.Success Response Has Uuid Keyed Results 507ms
Response Format Validation.Success Response Has Ok For Each Event 509ms
Response Format Validation.Success No Retry After When All Ok 509ms
Response Format Validation.Success Retry After Present When Retry Events 1509ms
Response Format Validation.Success No Retry After When Drop Only 508ms
Response Format Validation.Response Echoes Request Id 508ms
Retry Behavior.Retries On 408 6513ms
Retry Behavior.Retries On 500 6514ms
Retry Behavior.Retries On 503 8517ms
Retry Behavior.Retries On 504 6513ms
Retry Behavior.Retryable Errors Have Retry After 3511ms
Retry Behavior.Respects Retry After On Retryable Error 11517ms
Retry Behavior.Does Not Retry On 400 2511ms
Retry Behavior.Does Not Retry On 401 2510ms
Retry Behavior.Does Not Retry On 402 2509ms
Retry Behavior.Does Not Retry On 413 2509ms
Retry Behavior.Does Not Retry On 415 2508ms
Retry Behavior.Non Retryable Errors Have No Retry After 2510ms
Retry Behavior.Implements Backoff 22527ms
Retry Behavior.Max Retries Respected 22528ms
Partial Batch Handling.Handles 200 Full Success 2510ms
Partial Batch Handling.Handles 200 With All Ok 3514ms
Partial Batch Handling.Does Not Retry Dropped Events 3513ms
Partial Batch Handling.Does Not Retry Limited Events 3513ms
Partial Batch Handling.Prunes Ok Events On Partial Retry 6515ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry 6516ms
Partial Batch Handling.Retries Only Retry Events From Partial 6519ms
Partial Batch Handling.Partial Retry Preserves Uuids 6514ms
Partial Batch Handling.Partial Retry Attempt Header Increments 6518ms
Partial Batch Handling.Partial Retry Request Id Preserved 6519ms
Partial Batch Handling.Respects Retry After On Partial 8518ms
Partial Batch Handling.Unknown Result Treated As Terminal 3514ms
Partial Batch Handling.Mixed Ok Drop Limited No Retry 3516ms
Compression.Sends Gzip Content Encoding 510ms
Compression.No Content Encoding When Disabled 508ms
Compression.Compressed Body Is Decompressible 509ms
Error Handling.Does Not Retry On Unknown 4Xx 2511ms
Event Options.Cookieless Mode Override 510ms
Event Options.Disable Skew Correction Override 509ms
Event Options.Process Person Profile Override 510ms
Event Options.Product Tour Id Override 509ms
Event Options.Unset Options Omitted 509ms
Event Options.Options Override In Batch 511ms
Geoip And Historical Migration.Geoip Disable Injected Into Properties 508ms
Geoip And Historical Migration.Historical Migration Set In Body 509ms
Geoip And Historical Migration.Historical Migration Absent By Default 509ms

Feature_Flags Tests

17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 9ms
Request Payload.Flags Request Uses V2 Query Param 8ms
Request Payload.Flags Request Hits Flags Path Not Decide 7ms
Request Payload.Flags Request Omits Authorization Header 7ms
Request Payload.Token In Flags Body Matches Init 7ms
Request Payload.Groups Round Trip 7ms
Request Payload.Groups Default To Empty Object 7ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 7ms
Request Payload.Disable Geoip Omitted Defaults To False 7ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 7ms
Request Lifecycle.No Flags Request On Init Alone 3ms
Request Lifecycle.No Flags Request On Normal Capture 508ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 11ms
Request Lifecycle.Mock Response Value Is Returned To Caller 7ms
Retry Behavior.Retries Flags On 502 310ms
Retry Behavior.Retries Flags On 504 311ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 509ms

@greptile-apps

greptile-apps Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Retrigger

The PR should not merge until clients re-enabled after disabled construction can start remote-config polling; the sync-mode exit cleanup gap should also be addressed.

Reviews (1) · Last reviewed commit: "feat: fetch project remote config at sta..."

Comment thread posthog/client.py Outdated
Comment thread posthog/client.py Outdated

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant