Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

IMPROVEMENTS:
* cli: Add registry now honors default main/master branch [[GH-843](https://github.com/hashicorp/nomad-pack/pull/843)]
* cli: Fixed stale-job reconciliation so nomad-pack run no longer stops active parameterized/periodic child jobs [[GH-855](https://github.com/hashicorp/nomad-pack/pull/855)]
* variable: Variables declaration now supports validation stanza [[GH-841](https://github.com/hashicorp/nomad-pack/pull/841)]

## 0.4.2 (March 16, 2026)
Expand Down
32 changes: 32 additions & 0 deletions internal/runner/job/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func (r *Runner) findStaleJobs(currentJobIDs map[string]struct{}) ([]*api.JobLis

var staleJobs []*api.JobListStub
for _, stub := range jobStubs {
if stub == nil {
continue
}

// Skip already-stopped jobs — nothing to do.
if stub.Status == "dead" {
continue
Expand All @@ -109,6 +113,11 @@ func (r *Runner) findStaleJobs(currentJobIDs map[string]struct{}) ([]*api.JobLis
continue
}

// Child jobs should not be treated as pack-managed root jobs that can be stopped.
if isChildJobStub(stub) {
continue
}

// If this job is not among the ones just deployed, it is stale.
if _, exists := currentJobIDs[stub.ID]; !exists {
staleJobs = append(staleJobs, stub)
Expand All @@ -117,3 +126,26 @@ func (r *Runner) findStaleJobs(currentJobIDs map[string]struct{}) ([]*api.JobLis

return staleJobs, nil
}

func isChildJobStub(stub *api.JobListStub) bool {
if stub == nil {
return false
}

// Preferred signal from Nomad.
if stub.ParentID != "" {
return true
}

// Metadata-based signal from nomad-pack tags. For child jobs, pack.job points
// to the parent/root job name, which differs from the child ID.
if stub.Meta != nil {
if packJob, ok := stub.Meta[PackJobKey]; ok && packJob != "" {
return packJob != stub.ID
}
}

// If neither ParentID nor pack.job metadata indicates a child job,
// treat it as a root job to avoid false positives.
return false
}
Loading
Loading