Skip to content

feat: add run status for cli and mcp#1022

Merged
amhsirak merged 2 commits intodevelopfrom
run-status
Apr 10, 2026
Merged

feat: add run status for cli and mcp#1022
amhsirak merged 2 commits intodevelopfrom
run-status

Conversation

@RohitR311
Copy link
Copy Markdown
Collaborator

@RohitR311 RohitR311 commented Apr 3, 2026

What this PR does?

Tracks the run status for MCP and CLI robot runs by updating the database accordingly.

Summary by CodeRabbit

  • New Features

    • Added support for distinguishing runs from CLI and MCP sources. These run origins now display with appropriate labels alongside existing API and SDK source types.
  • Chores

    • Updated and expanded run-type label translations across German, English, Spanish, Japanese, Turkish, and Chinese language files.

@RohitR311 RohitR311 added Type: Enhancement Improvements to existing features Scope: UI/UX Issues/PRs related to UI/UX labels Apr 3, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

Walkthrough

This PR extends run source tracking from a boolean isSDK flag to a discriminated union covering 'api', 'sdk', 'mcp', and 'cli' sources. The system now identifies run origins via request headers, persists MCP and CLI metadata in the database, and displays these new run types across the UI with multilingual localization support.

Changes

Cohort / File(s) Summary
Localization Strings
public/locales/de.json, public/locales/en.json, public/locales/es.json, public/locales/ja.json, public/locales/tr.json, public/locales/zh.json
Added translations for new run-type chips: sdk, mcp, and cli across six languages under runs_table.run_type_chips.
Run Recording & Source Detection
server/src/api/record.ts, server/src/api/sdk.ts
Changed handleRunRecording signature from isSDK: boolean to runSource: 'api' | 'sdk' | 'mcp' | 'cli'. Both files now derive runSource from the x-run-source request header and pass it to metadata persistence logic that sets corresponding runByAPI, runBySDK, runByMCP, and runByCLI flags.
MCP Header Injection
server/src/mcp-worker.ts
Added x-run-source: 'mcp' HTTP header to all outbound API requests made by makeApiRequest.
Data Model
server/src/models/Run.ts
Extended RunAttributes interface and Run class with two new optional boolean fields: runByMCP and runByCLI, persisted as Sequelize columns.
Frontend UI & Type Definitions
src/components/run/RunsTable.tsx, src/components/run/ColapsibleRow.tsx
Extended Data interface in RunsTable with runByMCP and runByCLI fields. Updated RunTypeChip component to handle and render the new run types with translated labels, inserted before existing SDK/API fallbacks.

Sequence Diagram

sequenceDiagram
    actor Client as Client<br/>(API/SDK/MCP/CLI)
    participant API as API Handler<br/>(record.ts/sdk.ts)
    participant DB as Database<br/>(Run Model)
    participant UI as Frontend<br/>(RunsTable/ColapsibleRow)

    Client->>API: Request with x-run-source header
    API->>API: Parse runSource from header<br/>(default: 'api')
    API->>DB: createWorkflowAndStoreMetadata()<br/>with runSource discriminant
    DB->>DB: Set runByAPI/SDK/MCP/CLI<br/>based on runSource
    DB->>DB: Persist to database
    API-->>Client: Response with run metadata
    UI->>DB: Fetch run records
    DB-->>UI: Return runs with runByMCP/runByCLI flags
    UI->>UI: Render RunTypeChip<br/>displaying MCP/CLI labels
    UI-->>Client: Display run type in table
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested labels

Type: Feature

Suggested reviewers

  • amhsirak

Poem

🐰 Four sources now flow through our warren deep,
MCP, CLI, SDKβ€”metadata we keep,
Request headers guide the run's true way,
From worker to table, displayed in every tongue,
A feature for run provenanceβ€”let's celebrate what's sprung! πŸŽ‰

πŸš₯ Pre-merge checks | βœ… 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
βœ… Passed checks (2 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title accurately summarizes the main change: adding run status tracking for CLI and MCP robot runs, which is evidenced across multiple file changes including model extensions, API endpoint updates, UI component modifications, and localization additions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch run-status

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
src/components/run/ColapsibleRow.tsx (1)

92-104: Consider refactoring the deeply nested ternary for readability.

The runByLabel computation has grown to 7 levels of nesting. While functionally correct, this could be simplified for maintainability:

♻️ Optional refactor suggestion
-  const runByLabel = row.runByScheduleId
-    ? `${row.runByScheduleId}`
-    : row.runByUserId
-      ? `${userEmail}`
-      : row.runByCLI
-        ? 'CLI'
-        : row.runByMCP
-          ? 'MCP'
-          : row.runBySDK
-            ? 'SDK'
-            : row.runByAPI
-              ? 'API'
-              : 'Unknown';
+  const getRunByLabel = (): string => {
+    if (row.runByScheduleId) return row.runByScheduleId;
+    if (row.runByUserId) return userEmail ?? 'Unknown';
+    if (row.runByCLI) return 'CLI';
+    if (row.runByMCP) return 'MCP';
+    if (row.runBySDK) return 'SDK';
+    if (row.runByAPI) return 'API';
+    return 'Unknown';
+  };
+  const runByLabel = getRunByLabel();
πŸ€– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/run/ColapsibleRow.tsx` around lines 92 - 104, The nested
ternary used to compute runByLabel is hard to read; replace the multi-level
conditional in runByLabel with a clearer control structure (e.g., an if/else
chain or a small helper function like getRunByLabel(row, userEmail)) that checks
row.runByScheduleId, row.runByUserId, row.runByCLI, row.runByMCP, row.runBySDK,
and row.runByAPI in order and returns the appropriate string (using userEmail
when runByUserId is true, otherwise 'CLI'/'MCP'/'SDK'/'API'/'Unknown') so the
logic is explicit and maintainable.
server/src/api/record.ts (1)

1385-1386: Implementation is correct; consider adding a clarifying comment.

CLI requests are properly routed through sdk.ts (which maps x-run-source: 'cli' correctly), so this API endpoint never receives CLI traffic. The POST handler only needs to distinguish MCP from regular API calls, and the current logic achieves this. Add a comment above line 1385 documenting this design:

// CLI traffic uses the SDK endpoint (sdk.ts); this API endpoint only handles API and MCP requests
const runSource = req.headers['x-run-source'] === 'mcp' ? 'mcp' : 'api';
πŸ€– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/src/api/record.ts` around lines 1385 - 1386, Add a clarifying comment
above the runSource assignment to explain that CLI traffic is routed through
sdk.ts and therefore this endpoint only needs to distinguish MCP vs API;
specifically, place a comment before the line that assigns runSource (const
runSource = ...) referencing that CLI uses the SDK endpoint (sdk.ts) and then
keep the existing logic that sets runSource and calls
handleRunRecording(req.params.id, req.user.id, runSource, requestedFormats).
πŸ€– Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@server/src/api/sdk.ts`:
- Around line 492-493: The runSource derivation currently maps only 'cli' to
'cli' and forces every other header value to 'sdk', causing MCP runs to be
misclassified; update the logic that sets runSource (the line reading
req.headers['x-run-source'] and the value passed into handleRunRecording) to
explicitly detect 'mcp' and set runSource to 'mcp' (in addition to preserving
'cli'), so handleRunRecording receives 'mcp' for MCP requests and downstream
code in record handling (e.g., runByMCP in server/src/api/record.ts) is set
correctly.

In `@server/src/models/Run.ts`:
- Around line 126-133: The Run model now defines two new nullable boolean fields
runByMCP and runByCLI but there is no DB migration; add a new migration that
alters the run table to ADD COLUMN "runByMCP" BOOLEAN and ADD COLUMN "runByCLI"
BOOLEAN (nullable) and implement the corresponding down migration to DROP those
columns so existing databases get the new columns; reference the Run model
(Run.ts) and the run table/column names when creating the migration.

---

Nitpick comments:
In `@server/src/api/record.ts`:
- Around line 1385-1386: Add a clarifying comment above the runSource assignment
to explain that CLI traffic is routed through sdk.ts and therefore this endpoint
only needs to distinguish MCP vs API; specifically, place a comment before the
line that assigns runSource (const runSource = ...) referencing that CLI uses
the SDK endpoint (sdk.ts) and then keep the existing logic that sets runSource
and calls handleRunRecording(req.params.id, req.user.id, runSource,
requestedFormats).

In `@src/components/run/ColapsibleRow.tsx`:
- Around line 92-104: The nested ternary used to compute runByLabel is hard to
read; replace the multi-level conditional in runByLabel with a clearer control
structure (e.g., an if/else chain or a small helper function like
getRunByLabel(row, userEmail)) that checks row.runByScheduleId, row.runByUserId,
row.runByCLI, row.runByMCP, row.runBySDK, and row.runByAPI in order and returns
the appropriate string (using userEmail when runByUserId is true, otherwise
'CLI'/'MCP'/'SDK'/'API'/'Unknown') so the logic is explicit and maintainable.
πŸͺ„ Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0a995ecc-7c7a-4d9a-ab82-e7963830bb21

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between bd818a5 and d933533.

πŸ“’ Files selected for processing (12)
  • public/locales/de.json
  • public/locales/en.json
  • public/locales/es.json
  • public/locales/ja.json
  • public/locales/tr.json
  • public/locales/zh.json
  • server/src/api/record.ts
  • server/src/api/sdk.ts
  • server/src/mcp-worker.ts
  • server/src/models/Run.ts
  • src/components/run/ColapsibleRow.tsx
  • src/components/run/RunsTable.tsx

Comment thread server/src/api/sdk.ts
Comment on lines +492 to +493
const runSource = req.headers['x-run-source'] === 'cli' ? 'cli' : 'sdk';
const runId = await handleRunRecording(robotId, user.id.toString(), runSource);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | πŸ”΄ Critical

Handle mcp explicitly when deriving runSource.

Line 492 currently maps only 'cli'; every other value (including 'mcp') is forced to 'sdk'. That causes MCP runs (sent with x-run-source: mcp from server/src/mcp-worker.ts, Line 41) to be persisted as SDK, so runByMCP never gets set in server/src/api/record.ts.

πŸ’‘ Proposed fix
-        const runSource = req.headers['x-run-source'] === 'cli' ? 'cli' : 'sdk';
+        const headerRunSource = Array.isArray(req.headers['x-run-source'])
+            ? req.headers['x-run-source'][0]
+            : req.headers['x-run-source'];
+        const runSource: 'sdk' | 'cli' | 'mcp' =
+            headerRunSource === 'cli' || headerRunSource === 'mcp'
+                ? headerRunSource
+                : 'sdk';
         const runId = await handleRunRecording(robotId, user.id.toString(), runSource);
πŸ“ 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 runSource = req.headers['x-run-source'] === 'cli' ? 'cli' : 'sdk';
const runId = await handleRunRecording(robotId, user.id.toString(), runSource);
const headerRunSource = Array.isArray(req.headers['x-run-source'])
? req.headers['x-run-source'][0]
: req.headers['x-run-source'];
const runSource: 'sdk' | 'cli' | 'mcp' =
headerRunSource === 'cli' || headerRunSource === 'mcp'
? headerRunSource
: 'sdk';
const runId = await handleRunRecording(robotId, user.id.toString(), runSource);
πŸ€– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/src/api/sdk.ts` around lines 492 - 493, The runSource derivation
currently maps only 'cli' to 'cli' and forces every other header value to 'sdk',
causing MCP runs to be misclassified; update the logic that sets runSource (the
line reading req.headers['x-run-source'] and the value passed into
handleRunRecording) to explicitly detect 'mcp' and set runSource to 'mcp' (in
addition to preserving 'cli'), so handleRunRecording receives 'mcp' for MCP
requests and downstream code in record handling (e.g., runByMCP in
server/src/api/record.ts) is set correctly.

Comment thread server/src/models/Run.ts
Comment on lines +126 to +133
runByMCP: {
type: DataTypes.BOOLEAN,
allowNull: true,
},
runByCLI: {
type: DataTypes.BOOLEAN,
allowNull: true,
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | πŸ”΄ Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for migration files that might add runByMCP or runByCLI columns
fd -e js -e ts migration | xargs -I{} grep -l -E 'runByMCP|runByCLI' {} 2>/dev/null || echo "No migration found"

# Also check for any migration files in common locations
fd -t f -e js -e ts . -p 'migrations|migrate' 2>/dev/null | head -20

Repository: getmaxun/maxun

Length of output: 40


🏁 Script executed:

# First, let's check the actual Run.ts file at the specified lines
head -140 server/src/models/Run.ts | tail -20

Repository: getmaxun/maxun

Length of output: 452


🏁 Script executed:

# Check if migrations directory exists and what's in it
find . -type d -name migrations -o -type d -name migrate 2>/dev/null | head -10

Repository: getmaxun/maxun

Length of output: 84


🏁 Script executed:

# Look for any SQL migration files
find . -type f -name "*.sql" 2>/dev/null | head -20

Repository: getmaxun/maxun

Length of output: 40


🏁 Script executed:

# Check for Sequelize configuration and migration patterns
find . -type f \( -name ".sequelizerc" -o -name "sequelize.config.*" -o -name "config.json" \) 2>/dev/null

Repository: getmaxun/maxun

Length of output: 100


🏁 Script executed:

# List all TypeScript/JS files in common migration paths
fd -t f -e js -e ts -e sql . -p '(migration|migrate|db/|database/)' 2>/dev/null | head -30

Repository: getmaxun/maxun

Length of output: 40


🏁 Script executed:

# Check what's in the migrations directory
ls -la server/src/db/migrations/

Repository: getmaxun/maxun

Length of output: 432


🏁 Script executed:

# Count and list migration files
find server/src/db/migrations -type f | sort

Repository: getmaxun/maxun

Length of output: 248


🏁 Script executed:

# Check .sequelizerc content to understand migration setup
cat .sequelizerc

Repository: getmaxun/maxun

Length of output: 349


🏁 Script executed:

# Check the config.json to see Sequelize setup
cat server/config/config.json

Repository: getmaxun/maxun

Length of output: 634


🏁 Script executed:

# Search the entire migrations directory for any reference to runByMCP or runByCLI
rg -i 'runByMCP|runByCLI' server/src/db/migrations/

Repository: getmaxun/maxun

Length of output: 40


🏁 Script executed:

# List all files in migrations directory with more details
find server/src/db/migrations -type f -exec basename {} \; | sort

Repository: getmaxun/maxun

Length of output: 173


🏁 Script executed:

# Check the most recent migration file
cat server/src/db/migrations/20250612000000-add-robot-name-unique-index.js

Repository: getmaxun/maxun

Length of output: 469


🏁 Script executed:

# Check the first migration which appears to add columns
cat server/src/db/migrations/20250327111003-add-airtable-columns.js

Repository: getmaxun/maxun

Length of output: 3263


🏁 Script executed:

# Check the Run.ts model to see all attributes and when they might have been added
grep -n "runBy\|type: DataTypes.BOOLEAN" server/src/models/Run.ts | head -30

Repository: getmaxun/maxun

Length of output: 685


🏁 Script executed:

# Check the webhooks migration
cat server/src/db/migrations/20250527105655-add-webhooks.js

Repository: getmaxun/maxun

Length of output: 853


🏁 Script executed:

# Verify which table the Run model uses
grep -n "tableName\|table:" server/src/models/Run.ts | head -5

Repository: getmaxun/maxun

Length of output: 83


🏁 Script executed:

# Search across all migrations for any reference to 'run' table
rg -i "addColumn.*'run'|addColumn.*\"run\"" server/src/db/migrations/

Repository: getmaxun/maxun

Length of output: 40


🏁 Script executed:

# Check git status to see what files are in this PR
git status --short

Repository: getmaxun/maxun

Length of output: 71


🏁 Script executed:

# Check if there are any uncommitted migration files
git diff --name-only

Repository: getmaxun/maxun

Length of output: 40


🏁 Script executed:

# Look for any migration files that might be timestamped with recent dates (April 2026)
ls -lt server/src/db/migrations/ | head -10

Repository: getmaxun/maxun

Length of output: 329


🏁 Script executed:

# Get the full Run.ts file to understand the context better
wc -l server/src/models/Run.ts

Repository: getmaxun/maxun

Length of output: 86


🏁 Script executed:

# Check if runBySDK was already in the model previously or if it's new
git log -1 --name-only server/src/models/Run.ts 2>/dev/null || echo "Not in git history"

Repository: getmaxun/maxun

Length of output: 257


🏁 Script executed:

# Check recent commits to the Run model
git log --oneline -n 10 -- server/src/models/Run.ts 2>/dev/null || echo "Unable to get git log"

Repository: getmaxun/maxun

Length of output: 99


🏁 Script executed:

# Let's check if there's a pending migration file that hasn't been added yet
find . -name "*runBy*" -o -name "*run-*.js" -o -name "*run-*.ts" 2>/dev/null | grep -i migrat

Repository: getmaxun/maxun

Length of output: 40


🏁 Script executed:

# Get the complete Run.ts model around the new columns
sed -n '110,140p' server/src/models/Run.ts

Repository: getmaxun/maxun

Length of output: 683


🏁 Script executed:

# Check if runBySDK exists in migrations (if it does, it shows a pattern)
rg -i 'runBySDK' server/src/db/migrations/

Repository: getmaxun/maxun

Length of output: 40


🏁 Script executed:

# Verify the table name one more time and check git diff for this file
git diff HEAD -- server/src/models/Run.ts | head -100

Repository: getmaxun/maxun

Length of output: 40


🏁 Script executed:

# Check what's actually staged for commit
git status -s

Repository: getmaxun/maxun

Length of output: 71


🏁 Script executed:

# Check the current HEAD to see what's committed vs what's being reviewed
git show --stat HEAD | head -30

Repository: getmaxun/maxun

Length of output: 1698


🏁 Script executed:

# Final verification: list all migration files with timestamps to see if any cover runBy* columns
ls -la server/src/db/migrations/ && echo "---" && grep -r "runByMCP\|runByCLI" server/src/db/migrations/ || echo "No runBy* columns in migrations"

Repository: getmaxun/maxun

Length of output: 468


Missing database migration for new columns.

The model defines runByMCP and runByCLI columns in the run table (lines 126-133), but no corresponding migration exists. Existing databases will throw a "column does not exist" error at runtime when attempting to write these fields.

Add a migration to alter the run table:

ALTER TABLE run ADD COLUMN "runByMCP" BOOLEAN;
ALTER TABLE run ADD COLUMN "runByCLI" BOOLEAN;
πŸ€– Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/src/models/Run.ts` around lines 126 - 133, The Run model now defines
two new nullable boolean fields runByMCP and runByCLI but there is no DB
migration; add a new migration that alters the run table to ADD COLUMN
"runByMCP" BOOLEAN and ADD COLUMN "runByCLI" BOOLEAN (nullable) and implement
the corresponding down migration to DROP those columns so existing databases get
the new columns; reference the Run model (Run.ts) and the run table/column names
when creating the migration.

@amhsirak amhsirak merged commit 82f4d7d into develop Apr 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: UI/UX Issues/PRs related to UI/UX Type: Enhancement Improvements to existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants