Skip to content

feat(surveys): collect partial responses and resume unfinished surveys - #807

Open
lucasheriques wants to merge 3 commits into
mainfrom
lucas/surveys-partial-responses
Open

feat(surveys): collect partial responses and resume unfinished surveys#807
lucasheriques wants to merge 3 commits into
mainfrom
lucas/surveys-partial-responses

Conversation

@lucasheriques

@lucasheriques lucasheriques commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

A user can answer the first question, leave the app, and continue the unfinished survey after restarting with the same submission ID and previous answers. With enable_partial_responses, each submitted question also emits a cumulative survey sent event immediately. When the setting is false or absent, events remain completion-only; persistent resume still works.

Progress is saved after each nonterminal answer using the SDK's persistent storage, keyed by survey ID and iteration. Restore the next branching destination, answers, answer-time question text and language. Completion, explicit dismissal and SDK reset clear progress; removed, ended, new-iteration or incompatible question definitions cannot reuse it. Merely showing a survey does not create progress.

Resumable surveys take priority and bypass seen/internal targeting checks, while other targeting conditions still apply. The built-in renderer starts at initialQuestionIndex; custom survey delegates must honor this additive display-model property. Preserve legacy response properties and reuse $survey_submission_id through partial events, completion and dismissal.

Closes #447. Includes a minor release changeset and updated public API snapshot. This does not add survey back navigation or abandonment events.

Testing

  • Regression coverage for enabled/disabled/absent partial collection, cumulative payloads, stable IDs, branching completion, optional answers, restart/resume, cleanup, corrupt state, iteration changes and resume eligibility.
  • make test: 169 XCTest and 789 Swift Testing tests passed.
  • make testOniOSSimulator: 190 XCTest and 911 Swift Testing tests passed, including restored-question and invalidated-attempt controller tests.
  • make format, make lint (no serious violations), and make apiCheck passed.
  • make build: iOS, macOS and Mac Catalyst SDK builds passed. The target stopped at tvOS because its SDK is unavailable; watchOS and visionOS SDKs are also unavailable locally. The full multi-platform/example build therefore remains unverified locally.
  • CodeScene pre-commit safeguard passed; survey integration code health improved after extracting existing branching/rating helpers.

Honor enable_partial_responses and emit cumulative survey sent events after
each submitted question. Reuse a submission UUID through completion or
dismissal, and report $survey_completed using the existing branching result.
Retain legacy response properties and completion-only behavior by default.

Verified red/green survey tests; make test (169 XCTest + 781 Swift Testing
tests); make lint; make apiCheck; iOS, macOS and Mac Catalyst builds.
Other platform builds require SDKs absent from this machine. CodeScene passed.
@lucasheriques
lucasheriques requested a review from a team as a code owner September 8, 2026 19:45
@greptile-apps

greptile-apps Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "feat(surveys): collect partial responses..." | Re-trigger Greptile

CI exposed a race between forced survey loading and the remote-config
listener's flag refresh. Seed survey data separately and await flag loading,
matching the neighboring feature-flag eligibility test.

The matching suite passes (10 tests), and the previously failing test passes
10 consecutive runs. CodeScene gate passed with stable test-file health.
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

posthog-ios Compliance Report

Date: 2026-09-08 22:06:50 UTC
Duration: 230080ms

✅ All Tests Passed!

45/45 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 2848ms
Format Validation.Event Has Uuid 2733ms
Format Validation.Event Has Lib Properties 545ms
Format Validation.Distinct Id Is String 2720ms
Format Validation.Token Is Present 325ms
Format Validation.Custom Properties Preserved 2871ms
Format Validation.Event Has Timestamp 2936ms
Retry Behavior.Retries On 503 11682ms
Retry Behavior.Does Not Retry On 400 4848ms
Retry Behavior.Does Not Retry On 401 4886ms
Retry Behavior.Respects Retry After Header 5501ms
Retry Behavior.Implements Backoff 21809ms
Retry Behavior.Retries On 500 9293ms
Retry Behavior.Retries On 502 9290ms
Retry Behavior.Retries On 504 9314ms
Retry Behavior.Max Retries Respected 21836ms
Deduplication.Generates Unique Uuids 3498ms
Deduplication.Preserves Uuid On Retry 9169ms
Deduplication.Preserves Uuid And Timestamp On Retry 16363ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 7974ms
Deduplication.No Duplicate Events In Batch 3011ms
Deduplication.Different Events Have Different Uuids 3043ms
Compression.Sends Gzip When Enabled 2844ms
Batch Format.Uses Proper Batch Structure 583ms
Batch Format.Flush With No Events Sends Nothing 369ms
Batch Format.Multiple Events Batched Together 3192ms
Error Handling.Does Not Retry On 403 5006ms
Error Handling.Does Not Retry On 413 4858ms
Error Handling.Retries On 408 9172ms

Feature_Flags Tests

16/16 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 2965ms
Request Payload.Flags Request Uses V2 Query Param 2860ms
Request Payload.Flags Request Hits Flags Path Not Decide 2708ms
Request Payload.Flags Request Omits Authorization Header 2921ms
Request Payload.Token In Flags Body Matches Init 2876ms
Request Payload.Groups Round Trip 2900ms
Request Payload.Groups Default To Empty Object 2824ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It 3002ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 2919ms
Request Payload.Disable Geoip Omitted Defaults To False 2967ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 3008ms
Request Lifecycle.No Flags Request On Init Alone 119ms
Request Lifecycle.No Flags Request On Normal Capture 2825ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 5665ms
Request Lifecycle.Mock Response Value Is Returned To Caller 2995ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 3069ms

Save progress after nonterminal answers and restore the submission ID,
answers, answer-time text/language and next branching destination. Clear
state on completion, dismissal, reset or incompatible survey updates.
Keep resumable surveys eligible and start built-in UI at the restored index;
document the additive initialQuestionIndex contract for custom delegates.

Verified: make test (169 XCTest + 789 Swift Testing),
make testOniOSSimulator (190 XCTest + 911 Swift Testing), make format,
make lint, make apiCheck. CodeScene safeguard passed.
make build passed iOS/macOS/Catalyst SDKs but stopped at missing tvOS SDK;
watchOS/visionOS and full example builds remain unverified locally.
@lucasheriques lucasheriques changed the title feat(surveys): collect partial responses incrementally feat(surveys): collect partial responses and resume unfinished surveys Sep 8, 2026
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.

Surveys: Support partial response collection

1 participant