---
name: lifecycle-and-side-effects-correctness
description: Audit and design lifecycle side-effect correctness for async UI, purchase, analytics, retry, cancellation, presentation, and session flows. Use when reviewing SwiftUI or other UI lifecycle code, paywalls, subscription or purchase flows, analytics emission, async tasks, retries, reloads, sheet dismissal, remount behavior, or any change where user-visible state and side effects must stay consistent across lifecycle transitions.
title: lifecycle-and-side-effects-correctness
canonical_url: https://skilld.dev/gh/fiveonecode/agent-skills/lifecycle-and-side-effects-correctness
last_updated: 2026-09-26T06:44:22.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [agents/openai.yaml](https://skilld.dev/api/skills-raw/fiveonecode/agent-skills/lifecycle-and-side-effects-correctness/agents/openai.yaml).
>
> If the user asked to install this Skill, run `npx skilld install fiveonecode/agent-skills/lifecycle-and-side-effects-correctness`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/lifecycle-and-side-effects-correctness`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/fiveonecode/agent-skills/lifecycle-and-side-effects-correctness) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/lifecycle-and-side-effects-correctness`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/lifecycle-and-side-effects-correctness --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/lifecycle-and-side-effects-correctness --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Lifecycle And Side Effects Correctness

## Overview

Use this skill to prevent duplicate, stale, missing, or misattributed side effects across lifecycle transitions. Treat analytics, purchases, network retries, persistence, and callbacks as contract-bearing effects, not incidental code inside a view or async closure.

## Workflow

### 1. Identify the owner

- Name the durable owner for each effect: service, coordinator, store, view model, view task, or external SDK.
- Keep one-shot effects out of view identity when remounts, `.id(...)`, previews, or sheet recreation can run the code again.
- Separate view-local state from session, purchase, analytics, or persisted state.

### 2. Map lifecycle transitions

List the transitions that can start, repeat, cancel, or complete work:

- appear, disappear, dismiss, remount, reload, retry, background, foreground;
- task start, cancellation, timeout, success, failure, fallback;
- purchase start, product/offering reload, checkout, restore, completion;
- analytics impression, dismiss, branch, conversion, error, and retry.

For each transition, write the expected state and allowed side effects.

### 3. Enforce side-effect invariants

- No duplicate side effects from view remount, `.task` restart, `.onAppear`, `.id(...)`, or sheet recreation.
- No stale completion side effects after cancellation, dismissal, navigation away, or superseded input.
- No false dismiss/present, impression, purchase, or retry analytics caused by view identity churn.
- In-flight purchase or mutation actions are idempotent, disabled, or otherwise guarded.
- Retry paths emit required lifecycle events exactly as specified and preserve session attribution.
- Failure paths either emit the required failure effect or explicitly suppress it under a documented rule.
- Persisted state, analytics properties, and user-visible copy derive from the same canonical source when they describe the same decision.

### 4. Check identity and attribution

- Define the stable session, impression, request, purchase, or operation ID before work starts.
- Preserve attribution through retries, slow loads, fallback, and personalized copy refresh.
- Do not derive experiment, package, offering, campaign, or branch attribution from display text when a canonical ID exists.
- Normalize stale IDs only at the boundary that owns the crosswalk; do not let tests erase identity bugs through broad normalization.

### 5. Verify cancellation and retry

- Prefer lifecycle-bound tasks such as `.task(id:)` when the effect should cancel with the view.
- Move effects to a longer-lived owner when they must survive view dismissal.
- After `await`, check cancellation, current identity, or generation token before emitting effects.
- Bound retries and state what happens to analytics, user-visible errors, and persisted state on each retry.
- Treat silent discard as invalid unless the spec names it and defines observability.

### 6. Design tests

Use focused tests around lifecycle edges:

- remount does not duplicate impression or purchase effects;
- dismissal cancels or suppresses stale completion effects;
- retry preserves the same session attribution when required;
- checkout disables plan changes or makes plan changes explicitly safe;
- failure, fallback, and cancellation emit the required event sequence;
- stale async completion cannot overwrite newer state.

Use exact event sequences when order is contractual. Use multiset checks only when order is intentionally irrelevant.

## Review output

When reviewing a lifecycle-sensitive change, report:

- `Effect owners`: which component owns each side effect.
- `Lifecycle transitions`: starts, repeats, cancellations, completions, and retries.
- `Risk findings`: duplicate, stale, missing, or misattributed effects.
- `Required tests`: the smallest tests that prove the lifecycle boundary.
- `Residual risk`: any behavior that still depends on manual QA, live SDK behavior, or product policy.
