Skip to content

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

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

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

Conversation

@lucasheriques

@lucasheriques lucasheriques commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

Add partial responses and persistent resume to iOS surveys, moving toward survey feature parity across all PostHog SDKs, with posthog-js as the reference. Closes #447. Auto-submit is separate in #808.

After submitting an answer, users can restart and resume at the next branching destination with saved answers and the same $survey_submission_id. With enable_partial_responses=true, each answer emits a cumulative survey sent event; false/absent emits only on completion. Resume works in both modes.

Key behavior:

  • Completion, dismissal, reset, removed/ended surveys and incompatible questions clear progress. Unavailable configuration preserves it; a confirmed empty list clears it.
  • Reset invalidates saved answers and stale callbacks across app-group processes, including when the anonymous ID is reused. Old attempts cannot overwrite newer ones.
  • Historical question wording is retained. Completion uses the current answer language; dismissal uses the last saved answer language.
  • Resuming bypasses seen/internal targeting checks; other targeting still applies. Custom renderers must honor initialQuestionIndex.

Review path

  1. Resume test: fresh SDK, restored branch, cumulative answers and language attribution.
  2. Progress store and integration: persistence, eligibility and event lifecycle.
  3. Storage and SDK: cross-process reset coordination and configured-delegate cleanup on close.

💚 How did you test it?

Passed: make test, make testOniOSSimulator (no retries), make format, make lint, make apiCheck, and CodeScene. Regression tests cover restart, branching, payloads, reset and stale callbacks; forcing the wrong resume index made the restart test fail.

Local validation covers macOS and iOS. Restart tests recreate SDKs through the real delegate/controller; OS process death and the full Apple-platform/example-app matrix were not exercised.

📝 Checklist

  • Regression tests and independent review completed.
  • Delegate documentation and changeset included.

🤖 Agent context

Autonomy: Human-driven (agent-assisted). Codex implemented the changes with independent QA agents; human review is required.

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-09 18:35:48 UTC
Duration: 224675ms

✅ All Tests Passed!

45/45 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 2837ms
Format Validation.Event Has Uuid 2750ms
Format Validation.Event Has Lib Properties 2777ms
Format Validation.Distinct Id Is String 2756ms
Format Validation.Token Is Present 2852ms
Format Validation.Custom Properties Preserved 2758ms
Format Validation.Event Has Timestamp 2666ms
Retry Behavior.Retries On 503 11209ms
Retry Behavior.Does Not Retry On 400 4736ms
Retry Behavior.Does Not Retry On 401 2373ms
Retry Behavior.Respects Retry After Header 7690ms
Retry Behavior.Implements Backoff 21711ms
Retry Behavior.Retries On 500 9226ms
Retry Behavior.Retries On 502 9261ms
Retry Behavior.Retries On 504 8784ms
Retry Behavior.Max Retries Respected 21819ms
Deduplication.Generates Unique Uuids 3193ms
Deduplication.Preserves Uuid On Retry 8728ms
Deduplication.Preserves Uuid And Timestamp On Retry 16321ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 7745ms
Deduplication.No Duplicate Events In Batch 2818ms
Deduplication.Different Events Have Different Uuids 2800ms
Compression.Sends Gzip When Enabled 2750ms
Batch Format.Uses Proper Batch Structure 2649ms
Batch Format.Flush With No Events Sends Nothing 234ms
Batch Format.Multiple Events Batched Together 2811ms
Error Handling.Does Not Retry On 403 2227ms
Error Handling.Does Not Retry On 413 4706ms
Error Handling.Retries On 408 9171ms

Feature_Flags Tests

16/16 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 2702ms
Request Payload.Flags Request Uses V2 Query Param 2748ms
Request Payload.Flags Request Hits Flags Path Not Decide 2774ms
Request Payload.Flags Request Omits Authorization Header 2770ms
Request Payload.Token In Flags Body Matches Init 2705ms
Request Payload.Groups Round Trip 2774ms
Request Payload.Groups Default To Empty Object 2656ms
Request Payload.Person Properties Distinct Id Auto Populated When Caller Omits It 2759ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 2754ms
Request Payload.Disable Geoip Omitted Defaults To False 2805ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 2811ms
Request Lifecycle.No Flags Request On Init Alone 61ms
Request Lifecycle.No Flags Request On Normal Capture 262ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 5432ms
Request Lifecycle.Mock Response Value Is Returned To Caller 2759ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 2988ms

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
Serialize progress read/modify/write operations with SDK identity reset,
reject snapshots invalidated by reset, and bind renderer callbacks to an
attempt token and reset generation. Capture events outside state locks
with an explicit identity so client callbacks can reset safely.

Merge seen history from storage when resuming, including completion and
dismissal, and document invalidated renderer callbacks.

Validation: focused regression tests, full SPM and iOS simulator suites,
formatting, lint, public API checks and CodeScene passed. Available iOS,
macOS and Catalyst SDK builds passed; tvOS/watchOS/visionOS SDKs are
unavailable locally, so those builds could not be validated here.
The following custom-distinct-ID test could receive the preceding
test's asynchronous identify upload after its batch recorder was reset.
Wait for and assert that upload before the preceding fixture ends.

Validation: all 25 identity tests and the full SPM suite passed.
Comment thread PostHog/PostHogStorage.swift
@veria-ai

veria-ai Bot commented Sep 9, 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

Bind progress and callbacks to a durable reset epoch and serialize survey
transactions with identity reset using a retained app-group file lock.
Reject stale and ownerless records, revoke a write-protected epoch across
processes, and recover when another process repairs the epoch.

Refresh event identity from shared storage and materialize missing identity
outside the file lock before validating the epoch again. Add isolated
shared-storage regressions and register them in the Xcode test target.

Verification: make test (169 XCTest, 805 Swift Testing); simulator tests
(190 XCTest, 927 Swift Testing); final focused event/shared-storage tests;
format, lint, API snapshot and CodeScene safeguard. A subprocess probe also
verified lock contention. Stable SDK size/function-count penalties remain.
The broad suites precede the final focused recovery/fixture adjustment.
Keep saved survey progress when remote configuration is unavailable, while
authoritative empty lists still reconcile removals. Retain the configured
survey delegate until SDK close has uninstalled its integrations.

Replace weaker restart checks with a fresh SDK/default-delegate/controller
journey covering restored branching, cumulative answers, submission IDs,
and answer-time wording and language. Consolidate duplicate cases and move
codec validation into a server-free suite. Verify reset recovery remains
usable.

Validation: make format, make lint apiCheck, and CodeScene passed.
make test passed 169 XCTest and 804 Swift Testing tests.
make testOniOSSimulator passed 190 XCTest and 926 Swift Testing tests,
without retries. A restored-index mutation failed all four restart
scenarios and was restored before final validation. Nil-config deletion
and configured-delegate cleanup were reproduced before their fixes.

The renderer journey uses the real display controller rather than mounted
touch UI or OS process death. Existing timing-based lock tests remain;
the full Apple platform/example-app build matrix was not rerun.
@lucasheriques lucasheriques self-assigned this Sep 9, 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