Skip to content

fix(webapp): let the dashboard agent use a configurable base URL - #4738

Merged
ericallam merged 1 commit into
mainfrom
fix/dashboard-agent-base-url-tri-13390
Aug 20, 2026
Merged

fix(webapp): let the dashboard agent use a configurable base URL#4738
ericallam merged 1 commit into
mainfrom
fix/dashboard-agent-base-url-tri-13390

Conversation

@ericallam

@ericallam ericallam commented Aug 20, 2026

Copy link
Copy Markdown
Member

Summary

Lets the dashboard agent point at a specific Trigger instance instead of assuming it runs on the same instance as the webapp. Adds an optional DASHBOARD_AGENT_BASE_URL; when unset it falls back to the SDK default.

Root cause

The agent's session start, token mint, head start, in-proxy and the client transport all built the agent's base URL from the webapp's own origin (API_ORIGIN ?? APP_ORIGIN). That only holds when the agent project runs on the same instance as the webapp. When it runs elsewhere, DASHBOARD_AGENT_SECRET_KEY belongs to that other instance, so the webapp's own API rejects it with an "Invalid API key" and the chat can't start.

Fix

dashboardAgentApiOrigin() now returns DASHBOARD_AGENT_BASE_URL or the SDK default, never the webapp origin. A concrete default (rather than an unset value) keeps it independent of TRIGGER_API_URL, which a webapp may point at a different host. Every server call site already routes through that helper; the client transport reads the value from the root loader via a new useDashboardAgentBaseUrl hook.

@coderabbitai

coderabbitai Bot commented Aug 20, 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 UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7521d147-0d44-4037-a102-5cdb3f717f02

📥 Commits

Reviewing files that changed from the base of the PR and between f50f437 and 2822edf.

📒 Files selected for processing (1)
  • apps/webapp/app/hooks/useDashboardAgentBaseUrl.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (32)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (5, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (6, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (22, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (17, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (12, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (14, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (15, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (2, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (1, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (19, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (9, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (16, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (18, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (24, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (21, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (10, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (13, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (8, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (20, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (11, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (23, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (4, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (7, 24)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (3, 24)
  • GitHub Check: fk-cascade-guard / fk-cascade-guard
  • GitHub Check: obsmap / 🧪 Unit Tests: Observability Map
  • GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp (2, 2)
  • GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp (1, 2)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: runops-guard / runops-guard
  • GitHub Check: code-quality / code-quality
  • GitHub Check: Analyze (javascript-typescript)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx}: Use types over interfaces for TypeScript
Avoid using enums; prefer string unions or const objects instead

**/*.{ts,tsx}: Prefer static imports over dynamic imports. Only use dynamic import() when:

  • Circular dependencies cannot be resolved otherwise
  • Code splitting is genuinely needed for performance
  • The module must be loaded conditionally at runtime

Files:

  • apps/webapp/app/hooks/useDashboardAgentBaseUrl.ts
{packages/core,apps/webapp}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use zod for validation in packages/core and apps/webapp

Files:

  • apps/webapp/app/hooks/useDashboardAgentBaseUrl.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use function declarations instead of default exports

Files:

  • apps/webapp/app/hooks/useDashboardAgentBaseUrl.ts
**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc)

**/*.ts: When creating or editing OTEL metrics (counters, histograms, gauges), ensure metric attributes have low cardinality by using only enums, booleans, bounded error codes, or bounded shard IDs
Do not use high-cardinality attributes in OTEL metrics such as UUIDs/IDs (envId, userId, runId, projectId, organizationId), unbounded integers (itemCount, batchSize, retryCount), timestamps (createdAt, startTime), or free-form strings (errorMessage, taskName, queueName)
When exporting OTEL metrics via OTLP to Prometheus, be aware that the exporter automatically adds unit suffixes to metric names (e.g., 'my_duration_ms' becomes 'my_duration_ms_milliseconds', 'my_counter' becomes 'my_counter_total'). Account for these transformations when writing Grafana dashboards or Prometheus queries

Files:

  • apps/webapp/app/hooks/useDashboardAgentBaseUrl.ts
apps/webapp/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/webapp.mdc)

apps/webapp/**/*.{ts,tsx}: Access environment variables through the env export of env.server.ts instead of directly accessing process.env
Use subpath exports from @trigger.dev/core package instead of importing from the root @trigger.dev/core path

Files:

  • apps/webapp/app/hooks/useDashboardAgentBaseUrl.ts
apps/webapp/app/**/*.{ts,tsx}

📄 CodeRabbit inference engine (apps/webapp/CLAUDE.md)

apps/webapp/app/**/*.{ts,tsx}: For dashboard changes, visually verify the running Remix app with Chrome DevTools MCP, using snapshots, screenshots, interaction, and console-message checks as appropriate.
Use useCallback and useMemo only for context provider values, expensive derived data used as a dependency, or stable references required by dependency arrays; do not wrap ordinary event handlers or trivial computations.
Use named constants for sentinel or placeholder values instead of scattering raw string literals across comparisons.

Files:

  • apps/webapp/app/hooks/useDashboardAgentBaseUrl.ts
apps/webapp/app/**/*.ts

📄 CodeRabbit inference engine (apps/webapp/CLAUDE.md)

apps/webapp/app/**/*.ts: Never use request.signal to detect client disconnects. Use getRequestAbortSignal() from app/services/httpAsyncStorage.server.ts, which is wired to Express response close events.
Access environment variables through the env export from app/env.server.ts; never use process.env directly.
Always use Prisma findFirst instead of findUnique.
Always use the $transaction helper from ~/db.server, never call prisma.$transaction or $replica.$transaction directly. Pass isolation levels as strings, use Serializable for correctness-critical read-then-write invariants, and guard possibly undefined helper results when a definite value is required.

Files:

  • apps/webapp/app/hooks/useDashboardAgentBaseUrl.ts
**/*

📄 CodeRabbit inference engine (AGENTS.md)

**/*: Add crumbs as you write code — not just when debugging. Mark lines with
// @Crumbs or wrap blocks in `// `#region` `@crumbs. They stay on the
branch throughout development and are stripped by agentcrumbs strip
before merge.
Do not invent new namespaces — pick from this table or ask first.
Do not flag // @Crumbs markers, `#region `@crumbs blocks, or agentcrumbs
imports in reviews. These are temporary debug instrumentation stripped
before merge. Data logged in crumbs (IDs, names, values) never reaches
production.

Files:

  • apps/webapp/app/hooks/useDashboardAgentBaseUrl.ts
🔇 Additional comments (1)
apps/webapp/app/hooks/useDashboardAgentBaseUrl.ts (1)

4-7: 🎯 Functional Correctness

No stale useApiOrigin callers remain.

DashboardAgentPanel.tsx is the only useDashboardAgentBaseUrl caller in apps/webapp, and it imports the renamed hook.

			> Likely an incorrect or invalid review comment.

Walkthrough

The change adds optional DASHBOARD_AGENT_BASE_URL configuration. The root loader exposes the configured URL with https://api.trigger.dev as the fallback. A new hook reads the root loader value. The dashboard agent panel uses this hook. The server-side dashboard agent API origin uses the same environment variable and fallback instead of API_ORIGIN or APP_ORIGIN.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the problem and fix, but it omits the template's issue reference, checklist, testing, changelog, and screenshots sections. Add the required template sections and provide the issue reference, checklist status, testing steps, changelog entry, and screenshots or state that they are not applicable.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the main change: configurable dashboard agent base URL support.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/dashboard-agent-base-url-tri-13390

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[bot]

This comment was marked as resolved.

@ericallam
ericallam force-pushed the fix/dashboard-agent-base-url-tri-13390 branch from f50f437 to 5075512 Compare August 20, 2026 12:43
@changeset-bot

changeset-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 2822edf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ericallam ericallam changed the title fix(webapp): let the dashboard agent target a different Trigger instance fix(webapp): let the dashboard agent use a configurable base URL Aug 20, 2026
The agent's session start, token mint, head start, in-proxy and the client
transport all assumed the agent project runs on the same Trigger instance as the
webapp, deriving the agent's base URL from the webapp's own origin. When the
agent project runs on a different instance, its secret key belongs to that
instance, so sending it to the webapp's own API is rejected with an "Invalid API
key" and the chat can't start.

Add an optional DASHBOARD_AGENT_BASE_URL. The agent's base URL now resolves to
it, or the SDK default when unset, and never the webapp's own origin. A concrete
default rather than an unset value keeps it independent of TRIGGER_API_URL, which
a webapp may point at a different host. The server call sites already funnel
through one helper; the client transport reads the value from the root loader via
a new useDashboardAgentBaseUrl hook.
@ericallam
ericallam force-pushed the fix/dashboard-agent-base-url-tri-13390 branch from 5075512 to 2822edf Compare August 20, 2026 12:59
@ericallam
ericallam marked this pull request as ready for review August 20, 2026 13:03

@devin-ai-integration devin-ai-integration 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.

Devin Review found 1 potential issue.

Open in Devin Review

Comment thread apps/webapp/app/services/dashboardAgent.server.ts
@ericallam
ericallam merged commit 56f8756 into main Aug 20, 2026
55 checks passed
@ericallam
ericallam deleted the fix/dashboard-agent-base-url-tri-13390 branch August 20, 2026 13:14
ericallam added a commit that referenced this pull request Aug 20, 2026
…ance

Follow-up to #4738. That change routed the agent's session (start, token,
transport, realtime) to a configurable instance, but it also moved the origin
the agent's read-tools call back to. Those tools act as the user with a
delegated token this webapp signs with its own SESSION_SECRET, scoped to its own
user and environment, so the token can only be verified by, and the data only
found on, that same instance.

Split the two origins. dashboardAgentApiOrigin() stays the instance hosting the
agent project (sessions, task triggers, realtime, the in forward). A new
dashboardAgentUserApiOrigin() returns this webapp's own origin and is injected
into the run metadata the tools use. When the agent runs on the same instance as
the webapp both resolve to the same host, so nothing changes there.
ericallam added a commit that referenced this pull request Aug 20, 2026
…ance (#4740)

## Summary

Follow-up to #4738. Splits the dashboard agent's base URL into two: the
instance that hosts the agent project (used for sessions), and the
instance the agent acts against as the user (used by its read-tools).
#4738 only needed the first, but moved the second along with it, which
breaks the tools when the agent runs on a different instance than the
webapp.

## Root cause

The agent's read-tools call the API as the logged-in user via a
delegated user-actor token. The webapp signs that token with its own
`SESSION_SECRET`, scoped to its own `userId` and `environmentId`, so it
can only be verified by, and only resolves the user's data on, that same
instance. #4738 routed the injected `apiOrigin` those tools use to the
agent's host instance, so the token no longer verifies and the data
isn't there.

## Fix

`dashboardAgentApiOrigin()` stays the agent's host instance (sessions,
task triggers, realtime, the `in` forward). A new
`dashboardAgentUserApiOrigin()` returns the webapp's own origin
(`API_ORIGIN ?? APP_ORIGIN`) and is injected into the run metadata the
tools use. Same-instance deployments resolve both to the same host, so
behavior is unchanged there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants