Skip to content

feat: per-job completion pub/sub channel for zero-poll waiting#103

Merged
Gonzih merged 1 commit into
mainfrom
feat/job-completion-pubsub
May 6, 2026
Merged

feat: per-job completion pub/sub channel for zero-poll waiting#103
Gonzih merged 1 commit into
mainfrom
feat/job-completion-pubsub

Conversation

@Gonzih
Copy link
Copy Markdown
Owner

@Gonzih Gonzih commented May 6, 2026

Summary

  • PUBLISH to cca:job:done:{job_id} on every terminal-state transition (done, failed, cancelled, rejected) so external coordinators can SUBSCRIBE and get notified instantly instead of polling
  • LPUSH to cca:job:done:{job_id}:queue so the new wait_for_job MCP tool can use BLPOP-style waiting without a dedicated subscriber connection
  • wait_for_job MCP tool blocks until a job reaches a terminal state (or timeout) — far cheaper than callers polling get_job_status in a loop
  • Updated get_job_status response includes pub_sub_channel field for discoverability; description mentions pub/sub as preferred waiting mechanism
  • Updated list_jobs + get_job_status descriptions explicitly mention the pattern

Key design decisions

  • Ordering guarantee: publishJobDone always fires after persistJob via ioredis command-queue ordering — the SET from saveJob is queued before the PUBLISH, so subscribers always see the final state when they query the job record
  • All terminal paths covered: run() finally block (done/failed), Docker finally block, approval timeout (rejected), doApprove catch (failed)
  • Resilient to partial mocks: LPUSH/EXPIRE are guarded with typeof redis.lpush === 'function' so PUBLISH still works even if the queue path fails

Test plan

  • npm test passes — 280 pass, 12 pre-existing failures in meta-agent.test.ts (unchanged)
  • New tests verify PUBLISH fires with correct channel and payload after job completion
  • New tests verify LPUSH fires to the queue key on job completion
  • New tests verify saveJob is called before publishJobDone

🤖 Generated with Claude Code

- Add publishJobDone() method that fires redis.PUBLISH to cca:job:done:{job_id}
  and LPUSH to cca:job:done:{job_id}:queue after every terminal-state transition
- Guarantees PUBLISH fires AFTER persistJob: ioredis queues commands in order so
  the SET from saveJob always precedes the PUBLISH on the same connection
- Add wait_for_job MCP tool that polls until job is terminal (done/failed/cancelled/
  rejected/interrupted) with configurable timeout, returning status + score
- Update get_job_status and list_jobs descriptions to mention the pub/sub channel
  and wait_for_job as the preferred waiting mechanisms over manual polling
- Add pub_sub_channel field to get_job_status response for discoverability
- Add 3 tests verifying PUBLISH and LPUSH fire on job completion with correct payload

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Gonzih Gonzih merged commit 3b3be6a into main May 6, 2026
1 check failed
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