Skip to content

Fix unsafe cast in job monitor shutdown path#709

Merged
selfcontained merged 1 commit into
mainfrom
agt_b9f8d0784b10/job-debt-collector-5da9635e
Jun 30, 2026
Merged

Fix unsafe cast in job monitor shutdown path#709
selfcontained merged 1 commit into
mainfrom
agt_b9f8d0784b10/job-debt-collector-5da9635e

Conversation

@selfcontained

Copy link
Copy Markdown
Owner

Summary

  • Removed an unsafe undefined as unknown as JobRunRecord double cast in apps/server/src/jobs/service.ts where the monitor's .catch() handler returns undefined during shutdown
  • Widened the monitors Map type from Promise<JobRunRecord> to Promise<JobRunRecord | undefined> to reflect the actual runtime behavior
  • Updated waitForTerminal to fall back to a DB lookup when the monitor resolves to undefined, which also fixes a latent bug where the caller would silently receive undefined typed as JobRunRecord

Why this is tech debt

The unsafe cast masked a type-level lie — the Map claimed to hold Promise<JobRunRecord> but could actually resolve to undefined. This meant TypeScript couldn't catch callers that failed to handle the undefined case. The fix aligns the types with reality and adds a safe fallback.

What's next

The backlog is empty after this fix. The next run will re-audit for new tech debt.

Test plan

  • pnpm run check — type checking passes
  • pnpm run test — 180 unit tests pass
  • pnpm run test:e2e — 171 E2E tests pass (12 pre-existing skips)

🤖 Generated with Claude Code

The monitors Map used `Promise<JobRunRecord>` but the `.catch()` handler
returned `undefined` during shutdown, requiring an unsafe double cast.
Widen the Map type to `Promise<JobRunRecord | undefined>` and fall back
to a DB lookup in `waitForTerminal` when the monitor resolves to
`undefined` — which also fixes a latent bug where the caller would
silently receive `undefined` typed as `JobRunRecord`.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@selfcontained
selfcontained merged commit 4896997 into main Jun 30, 2026
1 check passed
@selfcontained
selfcontained deleted the agt_b9f8d0784b10/job-debt-collector-5da9635e branch June 30, 2026 09:11
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.

1 participant