fix: remove obsolete slot-based concurrency mechanism

The session-counting approach (PR #65) now properly handles agent
concurrency limits. Remove the broken slot-based mechanism:

- Remove acquire_agent_slot() and release_agent_slot() functions
- Remove AGENT_COUNT_FILE and AGENT_LOCK_FILE variables
- Remove unused run_with_limit() function
- Remove release-slot.sh script
- Update cmd_delegate to use fire-and-forget without slot management

Both cmd_start and cmd_delegate now use count_active_dev_sessions()
for concurrency checking.
This commit is contained in:
shokollm
2026-04-01 06:56:45 +00:00
parent 6c23d4f5e9
commit 4d3205de86
2 changed files with 1 additions and 67 deletions

View File

@@ -9,44 +9,6 @@ INDEX_FILE="$KUGETSU_DIR/index.json"
NOTIFICATIONS_FILE="$KUGETSU_DIR/notifications.json" NOTIFICATIONS_FILE="$KUGETSU_DIR/notifications.json"
LOGS_DIR="$KUGETSU_DIR/logs" LOGS_DIR="$KUGETSU_DIR/logs"
MAX_CONCURRENT_AGENTS="${MAX_CONCURRENT_AGENTS:-3}" MAX_CONCURRENT_AGENTS="${MAX_CONCURRENT_AGENTS:-3}"
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"
}
count_active_dev_sessions() { count_active_dev_sessions() {
local count=0 local count=0
@@ -63,17 +25,6 @@ count_active_dev_sessions() {
echo "$count" echo "$count"
} }
run_with_limit() {
local log_file="$1"
shift
local cmd=("$@")
(
"${cmd[@]}" >> "$log_file" 2>&1
release_agent_slot
) &
disown
}
usage() { usage() {
cat << 'EOF' cat << 'EOF'
kugetsu - OpenCode Session Manager (Issue-Driven) kugetsu - OpenCode Session Manager (Issue-Driven)
@@ -148,8 +99,6 @@ EOF
ensure_dirs() { ensure_dirs() {
mkdir -p "$SESSIONS_DIR" mkdir -p "$SESSIONS_DIR"
[ -f "$AGENT_COUNT_FILE" ] || echo 0 > "$AGENT_COUNT_FILE"
} }
ensure_worktree_dir() { ensure_worktree_dir() {
@@ -569,11 +518,7 @@ cmd_delegate() {
mkdir -p "$LOGS_DIR" mkdir -p "$LOGS_DIR"
local log_file="$LOGS_DIR/delegate-$(date +%s).log" local log_file="$LOGS_DIR/delegate-$(date +%s).log"
if ! acquire_agent_slot; then nohup sh -c "opencode run '$message' --continue --session '$pm_session' >> '$log_file' 2>&1" > /dev/null 2>&1 &
echo "Error: Max concurrent agents ($MAX_CONCURRENT_AGENTS) reached. Try again later." >&2
exit 1
fi
nohup sh -c "opencode run '$message' --continue --session '$pm_session' >> '$log_file' 2>&1; ~/.kugetsu/release-slot.sh" > /dev/null 2>&1 &
disown disown
echo "Delegated to PM agent (logged to $(basename "$log_file"))" echo "Delegated to PM agent (logged to $(basename "$log_file"))"
} }

View File

@@ -1,11 +0,0 @@
#!/bin/bash
KUGETSU_DIR="${KUGETSU_DIR:-$HOME/.kugetsu}"
AGENT_COUNT_FILE="$KUGETSU_DIR/.agent_count"
AGENT_LOCK_FILE="$KUGETSU_DIR/.agent_lock"
(
flock -w 1 200 || true
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"