From 0b90495391a492a49e918d2ba808ff1cfd93a509 Mon Sep 17 00:00:00 2001 From: Alex Newman Date: Thu, 16 Apr 2026 19:24:43 -0700 Subject: [PATCH] feat(worktree): auto-adopt merged worktrees on worker startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Invokes adoptMergedWorktrees() right after runOneTimeCwdRemap() and before dbManager.initialize(), wrapped in try/catch so adoption failures never block startup. Idempotent, so running every startup is cheap — the SQL UPDATE only touches rows where merged_into_project IS NULL. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/services/worker-service.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/services/worker-service.ts b/src/services/worker-service.ts index 47b772d3..e723d8a6 100644 --- a/src/services/worker-service.ts +++ b/src/services/worker-service.ts @@ -59,6 +59,7 @@ import { httpShutdown } from './infrastructure/HealthMonitor.js'; import { performGracefulShutdown } from './infrastructure/GracefulShutdown.js'; +import { adoptMergedWorktrees } from './infrastructure/WorktreeAdoption.js'; // Server imports import { Server } from './server/Server.js'; @@ -364,6 +365,21 @@ export class WorkerService { // Must run before dbManager.initialize() so we don't hold the DB open. runOneTimeCwdRemap(); + // Stamp merged worktrees so their observations surface under the parent + // project. Runs every startup (not marker-gated) because git state evolves + // and the engine is fully idempotent. Must also precede dbManager.initialize(). + try { + const adoption = await adoptMergedWorktrees({}); + if (adoption.adoptedObservations > 0 || adoption.adoptedSummaries > 0 || adoption.chromaUpdates > 0) { + logger.info('SYSTEM', 'Merged worktrees adopted on startup', adoption); + } + if (adoption.errors.length > 0) { + logger.warn('SYSTEM', 'Worktree adoption had per-branch errors', { errors: adoption.errors }); + } + } catch (err) { + logger.error('SYSTEM', 'Worktree adoption failed (non-fatal)', {}, err as Error); + } + // Initialize ChromaMcpManager only if Chroma is enabled const chromaEnabled = settings.CLAUDE_MEM_CHROMA_ENABLED !== 'false'; if (chromaEnabled) {