Skip to content

fix(frontend): stop in-app template picks looping agent creation - #5832

Merged
mmabrouk merged 4 commits into
release/v0.112.0from
fix/template-create-redirect-loop
Aug 9, 2026
Merged

fix(frontend): stop in-app template picks looping agent creation#5832
mmabrouk merged 4 commits into
release/v0.112.0from
fix/template-create-redirect-loop

Conversation

@mmabrouk

@mmabrouk mmabrouk commented Aug 9, 2026

Copy link
Copy Markdown
Member

What happened

Creating an app from a template threw the user into a loop: every visit to the site redirected to the newest changelog-writer playground, every UI action created yet another agent (15 duplicates in the QA database, eleven of them in a one-minute burst), and new sessions/chats got stuck.

Root cause

The in-app create surface (?new=1&template=...) reuses the template query param to pre-select a template in its composer. The website deep-link capture (captureTemplateFromUrl) treated those in-app URLs as deep links, so each arrival persisted a pending-template key to localStorage. useConsumePendingTemplate then minted an agent from it and redirected to its playground. When the claim raced and lost, the stored key was never cleared, so the loop re-armed on every page load.

The fix

  • captureTemplateFromUrl ignores create-surface URLs (?new=1), so an in-app template pick never registers as a deep link.
  • A lost claim now clears the stored key, so a browser already stuck in this state recovers on its own.
  • OnboardingEntry stands down from its first-run playground redirect when the user asked for the create surface by name (?new=1).

Verification

  • 18/18 unit tests pass in web/oss/src/state/url/template.test.ts, including new cases for the create-surface URLs.
  • On the rel112 QA stack, no new duplicate agents have been created since the fix hot-reloaded; the 15 junk agents were soft-deleted.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug report Something isn't working frontend labels Aug 9, 2026
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: b8446149-7bfc-434d-8d27-62c6226a0dfa

📥 Commits

Reviewing files that changed from the base of the PR and between 3ad365f and d58dac0.

📒 Files selected for processing (3)
  • web/oss/src/components/pages/agent-home/hooks/useConsumePendingTemplate.ts
  • web/oss/src/state/url/template.test.ts
  • web/oss/src/state/url/template.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/oss/src/components/pages/agent-home/hooks/useConsumePendingTemplate.ts
  • web/oss/src/state/url/template.test.ts

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of the create flow when opened with ?new=1 or ?new=true.
    • Prevented create-flow template selections from being treated as website deep links.
    • Fixed stale pending templates from remaining after another process claims them.
    • Preserved stored template selections for later use while clearing conflicting active selections.
    • Prevented unintended redirects and loading states during create-flow navigation.

Walkthrough

The agent-home create surface now takes precedence over first-run redirects and onboarding loading. Template deep-link capture skips create-surface URLs, while pending templates are cleared when another consumer wins the claim.

Changes

Agent-home create flow

Layer / File(s) Summary
Create-surface template handling
web/oss/src/state/url/template.ts, web/oss/src/state/url/template.test.ts, web/oss/src/components/pages/agent-home/hooks/useConsumePendingTemplate.ts
Create-surface URLs do not activate or persist template deep links. Active template state is cleared, and stored template records remain available. Lost template claims clear the pending template only for the current generation. Tests cover the URL behavior.
Create-surface onboarding routing
web/oss/src/components/pages/agent-home/OnboardingEntry.tsx
OnboardingEntry detects creatingAgent, skips first-run redirection, and suppresses the onboarding loader during create mode.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the frontend fix for the agent creation loop caused by in-app template selection.
Description check ✅ Passed The description directly explains the loop, root cause, implemented fixes, and verification results.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 60.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/template-create-redirect-loop

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vercel

vercel Bot commented Aug 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Error Error Aug 9, 2026 8:56pm

Request Review

@mmabrouk

mmabrouk commented Aug 9, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

The create surface (?new=1&template=...) reuses the template param to pre-select
a template in its composer. The website deep-link capture treated those URLs as
deep links, so every arrival stored a pending create; the consumer hook then
minted an agent and redirected to its playground, and a lost claim never cleared
the stored key, re-arming the loop on every page. Ignore create-surface URLs in
capture, drop the key when the claim is lost, and let ?new=1 outrank the
first-run playground redirect.
@mmabrouk
mmabrouk force-pushed the fix/template-create-redirect-loop branch from 3ad365f to 829599c Compare August 9, 2026 19:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a1425c15-bf09-4ef8-ac4b-9250611d5c36

📥 Commits

Reviewing files that changed from the base of the PR and between ae71a92 and 3ad365f.

📒 Files selected for processing (4)
  • web/oss/src/components/pages/agent-home/OnboardingEntry.tsx
  • web/oss/src/components/pages/agent-home/hooks/useConsumePendingTemplate.ts
  • web/oss/src/state/url/template.test.ts
  • web/oss/src/state/url/template.ts

Comment thread web/oss/src/components/pages/agent-home/OnboardingEntry.tsx
Comment thread web/oss/src/state/url/template.test.ts
Comment thread web/oss/src/state/url/template.ts Outdated
CodeRabbit caught a race in the lost-claim branch: setHolding(false) fired
unconditionally, so an older in-flight claim could drop the onboarding
loader that a newer capture had just raised. Clear holding only when this
generation is still the current one - the discipline the success path
already follows.
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Railway Preview Environment

Status Destroyed (PR closed)

Updated at 2026-08-09T21:17:59.650Z

…its test

Two more CodeRabbit findings: the new test asserted on a detached URL
object nothing could mutate (now asserts on the installed window's real
location, like the neighbouring stale-key test), and isCreateSurfaceUrl
accepted any non-empty ?new= while useAgentHomeVariants accepts only
1/true - ?new=0 would have skipped capture yet rendered Home, silently
losing the key. Both sites now agree on the two values and name each
other as the constraint. 18/18 tests pass.
…red template

Codex P1: a record another tab stored from a real deep link was still
restored into activeTemplateAtom on ?new=1 URLs, re-arming the consumer -
the side door to the exact create+redirect this branch closes. Create-
surface loads now clear the active atom and return early; the stored
record stays (that tab's intent is its own, the TTL bounds it) so a later
non-create load still honours it. Two new tests; 20/20 pass.
@mmabrouk
mmabrouk merged commit df0b9d8 into release/v0.112.0 Aug 9, 2026
61 of 63 checks passed
@mmabrouk mmabrouk added the lgtm This PR has been approved by a maintainer label Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug report Something isn't working frontend lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant