-
-
Notifications
You must be signed in to change notification settings - Fork 8
feat: migrate commands to skills + background job system #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Background Job System: - Add background_jobs and hook_executions tables to schema - Create src/jobs/ module with manager, workers, and worker-entry - Add matrix_job_status, matrix_job_cancel, matrix_job_list MCP tools - Support async: true for matrix_reindex to avoid timeouts One-Time Hook Execution: - Add src/hooks/once.ts with hasRunThisSession/markAsRun helpers - Database-backed tracking for hooks that should only run once per session - Auto-cleanup of old records after 7 days Also exports getRepoInfo from index-tools for use by job workers.
Greptile SummaryThis PR successfully migrates all commands to the new skills format and introduces a robust background job system with one-time hook execution support. Key Changes:
Implementation Quality: Minor Concerns:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant MCP as MCP Server
participant Handler as handlers.ts
participant Manager as Job Manager
participant Spawner as workers.ts
participant Worker as worker-entry.ts
participant Indexer as indexRepository
User->>MCP: matrix_reindex(async: true)
MCP->>Handler: handleToolCall('matrix_reindex')
Handler->>Manager: createJob('matrix_reindex', input)
Manager->>Manager: generateJobId()
Manager->>Manager: INSERT INTO background_jobs
Manager-->>Handler: jobId
Handler->>Spawner: spawnBackgroundJob('reindex', jobId, input)
Spawner->>Worker: Bun.spawn([bun, run, worker-entry.ts])
Note over Spawner,Worker: Detached process
Handler-->>User: {jobId, status: 'queued', message}
Worker->>Worker: Parse args (workerName, jobId, input)
Worker->>Manager: updateJob(jobId, {status: 'running'})
Worker->>Indexer: runReindexJob(jobId, input)
loop Progress Updates
Indexer->>Manager: updateJob(jobId, {progressPercent, progressMessage})
end
Indexer-->>Worker: result
Worker->>Manager: updateJob(jobId, {status: 'completed', result})
Worker->>Worker: process.exit(0)
User->>MCP: matrix_job_status(jobId)
MCP->>Handler: handleToolCall('matrix_job_status')
Handler->>Manager: getJob(jobId)
Manager->>Manager: SELECT FROM background_jobs
Manager-->>Handler: job data
Handler-->>User: {status, progress, result}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
12 files reviewed, 2 comments
src/jobs/workers.ts
Outdated
| Bun.spawn(['bun', 'run', workerScript, workerName, jobId, JSON.stringify(input)], { | ||
| stdio: ['ignore', 'ignore', 'ignore'], | ||
| // Detach from parent process | ||
| detached: true, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider storing the process PID in the background_jobs table to enable cleanup of orphaned processes on restart. Detached processes without tracking could leak if the parent crashes. Have you considered storing the PID for cleanup of orphaned processes on restart?
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/jobs/workers.ts
Line: 112:116
Comment:
**style:** Consider storing the process PID in the `background_jobs` table to enable cleanup of orphaned processes on restart. Detached processes without tracking could leak if the parent crashes. Have you considered storing the PID for cleanup of orphaned processes on restart?
How can I resolve this? If you propose a fix, please make it concise.Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
…d jobs - Fix missing closing brace for main() function (CI lint failure) - Add pid column to background_jobs table for orphan process tracking - Add updateJobPid() to store spawned process PIDs - Add cleanupOrphanedProcesses() to detect and mark stale jobs on restart - Update spawnBackgroundJob() to capture and store PID Addresses review comment about detached process cleanup.
Summary
Changes
Skills Migration
commands/toskills/*/SKILL.mdformatagent: haikufor simple ops)context: forkfor review/deep-research)allowed-toolspermissionsBackground Job System
matrix_job_status,matrix_job_cancel,matrix_job_listMCP toolsmatrix_reindexnow supportsasync: truefor background executionOne-Time Hooks
hasRunThisSession()/markAsRun()helpers for hooks that should run once per sessionTest Plan