fix: Stop button database reset + UI state display (DATABASE-FIRST ARCHITECTURE)

CRITICAL FIXES:
1. Stop button now resets database FIRST (before pkill)
   - Database cleanup happens even if coordinator crashed
   - Prevents stale 'running' chunks blocking restart
   - Uses Node.js sqlite library (not CLI - Docker compatible)

2. UI enhancement - 4-state display
   -  Processing (running > 0)
   -  Pending (pending > 0, running = 0)
   -  Complete (all completed)
   - ⏸️ Idle (no work queued) [NEW]
   - Shows pending chunk count when present

TECHNICAL DETAILS:
- Replaced sqlite3 CLI calls with proper Node.js API
- Fixed permissions: chown 1001:1001 cluster/ for container write
- Database-first logic: reset → pkill → verify
- Detailed logging for each operation step

FILES CHANGED:
- app/api/cluster/control/route.ts (database operations refactored)
- app/cluster/page.tsx (4-state UI display)

VERIFIED:
- Stop button successfully reset 3 'running' chunks → 'pending'
- UI correctly shows Idle state after Stop
- Container logs show detailed operation flow
- Database operations work in Docker environment

DEPLOYMENT:
- Container rebuilt with fixed code
- Tested with real stale database (3 running chunks)
- All operations working correctly
This commit is contained in:
mindesbunister
2025-12-01 11:34:47 +01:00
parent c343daeb44
commit db33af9f17
2 changed files with 55 additions and 17 deletions

View File

@@ -254,6 +254,9 @@ export default function ClusterPage() {
{status.exploration.chunks.running > 0 && (
<span className="text-yellow-400 ml-2">({status.exploration.chunks.running} running)</span>
)}
{status.exploration.chunks.pending > 0 && status.exploration.chunks.running === 0 && (
<span className="text-gray-400 ml-2">({status.exploration.chunks.pending} pending)</span>
)}
</div>
</div>
<div>
@@ -263,8 +266,10 @@ export default function ClusterPage() {
<span className="text-yellow-400"> Processing</span>
) : status.exploration.chunks.pending > 0 ? (
<span className="text-blue-400"> Pending</span>
) : (
) : status.exploration.chunks.completed === status.exploration.chunks.total && status.exploration.chunks.total > 0 ? (
<span className="text-green-400"> Complete</span>
) : (
<span className="text-gray-400"> Idle</span>
)}
</div>
</div>
@@ -277,6 +282,9 @@ export default function ClusterPage() {
</div>
<div className="text-right text-sm text-gray-400 mt-1">
{status.exploration.progress.toFixed(2)}% complete
{status.exploration.testedCombinations > 0 && (
<span className="ml-3">({status.exploration.testedCombinations.toLocaleString()} strategies tested)</span>
)}
</div>
</div>