Files
foxhunt/.claude/helpers/worker-manager.sh
jgrusewski 12fdd18223 refactor: remove entire CPU training path — 5,307 lines of dead code
Deleted:
- DQN::compute_loss_internal (280 lines) — old Candle forward+loss
- DQN::train_step (55 lines) — old Candle training step
- DQN::compute_gradients (47 lines) — old gradient accumulation
- ComputeLossResult struct — only used by deleted functions
- RegimeConditionalDQN::train_step (65 lines) — old dispatch
- RegimeConditionalDQN::train_step_gpu_regime (100 lines) — old GPU path
- RegimeConditionalDQN::compute_gradients_gpu (130 lines) — old regime gradients
- RegimeConditionalDQN::compute_gradients (92 lines) — old dispatch
- DQNAgentType::train_step dispatch — dead
- DQNAgentType::compute_gradients dispatch — dead
- GpuDqnTrainer::upload_batch (71 lines) — old CPU→GPU upload
- train_step.rs (500 lines) — entire module including ensure_fused_ctx
- dqn_benchmark.rs — used old train_step
- examples.rs — used old train_step
- validation/adapters.rs (289 lines) — used old train_step
- dqn/trainable_adapter.rs — used old train_step
- gpu_smoketest.rs — tested old train_step
- Gradient accumulation path in training_loop.rs (144 lines)
- IQN d_h_s2().clone() → raw pointer (zero alloc)
- Causal intervention format! string alloc removed
- Dead HER relabel functions (320 lines)

Kept:
- ensure_fused_ctx logic inlined into training_loop.rs
- set_noise_sigma_scale re-added to RegimeConditionalDQN

Fixed:
- GpuReplayBuffer max_batch_size wired from batch_size parameter
  (was hardcoded 1024, blocking batch_size=8192)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 09:06:23 +02:00

171 lines
5.0 KiB
Bash
Executable File

#!/bin/bash
# Claude Flow V3 - Unified Worker Manager
# Orchestrates all background workers with proper scheduling
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
METRICS_DIR="$PROJECT_ROOT/.claude-flow/metrics"
PID_FILE="$METRICS_DIR/worker-manager.pid"
LOG_FILE="$METRICS_DIR/worker-manager.log"
mkdir -p "$METRICS_DIR"
# Worker definitions: name:script:interval_seconds
WORKERS=(
"perf:perf-worker.sh:300" # 5 min
"health:health-monitor.sh:300" # 5 min
"patterns:pattern-consolidator.sh:900" # 15 min
"ddd:ddd-tracker.sh:600" # 10 min
"adr:adr-compliance.sh:900" # 15 min
"security:security-scanner.sh:1800" # 30 min
"learning:learning-optimizer.sh:1800" # 30 min
)
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"
}
run_worker() {
local name="$1"
local script="$2"
local script_path="$SCRIPT_DIR/$script"
if [ -x "$script_path" ]; then
"$script_path" check 2>/dev/null &
fi
}
run_all_workers() {
log "Running all workers (non-blocking)..."
for worker_def in "${WORKERS[@]}"; do
IFS=':' read -r name script interval <<< "$worker_def"
run_worker "$name" "$script"
done
# Don't wait - truly non-blocking
log "All workers spawned"
}
run_daemon() {
local interval="${1:-60}"
log "Starting worker manager daemon (interval: ${interval}s)"
echo $$ > "$PID_FILE"
trap 'log "Shutting down..."; rm -f "$PID_FILE"; exit 0' SIGTERM SIGINT
while true; do
run_all_workers
sleep "$interval"
done
}
status_all() {
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║ Claude Flow V3 - Worker Status ║"
echo "╠══════════════════════════════════════════════════════════════╣"
for worker_def in "${WORKERS[@]}"; do
IFS=':' read -r name script interval <<< "$worker_def"
local script_path="$SCRIPT_DIR/$script"
if [ -x "$script_path" ]; then
local status=$("$script_path" status 2>/dev/null || echo "No data")
printf "║ %-10s │ %-48s ║\n" "$name" "$status"
fi
done
echo "╠══════════════════════════════════════════════════════════════╣"
# Check if daemon is running
if [ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then
echo "║ Daemon: RUNNING (PID: $(cat "$PID_FILE")) ║"
else
echo "║ Daemon: NOT RUNNING ║"
fi
echo "╚══════════════════════════════════════════════════════════════╝"
}
force_all() {
log "Force running all workers..."
for worker_def in "${WORKERS[@]}"; do
IFS=':' read -r name script interval <<< "$worker_def"
local script_path="$SCRIPT_DIR/$script"
if [ -x "$script_path" ]; then
log "Running $name..."
"$script_path" force 2>&1 | while read -r line; do
log " [$name] $line"
done
fi
done
log "All workers completed"
}
case "${1:-help}" in
"start"|"daemon")
if [ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then
echo "Worker manager already running (PID: $(cat "$PID_FILE"))"
exit 1
fi
run_daemon "${2:-60}" &
echo "Worker manager started (PID: $!)"
;;
"stop")
if [ -f "$PID_FILE" ]; then
kill "$(cat "$PID_FILE")" 2>/dev/null || true
rm -f "$PID_FILE"
echo "Worker manager stopped"
else
echo "Worker manager not running"
fi
;;
"run"|"once")
run_all_workers
;;
"force")
force_all
;;
"status")
status_all
;;
"logs")
tail -50 "$LOG_FILE" 2>/dev/null || echo "No logs available"
;;
"help"|*)
cat << EOF
Claude Flow V3 - Worker Manager
Usage: $0 <command> [options]
Commands:
start [interval] Start daemon (default: 60s cycle)
stop Stop daemon
run Run all workers once
force Force run all workers (ignore throttle)
status Show all worker status
logs Show recent logs
Workers:
perf Performance benchmarks (5 min)
health System health monitoring (5 min)
patterns Pattern consolidation (15 min)
ddd DDD progress tracking (10 min)
adr ADR compliance checking (15 min)
security Security scanning (30 min)
learning Learning optimization (30 min)
Examples:
$0 start 120 # Start with 2-minute cycle
$0 force # Run all now
$0 status # Check all status
EOF
;;
esac