Skip to content

Fix /monitor-job to pick up most recent job by timestamp, not cache order#62

Merged
punit-naik-amp merged 1 commit intomainfrom
fix-job-cache-and-job-status-cmds
Jan 13, 2026
Merged

Fix /monitor-job to pick up most recent job by timestamp, not cache order#62
punit-naik-amp merged 1 commit intomainfrom
fix-job-cache-and-job-status-cmds

Conversation

@punit-naik-amp
Copy link
Contributor

The /monitor-job command was incorrectly selecting old jobs when called without a job ID because get_last_job_id() relied on cache insertion order rather than actual job timestamps.

Root cause:

  • When /jobs runs, it queries and caches job status for all jobs
  • Jobs with errors or not found get cached with state "UNKNOWN"
  • Cache uses deque.appendleft(), moving re-cached jobs to position 0
  • get_last_job_id() simply returned cache[0], which could be an old job that was just re-cached, not the most recently started job

Changes:

  • Modified get_last_job_id() to find job with most recent start-time or created-at timestamp from job_data, with fallback to cached_at
  • Updated /jobs command to cache running/pending jobs to maintain proper ordering and avoid unnecessary re-caching of UNKNOWN state jobs
  • Added tests for timestamp-based selection and fallback behavior

Result:
/monitor-job now correctly picks up the most recently started job even after /jobs re-caches older jobs

…rder

The /monitor-job command was incorrectly selecting old jobs when called
without a job ID because get_last_job_id() relied on cache insertion
order rather than actual job timestamps.

Root cause:
- When /jobs runs, it queries and caches job status for all jobs
- Jobs with errors or not found get cached with state "UNKNOWN"
- Cache uses deque.appendleft(), moving re-cached jobs to position 0
- get_last_job_id() simply returned cache[0], which could be an old job
  that was just re-cached, not the most recently started job

Changes:
- Modified get_last_job_id() to find job with most recent start-time or
  created-at timestamp from job_data, with fallback to cached_at
- Updated /jobs command to cache running/pending jobs to maintain proper
  ordering and avoid unnecessary re-caching of UNKNOWN state jobs
- Added tests for timestamp-based selection and fallback behavior

Result:
/monitor-job now correctly picks up the most recently started job even after /jobs re-caches older jobs
@punit-naik-amp punit-naik-amp self-assigned this Jan 13, 2026
@punit-naik-amp punit-naik-amp merged commit 7ba80a2 into main Jan 13, 2026
2 checks passed
@punit-naik-amp punit-naik-amp deleted the fix-job-cache-and-job-status-cmds branch January 13, 2026 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants