Skip to content

fix: reapply automatic error hooks on repeated setup - #629

Merged
marandaneto merged 6 commits into
mainfrom
fix/repeated-setup-hooks
Sep 30, 2026
Merged

marandaneto merged 6 commits into
mainfrom
fix/repeated-setup-hooks

Conversation

@marandaneto

@marandaneto marandaneto commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

💡 Motivation and Context

Repeated Posthog().setup(config) stores the new config but leaves the first Dart error-tracking integration installed. Turning automatic hooks off does not stop captures. Turning another hook on does not install it. A replacement config also leaves the old silent-error policy active.

The shared installation path now uninstalls the previous integration before applying the current flags. This restores disabled hooks, installs enabled hooks, and uses the current error-tracking config. The setup documentation clarifies that repeated setup reapplies Dart-side settings, including these hooks. Most native settings still require close() before setup.

The setup spec permits repeated setup to be a no-op and does not require live reconfiguration. This change deliberately reapplies Dart error hooks while preserving one active integration. Native repeated-setup behavior is unchanged. There are no public API signature changes.

💚 How did you test it?

  • Verified five regression cases fail without the teardown call for the intended reasons. All 11 focused cases pass with the fix, including reused config, handler restoration, duplicate-capture protection, and wrapped-handler forwarding.
  • Added a VM-only test that generates real uncaught errors in a disposable isolate across on/off/on setup. It checks capture counts [1, 0, 1] and passed 10 consecutive runs. Removing the setup teardown call makes it fail with [1, 1, 1].
  • Ran the full Flutter VM suite after merging main: 777 tests passed.
  • Ran the new test file in Chrome: seven tests passed, with four native-only cases skipped.
  • Ran the CI browser test selection: 83 tests passed.
  • Ran the isolate handler test in Chrome with Wasm: one test passed.
  • Ran the finite compliance adapter test selection: 25 tests passed.
  • Passed make checkFormatDart, make analyzeDart, make checkApiDart, and git diff --check.
  • Completed the diff-scoped test audit. The tests exercise real global handlers and VM error listeners through public setup and reuse the existing platform fake only to record capture calls. The isolate regression is collected by the full VM suite. No shared fixture or discovery changes were needed.
  • Verified pnpm exec changeset status --since=origin/main schedules a patch for posthog_flutter. Corrected this PR's package name and removed the already-released changeset inherited from fix: preserve chained error handlers across restarts #624.
  • Confirmed the original-config silent-error test passes both with and without setup teardown. It is retained as a characterization control, not counted among the five regression cases.
  • Completed isolated autoreview with no actionable findings at 426feee: autoreview --mode branch --base origin/main.

Native example builds were not run locally. CI covers the example builds.

📝 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

  • Added a patch changeset.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Investigated and fixed with Pi using Git, Flutter/Dart, GitHub CLI, and isolated autoreview. The work stayed in the dedicated investigation worktree. The fix reuses the existing integration teardown rather than adding per-callback flag checks or a new configuration API. The investigation notes remain local and are not part of this PR.

@marandaneto marandaneto self-assigned this Sep 30, 2026
@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Retrigger

[Medium risk] Resets error-tracking hooks when setup is called again.

The PR appears safe to merge; native isolate-listener reconfiguration would benefit from a regression test.

Reviews (1) · Last reviewed commit: "fix: reapply automatic error hooks on re..."

Comment thread posthog_flutter/test/repeated_setup_hooks_test.dart
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

posthog-flutter Compliance Report

Date: 2026-09-30 15:41:31 UTC
Duration: 96820ms

✅ All Tests Passed!

45/45 tests passed


Capture Tests

✅ 29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 142ms
Format Validation.Event Has Uuid ✅ 117ms
Format Validation.Event Has Lib Properties ✅ 116ms
Format Validation.Distinct Id Is String ✅ 116ms
Format Validation.Token Is Present ✅ 116ms
Format Validation.Custom Properties Preserved ✅ 117ms
Format Validation.Event Has Timestamp ✅ 115ms
Retry Behavior.Retries On 503 ✅ 5330ms
Retry Behavior.Does Not Retry On 400 ✅ 2117ms
Retry Behavior.Does Not Retry On 401 ✅ 2117ms
Retry Behavior.Respects Retry After Header ✅ 8127ms
Retry Behavior.Implements Backoff ✅ 15444ms
Retry Behavior.Retries On 500 ✅ 5225ms
Retry Behavior.Retries On 502 ✅ 5225ms
Retry Behavior.Retries On 504 ✅ 5224ms
Retry Behavior.Max Retries Respected ✅ 15446ms
Deduplication.Generates Unique Uuids ✅ 125ms
Deduplication.Preserves Uuid On Retry ✅ 5223ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10334ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5230ms
Deduplication.No Duplicate Events In Batch ✅ 124ms
Deduplication.Different Events Have Different Uuids ✅ 118ms
Compression.Sends Gzip When Enabled ✅ 115ms
Batch Format.Uses Proper Batch Structure ✅ 113ms
Batch Format.Flush With No Events Sends Nothing ✅ 108ms
Batch Format.Multiple Events Batched Together ✅ 123ms
Error Handling.Does Not Retry On 403 ✅ 2116ms
Error Handling.Does Not Retry On 413 ✅ 2118ms
Error Handling.Retries On 408 ✅ 5225ms

Feature_Flags Tests

✅ 16/16 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 13ms
Request Payload.Flags Request Uses V2 Query Param ✅ 9ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 10ms
Request Payload.Flags Request Omits Authorization Header ✅ 9ms
Request Payload.Token In Flags Body Matches Init ✅ 10ms
Request Payload.Groups Round Trip ✅ 10ms
Request Payload.Groups Default To Empty Object ✅ 10ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It ✅ 10ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 9ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 9ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 10ms
Request Lifecycle.No Flags Request On Init Alone ✅ 5ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 112ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 15ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 9ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 115ms

@marandaneto
marandaneto marked this pull request as ready for review September 30, 2026 14:18
@marandaneto
marandaneto requested a review from a team as a code owner September 30, 2026 14:18

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This review was skipped because it would exceed your organization's monthly flex usage limit. Raise the limit in billing settings or wait until the next billing period resets limits.

Comment thread posthog_flutter/lib/src/posthog.dart Outdated
Comment thread posthog_flutter/test/repeated_setup_hooks_test.dart
Base automatically changed from fix/chained-error-handler-lifecycle to main September 30, 2026 15:14
@marandaneto
marandaneto enabled auto-merge (squash) September 30, 2026 15:39
@marandaneto
marandaneto merged commit cadba6d into main Sep 30, 2026
34 of 35 checks passed
@marandaneto
marandaneto deleted the fix/repeated-setup-hooks branch September 30, 2026 15:50
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