fix(frontend): peek and restart take <array-id>[k] and written job IDs

- apiserver peek (parseJobIDParam): <array-id>[k] now resolves to the
  element; it used to drop [k] and look up the array identity itself
  (and panicked in parseArrayName on some inputs). A job number still
  names that job exactly (an element by its own XCE_JOBID); ranges and
  invalid selections are rejected.
- apiserver restart: the decimal-only pre-check (isValidJobId, now
  unused and removed) rejected the written form c-a-ts-seq[k];
  ParseIdentitySelection, already used for the lookup, validates it.
- xcecli jobs restart converts its argument with ToAPIJobID like the
  control commands, so written IDs work and invalid ones fail locally.
- docs: the peek/restart caveat in the Job arrays section.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Rongsong Shen 2026-10-02 09:42:27 +00:00
parent a65146a9ae
commit c15580a7f3
Signed by untrusted user: rshen
GPG key ID: 80533536B0EB651C
7 changed files with 126 additions and 35 deletions

View file

@ -9,7 +9,6 @@ import (
"apiserver/common"
"apiserver/models"
"apiserver/store"
"apiserver/utils"
logger "apiserver/utils"
@ -220,25 +219,29 @@ func resolveOutputPath(path string, job models.JobInfo) string {
return path
}
// parseJobIDParam parses a job ID string and returns the corresponding JobInfo.
// parseJobIDParam parses the job peek names and returns the corresponding
// JobInfo: a job number (an ordinary job, or an element by its own number,
// XCE_JOBID) names that job exactly; <array-id>[k] names element k. A range
// or an invalid selection is an error -- peek shows one job.
func parseJobIDParam(jobidStr string) (models.JobInfo, error) {
// Use the same parsing logic as GetJobByIDs
jobArrInfo, err := parseArrayName(jobidStr)
if err != nil {
return models.JobInfo{}, err
raw := strings.TrimSpace(jobidStr)
if n, err := strconv.ParseUint(raw, 10, 64); err == nil {
return models.JobInfo{Unique_JobID: int64(n), ArrayIdx: backend.ExtractArrayIdx(n)}, nil
}
if !utils.IsNumeric(jobArrInfo.KeyID) {
return models.JobInfo{}, fmt.Errorf("bad jobid: %s", jobArrInfo.KeyID)
sel, selErr := ParseIdentitySelection(raw)
if selErr != nil {
return models.JobInfo{}, selErr
}
uniqueJobID, err := strconv.ParseInt(jobArrInfo.KeyID, 10, 64)
if err != nil {
return models.JobInfo{}, fmt.Errorf("bad jobid: %s", jobArrInfo.KeyID)
switch sel.Form {
case SelSingle:
return models.JobInfo{
Unique_JobID: int64(backend.MakeElementID(sel.Key, sel.Lo)),
ArrayIdx: sel.Lo,
}, nil
case SelRange:
return models.JobInfo{}, fmt.Errorf("'%s' names several jobs; peek one element as <array-id>[k]", raw)
default:
return models.JobInfo{Unique_JobID: int64(sel.Key)}, nil
}
return models.JobInfo{
Unique_JobID: uniqueJobID,
ArrayIdx: 0, // peek defaults to base job; array idx can be added later
}, nil
}