Skip to content

fix(desktop): skip phx_ keys, keep response bodies out of logs, count duplicate copies - #681

Open
turnipdabeets wants to merge 11 commits into
feat/v6-desktop-capture-v1from
fix/v6-desktop-rubric-followups
Open

turnipdabeets wants to merge 11 commits into
feat/v6-desktop-capture-v1from
fix/v6-desktop-rubric-followups

Conversation

@turnipdabeets

@turnipdabeets turnipdabeets commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Small follow-ups on the Windows/Linux capture v1 client (#679), to match the native iOS and Android SDKs.

  • Personal API keys (phx_): capture always rejects them, and iOS/Android already disable the SDK for one. Desktop sent the key on every request. Posthog.setup now skips setup with one log line, the same way it handles a blank token.
  • No response bodies in logs: PostHogFetchHttpError.toString() included the server's response, which can echo values from the request. That string is printed by the flush error log. The responseBody field is still there for code that needs it.
  • duplicates_dropped: capture now keeps the first copy of a repeated uuid and reports how many later copies it dropped. The per-batch log now counts them. Desktop always generates its own uuids, so this should never fire. The count is there in case an SDK bug causes duplicates.

Empty event names are already dropped locally on desktop (_hasName), so nothing changed there.

💚 How did you test it?

  • New unit tests: setup is skipped for blank and phx_ tokens, the error string leaves out the response body, and captureV1Results sums duplicates_dropped.
  • flutter analyze clean, flutter test all passing (1376).

📝 Checklist

  • All commits are signed (see Commit signing)
  • 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 pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Claude Code checked the v6 desktop stack against the capture v1 SDK requirements and made these fixes. The phx_ check lives in Posthog.setup next to the blank-token check, not in the desktop client. That means it also applies on web. That's fine: capture rejects these keys anyway, so nothing that works today stops working.

🤖 Generated with Claude Code

@turnipdabeets turnipdabeets self-assigned this Oct 28, 2026
@turnipdabeets
turnipdabeets requested a review from a team as a code owner October 28, 2026 23:24
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

posthog-flutter Compliance Report

Date: 2026-10-31T02:17:43.415342+00:00
Duration: 96888ms

✅ All Tests Passed!

47/47 tests passed


Capture Tests

✅ 30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 126ms
Format Validation.Event Has Uuid ✅ 112ms
Format Validation.Event Has Lib Properties ✅ 111ms
Format Validation.Distinct Id Is String ✅ 112ms
Format Validation.Token Is Present ✅ 110ms
Format Validation.Custom Properties Preserved ✅ 111ms
Format Validation.Event Has Timestamp ✅ 112ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 111ms
Retry Behavior.Retries On 503 ✅ 5322ms
Retry Behavior.Does Not Retry On 400 ✅ 2113ms
Retry Behavior.Does Not Retry On 401 ✅ 2112ms
Retry Behavior.Respects Retry After Header ✅ 8118ms
Retry Behavior.Implements Backoff ✅ 15425ms
Retry Behavior.Retries On 500 ✅ 5220ms
Retry Behavior.Retries On 502 ✅ 5220ms
Retry Behavior.Retries On 504 ✅ 5216ms
Retry Behavior.Max Retries Respected ✅ 15424ms
Deduplication.Generates Unique Uuids ✅ 114ms
Deduplication.Preserves Uuid On Retry ✅ 5214ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10324ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5218ms
Deduplication.No Duplicate Events In Batch ✅ 115ms
Deduplication.Different Events Have Different Uuids ✅ 109ms
Compression.Sends Gzip When Enabled ✅ 109ms
Batch Format.Uses Proper Batch Structure ✅ 108ms
Batch Format.Flush With No Events Sends Nothing ✅ 105ms
Batch Format.Multiple Events Batched Together ✅ 116ms
Error Handling.Does Not Retry On 403 ✅ 2110ms
Error Handling.Does Not Retry On 413 ✅ 2111ms
Error Handling.Retries On 408 ✅ 5216ms

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 ✅ 6ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 5ms
Request Payload.Flags Request Omits Authorization Header ✅ 5ms
Request Payload.Token In Flags Body Matches Init ✅ 5ms
Request Payload.Groups Round Trip ✅ 6ms
Request Payload.Groups Default To Empty Object ✅ 5ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 4ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 6ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 5ms
Request Lifecycle.No Flags Request On Init Alone ✅ 3ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 107ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 9ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 5ms
Retry Behavior.Retries Flags On 502 ✅ 107ms
Retry Behavior.Retries Flags On 504 ✅ 107ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 108ms

@marandaneto marandaneto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Automated advisory code review.

@marandaneto
marandaneto requested a review from a team October 29, 2026 11:44
Base automatically changed from feat/v6-desktop-capture-ai to feat/v6-desktop-capture-v1 October 29, 2026 21:05
turnipdabeets and others added 4 commits October 30, 2026 11:06
… duplicate copies

- Posthog.setup skips a projectToken that is a personal API key (phx_), like the native SDKs, so the key never goes on the wire (INV-32).
- PostHogFetchHttpError.toString leaves out the response body, which can echo request values (FC-5/FQ-18); the flush error log names the lane.
- captureV1Results reads duplicates_dropped and the per-batch log reports the dropped copies (FQ-19).
…dpoint and reasons

- A 2xx whose body has no readable per-event results fails the batch for
  good: it's dropped, not resent, and reported through the error event,
  matching posthog-ios and posthog-android.
- One aggregate line per batch that lost events, naming the endpoint, the
  count and capture's `details` tags (never uuids or content). A terminal
  status logs how many events it lost; a multi-event 413 still halves.
- A `limited` result counts as delivered, like any unknown result.
- The non-string session/window id warning names the JSON type `boolean`.
- Test fakes answer capture requests with per-event results, as capture
  v1 does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@turnipdabeets
turnipdabeets force-pushed the fix/v6-desktop-rubric-followups branch from 2c15a52 to 9942076 Compare October 30, 2026 15:15
@veria-ai

veria-ai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

}

final results = captureV1Results(response.body, uuids);
final results = captureV1Results(response.body, eventUuids);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The Linux and Windows desktop integration tests fail with this change: the example app's test server (example/integration_test/desktop_test.dart, /i/v1/analytics/events) answers with a bare 200 and no body, so this check now drops the batch and throws. Capture v1 always returns {"results": {...}}, and an empty {"results": {}} counts every event as delivered, so can the test server send that instead? The check itself matches the other SDKs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7dbc213 — the test server now answers {"results": {}}.

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.

3 participants