feat(DIARCHERS-1521): add MCP write endpoints + fix log/artifacts/trigger#627
Closed
Jiachen0715 wants to merge 1 commit into
Closed
feat(DIARCHERS-1521): add MCP write endpoints + fix log/artifacts/trigger#627Jiachen0715 wants to merge 1 commit into
Jiachen0715 wants to merge 1 commit into
Conversation
…eorder UserGlobalTokens
Three defects in the MCP backend surfaced during test-env integration
(build_3201), and the 5 MCP write endpoints promised by the
feat/mcp-restart-rerun branch name had never been implemented. Also
reordered the token UI to put MCP Tokens first. Bug identifiers
follow the internal tracker; Bug C is handled separately.
Bug E (get_job_log silent empty response):
- MCP endpoint only queried the `console` streaming table
- Scheduler archives logs to `job.console` on termination and DELETEs
the streaming rows, so every finished job returned HTTP 200 with
empty body
- Fixed with a two-stage lookup: `job.console` archive column first,
fall back to `console` streaming table for jobs still running
Bug F (list_job_artifacts returns 500 unconditionally):
- MCP endpoint queried a non-existent `archive` table
- `archive` is actually a jsonb[] column on the `job` table
(see migration 00009.sql)
- Rewrote the query to `SELECT archive FROM job` and unpack the
array, matching the legacy endpoint behavior
Bug G (POST /trigger creates zombie builds):
- MCP endpoint only inserted a build row without the seed
create_job_matrix job that the scheduler polls for
- Every trigger returned HTTP 200 + build_id but left a build that
never ran, punching holes in the build_number sequence
- Also hardcoded restart_counter=0, diverging from the schema
default of 1 and making the build invisible to legacy UI filters
- Fixed by adding source_upload_id resolution (upload projects
reuse the most recent source_upload; test projects allow NULL),
inserting the Create Jobs seed in the same transaction, moving
the success audit entry to after the seed job commits, and
removing the restart_counter=0 override
5 new MCP write endpoints, all requiring allow_trigger on the token,
sharing the trigger_build rate-limit bucket, and fully audited:
- POST /api/v1/mcp/projects/<id>/builds/<bid>/restart
- DELETE /api/v1/mcp/projects/<id>/builds/<bid>/abort
- POST /api/v1/mcp/projects/<id>/jobs/<jid>/restart (cascades downstream)
- POST /api/v1/mcp/projects/<id>/jobs/<jid>/rerun (does NOT cascade)
- DELETE /api/v1/mcp/projects/<id>/jobs/<jid>/abort
Handlers do not delegate to legacy /api/v1/* implementations which
hard-depend on g.token['type'] in ('user', 'project'); MCP handlers
use get_mcp_user_id() and reimplement the SQL directly. Shared
helper _restart_or_rerun_job() covers both the DAG-propagating
restart_job and the single-job rerun_job paths.
Dashboard UI:
- src/dashboard-client/src/components/user/UserGlobalTokens.vue:
moved MCP Tokens section to the top of the page, ahead of Global
Viewer Tokens and Project Tokens. Rationale: MCP Tokens is the
newest feature and the highest-traffic section for users
onboarding to the MCP integration.
Verified:
- Python syntax check passes on builds.py and jobs.py
- All 5 new handlers registered by Flask-RESTX (verified via ast walk)
- Existing MCP endpoints unaffected (legacy /api/v1/projects/*
handlers left untouched)
Follows: DIARCHERS-1498
Corresponding client PR: sparta-infra/InfraBox-mcp#6
Collaborator
Author
|
Closing to trigger a clean CI run. Will reopen. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes three defects in the MCP backend surfaced during test-env
integration (build_3201) and adds the 5 MCP write endpoints the
feat/mcp-restart-rerunbranch name promised.Branch base:
feat/mcp-restart-rerun. This PR therefore carriesthe 8 upstream commits from #617-#625 in addition to the single
commit authored here. Once #620 (traffic isolation) and #621
(restart/rerun endpoints) land on
master, the base can be switchedor this PR can be rebased.
DIARCHERS-1521 — Backend fixes
get_job_logsilent empty response: the MCP endpoint queriedonly the
consolestreaming table. The scheduler archives joblogs to
job.consoleon termination and DELETEs the streamingrows, so every finished job returned HTTP 200 with an empty body.
Fixed with a two-stage lookup:
job.consolearchive columnfirst, fall back to
consolefor jobs still running.list_job_artifactsreturns 500 unconditionally: the MCPendpoint queried a non-existent
archivetable.archiveis ajsonb[]column on thejobtable (migration00009.sql).Rewrote to
SELECT archive FROM joband unpack the array,matching the legacy endpoint behavior.
POST /triggercreates zombie builds: the MCP endpoint onlyinserted a
buildrow without the seedcreate_job_matrixjobthe scheduler polls for, so every trigger returned HTTP 200 +
build_id but the build never ran. Also hardcoded
restart_counter=0, diverging from schema default 1 and hidingthe build from legacy UI filters. Fixed by resolving
source_upload_idper project type (upload projects reuse themost recent source_upload; test projects allow NULL), inserting
the Create Jobs seed in the same transaction, moving the success
audit entry to after the seed job commits, and removing the
restart_counter=0override.5 new MCP write endpoints
All require
allow_trigger=trueon the MCP token, share thetrigger_buildrate-limit bucket (5 RPM), and are fully audited./builds/<bid>/restartMCPBuildRestart/builds/<bid>/abortMCPBuildAbort/jobs/<jid>/restartMCPJobRestart/jobs/<jid>/rerunMCPJobRerun/jobs/<jid>/abortMCPJobAbortHandlers do not delegate to the legacy
/api/v1/*implementations, which hard-depend on
g.token['type'] in ('user', 'project'). MCP handlers useget_mcp_user_id()and reimplement the SQL directly. Shared helper_restart_or_rerun_job()covers bothrestart_job(DAG-propagating)and
rerun_job(single-job) paths.Dashboard UI
src/dashboard-client/src/components/user/UserGlobalTokens.vue:moved the MCP Tokens section to the top of the page, ahead of Global
Viewer Tokens and Project Tokens. Rationale: MCP Tokens is the
newest feature and the highest-traffic section for users onboarding
to the MCP integration.