Skip to content

[superlog] Warn on stalled insights worker jobs#515

Merged
izadoesdev merged 1 commit into
stagingfrom
codex/superlog-warn-insights-stalled-job
Jun 30, 2026
Merged

[superlog] Warn on stalled insights worker jobs#515
izadoesdev merged 1 commit into
stagingfrom
codex/superlog-warn-insights-stalled-job

Conversation

@izadoesdev

@izadoesdev izadoesdev commented Jun 30, 2026

Copy link
Copy Markdown
Member

Clean replacement for #501, based on staging.\n\nWhat changed:\n- Downgrades insights worker stalled-job telemetry from ERROR to WARN.\n- Adds deterministic stalled job-name inference for website, rollup, dispatch, and maintenance jobs.\n- Preserves the existing transient Redis worker error WARN helper from #482.\n\nVerification:\n- cd apps/insights && bun test src/worker-events.test.ts src/worker-errors.test.ts\n- bunx ultracite check apps/insights/src/worker.ts apps/insights/src/worker-events.ts apps/insights/src/worker-events.test.ts\n- bun run lint\n- bun run check-types\n- bun run test


Summary by cubic

Warn instead of error on stalled insights worker jobs and attach a deterministic job_name based on the job ID. This reduces noisy alerts and makes stalled events easier to triage.

  • New Features
    • Added inferInsightsStalledJobName and an event builder to map website, rollup, dispatch, and maintenance IDs from @databuddy/redis.
    • Stalled handler now emits "warn" with {job_id, job_name} built locally (no Redis lookup).
    • Added tests for job-name inference and event payload.

Written for commit 6aa7ed7. Summary will update on new commits.

Review in cubic

@vercel

vercel Bot commented Jun 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
databuddy-status Ready Ready Preview, Comment Jun 30, 2026 4:20pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
dashboard Skipped Skipped Jun 30, 2026 4:20pm
documentation Skipped Skipped Jun 30, 2026 4:20pm

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 299070ee-e72a-43c6-bb10-7fea35717dab

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/superlog-warn-insights-stalled-job

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR replaces #501 with a clean implementation on top of staging. It downgrades the worker.job_stalled telemetry event from "error" to "warn" and enriches it with a deterministically inferred job_name — derived purely from the BullMQ job ID string, with no Redis lookup required.

  • worker-events.ts: new pure-function module with inferInsightsStalledJobName (prefix-based dispatch over the four known job-ID patterns) and buildInsightsStalledJobEvent (returns { job_id, job_name }).
  • worker.ts: spreads the result of buildInsightsStalledJobEvent into the existing emitInsightsEvent(\"warn\", ...) call; all other worker event handlers are unchanged.
  • worker-events.test.ts: unit tests cover all four named patterns plus the \"unknown\" fallback; the job ID prefixes match what insightsWebsiteJobId and insightsRollupJobId actually produce in packages/redis/insights-queue.ts.

Confidence Score: 4/5

Safe to merge — the only call-site change is the log level and the addition of an inferred job name; no job processing or data path is affected.

The logic change is tiny and well-covered by tests. The one thing worth keeping an eye on is that the repeat:insights-dispatch: / repeat:insights-maintenance: prefix strings are BullMQ internals; if BullMQ ever alters that format the inference will silently degrade to unknown rather than producing an error.

All three files are straightforward; worker-events.ts lines 17-21 are the only place where an assumption about BullMQ's internal key format is encoded.

Important Files Changed

Filename Overview
apps/insights/src/worker-events.ts New module providing deterministic stalled-job-name inference based on BullMQ job ID prefixes; pure functions, no async or Redis dependency.
apps/insights/src/worker-events.test.ts Unit tests covering all four named job-ID patterns and the unknown fallback for inferInsightsStalledJobName, plus a single smoke test for buildInsightsStalledJobEvent.
apps/insights/src/worker.ts Downgrade of stalled-job telemetry from "error" to "warn" and enrichment with inferred job_name via buildInsightsStalledJobEvent; no logic change to job processing.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant BullMQ as BullMQ Worker
    participant WK as worker.ts
    participant WE as worker-events.ts
    participant EL as evlog-insights

    BullMQ->>WK: stalled(jobId)
    WK->>WE: buildInsightsStalledJobEvent(jobId)
    WE->>WE: inferInsightsStalledJobName(jobId)
    Note over WE: Prefix match on jobId:<br/>insights-website-* → insights-generate-website<br/>insights-rollup-* → insights-rollup<br/>repeat:insights-dispatch:* → insights-dispatch<br/>repeat:insights-maintenance:* → insights-maintenance<br/>else → unknown
    WE-->>WK: "{ job_id, job_name }"
    WK->>EL: "emitInsightsEvent("warn", "worker.job_stalled", { job_id, job_name })"
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant BullMQ as BullMQ Worker
    participant WK as worker.ts
    participant WE as worker-events.ts
    participant EL as evlog-insights

    BullMQ->>WK: stalled(jobId)
    WK->>WE: buildInsightsStalledJobEvent(jobId)
    WE->>WE: inferInsightsStalledJobName(jobId)
    Note over WE: Prefix match on jobId:<br/>insights-website-* → insights-generate-website<br/>insights-rollup-* → insights-rollup<br/>repeat:insights-dispatch:* → insights-dispatch<br/>repeat:insights-maintenance:* → insights-maintenance<br/>else → unknown
    WE-->>WK: "{ job_id, job_name }"
    WK->>EL: "emitInsightsEvent("warn", "worker.job_stalled", { job_id, job_name })"
Loading

Reviews (1): Last reviewed commit: "fix(insights): warn on stalled worker jo..." | Re-trigger Greptile

Comment on lines +17 to +21
if (jobId.startsWith("repeat:insights-dispatch:")) {
return INSIGHTS_DISPATCH_JOB_NAME;
}
if (jobId.startsWith("repeat:insights-maintenance:")) {
return INSIGHTS_MAINTENANCE_JOB_NAME;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Inference tied to BullMQ's internal repeat-key format

The repeat:insights-dispatch: and repeat:insights-maintenance: prefix checks rely on BullMQ's undocumented internal key format for upsertJobScheduler-generated jobs. BullMQ v5 changed the scheduler API significantly, and a future version could alter this prefix without a breaking-change notice. If the format changes, stalled scheduler jobs will silently fall through to "unknown" rather than surfacing the correct job name — degrading the usefulness of the telemetry without any error to alert the team.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@izadoesdev
izadoesdev merged commit 8fdb1b1 into staging Jun 30, 2026
18 checks passed
@izadoesdev
izadoesdev deleted the codex/superlog-warn-insights-stalled-job branch June 30, 2026 16:22
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