Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions .agents/scripts/supervisor-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,32 @@

# Configuration - resolve relative to this script's location
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
readonly SCRIPT_DIR
source "${SCRIPT_DIR}/shared-constants.sh"

# Source all supervisor module files
# Define all globals BEFORE sourcing modules — modules reference these in
# functions and traps. With set -u, any reference to an undefined variable
# is a fatal error. The t1031 modularisation moved functions into modules
# but left the globals defined after the source block, causing
# "PULSE_LOCK_DIR: unbound variable" errors in cron pulse (t1031 regression).
readonly SUPERVISOR_DIR="${AIDEVOPS_SUPERVISOR_DIR:-$HOME/.aidevops/.agent-workspace/supervisor}"
readonly SUPERVISOR_DB="$SUPERVISOR_DIR/supervisor.db"

Check warning on line 175 in .agents/scripts/supervisor-helper.sh

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.agents/scripts/supervisor-helper.sh#L175

SUPERVISOR_DB appears unused. Verify use (or export if used externally).
readonly MAIL_HELPER="${SCRIPT_DIR}/mail-helper.sh" # Used by pulse command (t128.2)
readonly MEMORY_HELPER="${SCRIPT_DIR}/memory-helper.sh" # Used by pulse command (t128.6)
readonly SESSION_REVIEW_HELPER="${SCRIPT_DIR}/session-review-helper.sh" # Used by batch completion (t128.9)
readonly SESSION_DISTILL_HELPER="${SCRIPT_DIR}/session-distill-helper.sh" # Used by batch completion (t128.9)
readonly MEMORY_AUDIT_HELPER="${SCRIPT_DIR}/memory-audit-pulse.sh" # Used by pulse Phase 9 (t185)
readonly SESSION_CHECKPOINT_HELPER="${SCRIPT_DIR}/session-checkpoint-helper.sh" # Used by respawn (t264.1)
readonly RESPAWN_LOG="${HOME}/.aidevops/logs/respawn-history.log" # Persistent respawn log (t264.1)

Check warning on line 182 in .agents/scripts/supervisor-helper.sh

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

.agents/scripts/supervisor-helper.sh#L182

RESPAWN_LOG appears unused. Verify use (or export if used externally).
SUPERVISOR_LOG_DIR="${HOME}/.aidevops/logs"
mkdir -p "$SUPERVISOR_LOG_DIR" 2>/dev/null || true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This line suppresses all errors from mkdir -p, including critical ones like permission denied. If mkdir -p fails, the script will continue silently due to || true, but will likely fail later when trying to write to the log file, making the root cause harder to debug.

This violates the repository style guide:

  • Line 13: || true guards are intended for commands like grep that can "fail" in normal operation, not for mkdir where a failure is a genuine error.
  • Line 50: 2>/dev/null is used for blanket suppression, which is disallowed.

Removing the error suppression will allow set -e to correctly halt the script on a legitimate directory creation failure, making it more robust.

Suggested change
mkdir -p "$SUPERVISOR_LOG_DIR" 2>/dev/null || true
mkdir -p "$SUPERVISOR_LOG_DIR"
References
  1. Use || true guards only for commands that are expected to fail during normal execution under set -e, like grep with no matches or arithmetic evaluations. mkdir failing is a genuine error. (link)
  2. Error stream redirection to /dev/null is only acceptable when redirecting to log files, not for blanket suppression of potential errors. (link)

SUPERVISOR_LOG="${SUPERVISOR_LOG_DIR}/supervisor.log"
readonly PULSE_LOCK_DIR="${SUPERVISOR_DIR}/pulse.lock"
readonly PULSE_LOCK_TIMEOUT="${SUPERVISOR_PULSE_LOCK_TIMEOUT:-600}"
export MAIL_HELPER MEMORY_HELPER SESSION_REVIEW_HELPER SESSION_DISTILL_HELPER MEMORY_AUDIT_HELPER SESSION_CHECKPOINT_HELPER
export SUPERVISOR_LOG SUPERVISOR_LOG_DIR PULSE_LOCK_DIR PULSE_LOCK_TIMEOUT

# Source all supervisor module files (globals must be defined above)
SUPERVISOR_MODULE_DIR="${SCRIPT_DIR}/supervisor"
source "${SUPERVISOR_MODULE_DIR}/_common.sh"
source "${SUPERVISOR_MODULE_DIR}/database.sh"
Expand All @@ -186,24 +209,6 @@
source "${SUPERVISOR_MODULE_DIR}/memory-integration.sh"
source "${SUPERVISOR_MODULE_DIR}/todo-sync.sh"

readonly SCRIPT_DIR
readonly SUPERVISOR_DIR="${AIDEVOPS_SUPERVISOR_DIR:-$HOME/.aidevops/.agent-workspace/supervisor}"
readonly SUPERVISOR_DB="$SUPERVISOR_DIR/supervisor.db"
readonly MAIL_HELPER="${SCRIPT_DIR}/mail-helper.sh" # Used by pulse command (t128.2)
readonly MEMORY_HELPER="${SCRIPT_DIR}/memory-helper.sh" # Used by pulse command (t128.6)
readonly SESSION_REVIEW_HELPER="${SCRIPT_DIR}/session-review-helper.sh" # Used by batch completion (t128.9)
readonly SESSION_DISTILL_HELPER="${SCRIPT_DIR}/session-distill-helper.sh" # Used by batch completion (t128.9)
readonly MEMORY_AUDIT_HELPER="${SCRIPT_DIR}/memory-audit-pulse.sh" # Used by pulse Phase 9 (t185)
readonly SESSION_CHECKPOINT_HELPER="${SCRIPT_DIR}/session-checkpoint-helper.sh" # Used by respawn (t264.1)
readonly RESPAWN_LOG="${HOME}/.aidevops/logs/respawn-history.log" # Persistent respawn log (t264.1)
SUPERVISOR_LOG_DIR="${HOME}/.aidevops/logs"
mkdir -p "$SUPERVISOR_LOG_DIR" 2>/dev/null || true
SUPERVISOR_LOG="${SUPERVISOR_LOG_DIR}/supervisor.log"
readonly PULSE_LOCK_DIR="${SUPERVISOR_DIR}/pulse.lock"
readonly PULSE_LOCK_TIMEOUT="${SUPERVISOR_PULSE_LOCK_TIMEOUT:-600}"
export MAIL_HELPER MEMORY_HELPER SESSION_REVIEW_HELPER SESSION_DISTILL_HELPER MEMORY_AUDIT_HELPER SESSION_CHECKPOINT_HELPER
export SUPERVISOR_LOG SUPERVISOR_LOG_DIR PULSE_LOCK_DIR PULSE_LOCK_TIMEOUT

# Valid states for the state machine
readonly VALID_STATES="queued dispatched running evaluating retrying complete pr_review review_triage merging merged deploying deployed verifying verified verify_failed blocked failed cancelled"

Expand Down
Loading