fix(apiserver): fix job control union discriminant, add human-readable job ID support (gitea#45)

ControlJob() set xce_jobctrl_t.action to the job_ctrl_type_t action code
(kill/stop/resume/checkpoint), but that field is actually the capnp
JobControl_u_which union discriminant -- a different enum entirely. This
made kill/resume/checkpoint hit request.c's -EINVAL default case, and made
stop collide with the checkpoint discriminant and read through the wrong
union member. Live-verified against a real deployed cluster: kill/stop/
resume/checkpoint now behave correctly with no apiserver crash.

Also additively accept a human-readable job ID ("{cluster}-{apiserver}-
{timestamp}-{seq}") on the job control endpoint, alongside the existing
numeric form xcecli already translates to -- lets a caller hit the REST
API directly without reimplementing xcecli's ID packing. Live-verified via
a direct curl call with the human-readable ID.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hb6Edtj4KbS8CrgEWYdA2E
This commit is contained in:
Rongsong Shen 2026-09-07 08:31:54 +00:00
parent 5ab344e1ae
commit 099dbdabdc
No known key found for this signature in database
GPG key ID: 5BCDAAE0123E9FE2
5 changed files with 191 additions and 5 deletions

View file

@ -2352,11 +2352,20 @@ func (j JobController) ControlJobByID(ctx *gin.Context) {
}
logger.Debug("GetJobByIDs after parseArrayName", zap.Any("jobid", jobid))
// gitea#45 follow-up: accept the human-readable job ID form
// ("{cluster}-{apiserver}-{timestamp}-{seq}", e.g. what `jobs list`
// prints) in addition to the numeric one xcecli already translates
// to -- lets a caller hit this endpoint directly without
// reimplementing xcecli's ID packing. Numeric IDs are unaffected.
if !utils.IsNumeric(jobid.KeyID) {
err := errors.New("bad jobid: " + jobid.KeyID)
logger.Error(err.Error())
ReturnError(ctx, common.INVALID_PARAMS_CODE, common.INVALID_PARAMS_MSG+": "+err.Error(), nil)
return
if packed, ok := backend.ParseHumanJobID(jobid.KeyID); ok {
jobid.KeyID = strconv.FormatUint(packed, 10)
} else {
err := errors.New("bad jobid: " + jobid.KeyID)
logger.Error(err.Error())
ReturnError(ctx, common.INVALID_PARAMS_CODE, common.INVALID_PARAMS_MSG+": "+err.Error(), nil)
return
}
}
mainFiltCond := utils.FilterCondition{