async-state
/async-state
Pomaga znaleźć przyczynę, gdy postęp utknął, sukces pojawia się za wcześnie albo stare wyniki nadpisują stan.
- Autor
- sallaumen ↗
- Repozytorium
- elixir-agent-kit ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 09.11.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 09.11.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
Co robi i kiedy
Pomaga znaleźć przyczynę, gdy postęp utknął, sukces pojawia się za wcześnie albo stare wyniki nadpisują stan.
Oryginalny opis (EN)
Use when progress stalls, success appears too early, stale asynchronous results overwrite current state, or a failed refresh erases the last good state.
Jak działa
- When to use
- Size
- Inputs to inspect
- Workflow
- Decision points
- Quality criteria
- Validation and evidence
- Avoid
- Completion
Podgląd SKILL.md
--- name: async-state description: "Use when progress stalls, success appears too early, stale asynchronous results overwrite current state, or a failed refresh erases the last good state." --- # Async State Default mode: **analyze-and-fix**. Read the [shared contract](../../CONTRACT.md) before applying this workflow. The user's explicit scope overrides the default mode. ## When to use Use when the interface says "done" before the work finished, when a spinner never ends, when a late or duplicate message changes the wrong record, when a reload or reconnect shows a different state than before, or when a retry repeats an effect. Use it for a new asynchronous feature as well as for a reported symptom. The question this workflow answers is: who owns each state transition, how is a result matched to the request that caused it, and what does every observer see after a disconnect, a duplicate or an out-of-order message. ## Size - **Small**: fix one transition's owner or key (one stale overwrite or one missing dedupe) with one ordering test; skip the full lifecycle. - **Medium**: run the workflow as written for one flow: the lifecycle with its owners, the trace and the duplicate, delayed and out-of-order tests. - **Large**: a whole flow across process, persisted state and interface, or several transitions; slice per transition and route process ownership to process-lifecycle as a later slice. ## Inputs to inspect - Start at: the LiveView or process whose assign or state is overwritten, and its `handle_async`, `handle_info` and `handle_event` clauses that write it. - The command path: the user action or trigger, the request it sends, the job or process that runs, the persisted result, and the message that tells the interface. - Identity: which stable identifier (entity id plus revision, job id, request id) travels through every step, and where a step uses something weaker (position, "latest", the socket). - Durable state versus transient state: what is in the database, what lives in a process, what lives in socket assigns, and which one the interface reads after reload. - Delivery semantics of each hop: PubSub broadcast, Oban retries, provider webhooks, HTTP responses. Assume at least-once and unordered unless the code proves otherwise. - The user-visible states and what each actor can observe during a disconnect. See [Phoenix and LiveView](../../elixir/phoenix-liveview.md) and [Oban](../../elixir/oban.md). ## Workflow 1. Draw the lifecycle as transitions with an owner: accepted, queued, running, completed, failed, cancelled, unknown. Name the component that may perform each transition and the durable record it writes. If two components can both write "completed", that is the first finding. Done when each transition has exactly one owner and no two components write "completed". 2. Trace one real request end to end with its identifiers. Mark every hop where the result is matched to the request by something other than a stable key. A message keyed by "the current task" instead of the task's id is a stale-overwrite bug waiting for a delay. Done when every hop is matched by a stable key and each weaker match is marked. 3. Reproduce the symptom with a controlled ordering: delay the first result until after the second request, deliver a message twice, disconnect between request and result, reload mid-progress. In LiveView, `start_async` and `handle_async` make the ordering explicit; in tests, send the messages yourself. Done when the symptom appears with a controlled ordering in a test. 4. Fix the owner and the key, not the symptom. Results carry the key they belong to and are dropped when the key no longer matches the current selection; the interface derives its state from the durable record after reconnect instead of trusting the last message; retries are idempotent at the effect, not only unique at the queue. Done when results carry the key they belong to, are dropped when the key no longer matches, and retries are idempotent at the effect. 5. Define cancellation and timeout as transitions with their own races: a cancel that arrives after completion, a timeout that fires while the job is finishing. Decide which wins and write it down. Done when cancellation and timeout have defined winners in their races with completion. 6. Exercise duplicate, delayed, out-of-order, disconnect and reload on the real flow, then run the focused tests and the project gate. Done when duplicate, delayed, out-of-order, disconnect and reload pass on the real flow and the gate is green. ## Decision points - One durable owner per state; the interface is a view of it, never the source. If the only record of completion is a flash or a toast, the state is lost on reload. - Push, do not poll: subscribe once in the connected mount, dedupe broadcasts by content or sequence, and let the server tell the view. Polling the database from the browser is a last resort and must be justified. - Match results by stable key (entity id plus revision or request id). "Most recent" is not a key. - Accepted is not done: an HTTP 200 for the enqueue, a job inserted, or a message sent are each one transition, not success. - One job of a kind at a time per owner: a second submit while the job runs is refused where the state lives (the LiveView, the context), not only by disabling the button; the running job is the receipt. - Idempotency per effect: a retried job must not charge, send or publish twice; uniqueness at enqueue time does not provide this. - On failure to read fresh state (network down, provider timeout), keep and label the last valid state; never invent a success or a zero. ## Quality criteria - After a reload or reconnect, the interface reconstructs the same state from persisted identifiers and a current-state read; no transition depends on the socket having been alive. - A delayed or duplicate message cannot advance state falsely or overwrite a newer selection; the test suite proves it with explicit orderings. - Cancellation and timeout are explicit transitions with defined winners in their races with completion. - Every failure surfaces as a recoverable or terminal status with enough context for the user or operator to act; "unknown" is a legitimate displayed state. - Retries and duplicate deliveries never repeat an irreversible effect. ## Validation and evidence - Minimum: one test that delivers the result out of order, twice or after a reconnect and asserts both the durable state and what the view renders. In LiveView, `Phoenix.LiveViewTest` with messages sent to the view process; for jobs, `Oban.Testing` with a retried `perform_job/3`. - When turns allow: a written lifecycle table (transition, owner, durable record) for the flow, and the identifiers traced through one real request. - When turns allow: a manual pass on the running application for the reported symptom and for a reload mid-progress, with what was observed at each step. - When turns allow: any external effect that could not be exercised, named. ## Avoid - Do not key results by position, "latest" or the socket; do not treat a broadcast as proof the record changed. - Do not equate HTTP success, enqueue success or "message sent" with completion. - Do not use a toast, flash or in-memory assign as the only record of a transition. - Do not add `Process.sleep` or longer timeouts to make an ordering test pass; make the ordering explicit instead. - Do not retry a paid or external effect to recover a stuck state without an idempotency key. ## Completion A lifecycle with one durable owner per transition, results matched by stable keys, explicit cancellation and timeout races, and tests that deliver duplicate, delayed and out-of-order messages across a reconnect. For a slow but correct flow use [performance](../performance/SKILL.md); for a paid or rate-limited provider call use [provider-calls](../provider-calls/SKILL.md); for state lost or doubled after restart use [process-lifecycle](../process-lifecycle/SKILL.md); for the operational alert that a stuck job should raise use [operational-alerts](../operational-alerts/SKILL.md). Use the [Elixir context](../../ELIXIR.md) only for technology present in the project. Record a useful [handoff](../../HANDOFF.md) when another person or agent will continue the work.
Wersje
W bazie nie ma innych skilli o nazwie async-state.
Migawka bazy z 13.11.2026 · wersja paczki 19a64d834e31 (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 95rust-async-patterns
Pomaga pisać asynchroniczny kod w Rust z tokio, async/await i futures. - 95async-rust
Pisze i sprawdza poprawny asynchroniczny kod w Rust: wybór runtime, granice Send i Sync, anulowanie, zadania blokujące i stan współdzielony. - 100interactive-state-flow
Naprawia laggujące, nieaktualne lub podatne na wyścigi przepływy interaktywne, w których mieszają się intencja użytkownika, stan źródłowy, prezentacja, asynchroniczne IO i praca w tle, chroniąc ścieżkę pilnej interakcji. - 91typescript-async-patterns
Pomaga pisać asynchroniczny kod TypeScript z Promises, async/await i iteratorami asynchronicznymi z poprawnym typowaniem. - 100async-execution
Pomaga dodawać i naprawiać zadania Spring @Async, obsługę błędów i przeciążenie puli wątków. - 100async-execution
Pomaga dodawać i debugować asynchroniczne zadania w Spring @Async, w tym przeciążenie puli wątków i błędy w tle.