Skip to content

feat(webapp): dashboard agent — chat, reports, investigate - #4418

Open
kathiekiwi wants to merge 494 commits into
mainfrom
feat/dashboard-agent-flows
Open

feat(webapp): dashboard agent — chat, reports, investigate#4418
kathiekiwi wants to merge 494 commits into
mainfrom
feat/dashboard-agent-flows

Conversation

@kathiekiwi

@kathiekiwi kathiekiwi commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

The system behind the dashboard agent: everything except the UI, which follows in #4529

The agent reads runs, errors, queues, deploys and health through the public API with a delegated, read-only user token. It has no database access of its own beyond its conversation store.

Structure

contracts   trigger:// URIs, intents, block envelope, watch specs
    ↓
storage     its own Postgres schema — chats, messages, investigations, watches
    ↓
agent       prompt, tools, evals — the task bundle
    ↓
webapp      routes and services that mint its token and proxy each turn

Each layer only knows the one above it. The UI PR sits on top and knows all four.

System-level changes

  • Delegated tokens — the existing user-actor credential gains an optional environment claim. One guard (userActorEnvironment.server.ts) enforces it; routes call it rather than deriving the rule.
  • RBAC fallback — a delegated token now gets an ability built from its own cap, never the blanket ability a PAT gets. Without this the agent's read-only cap buys a write JWT on self-hosted.
  • Query boundary — TRQL is pinned read-only; no mutating query can reach the database.
  • Images — model output never renders images, and img-src drops its wildcard.
  • Reports — layout declared once, shared by the card and the text surfaces.
  • Migration — one additive migration on top of the two already shipped.

Notes

  • Gated by canAccessDashboardAgent; no behavior change with the flag off.
  • Ships @trigger.dev/core (report schemas) — see the changeset.

@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0db1cf0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
@trigger.dev/core Patch
trigger.dev Patch
@trigger.dev/build Patch
@trigger.dev/python Patch
@trigger.dev/redis-worker Patch
@trigger.dev/schema-to-json Patch
@trigger.dev/sdk Patch
@internal/cache Patch
@internal/clickhouse Patch
@internal/llm-model-catalog Patch
@internal/metrics-pipeline Patch
@trigger.dev/rbac Patch
@internal/redis Patch
@internal/replication Patch
@internal/run-engine Patch
@internal/run-store Patch
@internal/schedule-engine Patch
@trigger.dev/sso Patch
@internal/testcontainers Patch
@internal/tracing Patch
@internal/tsql Patch
@internal/dashboard-agent Patch
@internal/sdk-compat-tests Patch
@trigger.dev/react-hooks Patch
@trigger.dev/rsc Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch

Not sure what this means? Click here to learn what changesets are.

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

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR adds dashboard-agent contracts, tools, persistence, investigations, watches, evaluation controls, and maintenance jobs. It adds delegated-token environment scoping and shared API authentication. It adds report schemas, JSON responses, health telemetry handling, caching, and rendering updates. It adds waiting-run diagnosis and queue-metrics routes. It also adds request limits, CSP image policies, agent UI updates, tests, documentation, and configuration changes.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 48.92% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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 summarizes the main dashboard agent, reporting, and investigation changes.
Description check ✅ Passed The description gives a detailed, relevant architecture and change summary, but it omits the template checklist, testing steps, changelog, and screenshots.
✨ 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 feat/dashboard-agent-flows

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.

Base automatically changed from feat/queue-metrics-and-health to main July 29, 2026 15:45
@pkg-pr-new

pkg-pr-new Bot commented Jul 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

@trigger.dev/build

npm i https://pkg.pr.new/@trigger.dev/build@8adf2b2

trigger.dev

npm i https://pkg.pr.new/trigger.dev@8adf2b2

@trigger.dev/core

npm i https://pkg.pr.new/@trigger.dev/core@8adf2b2

@trigger.dev/python

npm i https://pkg.pr.new/@trigger.dev/python@8adf2b2

@trigger.dev/react-hooks

npm i https://pkg.pr.new/@trigger.dev/react-hooks@8adf2b2

@trigger.dev/redis-worker

npm i https://pkg.pr.new/@trigger.dev/redis-worker@8adf2b2

@trigger.dev/rsc

npm i https://pkg.pr.new/@trigger.dev/rsc@8adf2b2

@trigger.dev/schema-to-json

npm i https://pkg.pr.new/@trigger.dev/schema-to-json@8adf2b2

@trigger.dev/sdk

npm i https://pkg.pr.new/@trigger.dev/sdk@8adf2b2

commit: 8adf2b2

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal-packages/dashboard-agent/src/tool-schemas.ts (1)

547-559: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Align the capability instructions with the new mutating tools.

The prompt now exposes schedule_watch, create_alert, and delete_alert, but it still describes the toolset as read-only and later says the agent cannot change anything. This contradiction can make the agent refuse supported watch/alert actions or incorrectly direct users to the dashboard. Update the blanket capability text to distinguish read-only data tools from these explicitly authorized mutations.

🧹 Nitpick comments (1)
apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx (1)

351-368: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Memoize the transcript-derived winner map.

Line 357 creates a new Map on every render, and Line 368 passes it to memoized turns; activity-only updates therefore rerender the entire transcript and rescan all parts. Memoize stripped and its winners from messages.

Proposed change
-  const stripped = messages.map(stripStepParts);
-
-  const investigationWinners = winningInvestigationOccurrences(stripped);
+  const { stripped, investigationWinners } = useMemo(() => {
+    const stripped = messages.map(stripStepParts);
+    return {
+      stripped,
+      investigationWinners: winningInvestigationOccurrences(stripped),
+    };
+  }, [messages]);

As per coding guidelines, useMemo is appropriate for expensive derived data and stable references required by dependency arrays.

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ae8860fd-cece-44f8-b032-c969b4234488

📥 Commits

Reviewing files that changed from the base of the PR and between fd5006e and 7abce81.

📒 Files selected for processing (2)
  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
  • internal-packages/dashboard-agent/src/tool-schemas.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (33)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (12, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (11, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (7, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (6, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (4, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (5, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (1, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (8, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (10, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (9, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (3, 12)
  • GitHub Check: webapp / 🧪 Unit Tests: Webapp (2, 12)
  • GitHub Check: sdk-compat / Node.js 22.23 (warp-ubuntu-latest-x64-4x)
  • GitHub Check: sdk-compat / Node.js 24.18 (warp-ubuntu-latest-x64-4x)
  • GitHub Check: sdk-compat / Bun Runtime
  • GitHub Check: sdk-compat / Node.js 26.4 (warp-ubuntu-latest-x64-4x)
  • GitHub Check: sdk-compat / Node.js 20.20 (warp-ubuntu-latest-x64-4x)
  • GitHub Check: e2e / 🧪 CLI v3 tests (warp-ubuntu-latest-x64-4x - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (warp-windows-latest-x64-8x - pnpm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: e2e / 🧪 CLI v3 tests (warp-ubuntu-latest-x64-4x - npm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (warp-windows-latest-x64-8x - npm)
  • GitHub Check: packages / 🧪 Unit Tests: Packages (2, 3)
  • GitHub Check: packages / 🧪 Unit Tests: Packages (3, 3)
  • GitHub Check: packages / 🧪 Unit Tests: Packages (1, 3)
  • GitHub Check: sdk-compat / Cloudflare Workers
  • GitHub Check: sdk-compat / Deno Runtime
  • GitHub Check: runops-guard / runops-guard
  • GitHub Check: internal / 🧪 Unit Tests: Internal
  • GitHub Check: e2e-webapp / 🧪 E2E Tests: Webapp
  • GitHub Check: code-quality / code-quality
  • GitHub Check: 🛡️ E2E Auth Tests (full)
  • 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 import(); use dynamic imports only for unresolvable circular dependencies, genuine performance code splitting, or conditional runtime loading.
Import Trigger.dev tasks from @trigger.dev/sdk; never use @trigger.dev/sdk/v3 or deprecated client.defineJob.
Add agentcrumbs while writing code using approved namespaces; mark lines with // @Crumbs or blocks with `// `#region` `@crumbs, and strip them before merging.

Files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
  • internal-packages/dashboard-agent/src/tool-schemas.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/components/dashboard-agent/DashboardAgentMessages.tsx
**/*.{ts,tsx,js,jsx}

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

Use function declarations instead of default exports

Files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
  • internal-packages/dashboard-agent/src/tool-schemas.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

Do not reintroduce the removed v1 execution path; RunEngineVersion.V1 branches may only reject or finalize gracefully so v3 clients receive a clean 4xx, never a 5xx.

Files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
apps/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

For apps, use typecheck for verification and never use build as the correctness check.

Files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
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/components/dashboard-agent/DashboardAgentMessages.tsx
**/*.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:

  • internal-packages/dashboard-agent/src/tool-schemas.ts
internal-packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

For internal packages, use typecheck for verification and never use build as the correctness check.

Files:

  • internal-packages/dashboard-agent/src/tool-schemas.ts
🧠 Learnings (18)
📚 Learning: 2026-02-11T16:37:32.429Z
Learnt from: matt-aitken
Repo: triggerdotdev/trigger.dev PR: 3019
File: apps/webapp/app/components/primitives/charts/Card.tsx:26-30
Timestamp: 2026-02-11T16:37:32.429Z
Learning: In projects using react-grid-layout, avoid relying on drag-handle class to imply draggability. Ensure drag-handle elements only affect dragging when the parent grid item is configured draggable in the layout; conditionally apply cursor styles based on the draggable prop. This improves correctness and accessibility.

Applied to files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
📚 Learning: 2026-07-28T21:57:20.061Z
Learnt from: samejr
Repo: triggerdotdev/trigger.dev PR: 4411
File: apps/webapp/app/routes/_app.orgs.$organizationSlug.settings.team/route.tsx:818-843
Timestamp: 2026-07-28T21:57:20.061Z
Learning: When using Radix UI `DialogClose` with `asChild` (e.g., Trigger.dev dashboard components), note that it injects `type="button"` into its child via `Slot`. If the child is a local `Button` that forwards its `type` prop to the native `<button>`, then placing it inside a `<form>` will *not* submit unless you explicitly set `type="submit"` (or otherwise override the injected type / wire up submission behavior). Review form actions to ensure the intended submit vs non-submit behavior is preserved.

Applied to files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
📚 Learning: 2026-03-22T13:26:12.060Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3244
File: apps/webapp/app/components/code/TextEditor.tsx:81-86
Timestamp: 2026-03-22T13:26:12.060Z
Learning: In the triggerdotdev/trigger.dev codebase, do not flag `navigator.clipboard.writeText(...)` calls for `missing-await`/`unhandled-promise` issues. These clipboard writes are intentionally invoked without `await` and without `catch` handlers across the project; keep that behavior consistent when reviewing TypeScript/TSX files (e.g., usages like in `apps/webapp/app/components/code/TextEditor.tsx`).

Applied to files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
  • internal-packages/dashboard-agent/src/tool-schemas.ts
📚 Learning: 2026-03-22T19:24:14.403Z
Learnt from: matt-aitken
Repo: triggerdotdev/trigger.dev PR: 3187
File: apps/webapp/app/v3/services/alerts/deliverErrorGroupAlert.server.ts:200-204
Timestamp: 2026-03-22T19:24:14.403Z
Learning: In the triggerdotdev/trigger.dev codebase, webhook URLs are not expected to contain embedded credentials/secrets (e.g., fields like `ProjectAlertWebhookProperties` should only hold credential-free webhook endpoints). During code review, if you see logging or inclusion of raw webhook URLs in error messages, do not automatically treat it as a credential-leak/secrets-in-logs issue by default—first verify the URL does not contain embedded credentials (for example, no username/password in the URL, no obvious secret/token query params or fragments). If the URL is credential-free per this project’s conventions, allow the logging.

Applied to files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
  • internal-packages/dashboard-agent/src/tool-schemas.ts
📚 Learning: 2026-05-18T08:21:27.694Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3632
File: apps/webapp/sentry.server.ts:4-21
Timestamp: 2026-05-18T08:21:27.694Z
Learning: When handling Prisma error P1001 ("Can't reach database server") in TypeScript, don’t assume a single error shape. Prisma can surface P1001 via two different error classes/fields: `PrismaClientKnownRequestError` exposes it as `err.code === "P1001"` (common during mid-query connection drops), while `PrismaClientInitializationError` exposes it as `err.errorCode === "P1001"` (common on client startup failure). Therefore, predicates should use `err.code === "P1001" || err.errorCode === "P1001"`. Do not flag `err.code === "P1001"` as “unreachable/never matches,” as it is expected in production.

Applied to files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
  • internal-packages/dashboard-agent/src/tool-schemas.ts
📚 Learning: 2026-05-18T08:21:27.694Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3632
File: apps/webapp/sentry.server.ts:4-21
Timestamp: 2026-05-18T08:21:27.694Z
Learning: When handling Prisma errors for P1001 ("Can't reach database server"), do not assume it only appears under a single property name. Prisma may surface P1001 via either `PrismaClientKnownRequestError` (`err.code === "P1001"`, e.g., mid-query connection drops) or `PrismaClientInitializationError` (`err.errorCode === "P1001"`, e.g., client startup connection failure). To reliably detect the condition, check `err.code === "P1001" || err.errorCode === "P1001"`, and avoid review rules that would incorrectly flag `err.code === "P1001"` as unreachable/never-matching.

Applied to files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
  • internal-packages/dashboard-agent/src/tool-schemas.ts
📚 Learning: 2026-06-13T19:53:13.759Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3937
File: packages/trigger-sdk/skills/realtime-and-frontend/SKILL.md:258-260
Timestamp: 2026-06-13T19:53:13.759Z
Learning: When reviewing code that uses `trigger.dev/react-hooks`’s `useRealtimeRun`, preserve the call signature where the first argument is the full realtime handle object (not `handle.id`). This is intentional to maintain type-safety and is consistent with the official docs; do not suggest changing the first argument from the handle object to `handle.id`.

Applied to files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
  • internal-packages/dashboard-agent/src/tool-schemas.ts
📚 Learning: 2026-06-17T17:13:49.929Z
Learnt from: matt-aitken
Repo: triggerdotdev/trigger.dev PR: 3948
File: apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.bulk-actions.$bulkActionParam/route.tsx:48-62
Timestamp: 2026-06-17T17:13:49.929Z
Learning: In triggerdotdev/trigger.dev, within `dashboardLoader`/`dashboardAction` (or similar context resolver code) whenever you resolve an organization ID from an organization slug for RBAC/enterprise authorization scope, always read from the primary Prisma client (`prisma`), not `$replica`. Using `$replica` can hit replica-lag and cause the RBAC lookup/authorization to run without the correct org scope (bypassing intended role enforcement). Implement the slug→org lookup with `prisma.organization.findFirst(...)` (or equivalent primary-client query) and add an inline comment documenting why the primary client is required (replica lag could lead to unscoped RBAC checks).

Applied to files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
  • internal-packages/dashboard-agent/src/tool-schemas.ts
📚 Learning: 2026-06-23T13:04:21.413Z
Learnt from: carderne
Repo: triggerdotdev/trigger.dev PR: 4023
File: apps/webapp/app/services/upsertBranch.server.ts:14-18
Timestamp: 2026-06-23T13:04:21.413Z
Learning: In TypeScript, it’s valid to `import { type X }` and then use `typeof X` in a type-only position, e.g. `type Alias = z.infer<typeof X>`. The `type` modifier suppresses the runtime import, but the type checker still has the full exported type so `z.infer<typeof X>` can resolve correctly. In code reviews, don’t flag this as a TypeScript compile error as long as `typeof X` is used in a type context (e.g., with `z.infer`, `type` aliases, generics), not as a runtime value.

Applied to files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
  • internal-packages/dashboard-agent/src/tool-schemas.ts
📚 Learning: 2026-04-16T14:21:15.229Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3368
File: apps/webapp/app/components/logs/LogsTaskFilter.tsx:135-163
Timestamp: 2026-04-16T14:21:15.229Z
Learning: When rendering lists of task registry items in apps/webapp (e.g., <SelectItem /> rows) and using `key={item.slug}`, do not flag it as potentially non-unique. In trigger.dev’s `TaskIdentifier` table, the DB constraint `@unique([runtimeEnvironmentId, slug])` guarantees `slug` is unique within a given runtime environment, so `item.slug` is safe as the React key as long as the list is derived from that registry/constraint (and not from a legacy query that could produce duplicate slugs).

Applied to files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
📚 Learning: 2026-05-08T21:00:20.973Z
Learnt from: samejr
Repo: triggerdotdev/trigger.dev PR: 3538
File: apps/webapp/app/components/primitives/Resizable.tsx:60-78
Timestamp: 2026-05-08T21:00:20.973Z
Learning: In the triggerdotdev/trigger.dev codebase, treat Zod as a boundary validation tool (API handlers, request/response validation, and storage/DB read/write validation), not as inline render-time validation inside React components/primitive UI code. For render-time guards, prefer small manual type-narrowing checks (e.g., a short predicate like ~10–20 lines) over importing Zod into UI primitives, to avoid per-render schema-parse overhead and unnecessary abstraction. Use the manual guard approach unless you truly need schema validation at a boundary; only then introduce Zod.

Applied to files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
📚 Learning: 2026-06-25T18:21:55.847Z
Learnt from: carderne
Repo: triggerdotdev/trigger.dev PR: 4039
File: apps/webapp/app/routes/invite-resend.tsx:0-0
Timestamp: 2026-06-25T18:21:55.847Z
Learning: In the triggerdotdev/trigger.dev Zod 4 migration, avoid importing from the root package `conform-to/zod` in webapp code. It can resolve to the Zod 3 build and may crash at module load under Zod 4. When reviewing TypeScript/TSX files in `apps/webapp`, prefer importing from the Zod 4 subpath `conform-to/zod/v4` for Zod 4-compatible schemas/types.

Applied to files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
📚 Learning: 2026-05-12T21:04:05.815Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3542
File: apps/webapp/app/components/sessions/v1/SessionStatus.tsx:1-3
Timestamp: 2026-05-12T21:04:05.815Z
Learning: In this Remix + TypeScript codebase, do not flag a server/client boundary violation when a file imports only types from a module matching `*.server`.

Specifically, it’s safe to import types using `import type { Foo } from "*.server"` or `import { type Foo } from "*.server"` because TypeScript erases type-only imports at compile time and they emit no JavaScript, so they won’t cross the Remix server/client bundle boundary.

Only raise the boundary concern for value imports (e.g., `import { Foo }` without `type`, or `import Foo`), since those produce JavaScript output.

Applied to files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
📚 Learning: 2026-06-25T18:21:51.905Z
Learnt from: carderne
Repo: triggerdotdev/trigger.dev PR: 4039
File: apps/webapp/app/routes/invite-revoke.tsx:0-0
Timestamp: 2026-06-25T18:21:51.905Z
Learning: During the Zod v4 migration in the triggerdotdev/trigger.dev webapp, ensure any imports from `conform-to/zod` use the Zod-4 subpath: `conform-to/zod/v4` (e.g., `import { parseWithZod } from "conform-to/zod/v4"`). Do not import from the package root `conform-to/zod`, because it is the Zod 3 implementation and may load Zod-3-only symbols (e.g., `ZodBranded`, `ZodEffects`), which can throw at module load (notably with `zod4.4.3`). This should be enforced across `apps/webapp/**/*` where helpers like `parseWithZod` and `conformZodMessage` are used.

Applied to files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
📚 Learning: 2026-07-03T17:10:21.498Z
Learnt from: 0ski
Repo: triggerdotdev/trigger.dev PR: 4148
File: apps/webapp/app/models/orgMember.server.ts:149-168
Timestamp: 2026-07-03T17:10:21.498Z
Learning: In triggerdotdev/trigger.dev, `User.email` (Prisma schema: `internal-packages/database/prisma/schema.prisma`) currently does NOT use `citext` and does NOT have a `lower(email)` functional unique index. Therefore, do not introduce Prisma queries like `where: { email: { equals: <value>, mode: "insensitive" } }` (or any case-insensitive lookup) against `User.email`, because it can force sequential scans of the `users` table under load. During review, ensure email is normalized (e.g., lowercased/trimmed) before both writes and subsequent lookups, and if true case-insensitive behavior/uniqueness is required, implement it via a separate app-wide migration (e.g., switch to `citext` and/or add a functional unique index with backfill) rather than bolting it onto individual feature PRs.

Applied to files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
📚 Learning: 2026-06-25T18:21:54.729Z
Learnt from: carderne
Repo: triggerdotdev/trigger.dev PR: 4039
File: apps/webapp/app/routes/confirm-basic-details.tsx:0-0
Timestamp: 2026-06-25T18:21:54.729Z
Learning: For Remix + TypeScript files that use Conform v1 (conform-to/react) and its getInputProps helper, when you intend to suppress the helper-provided default value for non-checkbox/non-radio inputs (e.g., hidden inputs managed via an explicit value prop), use the Conform v1 option key `value: false`. Do not recommend `defaultValue: false` here, because `defaultValue` is not a valid option key for these input types in Conform v1 typings.

Applied to files:

  • apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx
📚 Learning: 2026-06-04T18:16:35.386Z
Learnt from: nicktrn
Repo: triggerdotdev/trigger.dev PR: 3836
File: apps/supervisor/src/backpressure/backpressureMonitor.ts:3-5
Timestamp: 2026-06-04T18:16:35.386Z
Learning: When reviewing TypeScript in this repo, apply the rule “prefer type aliases over interfaces” only to data/object shapes and union/intersection type modeling. If an interface is being used as a behavioral contract for collaborators to implement (e.g., method-shape interfaces that define required behavior, such as `BackpressureLogger` / `BackpressureSignalSource` in `apps/supervisor/src/backpressure/backpressureMonitor.ts`), keep it as an `interface` and do not flag it as a type-alias-vs-interface violation.

Applied to files:

  • internal-packages/dashboard-agent/src/tool-schemas.ts
📚 Learning: 2026-06-09T17:58:04.699Z
Learnt from: 0ski
Repo: triggerdotdev/trigger.dev PR: 3879
File: apps/webapp/app/models/vercelIntegration.server.ts:619-630
Timestamp: 2026-06-09T17:58:04.699Z
Learning: In this codebase, outbound raw `fetch` calls should typically rely on Node/undici’s default request timeout (about ~300s) rather than adding a per-call `AbortController` + `setTimeout` wrapper inside individual functions (e.g. in files like `apps/webapp/app/models/vercelIntegration.server.ts`). During code review, do not flag the absence of a per-call timeout on a single `fetch` as an issue; if per-call timeouts are needed, they should be implemented via a codebase-wide convention (e.g., a shared fetch wrapper or documented pattern) rather than ad-hoc per-function changes.

Applied to files:

  • internal-packages/dashboard-agent/src/tool-schemas.ts
🔇 Additional comments (1)
apps/webapp/app/components/dashboard-agent/DashboardAgentMessages.tsx (1)

99-146: LGTM!

Also applies to: 245-287

@kathiekiwi kathiekiwi changed the title Dashboard Agent: investigations, watches, alerts, and notifications Dashboard Agent: UI & investigations Aug 1, 2026
kathiekiwi added a commit that referenced this pull request Aug 2, 2026
- waiting-run diagnosis: 'unknown' with concurrency evidence in hand no longer
  claims the evidence is missing; an elapsed delay says 'not yet enqueued'
  instead of hiding behind time-from-creation
- queue metrics route: drop the double decode that 500ed on names with a
  literal percent sign
- evidence schema: kind must match the URI's own kind
- seed-queue-metrics: default-binding imports like the other seeders
kathiekiwi added a commit that referenced this pull request Aug 3, 2026
…ions + alerts) (#4456)

Stacked on #4418 — the diff against that branch is the complete Watch
feature, extracted so the base agent PR can land without it.
@kathiekiwi kathiekiwi changed the title Dashboard Agent: UI & investigations Dashboard Agent V1 — chat, reports, Investigate, Watch Aug 3, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Observability map

As of 0db1cf0.

19/100 over 417 measured of 433 entry points (base 18, up 1)

What this PR changed

route base head now failing
/api/v1/dashboard-agent/eval-policy new 0 request-context

FIX FIRST

  • /api/v1/projects/:projectRef/envvars (sensitive) - auth-boundary, request-context
  • /auth/sso (sensitive) - auth-boundary, request-context
  • /_app/orgs/:organizationSlug/settings/team (sensitive) - error-classification, auth-scope, request-context

AUDIT 3 of 50 sensitive mutations record an actor. 47 without one.
CONTEXT 14 of 417 entry points name a tenant on a failure path. 326 appear only here, 39 of them sensitive, in the JSON rather than the fix list.

What the score is made of
CHECKS
  error-classification  171 applicable,  97 pass,   0 sole, global without it 10
  auth-boundary          62 applicable,  57 pass,   0 sole, global without it 15
  auth-scope             19 applicable,  17 pass,   0 sole, global without it 18
  request-context       417 applicable,  14 pass, 224 sole, global without it 64
  audit-trail            50 applicable,   3 pass,   0 sole, not in the score

The score and findings here are report-only and never gate the merge. Separately, a required test suite keeps this tool's symbol and route lists in sync with the code they name, and can fail a pull request that renames or removes a symbol they reference, or that adds the first route with a segment they anticipate. Each failure names the list to edit. The rules and their reasons: internal-packages/observability-map/README.md.

The Badge primitive's small variant paints a blue tinted chip on system
themes, which overrode the severity/confidence tones — Degraded and Medium
confidence rendered blue instead of amber.
New "actions" view block: a row of 1-3 buttons the model may emit. A watch
action opens the watch configuration card pre-filled; ask sends the labelled
question as the user's next message; a navigate target that doesn't parse is
dropped at render time, as on chart actions.
…ger button

Agent logo instead of the indigo bubble, the button's own surface (charcoal
on dark, white on light) and softened green border.
Third ToastUI variant: success's layout with the agent glyph and the Ask
Trigger border. The wake toast drops its Callout composition for it.
…allery section id

The wake toast moved to the standard toast's agent status, leaving the
Callout variant with no consumer.
The root already mounts one; a fired toast rendered in both and the two
copies stacked.
Sonner stamps data-theme="light" (its default) on the toast list; since the
theme system remaps tokens by that attribute, every custom toast rendered
light regardless of the page's theme.
…ast surface matches Ask Trigger on dark themes

A wake read on screen before the next poll never toasted. The toast list is
now recent deliveries (15 min, id-deduped client-side); the dot still counts
unread only.
The wake seeded the card and said it had started looking, then nothing ran
it — the findings were left to a turn only the user could start. The watcher
now reports a delivered consented wake to the webapp, which mints the same
delegated user-actor token a turn gets and sends a `watch.investigate` action
into the chat; the agent conducts a real investigating turn on that card and
delivers the findings as its own message. Best-effort throughout: nothing here
can retry or invalidate the wake.
Chats belong to (organization, user); several queries enforced only the user,
so a user's own chat from another org could be opened, renamed, pinned or
appended to through a different org's route.
Crossing orgs re-renders the layout without remounting, so the previous
org's open chat and history lingered in the panel.

@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 5 potential issues.

View 1 additional finding in Devin Review.

Open in Devin Review

Comment thread apps/webapp/app/routes/projects.$projectRef.ai-help.ts
Comment on lines +117 to +121
if (checkMessageParts(parsed.payload.message?.parts) !== null) {
return tooLarge();
}
parsed.payload.metadata = {
...(parsed.payload.metadata ?? {}),
userActorToken: await mintDashboardAgentUserActorToken(user.id),
...pickAgentClientMetadata(parsed.payload.metadata),

@devin-ai-integration devin-ai-integration Bot Aug 7, 2026

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.

🟡 A failure to mint the agent's access token is treated as a malformed message and the turn is sent without any access

The step that creates the chat's short-lived access credential (mintDashboardAgentUserActorToken(...) inside the try at apps/webapp/app/routes/resources.$organizationSlug.projects.$projectParam.env.$envParam.dashboard-agent.in.$.ts:117-121) is covered by a catch meant for unreadable message bodies, so a failure there is ignored and the message is forwarded with no credential attached.

Impact: If credential creation fails, the assistant answers the question with no access to the user's data and claims it can't see anything, instead of reporting an error.

The catch's intent versus what it covers

The try block was written around JSON.parse(raw) — its catch comment reads "Non-JSON or unexpected shape — forward unchanged rather than break the turn." But the awaited mint call is inside the same block, so any rejection from it (signing error, missing secret) takes the same path: body stays as the raw, un-augmented request and is proxied upstream. The agent then runs the turn with no userActorToken, apiOrigin, projectRef, environmentId or repo snapshot in its metadata, and every data tool falls into its no-auth branch (NO_AUTH in internal-packages/dashboard-agent/src/tool-api-client.ts).

Narrowing the try to the JSON.parse call (or awaiting the mint before entering it) makes a mint failure surface as a 5xx the client can retry.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +118 to +123
bucketIntervalMs: bucketSeconds * 1000,
// Oldest first; buckets with no sample are omitted, so gaps carry the previous depth.
depthTrend: (trendRows ?? [])
.slice()
.sort((a, b) => a.bucket.localeCompare(b.bucket))
.map((row) => row.depth),

@devin-ai-integration devin-ai-integration Bot Aug 7, 2026

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.

🟡 Queue depth trend can be mis-timed when a bucket reports no data

The queue depth series drops any interval that reported nothing (.map((row) => row.depth) at apps/webapp/app/routes/api.v1.queues.$queueParam.metrics.ts:120-123) while still being labelled with a fixed interval width, so the points shift in time whenever a gap exists.

Impact: A queue's depth-over-time answer can place values at the wrong times after any quiet interval.

The comment describes carry-forward, but the code omits

The inline comment says "buckets with no sample are omitted, so gaps carry the previous depth", but omitting a bucket does not carry the previous depth — it compresses the timeline, so the Nth element of depthTrend no longer corresponds to from + N * bucketIntervalMs.

The sibling reader does this correctly: apps/webapp/app/presenters/v3/waitingRun/waitingRunDiagnosis.server.ts:138-146 builds a fixed-width grid and carry-forwards the last known depth into missing buckets. Applying the same fill here (or returning { bucket, depth } pairs) would make bucketIntervalMs meaningful.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread packages/cli-v3/src/mcp/prompts.ts
Comment on lines +301 to +324
const ROLLOUT_ERROR_PATTERNS = [
/\bUNKNOWN_(?:TABLE|IDENTIFIER|DATABASE)\b/,
/\bCode:\s*(?:60|47|81)\b/,
/\bTable\b[^.]*\bdoes\s?n?o?t?'?t?\s*exist/i,
/\bUnknown (?:table|identifier|column|database)\b/i,
];

function isRolloutError(error: unknown): boolean {
// Prefer a structured code/type if one ever survives the wrapping.
if (typeof error === "object" && error !== null) {
const record = error as Record<string, unknown>;
const code = String(record.code ?? "");
const type = String(record.type ?? "");
if (code === "60" || code === "47" || code === "81") return true;
if (/^UNKNOWN_(TABLE|IDENTIFIER|DATABASE)$/.test(type)) return true;
}
const message =
error instanceof Error
? error.message
: typeof error === "string"
? error
: String(error ?? "");
return ROLLOUT_ERROR_PATTERNS.some((pattern) => pattern.test(message));
}

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.

🔍 Rollout-error detection for env_metrics is text-matched and may misclassify

isRolloutError decides whether a measured-flow failure is a benign "table not there yet" (fall through to the snapshot silently) or a real failure (mark the depth unmeasurable). It first checks record.code/record.type, then falls back to regexes over the error message. Two things to keep in mind: the structured branch compares String(record.code) against "60"|"47"|"81" — a numeric code: 60 stringifies to "60" so that works, but a ClickHouse client that reports code as e.g. "DB::Exception 60" will not match and will fall through to the text patterns. And /\bUnknown (?:table|identifier|column|database)\b/i will also match an unrelated error message that merely contains that phrase (e.g. a bad user-authored query surfaced through the same client), silently downgrading a real failure to "unavailable". Worth confirming the exact error shape the query service produces for a missing env_metrics table.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@kathiekiwi kathiekiwi changed the title feat(webapp): dashboard agent — chat, reports, Investigate feat(webapp): dashboard agent — chat, reports, investigate Aug 7, 2026

@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: 13

Note

Due to the large number of review comments, Critical, Major severity comments were prioritized as inline comments.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
apps/webapp/app/presenters/v3/reports/health/health.ts (1)

104-118: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Footer can now exceed the documented maximum of two entries.

raise_env_limit emits two entries. If the dominant finding is flow, the block at Lines 112-118 pushes a third entry (do_nothing_drains or region_failover). env_limit_saturation is a flow cause with the raise_env_limit recommendation, so this path is reachable. The footer field in packages/core/src/v3/schemas/reports.ts (Line 171) documents "Max two entries". Update that comment, or cap the footer length here, so renderers and clients share one contract.

apps/webapp/app/tailwind.css (1)

704-733: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add an empty line before the background-color declarations.

Stylelint reports declaration-empty-line-before errors at Line 707 and Line 733. The rule triggers because a plain declaration follows the @apply at-rule without a blank line.

🎨 Proposed fix
   & code:not(pre code) {
     `@apply` px-1 py-0.5 rounded-sm text-text-bright font-mono;
+
     background-color: var(--muted);
   }
   & th {
     `@apply` font-semibold;
+
     background-color: var(--muted);
   }

Source: Linters/SAST tools

🟡 Minor comments (24)
.server-changes/dashboard-agent.md-6-6 (1)

6-6: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix the grammar in this published sentence.

The clause "everywhere that used to appear" has no subject. Add the pronoun. This text publishes verbatim as release notes.

📝 Proposed wording
-Meet the dashboard agent: a chat in every environment that answers questions about your runs, queues, errors and health with real data and links. It takes over from Ask AI everywhere that used to appear; on the Free plan you get 20 messages.
+Meet the dashboard agent: a chat in every environment that answers questions about your runs, queues, errors and health with real data and links. It takes over from Ask AI everywhere that used to appear; on the Free plan you get 20 messages.

Change "everywhere that used to appear" to "everywhere Ask AI used to appear".

Source: Learnings

internal-packages/dashboard-agent/src/tool-curation.ts-84-109 (1)

84-109: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

truncated reports true for a complete 60-span trace.

truncated is spans.length >= MAX_TRACE_SPANS. A trace with exactly 60 spans and no further children sets truncated: true although no span was dropped. The model then hedges on a complete trace. Set the flag only when a span is actually skipped.

🐛 Proposed fix
 const MAX_TRACE_SPANS = 60;
 export function curateTrace(data: unknown) {
   const root = (data as any)?.trace?.rootSpan;
   const spans: Array<Record<string, unknown>> = [];
+  let dropped = false;
   const walk = (span: any, depth: number) => {
-    if (!span || spans.length >= MAX_TRACE_SPANS) return;
+    if (!span) return;
+    if (spans.length >= MAX_TRACE_SPANS) {
+      dropped = true;
+      return;
+    }
     const d = span.data ?? {};
@@
   walk(root, 0);
   return {
     traceId: (data as any)?.trace?.traceId,
     spans,
-    truncated: spans.length >= MAX_TRACE_SPANS,
+    truncated: dropped,
   };
 }
apps/webapp/app/components/AskAI.tsx-1-5 (1)

1-5: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Update the deprecation note for live Ask AI mounts.

AskAIRoot is still mounted in apps/webapp/app/components/navigation/HelpAndFeedbackPopover.tsx, and AskAI is still mounted from apps/webapp/app/components/BlankStatePanels.tsx. The comment “nothing mounts this any more” is inaccurate, or the deprecated components/routes need to be removed.

.changeset/report-json-and-period-units.md-6-6 (1)

6-6: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Clarify the period statement; the examples do not show the stated minimum.

The sentence states that the shortest period is one minute. The examples are 30m, 1h, and 7d. None of them is one minute. Separate the minimum from the format examples.

📝 Proposed wording
-Reports can be fetched as structured data with the `json` format. The shortest report period is now one minute (`30m`, `1h`, `7d`).
+Reports can be fetched as structured data with the `json` format. Report periods now accept minute units, for example `30m`, `1h` or `7d`, with a one minute minimum.
apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.dashboard-agent.ts-223-235 (1)

223-235: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Resolve the environment before you create the chat row.

createChat runs at line 225. The environment lookup runs at line 234. If the environment does not resolve, the handler returns 404 and leaves an empty chat row behind. That row then appears in listChats with no session and no messages.

Move the environment lookup above createChat so no row is written when the request cannot proceed.

🐛 Proposed reorder
     const chatId = generateFriendlyId("chat");
     try {
+      // Membership-scoped: dev rows are per-developer, so a token must never be minted for
+      // someone else's environment — or, when nothing resolves, for no environment at all.
+      const runtimeEnv = await findEnvironmentBySlug(project.id, envParam, userId);
+      if (!runtimeEnv) return json({ error: "Environment not found" }, { status: 404 });
+
       await createChat(dashboardAgentDb, {
         id: chatId,
         organizationId: project.organizationId,
         userId,
         ...(clientData ? { metadata: { context: clientContext } } : {}),
       });
 
-      // Membership-scoped: dev rows are per-developer, so a token must never be minted for
-      // someone else's environment — or, when nothing resolves, for no environment at all.
-      const runtimeEnv = await findEnvironmentBySlug(project.id, envParam, userId);
-      if (!runtimeEnv) return json({ error: "Environment not found" }, { status: 404 });
       const environmentName = ENV_NAME_BY_TYPE[runtimeEnv.type];
apps/webapp/app/presenters/v3/reports/health/health-data.ts-301-306 (1)

301-306: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Tighten the "does not exist" pattern.

/\bTable\b[^.]*\bdoes\s?n?o?t?'?t?\s*exist/i makes every character of the negation optional, so it also matches "Table foo does exist". A false positive here classifies a real failure as unavailable, which the doc comment at lines 280-282 states must never happen. Match the two intended spellings explicitly.

🐛 Proposed fix
-  /\bTable\b[^.]*\bdoes\s?n?o?t?'?t?\s*exist/i,
+  /\bTable\b[^.]*\b(?:does\s+not|doesn'?t)\s+exist/i,
apps/webapp/app/services/dashboardAgentBodyCap.server.ts-34-39 (1)

34-39: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Destroy the request on the declared-oversize path too.

The streaming path tears the request down after the refusal reaches the wire (line 49). The content-length path returns immediately and leaves the request stream open and unread. The client can keep sending the whole oversize body, and nothing consumes or aborts it.

Apply the same teardown to both refusal paths.

🛡️ Proposed fix
 export function capRequestBody(req: Request, res: Response, limit: number): void {
   const declared = Number.parseInt(req.headers["content-length"] ?? "", 10);
   if (Number.isFinite(declared) && declared > limit) {
     refuse(res);
+    // Torn down only once the refusal is on the wire, or the client never reads it.
+    res.once("finish", () => req.destroy());
     return;
   }
apps/webapp/test/reportsApiRoute.test.ts-160-165 (1)

160-165: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

The format tests assert on a bare [ instead of the ESC constant. The file defines ESC at Line 19 as the ANSI CSI introducer, but both format assertions test for the [ character alone. A bare [ also appears in markdown link syntax and in bracketed values, so these assertions are imprecise in both directions.

  • apps/webapp/test/reportsApiRoute.test.ts#L160-L165: replace expect(await response.text()).toContain("[") with toContain(ESC).
  • apps/webapp/test/reportsApiRoute.test.ts#L156-L157: remove the expect(body).not.toContain("[") line; the preceding not.toContain(ESC) already proves the markdown render carries no escape sequence.
apps/webapp/test/apiAuthActorClaim.test.ts-94-108 (1)

94-108: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Three new tests assert against test-constructed values instead of production output. In each case the assertion input is built by the test rather than read from the code under test, so the test still passes if the delegated-token path regresses. Bind each assertion to the value the production code returns.

  • apps/webapp/test/apiAuthActorClaim.test.ts#L94-L108: build the ability from the scopes on the authentication result, not from forged.scopes, so a regression that merges act.scopes into the effective scopes fails the test.
  • apps/webapp/test/dashboardAgentDelegatedScopeCeiling.test.ts#L19-L42: pass result.claims from authenticateUserActor into clampUserActorScopes instead of the hand-built { userId, client, cap } object.
  • apps/webapp/test/userActorEnvironmentScopeRouteBuilder.test.ts#L172-L185: target the matching project and assert a 200 with the claimed environment, so only a real claim recovery satisfies the test.
apps/webapp/test/userActorTokenClaimsAndScopes.test.ts-89-109 (1)

89-109: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Reset ctx.omitClaims in an afterEach hook.

ctx.omitClaims is module-level mutable state. The test on line 100 sets it to true and resets it on line 107. If the awaited call on lines 103-105 rejects, line 107 never runs and the flag stays true. The four postgresTest cases below never set the flag, so they would then run against a controller that omits claims, and the failures would point away from the real cause.

💚 Suggested change
+import { afterEach, expect, it, vi } from "vitest";
+
+afterEach(() => {
+  ctx.omitClaims = false;
+});
+
 it("recovers the claim when the RBAC controller doesn't return it", async () => {
   ctx.omitClaims = true;

   const result = await authenticateApiRequestWithPersonalAccessToken(
     bearer(await token({ environmentId: "env_claimed" }))
   );

-  ctx.omitClaims = false;
   expect(result?.userActor?.environmentId).toBe("env_claimed");
 });

Merge the afterEach into the existing import on line 11.

apps/webapp/app/services/dashboardAgentEvalRetention.server.ts-43-55 (1)

43-55: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

No change needed for the retention sweep cadence.

The sweep runs every 5 minutes and drains the backlog over multiple runs; the 500-row cap is documented as part of a bounded per-run statement.

♻️ Preserve the original failure on the rethrow
-  } catch (error) {
-    result.failed++;
-    logger.error("Dashboard agent turn-eval retention failed", { error });
-  }
-
-  if (result.failed > 0) {
-    throw new Error("The dashboard agent turn-eval retention pass failed");
-  }
+  } catch (error) {
+    result.failed++;
+    logger.error("Dashboard agent turn-eval retention failed", { error });
+    throw new Error("The dashboard agent turn-eval retention pass failed", { cause: error });
+  }
internal-packages/dashboard-agent/src/dashboard-agent.eval.ts-1039-1045 (1)

1039-1045: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

The identityClaim regex rejects a correctly hedged answer.

The comment on Lines 1039-1040 states that naming the phrase in order to deny it is the hedge the test wants. The regex does not implement that. It matches the phrase wherever it appears, including inside a denial. An answer such as "I cannot confirm this is the exact deployed code" matches and fails the assertion, even though it is the behavior the case is checking for.

The negative lookahead cases that do pass, such as "is not necessarily the exact deployed code", pass by accident: the optional literal groups happen not to absorb the intervening words.

Since judgeClaim on Lines 1047-1054 already evaluates this claim in full, the regex adds a flake source without adding coverage. Consider removing the two not.toMatch assertions and keeping the judge verdict plus the snapshot|not provably|may differ check.

💚 Proposed fix
-        // The forbidden claim: asserting the source it read IS what ran. Match the assertion,
-        // not the words: naming the phrase in order to deny it is the hedge we want.
-        const identityClaim =
-          /(is|was|matches|reflects) (exactly )?(the )?(exact )?deployed code\b|is (exactly )?what (actually )?ran\b/i;
-        expect(answer).not.toMatch(identityClaim);
-        expect(card).not.toMatch(identityClaim);
+        // The hedge must be present. Whether the answer wrongly asserts identity is left to
+        // the judge below: a regex cannot tell an assertion from a denial of the same phrase.
         expect(`${answer}\n${card}`).toMatch(/snapshot|not provably|may differ/i);
apps/webapp/app/utils/cspImageOrigins.ts-104-108 (1)

104-108: 🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Match img-src case-insensitively.

CSP directive names are ASCII case-insensitive. The regex on Line 106 is case-sensitive, so an existing policy that spells the directive Img-Src or IMG-SRC is not detected. withImgSrc then appends a second img-src directive. A duplicate directive is ignored by the browser, so the route's directive still wins, but the emitted header is malformed and browsers log a warning.

The companion scanner in apps/webapp/test/routeCspImgSrc.test.ts (Line 53) already uses the i flag, so the two disagree today.

🔒️ Proposed fix
 export function withImgSrc(existing: string | null | undefined, directive: string): string {
   if (!existing) return directive;
-  if (/(^|;)\s*img-src\s/.test(existing)) return existing;
+  if (/(^|;)\s*img-src\s/i.test(existing)) return existing;
   return `${existing.replace(/;\s*$/, "")}; ${directive}`;
 }
internal-packages/dashboard-agent/src/agent-runtime.ts-324-340 (1)

324-340: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

isBadInput treats an array as a valid tool input.

The check is typeof input !== "object" || input === null. typeof [] === "object", so an array input passes as valid and is left in the replayed history. The Anthropic API rejects a non-object for tool_use.input, and an array fails the same way an empty string does. The turn then fails with the exact error this function exists to prevent.

An empty string and null are the common cases, so this is a narrow gap, but closing it is one predicate.

🛡️ Proposed fix
   const isBadInput = (part: unknown) =>
     typeof part === "object" &&
     part !== null &&
     (part as { type?: string }).type === "tool-call" &&
     (typeof (part as { input?: unknown }).input !== "object" ||
-      (part as { input?: unknown }).input === null);
+      (part as { input?: unknown }).input === null ||
+      Array.isArray((part as { input?: unknown }).input));
internal-packages/dashboard-agent-contracts/src/watch.ts-21-25 (1)

21-25: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reject an empty note.

note is documented as the reason shown to the user when the watch fires. z.string() accepts "", so a caller can create a watch whose fired card explains nothing. The schema already rejects a missing note; add a minimum length so it also rejects a blank one.

Consider trimming as well, so " " is rejected too.

🛡️ Proposed fix
 export const watchCommonSchema = z.object({
   maxHours: z.number().positive().max(WATCH_MAX_HOURS),
   /** Why this watch exists, in the user's terms. Shown when it fires. */
-  note: z.string(),
+  note: z.string().trim().min(1),
 });
internal-packages/dashboard-agent/src/tool-docs.ts-59-66 (1)

59-66: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

The separator length is not counted against DOCS_RESULT_MAX_CHARS.

used accumulates only entry.length. Line 66 joins the entries with "\n\n---\n\n", which adds 8 characters between each pair. With the maximum of 5 entries the returned string can exceed the cap by up to 32 characters.

The overshoot is negligible for token cost, but it breaks the invariant the test asserts. apps/webapp-style byte caps aside, tool-docs.test.ts Line 29 asserts formatted.length <= DOCS_RESULT_MAX_CHARS. That assertion holds today only because the byte cap never binds in that case. Once a case does bind the cap, the test can fail against correct-looking code.

Count the separator when the entry is not the first.

🐛 Proposed fix
+const RESULT_SEPARATOR = "\n\n---\n\n";
+
 export function formatDocsResults(parts: string[]): string {
   const rendered: string[] = [];
   let used = 0;
@@
     // Stop on the overall cap rather than truncating mid-excerpt: a half-quoted
     // sentence is worse than one fewer result.
-    if (used + entry.length > DOCS_RESULT_MAX_CHARS) break;
+    const cost = entry.length + (rendered.length > 0 ? RESULT_SEPARATOR.length : 0);
+    if (used + cost > DOCS_RESULT_MAX_CHARS) break;
     rendered.push(entry);
-    used += entry.length;
+    used += cost;
   }
 
-  return rendered.join("\n\n---\n\n");
+  return rendered.join(RESULT_SEPARATOR);
 }
internal-packages/dashboard-agent/src/tool-docs.test.ts-24-33 (1)

24-33: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

This test never exercises the DOCS_RESULT_MAX_CHARS break.

The case is named for the byte cap, but the count cap is what limits the output. formatDocsResults slices to MAX_DOC_RESULTS (5) first. Each of the 5 bodies is truncated to DOC_EXCERPT_MAX_CHARS (1200) plus the suffix and the three header lines, so the total is roughly 6.5k against a 7,000 cap. The if (used + entry.length > DOCS_RESULT_MAX_CHARS) break; branch on Line 61 of tool-docs.ts is never reached.

expect(formatted.split("\n---\n").length).toBeLessThanOrEqual(5) passes at exactly 5, which is what MAX_DOC_RESULTS guarantees on its own.

Add a case where the byte cap binds before the count cap, so a regression in the cap logic fails a test.

💚 Proposed additional case
   it("stays inside the cap however much the endpoint returns", () => {
     const parts = Array.from({ length: 12 }, (_, i) =>
       part({ title: `Result ${i}`, page: `page-${i}`, body: "x".repeat(9_000) })
     );
     const formatted = formatDocsResults(parts);
     expect(formatted.length).toBeLessThanOrEqual(DOCS_RESULT_MAX_CHARS);
     // A handful of results, each an excerpt rather than the whole section.
     expect(formatted.split("\n---\n").length).toBeLessThanOrEqual(5);
     expect(formatted).toContain("[excerpt — the rest is on the page]");
   });
+
+  it("stops on the byte cap before it runs out of results", () => {
+    // A long title pushes each entry over 1/5th of the cap, so the break fires
+    // before MAX_DOC_RESULTS does.
+    const parts = Array.from({ length: 5 }, (_, i) =>
+      part({ title: "T".repeat(1_500), page: `page-${i}`, body: "x".repeat(9_000) })
+    );
+    const formatted = formatDocsResults(parts);
+    expect(formatted.length).toBeLessThanOrEqual(DOCS_RESULT_MAX_CHARS);
+    expect(formatted.split("\n---\n").length).toBeLessThan(5);
+  });
internal-packages/dashboard-agent-contracts/src/watch.ts-245-265 (1)

245-265: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Derive the failed disposition list from TaskRunStatus.

WATCH_FAILED_RUN_STATUSES is a hardcoded copy of the Prisma enum’s terminal statuses. If the source enum adds a new terminal failure status, watchRunDisposition() silently returns "unknown", and resolveWatchResult() reports a failed watch result as neutral. Keep this list tied to the shared status type or generated from the schema so new statuses are caught at typecheck time.

internal-packages/dashboard-agent/src/dashboard-agent.eval.ts-499-519 (1)

499-519: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Classify exhausted AI SDK retries as provider failures.

When the AI SDK internal retries are exhausted, it can throw an AI_RetryError, but goldenCase only treats APICallError names as infrastructure. That path spends a behavior retry instead of retrying provider failure. Import the SDK retry error guard/instance check, or classify provider errors by their AI_ class/name family/status code, not only APICallError.

internal-packages/dashboard-agent/src/dashboard-agent.test.ts-104-119 (1)

104-119: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Wait for the second turn to settle before asserting the title count.

The other turn-completion tests in this file wait a tick, because setChatTitleIfDefault is written after the turn-complete chunk. This test asserts that the count is exactly 1 without waiting. If a second title write were queued, the assertion could run before that write lands, and the test would pass for the wrong reason.

💚 Proposed fix
     await harness.sendMessage(userMessage("first question"));
     await harness.sendMessage(userMessage("second question"));
+    // Give a second title write a chance to land, so the count is a real "once".
+    await new Promise((r) => setTimeout(r, 30));
 
     expect(calls.setChatTitleIfDefault).toHaveLength(1);
internal-packages/dashboard-agent-db/drizzle/meta/0002_snapshot.json-1-6 (1)

1-6: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Run the formatter to clear the failing code-quality job.

Both code-quality pipeline jobs fail with "formatting check failed. Run 'pnpm exec oxfmt .' to fix formatting." The failure carries no file or line, so it may originate in any file in this PR rather than in this generated snapshot.

Run pnpm exec oxfmt . and commit the result. If oxfmt reformats this drizzle-generated snapshot, exclude internal-packages/dashboard-agent-db/drizzle/meta/** from the formatter instead, so the next drizzle-kit generate does not reintroduce the diff.

Source: Pipeline failures

internal-packages/dashboard-agent-db/src/queries.ts-454-491 (1)

454-491: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

The doc comment overstates the idempotency guarantee under concurrency.

Lines 455-456 state that a repeat of the same id writes "nothing at all — not the row, not the position, not the chat's timestamps". That holds for the sequential redelivery the not exists guard catches, which is the case the test on lines 152-157 of apps/webapp/test/dashboardAgentTranscriptStore.test.ts covers.

It does not hold for the concurrent case the next paragraph relies on on conflict do nothing to settle. When two callers both pass the not exists check, the losing statement has already executed the reserved CTE: next_message_position is incremented and last_message_at and updated_at are set. Only the insert is discarded. The function correctly returns false, but a position is consumed and the chat timestamps move.

The consequences are benign — position only has to be unique and ordered, and gaps are expected. Narrow the comment so a later reader does not build on a guarantee the statement does not provide.

📝 Proposed comment fix
 /**
- * Append one message, exactly once. A repeat of the same id writes nothing at all — not
- * the row, not the position, not the chat's timestamps — and says so by returning false.
+ * Append one message, exactly once. A redelivery the `not exists` guard sees writes
+ * nothing at all — not the row, not the position, not the chat's timestamps — and says
+ * so by returning false.
  *
  * Reserve-and-insert is one statement so a concurrent append can neither take the same
  * position nor be lost, and `on conflict do nothing` is what settles the race two
- * callers that both saw the message missing would otherwise lose.
+ * callers that both saw the message missing would otherwise lose. That loser still
+ * spends its reserved position and bumps the chat's timestamps; only the row is
+ * discarded. Positions are unique and ordered, never contiguous, so the gap is inert.
  */
internal-packages/dashboard-agent-db/src/watch-queries.ts-443-460 (1)

443-460: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

spec.note is guarded in one mapper and not in the other.

Line 451 assigns note: row.spec.note directly into ActiveWatchSummary.note, which is declared string on line 398. toUnreadWatchWake reads the same field from the same column on line 609 and guards it: row.spec.note?.trim() || row.identity.

spec is a jsonb column with no database-level shape check, and PersistedWatchSpec is only a TypeScript view of it. A row written before note existed, or with a blank note, therefore reaches the wake banner as undefined through this path while the other path falls back to identity.

Apply the same fallback in both mappers.

🐛 Proposed fix
-      note: row.spec.note,
+      note: row.spec.note?.trim() || row.identity,
internal-packages/dashboard-agent-contracts/src/intent.ts-12-12 (1)

12-12: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Require a non-empty prompt for ask intents.

agentIntentSchema accepts { kind: "ask", prompt: "" }. The lenient variants in blocks.ts (chartActionIntentSchema, actionIntentSchema) both use z.string().min(1). investigationActionSchema validates with agentIntentSchema, so an executor-built button can carry an empty prompt and send an empty message on click. Align the constraint.

🛡️ Proposed fix
-  z.object({ kind: z.literal("ask"), prompt: z.string() }),
+  z.object({ kind: z.literal("ask"), prompt: z.string().min(1) }),

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a4f8f415-64ba-4b82-a190-87095e4c1724

📥 Commits

Reviewing files that changed from the base of the PR and between 0a44b88 and 798fdf9.

⛔ Files ignored due to path filters (3)
  • apps/webapp/test/__snapshots__/reportRenderParity.test.ts.snap is excluded by !**/*.snap
  • internal-packages/dashboard-agent/src/__snapshots__/prompt-prefix.test.ts.snap is excluded by !**/*.snap
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (189)
  • .changeset/report-json-and-period-units.md
  • .gitignore
  • .server-changes/dashboard-agent.md
  • apps/webapp/.gitignore
  • apps/webapp/app/components/AskAI.tsx
  • apps/webapp/app/components/dashboard-agent/message-limits.test.ts
  • apps/webapp/app/components/dashboard-agent/message-limits.ts
  • apps/webapp/app/components/dashboard-agent/resolve-uris.test.ts
  • apps/webapp/app/components/dashboard-agent/resolve-uris.ts
  • apps/webapp/app/components/metrics/MiniLineChart.tsx
  • apps/webapp/app/components/navigation/SideMenuItem.tsx
  • apps/webapp/app/components/primitives/AgentDotMatrix.tsx
  • apps/webapp/app/components/primitives/Buttons.tsx
  • apps/webapp/app/components/primitives/Popover.tsx
  • apps/webapp/app/components/primitives/Spinner.tsx
  • apps/webapp/app/components/primitives/TextLink.tsx
  • apps/webapp/app/components/primitives/Toast.tsx
  • apps/webapp/app/components/queues/queue-thresholds.ts
  • apps/webapp/app/components/runs/v3/agent/AgentMessageView.tsx
  • apps/webapp/app/entry.server.tsx
  • apps/webapp/app/env.server.ts
  • apps/webapp/app/hooks/useThemeMode.ts
  • apps/webapp/app/presenters/v3/reports/ReportPresenter.server.ts
  • apps/webapp/app/presenters/v3/reports/health/execution.ts
  • apps/webapp/app/presenters/v3/reports/health/flow.ts
  • apps/webapp/app/presenters/v3/reports/health/health-core.ts
  • apps/webapp/app/presenters/v3/reports/health/health-data.ts
  • apps/webapp/app/presenters/v3/reports/health/health-messages.ts
  • apps/webapp/app/presenters/v3/reports/health/health.ts
  • apps/webapp/app/presenters/v3/reports/health/liveness.ts
  • apps/webapp/app/presenters/v3/reports/renderMarkdown.ts
  • apps/webapp/app/presenters/v3/reports/report-layout.ts
  • apps/webapp/app/presenters/v3/reports/report-message-catalogs.ts
  • apps/webapp/app/presenters/v3/reports/report-messages.ts
  • apps/webapp/app/presenters/v3/reports/report-registry.ts
  • apps/webapp/app/presenters/v3/reports/report-view-model.ts
  • apps/webapp/app/presenters/v3/reports/reportsApi.server.ts
  • apps/webapp/app/presenters/v3/waitingRun/waitingRunDiagnosis.server.ts
  • apps/webapp/app/presenters/v3/waitingRun/waitingRunDiagnosis.ts
  • apps/webapp/app/root.tsx
  • apps/webapp/app/routes/_app.orgs.$organizationSlug.settings.private-connections._index/route.tsx
  • apps/webapp/app/routes/_app.orgs.$organizationSlug.settings.private-connections.new/route.tsx
  • apps/webapp/app/routes/account.tokens/route.tsx
  • apps/webapp/app/routes/api.v1.dashboard-agent.eval-policy.ts
  • apps/webapp/app/routes/api.v1.projects.$projectRef.$env.jwt.ts
  • apps/webapp/app/routes/api.v1.projects.$projectRef.$env.repo.snapshot.ts
  • apps/webapp/app/routes/api.v1.projects.$projectRef.$env.runs.$runId.commit.ts
  • apps/webapp/app/routes/api.v1.projects.$projectRef.$env.runs.$runId.waiting.ts
  • apps/webapp/app/routes/api.v1.projects.$projectRef.$env.workers.$tagName.ts
  • apps/webapp/app/routes/api.v1.projects.$projectRef.environments.ts
  • apps/webapp/app/routes/api.v1.projects.$projectRef.runs.ts
  • apps/webapp/app/routes/api.v1.query.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.metrics.ts
  • apps/webapp/app/routes/api.v1.reports.$key.ts
  • apps/webapp/app/routes/projects.$projectRef.ai-help.ts
  • apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.dashboard-agent.in.$.ts
  • apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.dashboard-agent.ts
  • apps/webapp/app/routes/storybook.ai-agent/route.tsx
  • apps/webapp/app/routes/storybook.buttons/route.tsx
  • apps/webapp/app/services/apiAuth.server.ts
  • apps/webapp/app/services/dashboardAgent.server.ts
  • apps/webapp/app/services/dashboardAgentBodyCap.server.ts
  • apps/webapp/app/services/dashboardAgentEvalPolicy.server.ts
  • apps/webapp/app/services/dashboardAgentEvalRetention.server.ts
  • apps/webapp/app/services/dashboardAgentHeadStart.server.ts
  • apps/webapp/app/services/dashboardAgentInvestigationSweep.server.ts
  • apps/webapp/app/services/personalAccessToken.server.ts
  • apps/webapp/app/services/queryService.server.ts
  • apps/webapp/app/services/resolveTriggerUri.server.ts
  • apps/webapp/app/services/routeBuilders/apiBuilder.server.ts
  • apps/webapp/app/services/tenantContext.server.ts
  • apps/webapp/app/services/uatRoutePreamble.server.ts
  • apps/webapp/app/services/userActorEnvironment.server.ts
  • apps/webapp/app/tailwind.css
  • apps/webapp/app/utils/boundedRequestBody.server.test.ts
  • apps/webapp/app/utils/boundedRequestBody.server.ts
  • apps/webapp/app/utils/cspImageOrigins.test.ts
  • apps/webapp/app/utils/cspImageOrigins.ts
  • apps/webapp/app/v3/canAccessDashboardAgent.server.ts
  • apps/webapp/app/v3/commonWorker.server.ts
  • apps/webapp/app/v3/featureFlags.ts
  • apps/webapp/app/v3/queryScope.ts
  • apps/webapp/app/v3/services/alerts/deliverAlert.server.ts
  • apps/webapp/package.json
  • apps/webapp/seed-queue-metrics.mts
  • apps/webapp/server.ts
  • apps/webapp/test/apiAuthActorClaim.test.ts
  • apps/webapp/test/dashboardAgentBodyCap.test.ts
  • apps/webapp/test/dashboardAgentClientMetadata.test.ts
  • apps/webapp/test/dashboardAgentDelegatedScopeCeiling.test.ts
  • apps/webapp/test/dashboardAgentEvalPolicyAuth.test.ts
  • apps/webapp/test/dashboardAgentEvalRetention.test.ts
  • apps/webapp/test/dashboardAgentHeadStart.test.ts
  • apps/webapp/test/dashboardAgentImageCsp.test.ts
  • apps/webapp/test/dashboardAgentInvestigationSweep.test.ts
  • apps/webapp/test/dashboardAgentLegacyMessagesColumn.test.ts
  • apps/webapp/test/dashboardAgentRoutes.test.ts
  • apps/webapp/test/dashboardAgentTranscriptStore.test.ts
  • apps/webapp/test/envJwtActorClaim.test.ts
  • apps/webapp/test/queryScope.test.ts
  • apps/webapp/test/rbacFallbackBranch.test.ts
  • apps/webapp/test/reportHealth.test.ts
  • apps/webapp/test/reportHealthData.test.ts
  • apps/webapp/test/reportPresenter.test.ts
  • apps/webapp/test/reportsApiRoute.test.ts
  • apps/webapp/test/resolveTriggerUri.test.ts
  • apps/webapp/test/routeCspImgSrc.test.ts
  • apps/webapp/test/tenantContextFromAuthEnvironment.test.ts
  • apps/webapp/test/uatEnvironmentClaim.test.ts
  • apps/webapp/test/userActorEnvironmentScopeRouteBuilder.test.ts
  • apps/webapp/test/userActorProjectWideScope.test.ts
  • apps/webapp/test/userActorTokenClaimsAndScopes.test.ts
  • apps/webapp/test/waitingRunDiagnosis.test.ts
  • apps/webapp/vite.config.ts
  • apps/webapp/vitest.config.ts
  • docs/self-hosting/env/webapp.mdx
  • internal-packages/dashboard-agent-contracts/package.json
  • internal-packages/dashboard-agent-contracts/src/blocks.test.ts
  • internal-packages/dashboard-agent-contracts/src/blocks.ts
  • internal-packages/dashboard-agent-contracts/src/contracts.test.ts
  • internal-packages/dashboard-agent-contracts/src/evidence.ts
  • internal-packages/dashboard-agent-contracts/src/index.ts
  • internal-packages/dashboard-agent-contracts/src/intent.ts
  • internal-packages/dashboard-agent-contracts/src/page-context.ts
  • internal-packages/dashboard-agent-contracts/src/run-filters.ts
  • internal-packages/dashboard-agent-contracts/src/suggested-prompts.ts
  • internal-packages/dashboard-agent-contracts/src/trigger-uri.test.ts
  • internal-packages/dashboard-agent-contracts/src/trigger-uri.ts
  • internal-packages/dashboard-agent-contracts/src/watch.test.ts
  • internal-packages/dashboard-agent-contracts/src/watch.ts
  • internal-packages/dashboard-agent-contracts/tsconfig.json
  • internal-packages/dashboard-agent-contracts/vitest.config.ts
  • internal-packages/dashboard-agent-db/README.md
  • internal-packages/dashboard-agent-db/drizzle/0002_watches_and_chat_messages.sql
  • internal-packages/dashboard-agent-db/drizzle/meta/0002_snapshot.json
  • internal-packages/dashboard-agent-db/drizzle/meta/_journal.json
  • internal-packages/dashboard-agent-db/package.json
  • internal-packages/dashboard-agent-db/src/ids.ts
  • internal-packages/dashboard-agent-db/src/index.ts
  • internal-packages/dashboard-agent-db/src/internal.ts
  • internal-packages/dashboard-agent-db/src/queries.ts
  • internal-packages/dashboard-agent-db/src/schema-base.ts
  • internal-packages/dashboard-agent-db/src/schema.ts
  • internal-packages/dashboard-agent-db/src/watch-queries.ts
  • internal-packages/dashboard-agent-db/src/watch-schema.ts
  • internal-packages/dashboard-agent/README.md
  • internal-packages/dashboard-agent/package.json
  • internal-packages/dashboard-agent/src/agent-runtime.ts
  • internal-packages/dashboard-agent/src/cache-breakpoint.test.ts
  • internal-packages/dashboard-agent/src/compaction.test.ts
  • internal-packages/dashboard-agent/src/compaction.ts
  • internal-packages/dashboard-agent/src/dashboard-agent.eval.ts
  • internal-packages/dashboard-agent/src/dashboard-agent.test.ts
  • internal-packages/dashboard-agent/src/dashboard-agent.ts
  • internal-packages/dashboard-agent/src/eval-error-category.test.ts
  • internal-packages/dashboard-agent/src/eval-policy.ts
  • internal-packages/dashboard-agent/src/eval-redaction.test.ts
  • internal-packages/dashboard-agent/src/eval-turn.ts
  • internal-packages/dashboard-agent/src/index.ts
  • internal-packages/dashboard-agent/src/prompt-prefix.test.ts
  • internal-packages/dashboard-agent/src/prompt-prefix.ts
  • internal-packages/dashboard-agent/src/repo-tools.test.ts
  • internal-packages/dashboard-agent/src/repo-tools.ts
  • internal-packages/dashboard-agent/src/step-cache.test.ts
  • internal-packages/dashboard-agent/src/step-cache.ts
  • internal-packages/dashboard-agent/src/test-support.ts
  • internal-packages/dashboard-agent/src/tool-api-client.ts
  • internal-packages/dashboard-agent/src/tool-api.ts
  • internal-packages/dashboard-agent/src/tool-context.ts
  • internal-packages/dashboard-agent/src/tool-curation.ts
  • internal-packages/dashboard-agent/src/tool-docs.test.ts
  • internal-packages/dashboard-agent/src/tool-docs.ts
  • internal-packages/dashboard-agent/src/tool-evidence.ts
  • internal-packages/dashboard-agent/src/tool-investigations.ts
  • internal-packages/dashboard-agent/src/tool-navigation.ts
  • internal-packages/dashboard-agent/src/tool-schemas.ts
  • internal-packages/dashboard-agent/src/tool-source-ledger.ts
  • internal-packages/dashboard-agent/src/tools.ts
  • internal-packages/dashboard-agent/vitest.eval.config.ts
  • internal-packages/rbac/src/fallback.ts
  • internal-packages/tsql/src/read-only.test.ts
  • packages/cli-v3/src/apiClient.ts
  • packages/cli-v3/src/mcp/prompts.test.ts
  • packages/cli-v3/src/mcp/prompts.ts
  • packages/cli-v3/src/mcp/schemas.ts
  • packages/core/src/v3/apiClient/index.ts
  • packages/core/src/v3/schemas/index.ts
  • packages/core/src/v3/schemas/reports.ts
  • packages/plugins/src/rbac.ts
💤 Files with no reviewable changes (1)
  • apps/webapp/app/presenters/v3/reports/report-message-catalogs.ts
🚧 Files skipped from review as they are similar to previous changes (29)
  • internal-packages/dashboard-agent/vitest.eval.config.ts
  • internal-packages/dashboard-agent-db/src/index.ts
  • apps/webapp/app/routes/api.v1.projects.$projectRef.$env.runs.$runId.commit.ts
  • apps/webapp/app/routes/account.tokens/route.tsx
  • internal-packages/dashboard-agent-db/src/ids.ts
  • internal-packages/dashboard-agent-contracts/tsconfig.json
  • apps/webapp/vitest.config.ts
  • apps/webapp/app/routes/api.v1.projects.$projectRef.$env.workers.$tagName.ts
  • apps/webapp/test/dashboardAgentHeadStart.test.ts
  • internal-packages/dashboard-agent-contracts/src/index.ts
  • apps/webapp/app/components/runs/v3/agent/AgentMessageView.tsx
  • internal-packages/dashboard-agent-contracts/src/suggested-prompts.ts
  • apps/webapp/app/routes/_app.orgs.$organizationSlug.settings.private-connections.new/route.tsx
  • apps/webapp/.gitignore
  • apps/webapp/app/routes/api.v1.queues.$queueParam.metrics.ts
  • apps/webapp/test/waitingRunDiagnosis.test.ts
  • apps/webapp/test/dashboardAgentRoutes.test.ts
  • internal-packages/dashboard-agent-db/package.json
  • apps/webapp/app/v3/featureFlags.ts
  • internal-packages/dashboard-agent/package.json
  • internal-packages/dashboard-agent-contracts/package.json
  • internal-packages/dashboard-agent-contracts/vitest.config.ts
  • apps/webapp/app/routes/api.v1.projects.$projectRef.$env.runs.$runId.waiting.ts
  • apps/webapp/app/presenters/v3/waitingRun/waitingRunDiagnosis.ts
  • apps/webapp/app/services/uatRoutePreamble.server.ts
  • internal-packages/dashboard-agent-contracts/src/trigger-uri.ts
  • apps/webapp/app/components/metrics/MiniLineChart.tsx
  • apps/webapp/seed-queue-metrics.mts
  • internal-packages/dashboard-agent/src/tool-schemas.ts

Comment thread apps/webapp/app/services/userActorEnvironment.server.ts Outdated
Comment thread apps/webapp/app/v3/commonWorker.server.ts
Comment on lines +39 to +42
/** A public access token is environment-bound; every other bearer credential isn't. */
export function queryScopeCeilingFor(authenticationType: string): QueryScopeCeiling {
return authenticationType === "PUBLIC_JWT" ? "environment" : "unbounded";
}

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.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Locate the authentication type union and every caller of queryScopeCeilingFor.
set -uo pipefail

rg -nP --type=ts -C 4 '\bqueryScopeCeilingFor\s*\('

rg -nP --type=ts -C 6 '"PUBLIC_JWT"' -g '!**/*.test.ts'

rg -nP --type=ts -C 4 'type\s+\w*Authentication\w*\s*='

Repository: triggerdotdev/trigger.dev

Length of output: 163


🏁 Script executed:

#!/bin/bash
set -uo pipefail

echo "Tracked files matching queryScope.ts:"
git ls-files | rg 'apps/webapp/app/v3/queryScope\.ts$|queryScope'

echo
echo "Search helper (including all files, excluding test files for caller context):"
rg -n -C 4 'queryScopeCeilingFor' || true

echo
echo "Search PUBLIC_JWT (excluding tests):"
rg -n -C 6 '"PUBLIC_JWT"|PUBLIC_JWT' --glob '!**/*.test.ts' --glob '!**/*.spec.ts' || true

echo
echo "Search authentication type declarations:"
rg -n -C 4 'Authentication|authentication' --type ts --type tsx | head -n 240 || true

Repository: triggerdotdev/trigger.dev

Length of output: 349


🏁 Script executed:

#!/bin/bash
set -eo pipefail

echo "Tracked files matching queryScope.ts:"
git ls-files | rg 'apps/webapp/app/v3/queryScope\.ts$|queryScope' || true

echo
echo "Helper contents:"
cat -n apps/webapp/app/v3/queryScope.ts || true

echo
echo "Tests mentioning queryScopeCeilingFor or queryScope:"
rg -n -C 5 'queryScopeCeilingFor|queryScope|PUBLIC_JWT' apps/webapp/test --glob '*.ts' --glob '*.tsx' || true

echo
echo "Repo-wide caller search:"
rg -n -C 5 'queryScopeCeilingFor' apps/webapp packages core 2>/dev/null || true

echo
echo "Repo-wide PUBLIC_JWT search (excluding tests):"
rg -n -C 6 'PUBLIC_JWT|PUBLIC-JWT' --glob '!**/*.test.ts' --glob '!**/*.spec.ts' . || true

echo
echo "Potential authenticator/authentication type declarations (TS files only):"
rg -n -C 5 'Authentication|authenticationType|accessTokenType|Auth\s*=\s*{|\{\s*"PUBLIC_JWT"|type "PUBLIC_JWT"|AuthenticationType\??:' --type ts --type tsx . | head -n 300 || true

Repository: triggerdotdev/trigger.dev

Length of output: 22074


🏁 Script executed:

#!/bin/bash
set -eo pipefail

echo "api v1 query route relevant section:"
cat -n apps/webapp/app/routes/api.v1.query.ts | sed -n '1,90p'

echo
echo "apiAuth relevant type declaration and helper:"
cat -n apps/webapp/app/services/apiAuth.server.ts | sed -n '60,80p;370,410p'

Repository: triggerdotdev/trigger.dev

Length of output: 6674


Reuse the API authentication type union for queryScopeCeilingFor.

authentication.type is "PUBLIC" | "PRIVATE" | "PUBLIC_JWT", but this helper accepts string and returns "unbounded" for anything that is not exactly "PUBLIC_JJWT". Rename the union to one shared constant or import the exact union; this keeps the public query credential as the only environment-bound token and adds a compile-time error if "PUBLIC_JWT" is renamed.

Comment thread internal-packages/dashboard-agent-db/drizzle/0002_watches_and_chat_messages.sql Outdated
Comment thread internal-packages/dashboard-agent-db/src/queries.ts
Comment on lines +1907 to +1924
it("render_view commits the chart when its query runs, validating it once", async () => {
const fetchStub = stubFetch((url, init) => {
if (url.endsWith("/jwt")) return { body: { token: "jwt_1" } };
// The validation runs the same window the panel will render.
expect(JSON.parse(String(init?.body))).toMatchObject({
scope: "environment",
period: "24h",
});
return { body: { results: [{ bucket: "2026-01-01T00:00:00Z", runs: 1 }] } };
});
try {
// The rows aren't embedded in the block — the panel stays the runner.
await expect(renderView(ENV_CTX, CHART_SPEC)).resolves.toEqual({ blocks: CHART_SPEC.blocks });
expect(queryRequests(fetchStub.requests)).toHaveLength(1);
} finally {
fetchStub.restore();
}
});

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Move the request-body assertion out of the fetch stub.

The expect at Line 1911 runs inside the respond callback, so a failure throws from inside globalThis.fetch. The test at Line 1926 proves render_view tolerates a thrown fetch and still commits the chart. A wrong request body would therefore make the stub throw, the tool would swallow it, and the assertion at Line 1919 would still pass. The test would report success while the validation request was never checked.

Record the body in the stub and assert it after the call.

💚 Proposed fix
   it("render_view commits the chart when its query runs, validating it once", async () => {
+    const bodies: unknown[] = [];
     const fetchStub = stubFetch((url, init) => {
       if (url.endsWith("/jwt")) return { body: { token: "jwt_1" } };
-      // The validation runs the same window the panel will render.
-      expect(JSON.parse(String(init?.body))).toMatchObject({
-        scope: "environment",
-        period: "24h",
-      });
+      bodies.push(JSON.parse(String(init?.body)));
       return { body: { results: [{ bucket: "2026-01-01T00:00:00Z", runs: 1 }] } };
     });
     try {
       // The rows aren't embedded in the block — the panel stays the runner.
       await expect(renderView(ENV_CTX, CHART_SPEC)).resolves.toEqual({ blocks: CHART_SPEC.blocks });
       expect(queryRequests(fetchStub.requests)).toHaveLength(1);
+      // The validation runs the same window the panel will render.
+      expect(bodies).toEqual([expect.objectContaining({ scope: "environment", period: "24h" })]);
     } finally {
       fetchStub.restore();
     }
   });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("render_view commits the chart when its query runs, validating it once", async () => {
const fetchStub = stubFetch((url, init) => {
if (url.endsWith("/jwt")) return { body: { token: "jwt_1" } };
// The validation runs the same window the panel will render.
expect(JSON.parse(String(init?.body))).toMatchObject({
scope: "environment",
period: "24h",
});
return { body: { results: [{ bucket: "2026-01-01T00:00:00Z", runs: 1 }] } };
});
try {
// The rows aren't embedded in the block — the panel stays the runner.
await expect(renderView(ENV_CTX, CHART_SPEC)).resolves.toEqual({ blocks: CHART_SPEC.blocks });
expect(queryRequests(fetchStub.requests)).toHaveLength(1);
} finally {
fetchStub.restore();
}
});
it("render_view commits the chart when its query runs, validating it once", async () => {
const bodies: unknown[] = [];
const fetchStub = stubFetch((url, init) => {
if (url.endsWith("/jwt")) return { body: { token: "jwt_1" } };
bodies.push(JSON.parse(String(init?.body)));
return { body: { results: [{ bucket: "2026-01-01T00:00:00Z", runs: 1 }] } };
});
try {
// The rows aren't embedded in the block — the panel stays the runner.
await expect(renderView(ENV_CTX, CHART_SPEC)).resolves.toEqual({ blocks: CHART_SPEC.blocks });
expect(queryRequests(fetchStub.requests)).toHaveLength(1);
// The validation runs the same window the panel will render.
expect(bodies).toEqual([expect.objectContaining({ scope: "environment", period: "24h" })]);
} finally {
fetchStub.restore();
}
});

Comment thread internal-packages/dashboard-agent/src/eval-policy.ts
Comment thread internal-packages/dashboard-agent/src/tool-api.ts
Comment thread internal-packages/dashboard-agent/src/tool-api.ts Outdated
Comment on lines +143 to +220
for (const block of blocks) {
if (block.type !== "investigation") {
rendered.push(block);
continue;
}

// Canonical URIs are built before anything is stored or emitted, and a citation
// that can't be canonicalized fails the call by name.
let canonicalized: ReturnType<typeof canonicalizeInvestigationState>;
try {
canonicalized = canonicalizeInvestigationState(
(block as InvestigationBlockBodyInput).investigation,
{ projectRef, environmentId: ctx.environmentId },
reads
);
} catch (error) {
return {
error: `Couldn't cite that evidence: ${
error instanceof Error ? error.message : "a citation was malformed"
}. Fix or remove those citations and render again.`,
};
}
if (canonicalized.errors.length > 0) {
return {
error: `Couldn't cite some of that evidence: ${canonicalized.errors.join(
"; "
)}. Fix or remove those citations and render again.`,
};
}
const state = canonicalized.state;

// A storage failure's message can carry the full SQL text, which must never reach
// the transcript.
let result: Awaited<ReturnType<InvestigationsCapability["upsert"]>>;
try {
result = await ctx.investigations.upsert({
id: currentInvestigationId ?? continueId,
projectRef,
environmentRef: ctx.environmentId,
state,
});
} catch (error) {
console.error("investigation upsert failed", error);
return {
error:
"Couldn't save the investigation right now. Say what you found in prose, honestly — if a card is already open it will be closed as inconclusive when the turn ends.",
};
}

if (!result.ok) {
// Nothing was written, so no card can be rendered.
return {
error:
result.error === "context_mismatch"
? "That investigation belongs to a different chat, project, or environment, so it can't be updated here."
: "That investigation no longer exists. Render again without an investigationId to start a new one.",
};
}

currentInvestigationId = result.id;
investigationId = result.id;
revision = result.revision;

const capabilities = investigationCapabilities(state, reads);

const parsed = investigationBlockSchema.safeParse({
...block,
investigation: state,
...(capabilities ? { capabilities } : {}),
id: result.id,
revision: result.revision,
version: VIEW_BLOCK_VERSION,
});
if (!parsed.success) {
return { error: "Couldn't render that investigation: the card payload didn't validate." };
}
rendered.push(parsed.data);
}

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.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect the render_view schema for a limit on investigation blocks.
rg -n -C15 'renderViewSchema' internal-packages/dashboard-agent/src/tool-schemas.ts
# Inspect the view block union and any max-length constraint on blocks.
rg -n -C10 'investigationBlockSchema|viewBlockSchema|blocks' internal-packages/dashboard-agent-contracts/src/blocks.ts

Repository: triggerdotdev/trigger.dev

Length of output: 7288


🏁 Script executed:

#!/bin/bash
# Inspect the exact schema shape for blocks and inspect the renderer's currentInvestigationId loop behavior.
sed -n '110,225p' internal-packages/dashboard-agent/src/tool-investigations.ts | cat -n
sed -n '294,306p' internal-packages/dashboard-agent/src/tool-schemas.ts | cat -n
sed -n '584,591p' internal-packages/dashboard-agent-contracts/src/blocks.ts | cat -n

Repository: triggerdotdev/trigger.dev

Length of output: 7204


Reject or separate multiple investigation blocks in one render.

renderViewSchema allows blocks as z.array(viewBlockInputSchema).min(1) without a max(1), and the renderer loops over every type === "investigation" block. After one block creates currentInvestigationId, subsequent investigation blocks reuse it and update the same record, erasing the earlier block’s state while still returning multiple cards. Return an error for more than one investigation block, or create a separate record for each.

… the mid-flight one

A turn stores its messages before the model finishes, so the completed bodies arrived against ids that already existed and were skipped. Reopening a chat then replayed a tool call that never ends.

@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 5 new potential issues.

Open in Devin Review

Comment on lines +525 to +536
function metricDelta(metric: LayoutMetricInput): LayoutDelta | undefined {
const delta = metric.delta;
if (delta && delta.mult !== undefined && delta.mult > 1 && delta.dir !== "flat") {
return {
text: `${delta.dir === "up" ? REPORT_GLYPH.up : REPORT_GLYPH.down} ${delta.mult}×`,
dir: delta.dir,
};
}
return metric.normal === undefined
? undefined
: { text: `${REPORT_GLYPH.flat} flat`, dir: "flat" };
}

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.

🟡 A metric that has collapsed well below normal is reported as unchanged

A measurement that fell below its baseline is labelled unchanged ({ text: "→ flat" } at apps/webapp/app/presenters/v3/reports/report-layout.ts:534-535) whenever the drop is large enough, so a report can say a number is steady while it has actually fallen away.

Impact: A reader of the health report sees "flat" next to a figure that has dropped by a factor of two or more.

A downward multiplier always rounds to 0 or 1, so it never clears the `> 1` gate

delta() (apps/webapp/app/presenters/v3/reports/report-view-model.ts:41-47) sets dir: "down" and mult: Math.round(value / normal), which for any value below 1.5 × normal is 0 or 1. metricDelta only emits an arrow when delta.mult > 1, so every down delta falls through to the normal !== undefined branch and renders → flat — including a metric that dropped from 100 to 5 (mult === 0).

The previous renderer handled this explicitly: deltaSegment returned the bare arrow for a down delta precisely because "a drop rounds to 0×/1×, meaningless — the arrow already says below normal". That case is now lost.

A fix is to keep the arrow-only rendering for dir === "down" rather than folding it into the flat branch.

Prompt for agents
In apps/webapp/app/presenters/v3/reports/report-layout.ts, `metricDelta` only renders a direction arrow when `delta.mult > 1`. Because `delta()` in report-view-model.ts computes `mult = Math.round(value / normal)`, a metric that is BELOW its baseline always has `mult` of 0 or 1, so every downward movement — including a collapse to 5% of normal — renders as `→ flat`. The pre-refactor renderer (`deltaSegment` in renderMarkdown.ts) deliberately rendered a bare `↓` for `dir === "down"` for exactly this reason. Restore a distinct rendering for a downward delta (arrow only, or an inverted multiplier such as `↓ 20×` computed from normal/value) so a real drop is not reported as unchanged, and update the affected snapshots.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +253 to +257
/** True when an output is a tool failure: unfolded (`isError`) or a plain `error` field. */
export function evalOutputErrored(output: unknown): boolean {
if (output === null || typeof output !== "object" || Array.isArray(output)) return false;
return (output as { isError?: unknown }).isError === true || "error" in output;
}

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.

🟡 Successful data lookups are recorded as tool failures in the quality-eval data

A perfectly successful lookup is treated as a failed one ("error" in output at internal-packages/dashboard-agent/src/eval-policy.ts:256) whenever its result merely mentions an error field with nothing in it, so the stored quality records say the assistant's tools broke when they didn't.

Impact: The judged-turn rows and the judge's own input claim a tool failure on turns where nothing failed, skewing the quality data.

`curateRun`/`curateDeploy` always emit an `error` key, set to `undefined` on success

curateRun returns error: run.error ? { name, message } : undefined (internal-packages/dashboard-agent/src/tool-curation.ts:50), and curateDeploy does the same. The key is therefore present on the returned object even for a run that completed. evalOutputErrored tests "error" in output, which is true for a present-but-undefined key, so:

  • extractToolActivityredactEvalToolValueannotateEvalErrorCategory stamps errorCategory: "unknown" onto the redacted result the judge sees, and JUDGE_SYSTEM tells the judge that an errorCategory marks a failed tool call.
  • evalTurn computes toolError = payload.toolActivity.some((t) => toolResultErrored(t.output)) (internal-packages/dashboard-agent/src/eval-turn.ts:179), so tool_error is written true on the chat_turn_evals row for any turn that called get_run on a healthy run.

(The toolError mis-classification pre-dates this PR; the new errorCategory annotation now propagates it into the judge prompt as well.) Checking for a non-undefined value — (output as any).error != null — rather than key presence fixes both.

Suggested change
/** True when an output is a tool failure: unfolded (`isError`) or a plain `error` field. */
export function evalOutputErrored(output: unknown): boolean {
if (output === null || typeof output !== "object" || Array.isArray(output)) return false;
return (output as { isError?: unknown }).isError === true || "error" in output;
}
/** True when an output is a tool failure: unfolded (`isError`) or a populated `error` field. */
export function evalOutputErrored(output: unknown): boolean {
if (output === null || typeof output !== "object" || Array.isArray(output)) return false;
const record = output as { isError?: unknown; error?: unknown };
// A curated result carries `error: undefined` on success, so key presence is not a failure.
return record.isError === true || ("error" in record && record.error != null);
}
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread apps/webapp/app/components/AskAI.tsx
Comment thread apps/webapp/app/services/dashboardAgentBodyCap.server.ts
Comment thread internal-packages/dashboard-agent/src/dashboard-agent.ts
…New chat

The gate counted transcript length, and a warm first turn arrives with the model's opening step already in it — so the very first exchange looked like a later one.

@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 3 new potential issues.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment on lines +270 to +277
const range = capRead(lines.slice(from - 1, to).join("\n"));
return {
path,
content: range.content,
startLine: from,
endLine: to,
...(range.truncated ? { truncated: true, notice: READ_TRUNCATION_NOTICE } : {}),
};

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.

🟡 A partly-shown source file is reported as if the whole requested range were returned

A requested line range that gets shortened to fit the size cap is still labelled with the originally requested end line (endLine: to at internal-packages/dashboard-agent/src/repo-tools.ts:275), so the caller is told it received lines it never got.

Impact: The agent can cite a line number that isn't in the text it actually read, so a code citation on an investigation card can point at the wrong place.

Why the reported range and the returned content disagree

capRead is applied after the slice, so range.content may contain far fewer lines than lines.slice(from - 1, to). The response still returns startLine: from, endLine: to verbatim. A caller asking for lines 1–4000 of a large file gets ~1500 lines back but is told the payload spans 1–4000. The unranged branch below it (repo-tools.ts:280-285) has no such claim, so only the range path is affected. The fix is to derive the reported endLine from the number of lines actually in range.content.

Suggested change
const range = capRead(lines.slice(from - 1, to).join("\n"));
return {
path,
content: range.content,
startLine: from,
endLine: to,
...(range.truncated ? { truncated: true, notice: READ_TRUNCATION_NOTICE } : {}),
};
const range = capRead(lines.slice(from - 1, to).join("\n"));
return {
path,
content: range.content,
startLine: from,
endLine: range.truncated ? from + range.content.split("\n").length - 1 : to,
...(range.truncated ? { truncated: true, notice: READ_TRUNCATION_NOTICE } : {}),
};
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +232 to +236
// Membership-scoped: dev rows are per-developer, so a token must never be minted for
// someone else's environment — or, when nothing resolves, for no environment at all.
const runtimeEnv = await findEnvironmentBySlug(project.id, envParam, userId);
if (!runtimeEnv) return json({ error: "Environment not found" }, { status: 404 });
const environmentName = ENV_NAME_BY_TYPE[runtimeEnv.type];

@devin-ai-integration devin-ai-integration Bot Aug 7, 2026

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.

🟡 A failed chat start still leaves an empty conversation in the user's history

The conversation row is written (createChat at apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.dashboard-agent.ts:225-230) before the environment it belongs to is looked up, so when that lookup fails the empty conversation stays behind.

Impact: Users can accumulate blank "New chat" entries in their history that were never actually started.

Ordering in the `create` intent

Inside the try block the sequence is createChat(...)findEnvironmentBySlug(...)if (!runtimeEnv) return json({ error: "Environment not found" }, { status: 404 }). There is no compensating delete, and listChats selects every non-deleted chat, so the orphan is visible. Resolving the environment before creating the chat (or soft-deleting on the failure path) removes the window.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines 273 to +275
},
// No plugin → permissive, matching the fallback's PAT behaviour.
ability: permissiveAbility,
// A delegated token is a downgrade of the user: never the blanket ability a PAT gets here.
ability: buildJwtAbility(claims.cap ?? CAPLESS_USER_ACTOR_SCOPES),

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.

🔍 Capless user-actor tokens lose their blanket ability on self-hosted — check every existing UAT mint site

The self-hosted RBAC fallback previously returned permissiveAbility for any verified user-actor token; it now builds the ability from claims.cap, defaulting a capless token to ["read:all"]. That is the right hardening for the dashboard agent (which always sets a cap), but every other UAT flow that mints without a cap silently becomes read-only on OSS. signUserActorToken is exported from @trigger.dev/plugins, and the comment in userActorEnvironment.server.ts notes "MCP and the CLI may use their existing ones." If any of those tokens are used for a write (triggering a task, minting a write-scoped env JWT), that call now 403s on self-hosted where it previously succeeded. Worth confirming no capless UAT is on a write path before merging.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

…finalise only this turn's messages

Review of #4418: the cloud path builds the ability from the user's role, so a read-only delegated token could exchange it for a write JWT; and the finalisable set was the whole replayed transcript rather than what the turn produced.

@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 4 new potential issues.

View 1 additional finding in Devin Review.

Open in Devin Review

Comment on lines +202 to +211
// Metrics are informational unless this is true. Stale, absent and unmeasurable all read false.
trustworthy: !telemetryStale && telemetry !== "none" && !flowUnmeasured,
telemetry,
untrustworthyReason: telemetryStale
? "telemetry_stale"
: telemetry === "none"
? "telemetry_absent"
: flowUnmeasured
? "flow_unmeasured"
: undefined,

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.

🟡 Healthy environments are labelled "stale data" in the health report

A report is marked untrustworthy (trustworthy: !telemetryStale && telemetry !== "none" && !flowUnmeasured at apps/webapp/app/presenters/v3/reports/health/health.ts:203) whenever there is simply no telemetry signal or the queue depth couldn't be measured, and every surface then shows the "stale data" flag and a note claiming the telemetry is stale.

Impact: Environments whose data is merely absent or unmeasurable — including every environment still on the fallback data path — are told their report is based on stale telemetry, which is not what happened.

How "absent" and "unmeasurable" get relabelled as "stale"

reportIsTrustworthy in apps/webapp/app/presenters/v3/reports/report-layout.ts:93 treats facts.trustworthy === false as one thing only — its own doc comment says "means the telemetry behind the verdict is stale" — and buildReportLayout therefore emits trust: { badge: REPORT_LABELS.staleBadge, note: REPORT_LABELS.staleNote } (report-layout.ts:351-353). The labels are "stale data" and "The telemetry behind this report is stale, so the numbers below are informational only." (report-layout.ts:55-57).

But assessHealth now sets trustworthy false for three distinct states, and only one of them is staleness:

  • telemetryStale — genuinely stale.
  • telemetry === "none"liveness.telemetryAgeMs === null, i.e. no signal at all. The surrounding comment even says such an env "stays neutral for the reader".
  • flowUnmeasured — the queue depth was a placeholder.

The untrustworthyReason discriminator written alongside it (health.ts:205-211) is never read by the layout, so all three collapse into the stale wording.

This is not a rare path. SnapshotFlowSource now returns telemetryLastTs: null unconditionally (apps/webapp/app/presenters/v3/reports/health/health-data.ts:523, previously freshestTs(ctx.liveScalar.last_activity)), so every report served from the snapshot fallback — any environment where env_metrics isn't populated yet — resolves to telemetry: "none" and renders with the stale-data flag, even when the verdict itself is green.

The existing coverage doesn't catch it: apps/webapp/test/reportHealth.test.ts asserts the no-signal case renders and not 🟡, but never asserts the absence of the 🚩 stale data badge.

Prompt for agents
`assessHealth` in apps/webapp/app/presenters/v3/reports/health/health.ts sets `facts.trustworthy` to false for three different states — telemetry stale, telemetry absent (`telemetry === "none"`), and flow unmeasured — and records which one in `facts.untrustworthyReason`. However `reportIsTrustworthy` / `buildReportLayout` in apps/webapp/app/presenters/v3/reports/report-layout.ts only look at `trustworthy` and unconditionally render `REPORT_LABELS.staleBadge` ("stale data") and `REPORT_LABELS.staleNote` ("The telemetry behind this report is stale…"), so an environment with no telemetry signal or an unmeasurable queue depth is told its data is stale.

This is the common case rather than an edge case: SnapshotFlowSource now always returns `telemetryLastTs: null` (health-data.ts), so every report served from the snapshot fallback resolves to `telemetry: "none"` and carries the stale flag even when the verdict is green.

Possible approaches: have the layout read `facts.untrustworthyReason` and choose badge/note wording per reason (stale vs. no telemetry vs. depth unmeasurable), or narrow `reportIsTrustworthy` so only genuine staleness produces the trust block and give the other two states their own, accurate caveat. Add a test asserting a no-signal healthy env does not render the stale badge.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread internal-packages/dashboard-agent/src/dashboard-agent.ts
Comment thread apps/webapp/app/presenters/v3/reports/health/health-data.ts
…s its metrics

The dashboard agent asks for a queue's live row — paused, depth, limit — through the environment JWT it exchanges for. The metrics route has accepted that JWT all along; the retrieve route answered 401, so the agent saw no queue at all.

@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.

🧹 Nitpick comments (1)
apps/webapp/test/queueRetrieveJwt.test.ts (1)

13-25: 🔒 Security & Privacy | 🔵 Trivial | 🏗️ Heavy lift

Add a behavior-level authentication test.

These assertions only search for literal source text. They can pass even if createLoaderApiRoute ignores allowJWT or the queues authorization check fails at runtime. The authentication path in apps/webapp/app/services/apiAuth.server.ts, Lines [137-203], is not exercised. Use the existing route/authentication harness to send an environment JWT and assert the queue response and authorization scope.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 881a64c9-f1c8-4bd0-891e-6fb528d45648

📥 Commits

Reviewing files that changed from the base of the PR and between 711b79e and c236601.

📒 Files selected for processing (2)
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
  • apps/webapp/test/queueRetrieveJwt.test.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (12)
**/*.{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 import(); use dynamic imports only for unresolvable circular dependencies, genuine performance code splitting, or conditional runtime loading.
Import Trigger.dev tasks from @trigger.dev/sdk; never use @trigger.dev/sdk/v3 or deprecated client.defineJob.
Add agentcrumbs while writing code using approved namespaces; mark lines with // @Crumbs or blocks with `// `#region` `@crumbs, and strip them before merging.

Files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.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/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
**/*.{ts,tsx,js,jsx}

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

Use function declarations instead of default exports

Files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
**/*.{test,spec}.{ts,tsx}

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

Use vitest for all tests in the Trigger.dev repository

**/*.{test,spec}.{ts,tsx}: Use Vitest exclusively and never mock dependencies; use Testcontainers for integration dependencies.
Place test files next to the source files they test.

Files:

  • apps/webapp/test/queueRetrieveJwt.test.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/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.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

Do not reintroduce the removed v1 execution path; RunEngineVersion.V1 branches may only reject or finalize gracefully so v3 clients receive a clean 4xx, never a 5xx.

Files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
apps/webapp/**/*.test.{ts,tsx}

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

Do not import env.server.ts directly or indirectly into test files; instead pass environment-dependent values through options/parameters to make code testable

Files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
apps/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

For apps, use typecheck for verification and never use build as the correctness check.

Files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
apps/webapp/**/*.{test,spec}.{ts,tsx}

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

Test files must not import app/env.server.ts; pass configuration as options instead.

Files:

  • apps/webapp/test/queueRetrieveJwt.test.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/routes/api.v1.queues.$queueParam.ts
apps/webapp/app/routes/**/*.ts

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

apps/webapp/app/routes/**/*.ts: Use Remix flat-file route conventions with dot-separated segments; for example, api.v1.tasks.$taskId.trigger.ts maps to /api/v1/tasks/:taskId/trigger.
PAT-authenticated API routes must resolve their target organization or project within the caller's membership scope, using a membership filter or a helper such as findProjectByRef or resolveOrganizationForApiUser; RBAC authorization alone is insufficient.

Files:

  • apps/webapp/app/routes/api.v1.queues.$queueParam.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/routes/api.v1.queues.$queueParam.ts
🧠 Learnings (17)
📚 Learning: 2026-03-22T13:26:12.060Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3244
File: apps/webapp/app/components/code/TextEditor.tsx:81-86
Timestamp: 2026-03-22T13:26:12.060Z
Learning: In the triggerdotdev/trigger.dev codebase, do not flag `navigator.clipboard.writeText(...)` calls for `missing-await`/`unhandled-promise` issues. These clipboard writes are intentionally invoked without `await` and without `catch` handlers across the project; keep that behavior consistent when reviewing TypeScript/TSX files (e.g., usages like in `apps/webapp/app/components/code/TextEditor.tsx`).

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
📚 Learning: 2026-03-22T19:24:14.403Z
Learnt from: matt-aitken
Repo: triggerdotdev/trigger.dev PR: 3187
File: apps/webapp/app/v3/services/alerts/deliverErrorGroupAlert.server.ts:200-204
Timestamp: 2026-03-22T19:24:14.403Z
Learning: In the triggerdotdev/trigger.dev codebase, webhook URLs are not expected to contain embedded credentials/secrets (e.g., fields like `ProjectAlertWebhookProperties` should only hold credential-free webhook endpoints). During code review, if you see logging or inclusion of raw webhook URLs in error messages, do not automatically treat it as a credential-leak/secrets-in-logs issue by default—first verify the URL does not contain embedded credentials (for example, no username/password in the URL, no obvious secret/token query params or fragments). If the URL is credential-free per this project’s conventions, allow the logging.

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
📚 Learning: 2026-05-18T08:21:27.694Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3632
File: apps/webapp/sentry.server.ts:4-21
Timestamp: 2026-05-18T08:21:27.694Z
Learning: When handling Prisma error P1001 ("Can't reach database server") in TypeScript, don’t assume a single error shape. Prisma can surface P1001 via two different error classes/fields: `PrismaClientKnownRequestError` exposes it as `err.code === "P1001"` (common during mid-query connection drops), while `PrismaClientInitializationError` exposes it as `err.errorCode === "P1001"` (common on client startup failure). Therefore, predicates should use `err.code === "P1001" || err.errorCode === "P1001"`. Do not flag `err.code === "P1001"` as “unreachable/never matches,” as it is expected in production.

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
📚 Learning: 2026-05-18T08:21:27.694Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3632
File: apps/webapp/sentry.server.ts:4-21
Timestamp: 2026-05-18T08:21:27.694Z
Learning: When handling Prisma errors for P1001 ("Can't reach database server"), do not assume it only appears under a single property name. Prisma may surface P1001 via either `PrismaClientKnownRequestError` (`err.code === "P1001"`, e.g., mid-query connection drops) or `PrismaClientInitializationError` (`err.errorCode === "P1001"`, e.g., client startup connection failure). To reliably detect the condition, check `err.code === "P1001" || err.errorCode === "P1001"`, and avoid review rules that would incorrectly flag `err.code === "P1001"` as unreachable/never-matching.

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
📚 Learning: 2026-06-13T19:53:13.759Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3937
File: packages/trigger-sdk/skills/realtime-and-frontend/SKILL.md:258-260
Timestamp: 2026-06-13T19:53:13.759Z
Learning: When reviewing code that uses `trigger.dev/react-hooks`’s `useRealtimeRun`, preserve the call signature where the first argument is the full realtime handle object (not `handle.id`). This is intentional to maintain type-safety and is consistent with the official docs; do not suggest changing the first argument from the handle object to `handle.id`.

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
📚 Learning: 2026-06-17T17:13:49.929Z
Learnt from: matt-aitken
Repo: triggerdotdev/trigger.dev PR: 3948
File: apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.bulk-actions.$bulkActionParam/route.tsx:48-62
Timestamp: 2026-06-17T17:13:49.929Z
Learning: In triggerdotdev/trigger.dev, within `dashboardLoader`/`dashboardAction` (or similar context resolver code) whenever you resolve an organization ID from an organization slug for RBAC/enterprise authorization scope, always read from the primary Prisma client (`prisma`), not `$replica`. Using `$replica` can hit replica-lag and cause the RBAC lookup/authorization to run without the correct org scope (bypassing intended role enforcement). Implement the slug→org lookup with `prisma.organization.findFirst(...)` (or equivalent primary-client query) and add an inline comment documenting why the primary client is required (replica lag could lead to unscoped RBAC checks).

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
📚 Learning: 2026-06-23T13:04:21.413Z
Learnt from: carderne
Repo: triggerdotdev/trigger.dev PR: 4023
File: apps/webapp/app/services/upsertBranch.server.ts:14-18
Timestamp: 2026-06-23T13:04:21.413Z
Learning: In TypeScript, it’s valid to `import { type X }` and then use `typeof X` in a type-only position, e.g. `type Alias = z.infer<typeof X>`. The `type` modifier suppresses the runtime import, but the type checker still has the full exported type so `z.infer<typeof X>` can resolve correctly. In code reviews, don’t flag this as a TypeScript compile error as long as `typeof X` is used in a type context (e.g., with `z.infer`, `type` aliases, generics), not as a runtime value.

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
📚 Learning: 2026-05-07T12:25:18.271Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3531
File: apps/webapp/test/sentryTraceContext.server.test.ts:9-47
Timestamp: 2026-05-07T12:25:18.271Z
Learning: In the triggerdotdev/trigger.dev webapp test suite, it is acceptable to leave `createInMemoryTracing()` calls that register a global `NodeTracerProvider` without `afterEach`/`afterAll` teardown. Do not flag this as a test-ordering risk when the code follows the established pattern used across webapp tests (e.g., replication service/benchmark/backfiller tests). This is considered safe because `trace.getActiveSpan()` when called outside a `context.with(...)` block reads `AsyncLocalStorage.getStore()` (undefined when no `run()` scope exists), so it falls back to `ROOT_CONTEXT` with no attached span—regardless of which provider is registered.

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
📚 Learning: 2026-05-28T20:02:10.647Z
Learnt from: myftija
Repo: triggerdotdev/trigger.dev PR: 3772
File: apps/webapp/test/findOrCreateBackgroundWorker.test.ts:1-1
Timestamp: 2026-05-28T20:02:10.647Z
Learning: In the triggerdotdev/trigger.dev monorepo, for the `apps/webapp` package use the established convention of storing Vitest tests (unit, integration, and e2e) under `apps/webapp/test/` rather than colocating them next to source files. Do not flag files located in `apps/webapp/test/` as violating any rule that says to colocate tests with source.

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
📚 Learning: 2026-07-30T18:43:56.874Z
Learnt from: 0ski
Repo: triggerdotdev/trigger.dev PR: 4426
File: apps/webapp/test/memberDevEnvironments.server.test.ts:124-125
Timestamp: 2026-07-30T18:43:56.874Z
Learning: In the `apps/webapp` test suite (`apps/webapp/test/**`), respect the established test harness in `apps/webapp/test/setup.ts`: it loads `.env` and provides default values for required environment variables so that transitive imports (e.g., `~/env.server`) work without production-style wiring.

During code review, do not require dependency injection/refactoring solely to avoid this existing import path. Only introduce configuration injection if it delivers production-level value (for example, a more general `createEnvironment` abstraction that improves runtime behavior beyond test setup).

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
📚 Learning: 2026-05-12T21:04:05.815Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3542
File: apps/webapp/app/components/sessions/v1/SessionStatus.tsx:1-3
Timestamp: 2026-05-12T21:04:05.815Z
Learning: In this Remix + TypeScript codebase, do not flag a server/client boundary violation when a file imports only types from a module matching `*.server`.

Specifically, it’s safe to import types using `import type { Foo } from "*.server"` or `import { type Foo } from "*.server"` because TypeScript erases type-only imports at compile time and they emit no JavaScript, so they won’t cross the Remix server/client bundle boundary.

Only raise the boundary concern for value imports (e.g., `import { Foo }` without `type`, or `import Foo`), since those produce JavaScript output.

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
📚 Learning: 2026-06-25T18:21:51.905Z
Learnt from: carderne
Repo: triggerdotdev/trigger.dev PR: 4039
File: apps/webapp/app/routes/invite-revoke.tsx:0-0
Timestamp: 2026-06-25T18:21:51.905Z
Learning: During the Zod v4 migration in the triggerdotdev/trigger.dev webapp, ensure any imports from `conform-to/zod` use the Zod-4 subpath: `conform-to/zod/v4` (e.g., `import { parseWithZod } from "conform-to/zod/v4"`). Do not import from the package root `conform-to/zod`, because it is the Zod 3 implementation and may load Zod-3-only symbols (e.g., `ZodBranded`, `ZodEffects`), which can throw at module load (notably with `zod4.4.3`). This should be enforced across `apps/webapp/**/*` where helpers like `parseWithZod` and `conformZodMessage` are used.

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
📚 Learning: 2026-07-03T17:10:21.498Z
Learnt from: 0ski
Repo: triggerdotdev/trigger.dev PR: 4148
File: apps/webapp/app/models/orgMember.server.ts:149-168
Timestamp: 2026-07-03T17:10:21.498Z
Learning: In triggerdotdev/trigger.dev, `User.email` (Prisma schema: `internal-packages/database/prisma/schema.prisma`) currently does NOT use `citext` and does NOT have a `lower(email)` functional unique index. Therefore, do not introduce Prisma queries like `where: { email: { equals: <value>, mode: "insensitive" } }` (or any case-insensitive lookup) against `User.email`, because it can force sequential scans of the `users` table under load. During review, ensure email is normalized (e.g., lowercased/trimmed) before both writes and subsequent lookups, and if true case-insensitive behavior/uniqueness is required, implement it via a separate app-wide migration (e.g., switch to `citext` and/or add a functional unique index with backfill) rather than bolting it onto individual feature PRs.

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
📚 Learning: 2026-05-18T14:40:02.173Z
Learnt from: ericallam
Repo: triggerdotdev/trigger.dev PR: 3658
File: packages/core/src/v3/realtimeStreams/manager.test.ts:1-147
Timestamp: 2026-05-18T14:40:02.173Z
Learning: In the triggerdotdev/trigger.dev repo, the policy “Never mock anything — use testcontainers instead” should only be enforced for integration tests that interact with real external services (e.g., Redis, Postgres) via actual infrastructure. For unit tests that exercise pure in-memory logic (e.g., cache semantics) it is OK to stub collaborators such as `ApiClient` using Vitest (`vi.fn()`) to assert call counts or control behavior. Do not flag `vi.fn()`-based `ApiClient` stubs in unit tests as violations of the testcontainers policy.

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
📚 Learning: 2026-06-04T18:16:35.386Z
Learnt from: nicktrn
Repo: triggerdotdev/trigger.dev PR: 3836
File: apps/supervisor/src/backpressure/backpressureMonitor.ts:3-5
Timestamp: 2026-06-04T18:16:35.386Z
Learning: When reviewing TypeScript in this repo, apply the rule “prefer type aliases over interfaces” only to data/object shapes and union/intersection type modeling. If an interface is being used as a behavioral contract for collaborators to implement (e.g., method-shape interfaces that define required behavior, such as `BackpressureLogger` / `BackpressureSignalSource` in `apps/supervisor/src/backpressure/backpressureMonitor.ts`), keep it as an `interface` and do not flag it as a type-alias-vs-interface violation.

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
📚 Learning: 2026-06-09T17:58:04.699Z
Learnt from: 0ski
Repo: triggerdotdev/trigger.dev PR: 3879
File: apps/webapp/app/models/vercelIntegration.server.ts:619-630
Timestamp: 2026-06-09T17:58:04.699Z
Learning: In this codebase, outbound raw `fetch` calls should typically rely on Node/undici’s default request timeout (about ~300s) rather than adding a per-call `AbortController` + `setTimeout` wrapper inside individual functions (e.g. in files like `apps/webapp/app/models/vercelIntegration.server.ts`). During code review, do not flag the absence of a per-call timeout on a single `fetch` as an issue; if per-call timeouts are needed, they should be implemented via a codebase-wide convention (e.g., a shared fetch wrapper or documented pattern) rather than ad-hoc per-function changes.

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.ts
📚 Learning: 2026-06-16T09:19:47.637Z
Learnt from: d-cs
Repo: triggerdotdev/trigger.dev PR: 3960
File: apps/webapp/test/prismaInfrastructureErrorCapture.test.ts:0-0
Timestamp: 2026-06-16T09:19:47.637Z
Learning: In this repo’s Vitest setup, `vitest.config.ts` uses `globals: true`, so identifiers like `vi`, `describe`, `it`, and `expect` are available as globals in Vitest test files. During code review, do not flag missing `vi`/`describe`/`it`/`expect` imports as a runtime error or correctness issue when they’re used in `*.test.ts/tsx` or `*.spec.ts/tsx` files. Explicit imports are still preferred for consistency, but they’re not required for runtime behavior.

Applied to files:

  • apps/webapp/test/queueRetrieveJwt.test.ts
🔇 Additional comments (2)
apps/webapp/app/routes/api.v1.queues.$queueParam.ts (1)

17-19: LGTM!

apps/webapp/test/queueRetrieveJwt.test.ts (1)

10-14: 🩺 Stability & Availability

Check whether the relative file paths need cwd adjustment.

readFileSync resolves these paths from process.cwd(), and webapp tests can be run with pnpm test:webapp from the repository root. If Vitest later runs from inside apps/webapp, these reads will fail unless the paths are resolved from the test file or an absolute repo root.

@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 3 new potential issues.

View 1 additional finding in Devin Review.

Open in Devin Review

Comment on lines +8 to +13
export const BASE_IMG_SRC_SOURCES = [
"'self'",
"data:",
"blob:",
"https://avatars.githubusercontent.com",
] as const;

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.

🟡 Profile photos disappear for people who signed in with Google

The dashboard now tells the browser it may only load images from its own site, inline data and the GitHub avatar host (buildImgSrcDirective at apps/webapp/app/utils/cspImageOrigins.ts:96-98), so the Google-hosted profile photos stored for people who signed in with Google are blocked and show as broken.

Impact: Anyone who signed in with Google sees their avatar (and their teammates' avatars) vanish across the dashboard on a fresh deploy, unless a self-hoster happens to add the host by hand.

How the Google avatar host gets excluded from the new document policy

apps/webapp/app/services/googleAuth.server.ts is a supported auth provider, and apps/webapp/app/models/user.server.ts:108-110 stores authenticationProfile.photos[0].value as avatarUrl. For Google that value is on lh3.googleusercontent.com.

Before this PR no Content-Security-Policy: img-src was emitted at all, so those URLs loaded. apps/webapp/app/entry.server.tsx:94-97 now sets the directive on every document response, and BASE_IMG_SRC_SOURCES only contains 'self', data:, blob: and https://avatars.githubusercontent.com. apps/webapp/test/dashboardAgentImageCsp.test.ts even asserts expect(directive).not.toContain("googleusercontent.com"), so the omission is locked in by a test rather than an oversight that CI would catch.

Cloud deployments would need CSP_IMG_SRC_ALLOWLIST set to restore them; self-hosters using Google SSO get no warning that avatars have stopped loading.

Prompt for agents
The new document `img-src` allowlist in apps/webapp/app/utils/cspImageOrigins.ts (BASE_IMG_SRC_SOURCES) only permits 'self', data:, blob: and https://avatars.githubusercontent.com. The webapp also supports Google sign-in (apps/webapp/app/services/googleAuth.server.ts), and apps/webapp/app/models/user.server.ts persists the provider's photo URL verbatim into User.avatarUrl — for Google that is an https://lh3.googleusercontent.com URL. Since entry.server.tsx now sets this directive on every document response (previously no img-src existed), those avatars will be blocked by the browser and render broken for every Google-authenticated user and anywhere teammates' avatars are shown (members list, deployments list, bulk actions, env vars).

Decide whether the Google avatar host should join the base allowlist alongside the GitHub one, or whether avatars should be proxied through the app's own origin so no third-party host is needed. Note that apps/webapp/test/dashboardAgentImageCsp.test.ts currently asserts the directive does NOT contain googleusercontent.com, so that assertion needs revisiting too.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +520 to +523
// No cause-tree evidence; interpret falls back to v1 symptoms.
evidence: EMPTY_EVIDENCE,
// This path has no pipeline heartbeat, and run activity is not one.
telemetryLastTs: null,

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.

🔍 Snapshot path no longer reports run activity as telemetry freshness

SnapshotFlowSource now returns telemetryLastTs: null unconditionally, where it previously returned freshestTs(ctx.liveScalar.last_activity). That is a deliberate semantic change (run activity is not a pipeline heartbeat, and the new test asserts it), but it has a knock-on effect worth being explicit about: on the snapshot path liveness is now always freshness_unknown, which makes facts.trustworthy always false there (assessHealth sets trustworthy: !telemetryStale && telemetry !== "none" && !flowUnmeasured).

So every environment still on the snapshot fallback — i.e. any env whose env_metrics pipeline hasn't populated yet — now serves a report flagged untrustworthy, which the new report layout renders with a ⚑ stale data badge and the "informational only" caveat. That may read as alarming for a brand-new environment that is simply young. Worth confirming this is the intended reader experience for the rollout period.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread apps/webapp/app/services/userActorEnvironment.server.ts

@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 2 new potential issues.

View 1 additional finding in Devin Review.

Open in Devin Review

"cadence_minutes" integer GENERATED ALWAYS AS (((spec ->> 'checkEveryMinutes')::int)) STORED
);
--> statement-breakpoint
ALTER TABLE "trigger_dashboard_agent"."chats" DROP COLUMN IF EXISTS "messages";

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.

🔴 Existing agent conversations lose their entire message history

The stored conversation text is deleted (DROP COLUMN IF EXISTS "messages" at internal-packages/dashboard-agent-db/drizzle/0002_watches_and_chat_messages.sql:89) without first copying it into the new per-message table, so every conversation that already exists comes back empty.

Impact: Anyone who had already used the assistant sees their past conversations listed but with nothing in them, permanently.

Why the transcript is unrecoverable after this migration

Migrations 0000/0001 created trigger_dashboard_agent.chats.messages (a JSONB array holding the whole transcript — see the pre-PR README description). Migration 0002 creates chat_messages and then drops chats.messages with no INSERT INTO chat_messages … SELECT … FROM chats backfill, and sets chats.next_message_position to the default 1 as though every chat were empty.

After deploy, getChatMessages (internal-packages/dashboard-agent-db/src/queries.ts) reads only chat_messages, so it returns [] for every pre-existing chat while listChats still lists the row. The drop is irreversible once applied.

Either add a backfill step that expands the old JSONB array into chat_messages (assigning position by array index and setting next_message_position accordingly), or defer the DROP COLUMN to a later migration.

Prompt for agents
Migration 0002 drops trigger_dashboard_agent.chats.messages (the JSONB transcript created by migrations 0000/0001) in the same migration that introduces the new chat_messages table, with no backfill. After it runs, getChatMessages() reads chat_messages only, so every conversation created before the migration renders as empty, and the original data is gone.

Decide whether pre-existing chats must survive. If they must, add a backfill before the DROP: expand each chats.messages array element into a chat_messages row keyed by (chat_id, message_id) with position = array index + 1 and role read from the message payload, then set chats.next_message_position to the resulting count + 1, and only then drop the column. If they need not survive (feature never deployed anywhere), say so explicitly in the migration and in the dashboard-agent-db README so the deletion is a recorded decision rather than an oversight.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines 44 to 49
const environments = await $replica.runtimeEnvironment.findMany({
where: {
projectId: project.id,
...(scope.scoped ? { id: scope.environmentId } : {}),
// Only base/parent environments. Branch children (preview branches)
// are excluded — syncs target the parent and branches override elsewhere.

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.

🔍 A delegated token minted for a preview-branch environment lists nothing

resolveUserActorEnvironmentScope narrows the query to id: scope.environmentId, but the existing filter keeps parentEnvironmentId: null. A dashboard-agent token minted for a preview branch child (which the in proxy will happily mint, since findEnvironmentBySlug accepts PREVIEW) therefore matches neither clause and the endpoint returns [] rather than the environment the caller is scoped to. Worth confirming whether preview branches are meant to reach this route at all.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

… root

The queue-JWT test read its route sources through repo-root-relative paths, so it
never resolved from the webapp's own working directory.
The scope ceiling rewrite landed here and was reverted two PRs up, leaving the
stack asserting both directions. The exchange intersects requested scopes with the
token's cap again, a capless token passes through like a PAT, and the route keeps
only the environment claim check and the acting client.
The test mocked the old preamble, so the route hit real rbac and a logger without
`info`, failing with a 403 and an uncaught type error.

@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 5 new potential issues.

View 1 additional finding in Devin Review.

Open in Devin Review

Comment on lines +112 to +120
type DataViewPart = { type: string; data?: { blocks?: unknown[] } };

function viewBlocks(message: UIMessage): unknown[] {
const parts = (message.parts ?? []) as DataViewPart[];
return parts.flatMap((part) =>
part.type === "data-view" && Array.isArray(part.data?.blocks) ? part.data!.blocks! : []
);
}

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.

🔴 Long chats can end up with a duplicate investigation card for the same question

When a long conversation is shortened, the code that preserves an unfinished investigation looks for the wrong kind of transcript entry (part.type === "data-view" at internal-packages/dashboard-agent/src/compaction.ts:117), so it never finds one and the investigation's identity is dropped.

Impact: After a long conversation is summarised, the agent loses the id of the investigation it is working on and opens a second card for the same question instead of updating the first.

Where the two readers disagree on the stored part shape

Every investigation card is written into the transcript as a tool-result part: investigationSettlementMessage builds { type: "tool-render_view", state: "output-available", output: { blocks: [...] } } (internal-packages/dashboard-agent-db/src/queries.ts:788-796), and the agent's own reader cardsInMessage matches exactly that (internal-packages/dashboard-agent/src/agent-runtime.ts:210-214, typed.type !== "tool-render_view" || !Array.isArray(typed.output?.blocks)). The webapp's winning-revision logic in apps/webapp/test/dashboard-agent.test.ts:320-323 matches the same shape.

compaction.ts's viewBlocks instead matches part.type === "data-view" and reads part.data.blocks. Nothing in this PR ever emits that shape, so collectDurableState returns { investigations: [] } for every real transcript, describeDurableState returns undefined, and both buildCompactedModelMessages and withDurableState become no-ops. The only reason compaction.test.ts passes is that its investigationMessage fixture hand-builds a data-view part rather than the shape the store writes.

The consequence is precisely the failure the module documents at the top of the file: the model loses the investigationId across the summary boundary and opens a SECOND card for the same question.

Suggested change
type DataViewPart = { type: string; data?: { blocks?: unknown[] } };
function viewBlocks(message: UIMessage): unknown[] {
const parts = (message.parts ?? []) as DataViewPart[];
return parts.flatMap((part) =>
part.type === "data-view" && Array.isArray(part.data?.blocks) ? part.data!.blocks! : []
);
}
type ViewToolPart = { type: string; output?: { blocks?: unknown[] } };
function viewBlocks(message: UIMessage): unknown[] {
const parts = (message.parts ?? []) as ViewToolPart[];
return parts.flatMap((part) =>
part.type === "tool-render_view" && Array.isArray(part.output?.blocks)
? part.output!.blocks!
: []
);
}
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +118 to +123
bucketIntervalMs: bucketSeconds * 1000,
// Oldest first; buckets with no sample are omitted, so gaps carry the previous depth.
depthTrend: (trendRows ?? [])
.slice()
.sort((a, b) => a.bucket.localeCompare(b.bucket))
.map((row) => row.depth),

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.

🔍 depthTrend omits empty buckets while advertising a fixed bucket interval

The response pairs bucketIntervalMs with a depthTrend array built by sorting and mapping only the rows ClickHouse returned. A bucket with no sample is dropped rather than carry-forward filled, so any consumer that reconstructs timestamps as from + i * bucketIntervalMs (which is exactly what MiniLineChart's bucketStartMs/bucketIntervalMs props do) will misplace every point after the first gap. readClickhouseSignals in waitingRunDiagnosis.server.ts:138-146 does carry-forward fill for the same data, so the two readers of depthSparklines disagree. Worth aligning before the UI PR consumes this endpoint.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +99 to +102
const requested = target.requestedEnvironmentSlugs;
if (requested && (requested.length !== 1 || requested[0] !== environment.slug)) {
throw forbiddenEnvironment(`This token is scoped to the "${environment.slug}" environment.`);
}

@devin-ai-integration devin-ai-integration Bot Aug 7, 2026

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.

🔍 Environment-scoped run listing refuses the public "staging" alias

resolveUserActorEnvironmentScope compares requestedEnvironmentSlugs against the raw RuntimeEnvironment.slug, which is stg for staging. Elsewhere the API deliberately accepts the public alias and maps it (resolveEnvironmentForAuthentication does if (slug === "staging") slug = "stg"). So an environment-scoped delegated token calling /projects/:ref/runs?filter[env]=staging against its own staging environment gets a 403 rather than its own runs. Only reachable for a token minted for a staging environment, but the mismatch is real.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +320 to +325
if (period) sp.append("period", period);
// Double-encoded: a task queue's ClickHouse name carries a `task/` prefix, and
// the route un-escapes `%2F` back to `/` itself.
const result = await envApiGet(
`/api/v1/queues/${encodeURIComponent(queue)}/metrics?${sp.toString()}`
);

@devin-ai-integration devin-ai-integration Bot Aug 7, 2026

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.

🔍 get_queue comment claims double-encoding that the code doesn't do

The comment says the queue name is "double-encoded" because the route un-escapes %2F back to /, but the call only does a single encodeURIComponent(queue). For a plain task id that's fine (the route adds the task/ prefix itself), but for type: "custom" with a name containing / the single encoding produces %2F, which the route's .replace(/%2F/g, "/") turns back into a path separator — so the comment and the code disagree about which layer owns the escaping. Worth a second look with a custom queue name that contains a slash.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +423 to +425
const totals = totalsRows[0];
// Zero means measured none; no rows means unmeasured.
const dlqDelta = totals !== undefined ? Math.round(num(totals.dlq_total)) : null;

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.

🔍 queueTotalsQuery returning a NULL-sum row is read as a measured zero

sum(dlq) over an empty subquery still returns one row, with NULL. totals !== undefined is therefore true and num(totals.dlq_total) coerces to 0, so dlqDelta becomes a measured none and the report can emit the "nothing dead-lettered" observation for an environment where dead-letter volume was never measured. The same applies to total_queued, which then suppresses worst-queue attribution rather than reporting it as unmeasured. This is pre-existing behaviour carried over from dlqTotalQuery, but the new comment ("Zero means measured none; no rows means unmeasured") states a guarantee the query shape doesn't provide.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

… nothing

assertUserActorScope returned early whenever the passed scope carried no
org, project or environment, and the route builder passes {} for any route
that declares no context — so the guard was a no-op there. api.v1.orgs's
action is such a route and has no authorization block either, letting a
read-only agent token create an organization.

Fail closed instead, with an explicit identityOnly opt-in for the two
contextless loaders that answer with the caller's own identity, and give
org creation the gate its siblings have.
list_environments, get_run, get_run_trace and get_error interpolated a bare
z.string() straight into the request path, so a model-chosen id could steer
the call at another same-origin route.
ask_support defaulted its URL to localhost and gated only on the secret, so
with the secret set and the URL unset the user's question and the bearer
secret went to a local port inside the agent's container.
…l judge

The shape descriptor for a redacted object copied its key names verbatim, so
a payload keyed by an email address sent that address to the judge model and
into the chat_turn_evals row. Emit a count instead, in both the shape and the
depth-cap descriptor, and stop allow-listing "keys" so a tool's own field of
that name is redacted like any other.
The route served a deployment's git blob — commit message, author, branch,
PR title — with no ability check, while the deployments list serves the same
blob behind read on deployments. Apply that check here too.

@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 new potential issue.

View 1 additional finding in Devin Review.

Open in Devin Review

Comment on lines +525 to +536
function metricDelta(metric: LayoutMetricInput): LayoutDelta | undefined {
const delta = metric.delta;
if (delta && delta.mult !== undefined && delta.mult > 1 && delta.dir !== "flat") {
return {
text: `${delta.dir === "up" ? REPORT_GLYPH.up : REPORT_GLYPH.down} ${delta.mult}×`,
dir: delta.dir,
};
}
return metric.normal === undefined
? undefined
: { text: `${REPORT_GLYPH.flat} flat`, dir: "flat" };
}

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.

🔍 A metric that fell against its baseline now renders as "flat"

metricDelta only emits a direction when mult > 1, so any metric with a baseline whose multiplier rounds to 0× or 1× renders → flat — including a genuine drop (dir: "down"). The previous deltaSegment in renderMarkdown.ts emitted a bare for exactly that case, deliberately ("a drop rounds to 0×/1×, meaningless — the arrow already says 'below normal'"). The new behaviour actively asserts "flat" for a metric that halved, which reads as a stronger claim than the old arrow-only rendering. The doc comment states the intent, so this is a judgement call rather than an obvious defect, but it is a semantic change to what the report tells users.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

… SSO avatars

Dropping the column was irreversible and blocked on a production row count; retiring it is not. The avatar host is an exact origin the app already knows, like the GitHub one.
The per-queue metrics route mapped ClickHouse rows straight to an array, so a
bucket with no sample shortened the trend and shifted every later point in time.
Fill a fixed-width grid the way the two sibling callers do.
A fall's multiplier rounds to 0 or 1, so every drop rendered as "flat" — a metric
that collapsed from 100 to 5 read as unchanged. Measure the fall against the
baseline instead, and show a bare arrow when it collapsed to nothing.
Absent telemetry and an unmeasured flow were both labelled stale data, so every
snapshot-based report claimed staleness it could not have measured. Choose the
badge and caveat from the reason instead.

@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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1d9c9c62-5867-43d6-a3fd-4f74d846ae81

📥 Commits

Reviewing files that changed from the base of the PR and between 8adf2b2 and 0db1cf0.

📒 Files selected for processing (35)
  • apps/webapp/app/presenters/v3/reports/report-layout.ts
  • apps/webapp/app/routes/api.v1.orgs.ts
  • apps/webapp/app/routes/api.v1.projects.$projectRef.$env.jwt.ts
  • apps/webapp/app/routes/api.v1.projects.$projectRef.$env.runs.$runId.commit.ts
  • apps/webapp/app/routes/api.v1.projects.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.metrics.ts
  • apps/webapp/app/services/environmentVariableApiAccess.server.ts
  • apps/webapp/app/services/routeBuilders/apiBuilder.server.ts
  • apps/webapp/app/services/userActorEnvironment.server.ts
  • apps/webapp/app/utils/cspImageOrigins.test.ts
  • apps/webapp/app/utils/cspImageOrigins.ts
  • apps/webapp/app/v3/queueDepthSeries.ts
  • apps/webapp/test/contextlessPatRoutes.test.ts
  • apps/webapp/test/dashboardAgentImageCsp.test.ts
  • apps/webapp/test/dashboardAgentLegacyMessagesColumn.test.ts
  • apps/webapp/test/dashboardAgentRoutes.test.ts
  • apps/webapp/test/envJwtActorClaim.test.ts
  • apps/webapp/test/queueDepthSeries.test.ts
  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/test/reportMetricDelta.test.ts
  • apps/webapp/test/reportTrust.test.ts
  • apps/webapp/test/runCommitAuthorization.test.ts
  • apps/webapp/test/uatEnvironmentClaim.test.ts
  • apps/webapp/test/userActorEnvironmentScopeRouteBuilder.test.ts
  • apps/webapp/test/userActorTokenClaimsAndScopes.test.ts
  • internal-packages/dashboard-agent-db/drizzle/0002_watches_and_chat_messages.sql
  • internal-packages/dashboard-agent-db/drizzle/meta/0002_snapshot.json
  • internal-packages/dashboard-agent-db/src/schema.ts
  • internal-packages/dashboard-agent/src/dashboard-agent.test.ts
  • internal-packages/dashboard-agent/src/eval-policy.ts
  • internal-packages/dashboard-agent/src/eval-redaction.test.ts
  • internal-packages/dashboard-agent/src/eval-turn.ts
  • internal-packages/dashboard-agent/src/tool-api-paths.test.ts
  • internal-packages/dashboard-agent/src/tool-api.ts
  • internal-packages/dashboard-agent/src/tool-ask-support.test.ts
💤 Files with no reviewable changes (1)
  • internal-packages/dashboard-agent-db/drizzle/0002_watches_and_chat_messages.sql
🚧 Files skipped from review as they are similar to previous changes (17)
  • apps/webapp/test/dashboardAgentImageCsp.test.ts
  • apps/webapp/app/routes/api.v1.projects.$projectRef.$env.runs.$runId.commit.ts
  • apps/webapp/test/dashboardAgentLegacyMessagesColumn.test.ts
  • apps/webapp/app/utils/cspImageOrigins.test.ts
  • apps/webapp/test/uatEnvironmentClaim.test.ts
  • apps/webapp/test/userActorTokenClaimsAndScopes.test.ts
  • apps/webapp/test/dashboardAgentRoutes.test.ts
  • apps/webapp/app/utils/cspImageOrigins.ts
  • apps/webapp/test/envJwtActorClaim.test.ts
  • internal-packages/dashboard-agent/src/tool-api.ts
  • internal-packages/dashboard-agent/src/eval-policy.ts
  • apps/webapp/app/routes/api.v1.queues.$queueParam.metrics.ts
  • apps/webapp/test/queueRetrieveJwt.test.ts
  • apps/webapp/app/services/userActorEnvironment.server.ts
  • internal-packages/dashboard-agent-db/drizzle/meta/0002_snapshot.json
  • internal-packages/dashboard-agent/src/eval-turn.ts
  • apps/webapp/app/routes/api.v1.projects.$projectRef.$env.jwt.ts

Comment on lines +503 to +506
// Opts a contextless route into being reachable by an environment-scoped user-actor token.
// Only for routes whose answer is the caller's own identity (their orgs, their projects) and
// which mutate nothing — otherwise such a token is refused for want of anything to check.
identityOnly?: true;

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.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Prevent identityOnly on action routes.

PATRouteBuilderOptions exposes identityOnly to createActionPATApiRoute(). The action builder then passes it to assertUserActorScope. A contextless mutation can therefore admit an environment-scoped user-actor token, despite the option contract requiring that the route “mutate nothing.”

Remove identityOnly from PATActionRouteBuilderOptions. Always call assertUserActorScope(claims, ctx) in action routes.

Proposed fix
-type PATActionRouteBuilderOptions<...> = PATRouteBuilderOptions<...> & {
+type PATActionRouteBuilderOptions<...> = Omit<PATRouteBuilderOptions<...>, "identityOnly"> & {
   // action-specific options
 };

-      identityOnly,
       authorization,

-        await assertUserActorScope(claims, ctx, { identityOnly });
+        await assertUserActorScope(claims, ctx);

Also applies to: 806-806, 939-939

Comment on lines +18 to +22
const bucketMs = Date.parse(row.bucket.replace(" ", "T") + "Z");
if (Number.isNaN(bucketMs)) continue;
const index = Math.round((bucketMs - grid.startMs) / grid.bucketIntervalMs);
if (index < 0 || index >= grid.numBuckets) continue;
byIndex.set(index, { depth: row.depth, throttled: row.throttled });

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reject out-of-window rows before calculating the bucket index.

Math.round() maps a row up to half a bucket before startMs into index 0. It also maps a row up to half a bucket after the grid end into the final index. The queue metrics API then returns incorrect depth and throttled values for those buckets.

Check the timestamp bounds first. Use Math.floor() to map an in-window timestamp to its containing bucket.

Proposed fix
     const bucketMs = Date.parse(row.bucket.replace(" ", "T") + "Z");
     if (Number.isNaN(bucketMs)) continue;
-    const index = Math.round((bucketMs - grid.startMs) / grid.bucketIntervalMs);
-    if (index < 0 || index >= grid.numBuckets) continue;
+    const offsetMs = bucketMs - grid.startMs;
+    if (offsetMs < 0 || offsetMs >= grid.numBuckets * grid.bucketIntervalMs) continue;
+    const index = Math.floor(offsetMs / grid.bucketIntervalMs);
     byIndex.set(index, { depth: row.depth, throttled: row.throttled });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const bucketMs = Date.parse(row.bucket.replace(" ", "T") + "Z");
if (Number.isNaN(bucketMs)) continue;
const index = Math.round((bucketMs - grid.startMs) / grid.bucketIntervalMs);
if (index < 0 || index >= grid.numBuckets) continue;
byIndex.set(index, { depth: row.depth, throttled: row.throttled });
const bucketMs = Date.parse(row.bucket.replace(" ", "T") + "Z");
if (Number.isNaN(bucketMs)) continue;
const offsetMs = bucketMs - grid.startMs;
if (offsetMs < 0 || offsetMs >= grid.numBuckets * grid.bucketIntervalMs) continue;
const index = Math.floor(offsetMs / grid.bucketIntervalMs);
byIndex.set(index, { depth: row.depth, throttled: row.throttled });

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