Repository navigation
Add MCP job inspection capabilities - #239
Conversation
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 47 minutes and 2 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (10)
📝 WalkthroughWalkthroughThis PR extends the job manager system with debugging and inspection capabilities. It introduces new APIs to retrieve debug state (binding availability, alarm scheduling status, next runnable job details) from the job manager, combines this with job data via new service functions, and exposes them through two new MCP capabilities ( Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant MCP as MCP Handler
participant Service as Job Service
participant JobStore as Job Store
participant JobManager as JobManager DO
User->>MCP: job_get(jobId)
activate MCP
MCP->>Service: getJobInspection({userId, jobId})
activate Service
par
Service->>JobStore: getJob(jobId)
activate JobStore
JobStore-->>Service: job data
deactivate JobStore
and
Service->>JobManager: getDebugState({userId})
activate JobManager
JobManager->>JobManager: read stored userId, alarm, next job
JobManager-->>Service: debug state
deactivate JobManager
end
Service-->>MCP: {job, alarm}
deactivate Service
MCP->>MCP: build inspection output
MCP-->>User: job + alarm details
deactivate MCP
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
|
🔎 Preview deployed: https://kody-pr-239.kentcdodds.workers.dev Worker: Mocks:
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
packages/worker/src/jobs/service.ts (1)
11-21: Consolidate duplicate import from./manager-client.ts.
syncJobManagerAlarmis imported on Line 11 andgetJobManagerDebugStateis imported again from the same module on Line 21. Merge them into a single import statement.♻️ Proposed fix
-import { syncJobManagerAlarm } from './manager-client.ts' import { deleteJobRow, getJobRowById, listDueJobRows, listJobRowsByUserId, getNextRunnableJobRow, insertJobRow, updateJobRow, } from './repo.ts' -import { getJobManagerDebugState } from './manager-client.ts' +import { + getJobManagerDebugState, + syncJobManagerAlarm, +} from './manager-client.ts'🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/worker/src/jobs/service.ts` around lines 11 - 21, The two imports from the same module should be consolidated: replace the separate imports of syncJobManagerAlarm and getJobManagerDebugState from './manager-client.ts' with a single import statement that imports both symbols together; locate the import declarations referencing syncJobManagerAlarm and getJobManagerDebugState in service.ts and merge them into one import { syncJobManagerAlarm, getJobManagerDebugState } from './manager-client.ts'.packages/worker/src/mcp/capabilities/jobs/shared.ts (1)
83-113: Constrain counters and durations to non-negative integers.
run_count,success_count,error_count,duration_ms, andlast_duration_msare counters and durations that should never be negative. Tighten the schemas toz.number().int().min(0)to strengthen output validation and catch corrupted persisted debug data.Proposed schema tightening
+const nonNegativeIntegerSchema = z.number().int().min(0) + const jobRunHistoryEntrySchema = z.object({ started_at: z.string(), finished_at: z.string(), status: z.enum(['success', 'error']), - duration_ms: z.number(), + duration_ms: nonNegativeIntegerSchema, error: z.string().nullable(), }) @@ - last_duration_ms: z.number().nullable(), - run_count: z.number(), - success_count: z.number(), - error_count: z.number(), + last_duration_ms: nonNegativeIntegerSchema.nullable(), + run_count: nonNegativeIntegerSchema, + success_count: nonNegativeIntegerSchema, + error_count: nonNegativeIntegerSchema,🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/worker/src/mcp/capabilities/jobs/shared.ts` around lines 83 - 113, Update numeric counter and duration fields to enforce non-negative integers: change jobRunHistoryEntrySchema.duration_ms to z.number().int().min(0), change jobInspectionSchema.run_count, success_count, and error_count to z.number().int().min(0), and change jobInspectionSchema.last_duration_ms to z.number().int().min(0).nullable(); keep existing nullability on published_commit/last_run_at/last_run_status/last_run_error as-is. These changes should be applied on the jobRunHistoryEntrySchema and jobInspectionSchema definitions referenced above.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/worker/src/jobs/manager-do.ts`:
- Around line 56-72: alarmInSync and status currently compare alarmScheduledFor
and nextRunnableRunAt as strings which can differ in formatting; change the
comparison to use normalized timestamps instead: convert alarmTimestamp/
alarmScheduledFor and nextJob.nextRunAt into numeric epochs (e.g., via new
Date(...).getTime()) or normalize both with new Date(...).toISOString() before
comparing, handling null/undefined the same way as now; update the logic that
sets alarmInSync and status to use these normalized values (symbols:
alarmScheduledFor, nextRunnableRunAt, alarmInSync, status) so equivalent
instants compare equal.
In `@packages/worker/src/mcp/capabilities/jobs/job-schedule.node.test.ts`:
- Around line 535-537: The object literal for the test job has inconsistent
indentation for the due_now key; align the indentation of "due_now" with its
sibling keys (next_run_at and last_run_at) in the job object (in this test
file's job literal) so it matches the surrounding spacing/indentation style,
then re-run the formatter or linter to ensure consistency.
- Around line 347-446: Test relies on the real clock so due_now is flaky; in the
test for job_list (which calls jobListCapability.handler and uses
buildJobInspectionOutput from shared.ts), enable fake timers and set the system
time to the expected moment (e.g., vi.useFakeTimers(); vi.setSystemTime(new
Date('2026-04-20T18:30:00.000Z'))) before invoking handler, then restore real
timers after the assertion with vi.useRealTimers(); insert these calls at the
start/end of the test so the due_now calculation is deterministic.
---
Nitpick comments:
In `@packages/worker/src/jobs/service.ts`:
- Around line 11-21: The two imports from the same module should be
consolidated: replace the separate imports of syncJobManagerAlarm and
getJobManagerDebugState from './manager-client.ts' with a single import
statement that imports both symbols together; locate the import declarations
referencing syncJobManagerAlarm and getJobManagerDebugState in service.ts and
merge them into one import { syncJobManagerAlarm, getJobManagerDebugState } from
'./manager-client.ts'.
In `@packages/worker/src/mcp/capabilities/jobs/shared.ts`:
- Around line 83-113: Update numeric counter and duration fields to enforce
non-negative integers: change jobRunHistoryEntrySchema.duration_ms to
z.number().int().min(0), change jobInspectionSchema.run_count, success_count,
and error_count to z.number().int().min(0), and change
jobInspectionSchema.last_duration_ms to z.number().int().min(0).nullable(); keep
existing nullability on
published_commit/last_run_at/last_run_status/last_run_error as-is. These changes
should be applied on the jobRunHistoryEntrySchema and jobInspectionSchema
definitions referenced above.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 42c81ca1-1488-4650-996c-ee09da5e13ee
📒 Files selected for processing (11)
packages/worker/src/jobs/manager-client.tspackages/worker/src/jobs/manager-do.tspackages/worker/src/jobs/service.node.test.tspackages/worker/src/jobs/service.tspackages/worker/src/mcp/capabilities/jobs/domain.tspackages/worker/src/mcp/capabilities/jobs/job-get.tspackages/worker/src/mcp/capabilities/jobs/job-list.tspackages/worker/src/mcp/capabilities/jobs/job-schedule.node.test.tspackages/worker/src/mcp/capabilities/jobs/shared.tspackages/worker/src/mcp/jobs-embed.tspackages/worker/src/mcp/server-instructions.ts
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 47a9d53. Configure here.
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>

Summary
job_listandjob_getjobs-domain capabilities so MCP callers can inspect scheduled jobs without direct DB accessdue_nowassertions deterministic, and tightening public numeric schemas for non-negative counters/durationsTesting
npm run typechecknpm run test -- packages/worker/src/jobs/manager-do.node.test.ts packages/worker/src/mcp/capabilities/jobs/job-schedule.node.test.ts packages/worker/src/jobs/service.node.test.ts packages/worker/src/mcp/capabilities/build-capability-registry.workers.test.ts packages/worker/src/mcp/capabilities/meta/meta-list-capabilities.node.test.tsnpm run test:mcp -- packages/worker/src/mcp/mcp-server.mcp-e2e.test.tsnpm run buildSummary by CodeRabbit
Release Notes