mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-03-19 10:43:08 +00:00
Merge pull request #781 from gsxdsm/fix/improve-restart-recovery
feat: Add feature state reconciliation on server startup
This commit is contained in:
@@ -21,6 +21,7 @@ import { createFollowUpFeatureHandler } from './routes/follow-up-feature.js';
|
||||
import { createCommitFeatureHandler } from './routes/commit-feature.js';
|
||||
import { createApprovePlanHandler } from './routes/approve-plan.js';
|
||||
import { createResumeInterruptedHandler } from './routes/resume-interrupted.js';
|
||||
import { createReconcileHandler } from './routes/reconcile.js';
|
||||
|
||||
/**
|
||||
* Create auto-mode routes.
|
||||
@@ -81,6 +82,11 @@ export function createAutoModeRoutes(autoModeService: AutoModeServiceCompat): Ro
|
||||
validatePathParams('projectPath'),
|
||||
createResumeInterruptedHandler(autoModeService)
|
||||
);
|
||||
router.post(
|
||||
'/reconcile',
|
||||
validatePathParams('projectPath'),
|
||||
createReconcileHandler(autoModeService)
|
||||
);
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
53
apps/server/src/routes/auto-mode/routes/reconcile.ts
Normal file
53
apps/server/src/routes/auto-mode/routes/reconcile.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Reconcile Feature States Handler
|
||||
*
|
||||
* On-demand endpoint to reconcile all feature states for a project.
|
||||
* Resets features stuck in transient states (in_progress, interrupted, pipeline_*)
|
||||
* back to resting states (ready/backlog) and emits events to update the UI.
|
||||
*
|
||||
* This is useful when:
|
||||
* - The UI reconnects after a server restart
|
||||
* - A client detects stale feature states
|
||||
* - An admin wants to force-reset stuck features
|
||||
*/
|
||||
|
||||
import type { Request, Response } from 'express';
|
||||
import { createLogger } from '@automaker/utils';
|
||||
import type { AutoModeServiceCompat } from '../../../services/auto-mode/index.js';
|
||||
|
||||
const logger = createLogger('ReconcileFeatures');
|
||||
|
||||
interface ReconcileRequest {
|
||||
projectPath: string;
|
||||
}
|
||||
|
||||
export function createReconcileHandler(autoModeService: AutoModeServiceCompat) {
|
||||
return async (req: Request, res: Response): Promise<void> => {
|
||||
const { projectPath } = req.body as ReconcileRequest;
|
||||
|
||||
if (!projectPath) {
|
||||
res.status(400).json({ error: 'Project path is required' });
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info(`Reconciling feature states for ${projectPath}`);
|
||||
|
||||
try {
|
||||
const reconciledCount = await autoModeService.reconcileFeatureStates(projectPath);
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
reconciledCount,
|
||||
message:
|
||||
reconciledCount > 0
|
||||
? `Reconciled ${reconciledCount} feature(s)`
|
||||
: 'No features needed reconciliation',
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error('Error reconciling feature states:', error);
|
||||
res.status(500).json({
|
||||
error: error instanceof Error ? error.message : 'Unknown error',
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user