Skip to content

fix(frontend): Refresh playground triggers when an agent tool settles - #5863

Open
ashrafchowdury wants to merge 2 commits into
mainfrom
fix/playground-trigger-refresh
Open

fix(frontend): Refresh playground triggers when an agent tool settles#5863
ashrafchowdury wants to merge 2 commits into
mainfrom
fix/playground-trigger-refresh

Conversation

@ashrafchowdury

Copy link
Copy Markdown
Contributor

Context

Ask an agent in the playground to schedule something. It calls create_schedule, tells you it worked, and the Triggers section of the config panel keeps showing the old list until you reload the page.

Platform ops run server-side. The runner POSTs the API endpoint directly, so the browser never sees the request and never learns the trigger list changed. The Triggers section reads a TanStack query with a 30s staleTime and no refetch on window focus, so nothing invalidates it.

Changes

A settled tool call in the chat stream is the only signal the client gets, so this PR reacts to it. A small registry maps the eight mutating trigger ops from op_catalog.py to the cache they stale, and useToolCacheInvalidation scans the streaming assistant turn and invalidates the matching query keys. list_*, discover_triggers, and test_subscription change nothing, so they are absent from the registry. Only output-available counts, so a failed create does not invalidate.

This mirrors useFileActivityDetector, which already reacts to settled write-ish tools the same way. Each toolCallId acts once, and the first pass of a session only records its history, so reopening a session does not replay it as refetches.

The registry keys on the canonical tool name, not the wire name. The same op arrives under three spellings depending on the harness, because Claude and Codex receive our platform tools through the runner's internal agenta-tools MCP server:

pi_core / pi_agenta   create_schedule
claude                mcp__agenta-tools__create_schedule
codex                 mcp.agenta-tools.create_schedule

canonicalToolName already unwrapped Claude's form. It now unwraps Codex's dot form too, matching the runner's own bareToolName stripper in client-tools.ts. Only our server is unwrapped, so a third-party mcp__other__create_schedule still resolves to nothing and cannot invalidate your cache. That extension also fixes a second surface: Codex-harness approval cards for commit_revision were falling back to the generic raw-JSON renderer for the same reason.

Two small cleanups came along. The two module-private invalidate helpers in @agenta/entities merge into one gatewayTrigger/state/invalidate module, so the trigger query keys live in one place. And the three inline copies of the isToolPart predicate collapse onto the one exported from messageParts.

Tests

  • Unit tests for the registry and the scanner, including both MCP-wrapped spellings and a third-party server that must not match.
  • npx vitest run src/components/AgentChatSlice in web/oss: 144 passing.
  • tsc --noEmit and pnpm lint-fix clean.

Worth a reviewer's eye: this is a client-side stand-in. The durable fix is a backend signal on the stream, such as a data-committed-revision frame, and the registry should go away when the runner can emit one.

What to QA

  • In the playground, ask a Pi agent to create a schedule. The Triggers section shows it as soon as the tool call settles, with no reload.
  • Repeat on a Claude-harness agent, then a Codex one. Same result. These are the two that were broken.
  • Ask the agent to pause, resume, then remove the schedule. Each action lands in the panel on its own.
  • Do the same four with a subscription. The subscriptions list updates and the schedules list is left alone.
  • Ask for a schedule that fails, for example an invalid cron. The panel must not change.
  • Reopen a session that already created a trigger. Opening it triggers no refetch, and the existing trigger is still listed.
  • Regression: create and delete a schedule from the Triggers drawer itself. It still updates as before.

ashrafchowdury and others added 2 commits August 9, 2026 19:42
Agent platform ops (create_schedule, remove_schedule, pause/resume_schedule and
the four subscription equivalents) execute server-side — the runner POSTs the
API endpoint directly — so the browser never learns the trigger lists changed.
The playground config panel's Triggers section renders from a singleton
TanStack query with a 30s staleTime and no window-focus refetch, so it kept
showing the pre-call list until a full page reload.

Detect the settled tool call by wire name in the chat stream and invalidate the
matching trigger query keys, mirroring how useFileActivityDetector reacts to
settled write-ish tools. The seen-set is seeded from a session's history at
mount so reopening a session doesn't replay it as refetches.

Also hoists the two module-private invalidate helpers in @agenta/entities into
one shared gatewayTrigger/state/invalidate module (query keys now live in one
place), and exports isToolPart from messageParts rather than adding another
copy of that predicate.

Fixes #5781

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 10, 2026
@vercel

vercel Bot commented Aug 10, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
agenta-documentation Blocked Blocked Aug 10, 2026 5:55am

Request Review

@dosubot dosubot Bot added enhancement New feature or request frontend labels Aug 10, 2026
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Chat-based schedule and subscription changes now automatically refresh related data.
    • Added support for recognizing tools from multiple MCP naming formats.
    • Tool-driven updates are processed once and avoid unnecessary refreshes.
  • Bug Fixes

    • Improved consistency when displaying tools, handling approvals, and detecting file activity.
    • Preserved correct behavior for failed, unknown, or previously processed tool calls.
    • Schedule and subscription updates now refresh reliably after successful actions and rollbacks.

Walkthrough

Changes

Tool cache invalidation

Layer / File(s) Summary
Tool recognition and canonicalization
web/oss/src/components/AgentChatSlice/assets/messageParts.ts, web/oss/src/components/AgentChatSlice/assets/toolDisplay.ts, web/oss/src/components/AgentChatSlice/components/ApprovalDock.tsx, web/oss/src/components/AgentChatSlice/hooks/useFileActivityDetector.ts, web/oss/src/components/AgentChatSlice/assets/*test.ts
Shared tool-part detection supports typed and dynamic tools. Agenta MCP names support Claude-style and Codex-style prefixes.
Trigger invalidation API
web/packages/agenta-entities/src/gatewayTrigger/state/*, web/packages/agenta-entities/src/gatewayTrigger/index.ts, web/packages/agenta-entities/src/gatewayTrigger/hooks/*
Shared schedule and subscription invalidators invalidate their query-key families. Trigger mutation flows use these helpers for success and rollback paths.
Chat tool cache collection
web/oss/src/components/AgentChatSlice/assets/toolCacheEffects.*, web/oss/src/components/AgentChatSlice/hooks/useToolCacheInvalidation.ts, web/oss/src/components/AgentChatSlice/hooks/useAgentChatSession.ts
Successful settled tool calls produce deduplicated cache effects. Hydrated history seeds processed calls without invalidation. Session updates invoke the invalidation hook.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 60.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes refreshing playground triggers after settled agent tool calls, which is the main change.
Description check ✅ Passed The description directly explains the trigger cache invalidation problem, implementation, tests, and expected behavior.
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 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/playground-trigger-refresh

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 65ecd5f1-8128-479e-be5f-4f06aca2b328

📥 Commits

Reviewing files that changed from the base of the PR and between adec2aa and 79b04bb.

📒 Files selected for processing (14)
  • web/oss/src/components/AgentChatSlice/assets/messageParts.ts
  • web/oss/src/components/AgentChatSlice/assets/toolCacheEffects.test.ts
  • web/oss/src/components/AgentChatSlice/assets/toolCacheEffects.ts
  • web/oss/src/components/AgentChatSlice/assets/toolDisplay.test.ts
  • web/oss/src/components/AgentChatSlice/assets/toolDisplay.ts
  • web/oss/src/components/AgentChatSlice/components/ApprovalDock.tsx
  • web/oss/src/components/AgentChatSlice/hooks/useAgentChatSession.ts
  • web/oss/src/components/AgentChatSlice/hooks/useFileActivityDetector.ts
  • web/oss/src/components/AgentChatSlice/hooks/useToolCacheInvalidation.ts
  • web/packages/agenta-entities/src/gatewayTrigger/hooks/useTriggerSchedule.ts
  • web/packages/agenta-entities/src/gatewayTrigger/hooks/useTriggerSubscription.ts
  • web/packages/agenta-entities/src/gatewayTrigger/index.ts
  • web/packages/agenta-entities/src/gatewayTrigger/state/index.ts
  • web/packages/agenta-entities/src/gatewayTrigger/state/invalidate.ts

Comment thread web/oss/src/components/AgentChatSlice/components/ApprovalDock.tsx
@github-actions

Copy link
Copy Markdown
Contributor

Railway Preview Environment

Preview URL https://gateway-pr-5863.up.railway.app/w
Project agenta-oss-clone-spike
Image tag pr-5863-2b3dfc5
Status Deployed
Railway logs Open logs
Workflow logs View workflow run
Updated at 2026-08-10T06:06:01.118Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request frontend size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Playground config does not refresh after creating a schedule

1 participant