Source: https://frameworkrecipes.dev/problems/stale-responses/

[Agent repair workflows by failure](https://frameworkrecipes.dev/problems/)

# Stop stale responses from replacing newer state

Invalidate the older request before the next one starts, and check that identity before writing either a result or an error. Cancellation saves work; the state guard decides which completion may update the screen.

## How do I stop an older response from overwriting a newer result?

Choose the implementation for your framework. Each linked guide includes the source, integration prerequisites, failure-path tests, saved requirement and recorded check.

Existing captured source checks; these are individual examples

| Implementation | Saved requirement | Broken source | Corrected source | Capture date |
| --- | --- | --- | --- | --- |
| [Keep old React search responses from replacing the current query](https://frameworkrecipes.dev/react/stale-request-cleanup/) | obsolete-search-does-not-update | Rule finding | No rule finding | [2026-10-14](https://frameworkrecipes.dev/react/stale-request-cleanup/capture.json) |
| [Cancel and invalidate Vue watcher requests before the next await](https://frameworkrecipes.dev/vue/watcher-cancellation/) | watcher-registers-cleanup | Rule finding | No rule finding | [2026-10-14](https://frameworkrecipes.dev/vue/watcher-cancellation/capture.json) |
| [Cancel obsolete Angular HttpClient searches with switchMap](https://frameworkrecipes.dev/angular/switchmap-search/) | search-switches-obsolete-request | Rule finding | No rule finding | [2026-10-14](https://frameworkrecipes.dev/angular/switchmap-search/capture.json) |
| [Reject stale Flutter search results after a newer query or disposal](https://frameworkrecipes.dev/flutter/generation-safe-search/) | search-generation-current | Rule finding | No rule finding | [2026-10-14](https://frameworkrecipes.dev/flutter/generation-safe-search/capture.json) |

## Inspect the requirement before installing it

The [Keep old React search responses from replacing the current query](https://frameworkrecipes.dev/react/stale-request-cleanup/) example uses this requirement on `src/useOrderSearch.js`:

```
- name: obsolete-search-does-not-update
  where: "src/useOrderSearch.js"
  ensure: >-
    The fulfilled search response must check obsolete before setting items, so a response for a previous query cannot replace the current result.
```

[Exact corrected source and broken edit](https://frameworkrecipes.dev/react/stale-request-cleanup/source.json) · [Recorded Perch output](https://frameworkrecipes.dev/react/stale-request-cleanup/capture.json) · [Download this requirement](https://reporules.fyi/react/stale-request-cleanup/rule-pack.zip)

## Make the agent check the requirement after its edit

Keep your existing perch.yaml. The [scoped rule pack](https://reporules.fyi/react/stale-request-cleanup/) installs the saved requirement under .perch/rules/. Review its file selector and use the implementation’s integration prerequisites before adapting it to your application.

### Install Perch and configure your agent

```
npm install -g @lakeday/perch
perch login
# Choose the setup command for your agent:
perch setup claude-code
# Or: perch setup codex
# Or: perch setup cursor
```

### Check the edit and recheck the repair

```
curl -fL 'https://reporules.fyi/react/stale-request-cleanup/rule-pack.zip' -o requirement.zip
unzip -n requirement.zip
perch check src/useOrderSearch.js --rules obsolete-search-does-not-update --json
# Read the finding, repair the implementation, then repeat:
perch check src/useOrderSearch.js --rules obsolete-search-does-not-update --json
```

Run the same check on the repaired working file before committing. Keep the application regression tests alongside it. Fresh model judgments can vary; an unchanged request can reuse its cached answer. A passing check does not prove application correctness.

## Compare the implementations before choosing a rule

- **[Keep old React search responses from replacing the current query](https://frameworkrecipes.dev/react/stale-request-cleanup/)**

  Requests can complete in a different order from the queries that started them. Aborting reduces wasted work; invalidating the old effect prevents a response already resolving from writing stale state. Protect the error branch as well as successful results. [Inspect its rule pack](https://reporules.fyi/react/stale-request-cleanup/).
- **[Cancel and invalidate Vue watcher requests before the next await](https://frameworkrecipes.dev/vue/watcher-cancellation/)**

  A tenant selection can change while an older query is still in flight. A watcher cleanup belongs to that invocation, so it can stop and invalidate exactly the work the next invocation supersedes. The onCleanup argument also works where onWatcherCleanup is unavailable. [Inspect its rule pack](https://reporules.fyi/vue/watcher-cancellation/).
- **[Cancel obsolete Angular HttpClient searches with switchMap](https://frameworkrecipes.dev/angular/switchmap-search/)**

  A search stream can issue a new request before the previous response arrives. switchMap keeps the latest request as the active subscription; mergeMap permits older responses to continue into the results stream. Debouncing reduces traffic but does not replace cancellation. [Inspect its rule pack](https://reporules.fyi/angular/switchmap-search/).
- **[Reject stale Flutter search results after a newer query or disposal](https://frameworkrecipes.dev/flutter/generation-safe-search/)**

  mounted prevents state updates after disposal, but two requests can race while the widget remains mounted. A generation token identifies the current request and rejects an older result that completes later. [Inspect its rule pack](https://reporules.fyi/flutter/generation-safe-search/).

## Keep the check tied to its source

The table reports saved checks on the exact linked source versions. Adapt the paths, adapters and regression tests to your repository. The example source may differ from the released framework or your service; the recorded outcome belongs to that example.

[Other agent-edit failure paths](https://frameworkrecipes.dev/problems/) · [All framework recipes](https://frameworkrecipes.dev/)

**Framework Recipes**

Implementation, failure path, check.

Published by Perch · © 2026 Verglas LLC. Framework Recipes is a Perch publication.

Perch’s MIT license covers the CLI; hosted model analysis is a paid service. Relevant source is sent to the configured model service.

[Perch CLI MIT license](https://github.com/lakeday-org/perch/blob/main/LICENSE) · [Article text](https://frameworkrecipes.dev/problems/stale-responses/index.md) · [Resource index](https://frameworkrecipes.dev/llms.txt)

[Privacy](https://frameworkrecipes.dev/privacy/) ·
