All jobs

Add Optimistic UI to an Angular App

Yes. An agent makes an Angular app's favorite and follow buttons flip at once and roll back on failure, with Vitest specs for both paths, and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads the components the issue names before it changes anything. In an app shaped like realworld-apps/angular-realworld-example-app, package.json pins @angular/core 21.2.12, rxjs ^7.8.2 and @rx-angular/template 21.0.0, with vitest ^4.0.18 through @analogjs/vite-plugin-angular, Playwright for end-to-end tests, prettier under lint-staged, and bun as the installer the workflows use. src/app/features/article/components/favorite-button.component.ts is an OnPush component with an isSubmitting signal: on click it checks userService.isAuthenticated, calls articleService.favorite(slug) or unfavorite(slug), and only in the next handler emits toggle with the new state. article-preview.component.ts and pages/article/article.component.ts receive that event and update their article signal's favorited and favoritesCount. src/app/features/profile/components/follow-button.component.ts has the same shape with profileService.follow and unfollow, which return a Profile, and profile.component.ts and the article page apply it. Every click waits a round trip before the button changes; on a slow API the heart does nothing for a second and users click twice.

The change keeps the contract the parents already understand. FavoriteButtonComponent.toggleFavorite records wasFavorited, emits toggle with !wasFavorited at once, then runs the request. On next it does nothing new, because the parent already applied the state. On error it emits toggle with wasFavorited again, which the parents' existing toggleFavorite and onToggleFavorite handlers turn back into the old favorited flag and count, since each handler adds or subtracts one based on the value it receives. FollowButtonComponent.toggleFollowing does the same with a Profile: it emits { ...profile, following: !profile.following } before the call, and on error emits the original profile. The isSubmitting signal stays, so a second click while the first request is in flight is ignored rather than queued, and the unauthenticated branch still navigates to /register or /login without emitting.

src/app/features/article/services/articles.service.ts returns Observable<void> from unfavorite and Observable<Article> from favorite; neither is awaited for state any more, so the parents' counts no longer drift from the server's favoritesCount on a race, and the pull request says so. The template classes btn-primary and btn-outline-primary already follow article.favorited, so the flip is visible with no CSS change. A short error message goes through the ListErrorsComponent the pages already render, keyed on the rollback, so a failed favorite is not silent.

Specs are new: favorite-button.component.spec.ts and follow-button.component.spec.ts beside the components, in the TestBed and HttpTestingController style of articles.service.spec.ts, with the src/test-setup.ts environment vitest.config.ts loads. Each spec clicks, asserts that toggle fired before httpMock.expectOne has flushed anything, flushes a success and asserts no second emission, then repeats with a flushed error and asserts the reverting emission. The run executes bun install, bun run test, bun run format:check and bun run build, and because the playwright.yml workflow runs bun run test:e2e against the realworld backend submodule, it runs that too where the sandbox can check out the submodule.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Make the favorite and follow buttons in this Angular app optimistic and open a pull request that links the Linear issue. Read package.json, vitest.config.ts, src/test-setup.ts, src/app/features/article/components/favorite-button.component.ts, article-preview.component.ts, pages/article/article.component.ts, src/app/features/article/services/articles.service.ts and its spec, src/app/features/profile/components/follow-button.component.ts, pages/profile/profile.component.ts and services/profile.service.ts first. In each button, emit the toggled state before the HTTP call and emit the previous state again when the call errors, keeping the isSubmitting guard and the redirect for unauthenticated users; do not change the parents' toggle handlers or the services. Surface a failed request through the existing ListErrorsComponent. Add favorite-button.component.spec.ts and follow-button.component.spec.ts with TestBed and HttpTestingController asserting the immediate emission, no second emission on success, and the reverting emission on error. Run bun install, bun run test, bun run format:check and bun run build, and paste the Vitest output in the pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request that edits the two button components, adds two spec files, and leaves articles.service.ts, profile.service.ts and the parent pages as they were. It links the Linear issue in its description, and the description shows the Vitest run with the new specs listed and the ng build summary.

On a repository with these workflows the pull request runs bun run format:check in lint.yml and the Playwright suite in playwright.yml against the backend the submodule provides. The Playwright tests click the same buttons and read the resulting state, and they pass because the final state after a successful request is unchanged.

A reviewer checks that a rollback restores the exact previous count rather than decrementing from the server's number, that the isSubmitting guard still blocks a double click, and that the error path shows something to the user. Then they merge and move the issue.

Run it on every Linear issue labelled agent

In the Project for this repository, add an automation with a Linear trigger on linear.issue.labeled filtered to the agent label and this prompt. The trigger adds the issue after the prompt; it fills in no placeholder. Each labelled UI issue starts its own run in its own sandbox and opens its own pull request on the repository, up to the automation's max_runs_per_hour cap.

Without an automation, a handler on your server can receive Linear's webhook, write the issue text into input, and POST to /o/{org}/sessions with the repository in resources. A run.completed webhook on the API key then carries the session_url to read the pull request from.

The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.

Why run it on Rush?

Optimistic updates are a timing change, and timing bugs do not show in a code review: the double click, the rollback that subtracts one from a count the server already corrected, the OnPush component that never repaints. In a Rush sandbox the agent runs the specs with HttpTestingController controlling when each response arrives, so the emission order is asserted rather than eyeballed, and the run's record keeps the Vitest output the pull request quotes.

The repository's toolchain is Angular 21 under Vite with Analog's plugin, installed by bun, with a backend submodule for end-to-end tests. Each run on Rush sets that up in its own sandbox, and the same automation handles every labelled issue, one pull request each.

Frequently asked questions

Will the count be wrong if the request fails?

No. The rollback emits the previous favorited value, and the parent handlers already compute the count from that value by adding or subtracting one, so the count returns to what it was before the click. The spec asserts both emissions in order.

Does this change the services or the API calls?

No. favorite, unfavorite, follow and unfollow keep their signatures and endpoints. Only when the components emit changes, which is why the parents need no edits.

Why not update the signal inside the button?

The button receives article or profile as an @Input and reports changes through @Output() toggle; the parent owns the state. Keeping that boundary means the article page, the preview card and the profile page all stay correct with one change in each button.

What happens on a double click?

The isSubmitting signal is set before the request and the template adds the disabled class while it is true, as today. The optimistic emit happens once per request, so a second click during the flight neither emits nor sends.

More Angular jobs

The same job on other stacks

Keep reading