agentleFS
fiveonecodefiveonecode/agent-skills/lifecycle-and-side-effects-correctness/SKILL.md

lifecycle-and-side-effects-correctness

Skill20 starsChanged 2 months agoMITView on GitHub

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.

The file

We split this skill into the rules it gives an agent

12 rules. About 0 are common, 8 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈8

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill to prevent duplicate, stale, missing, or misattributed side effects across lifecycle transitions.

    line 10
  2. Very specific:

    Keep one-shot effects out of view identity when remounts, .id(...), previews, or sheet recreation can run the code again.

    line 17
  3. Very specific:

    No duplicate side effects from view remount, .task restart, .onAppear, .id(...), or sheet recreation.

    line 33
  4. Distinctive:

    No stale completion side effects after cancellation, dismissal, navigation away, or superseded input.

    line 34
  5. Distinctive:

    No false dismiss/present, impression, purchase, or retry analytics caused by view identity churn.

    line 35
  6. Distinctive:

    Do not derive experiment, package, offering, campaign, or branch attribution from display text when a canonical ID exists.

    line 45
  7. Very specific:

    Prefer lifecycle-bound tasks such as .task(id:) when the effect should cancel with the view.

    line 50
  8. Very specific:

    After await, check cancellation, current identity, or generation token before emitting effects.

    line 52
  9. Distinctive:

    Treat silent discard as invalid unless the spec names it and defines observability.

    line 54
  10. Distinctive:

    Use focused tests around lifecycle edges:

    line 58
  11. Distinctive:

    Use exact event sequences when order is contractual.

    line 67
  12. Distinctive:

    When reviewing a lifecycle-sensitive change, report:

    line 71

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.