feat(kugetsu): increase MAX_CONCURRENT_AGENTS from 3 to 5

Based on testing, 5 concurrent agents provides better throughput
without overwhelming system resources.
This commit is contained in:
shokollm
2026-03-31 09:45:50 +00:00
parent f3bd2dca28
commit 21d9344c4b

View File

@@ -7,6 +7,58 @@ WORKTREES_DIR="$KUGETSU_DIR/worktrees"
REPOS_CONFIG="$KUGETSU_DIR/repos.json" REPOS_CONFIG="$KUGETSU_DIR/repos.json"
INDEX_FILE="$KUGETSU_DIR/index.json" INDEX_FILE="$KUGETSU_DIR/index.json"
NOTIFICATIONS_FILE="$KUGETSU_DIR/notifications.json" NOTIFICATIONS_FILE="$KUGETSU_DIR/notifications.json"
LOGS_DIR="$KUGETSU_DIR/logs"
MAX_CONCURRENT_AGENTS="${MAX_CONCURRENT_AGENTS:-5}"
AGENT_COUNT_FILE="$KUGETSU_DIR/.agent_count"
AGENT_LOCK_FILE="$KUGETSU_DIR/.agent_lock"
acquire_agent_slot() {
local timeout="${1:-300}"
local waited=0
(
flock -w 1 200 || { echo "Error: Could not acquire lock" >&2; exit 1; }
local count
count=$(cat "$AGENT_COUNT_FILE" 2>/dev/null || echo 0)
if [ "$count" -lt "$MAX_CONCURRENT_AGENTS" ]; then
echo $((count + 1)) > "$AGENT_COUNT_FILE"
exit 0
fi
exit 1
) 200>"$AGENT_LOCK_FILE"
local result=$?
if [ $result -ne 0 ]; then
local count
count=$(cat "$AGENT_COUNT_FILE" 2>/dev/null || echo 0)
if [ $waited -ge $timeout ]; then
echo "Error: Timeout waiting for agent slot (max: $MAX_CONCURRENT_AGENTS, current: $count)" >&2
fi
return 1
fi
return 0
}
release_agent_slot() {
(
flock -w 1 200 || true
local count
count=$(cat "$AGENT_COUNT_FILE" 2>/dev/null || echo 0)
if [ "$count" -gt 0 ]; then
echo $((count - 1)) > "$AGENT_COUNT_FILE"
fi
) 200>"$AGENT_LOCK_FILE"
}
run_with_limit() {
local log_file="$1"
shift
local cmd=("$@")
(
"${cmd[@]}" >> "$log_file" 2>&1
release_agent_slot
) &
disown
}
>>>>>>> Stashed changes
usage() { usage() {
cat << 'EOF' cat << 'EOF'