Skip to content

feat(run-tracking): store BullMQ jobId immediately after run creation#776

Merged
aaight merged 1 commit intodevfrom
feature/store-bullmq-jobid
Mar 13, 2026
Merged

feat(run-tracking): store BullMQ jobId immediately after run creation#776
aaight merged 1 commit intodevfrom
feature/store-bullmq-jobid

Conversation

@aaight
Copy link
Copy Markdown
Collaborator

@aaight aaight commented Mar 13, 2026

Summary

Store the BullMQ jobId on the agent_runs record immediately after run creation in the worker container. This enables the cancel flow mapping (runId → jobId → container) needed for the cancel listener implementation.

Implementation Details

  • Modified tryCreateRun() in src/agents/shared/runTracking.ts to call updateRunJobId(runId, process.env.JOB_ID) after successful run creation
  • The JOB_ID env var is already passed to worker containers by the Router's buildWorkerEnv() in container-manager.ts
  • Job ID storage is wrapped in a try/catch — failure is logged but does not block agent execution (fire-and-forget pattern)
  • updateRunJobId is NOT called when JOB_ID env var is absent (local dev / non-Docker mode)

Testing

Added comprehensive unit tests to verify:

  • updateRunJobId is called with correct runId and jobId when JOB_ID is set
  • updateRunJobId is NOT called when JOB_ID is unset
  • Failure to store jobId is logged but does not block run creation
  • All existing tests pass with no regressions

Verification

  • Type checking: ✅ PASS
  • Linting: ✅ PASS (no fixes applied)
  • Tests: ✅ PASS (12 tests in runTracking.test.ts)
  • All agent tests: ✅ PASS (569 tests)

Closes: https://trello.com/c/afFdwvgk/304-as-a-developer-i-want-the-worker-to-store-its-bullmq-jobid-on-the-run-record-so-that-cancel-commands-can-map-runs-to-containers

Copy link
Copy Markdown
Collaborator

@nhopeatall nhopeatall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

LGTM — Clean, well-scoped change that stores the BullMQ jobId on the run record immediately after creation, enabling the cancel flow mapping. The implementation correctly follows the existing fire-and-forget error handling pattern used throughout runTracking.ts.

Verified:

  • updateRunJobId exists in runsRepository.ts and performs a straightforward DB update on the jobId column (confirmed in schema at src/db/schema/runs.ts:36)
  • JOB_ID env var is confirmed set by buildWorkerEnv() in container-manager.ts:81
  • Inner try/catch correctly isolates jobId storage failure from run creation — the run ID is still returned even if updateRunJobId throws
  • Guard on process.env.JOB_ID correctly skips the update in local dev / non-Docker mode
  • Tests cover all three paths: happy path, absent env var, and failure resilience
  • All CI checks pass

@aaight aaight merged commit 2f8c983 into dev Mar 13, 2026
6 checks passed
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