Skip to content
Merged
Show file tree
Hide file tree
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
35 changes: 33 additions & 2 deletions .agents/scripts/auto-update-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,27 @@ cmd_check() {
if [[ "$current" == "$remote" ]]; then
log_info "Already up to date (v$current)"
update_state "check" "$current" "up_to_date"

# Even when repo matches remote, deployed agents may be stale
# (e.g., previous setup.sh was interrupted or failed silently)
# See: https://github.com/marcusquinn/aidevops/issues/3980
local deployed_version
deployed_version=$(cat "$HOME/.aidevops/agents/VERSION" 2>/dev/null || echo "none")
Comment on lines +910 to +911
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The command to get the deployed version, cat "$HOME/.aidevops/agents/VERSION" 2>/dev/null || echo "none", is used three times within the cmd_check function (here, on line 916, and on line 975). To improve maintainability and reduce duplication, consider defining a local helper function at the beginning of cmd_check and using it in all three places.

References
  1. In shell scripts, extract repeated logic into an internal helper function to improve maintainability. This applies even for standalone scripts where external source dependencies are avoided.

if [[ "$current" != "$deployed_version" ]]; then
log_warn "Deployed agents stale ($deployed_version), re-deploying..."
if bash "$INSTALL_DIR/setup.sh" --non-interactive >>"$LOG_FILE" 2>&1; then
local redeployed_version
redeployed_version=$(cat "$HOME/.aidevops/agents/VERSION" 2>/dev/null || echo "none")
if [[ "$current" == "$redeployed_version" ]]; then
log_info "Agents re-deployed successfully ($deployed_version -> $redeployed_version)"
else
log_error "Agent re-deploy incomplete: repo=$current, deployed=$redeployed_version"
fi
else
log_error "setup.sh failed during stale-agent re-deploy (exit code: $?)"
fi
fi

check_skill_freshness
check_openclaw_freshness
check_tool_freshness
Expand Down Expand Up @@ -947,8 +968,18 @@ cmd_check() {
if bash "$INSTALL_DIR/setup.sh" --non-interactive >>"$LOG_FILE" 2>&1; then
local new_version
new_version=$(get_local_version)
log_info "Update complete: v$current -> v$new_version"
update_state "update" "$new_version" "success"

# Verify agents were actually deployed (setup.sh may exit 0 without deploying)
# See: https://github.com/marcusquinn/aidevops/issues/3980
local deployed_version
deployed_version=$(cat "$HOME/.aidevops/agents/VERSION" 2>/dev/null || echo "none")
if [[ "$new_version" != "$deployed_version" ]]; then
log_warn "Update pulled v$new_version but agents at v$deployed_version — deployment incomplete"
update_state "update" "$new_version" "agents_stale"
else
log_info "Update complete: v$current -> v$new_version (agents deployed)"
update_state "update" "$new_version" "success"
fi
else
log_error "setup.sh failed (exit code: $?)"
update_state "update" "$remote" "setup_failed"
Expand Down
23 changes: 21 additions & 2 deletions aidevops.sh
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,6 @@ cmd_update() {
local new_version new_hash
new_version=$(get_version)
new_hash=$(git rev-parse HEAD)
print_success "Updated to version $new_version"

# Print bounded summary of meaningful changes
if [[ "$old_hash" != "$new_hash" ]]; then
Expand All @@ -741,12 +740,32 @@ cmd_update() {

echo ""
print_info "Running setup to apply changes..."
bash "$INSTALL_DIR/setup.sh" --non-interactive
local setup_exit=0
bash "$INSTALL_DIR/setup.sh" --non-interactive || setup_exit=$?

# Safety net: discard any working tree changes setup.sh may have introduced
# (e.g. chmod on tracked scripts, scan results written to repo)
# See: https://github.com/marcusquinn/aidevops/issues/2286
git checkout -- . 2>/dev/null || true

# Verify deployment: compare repo VERSION with deployed agents VERSION
# This catches silent setup.sh failures (e.g., non-interactive mode in
# environments where setup.sh exits early without deploying agents)
# See: https://github.com/marcusquinn/aidevops/issues/3980
local repo_version deployed_version
repo_version=$(cat "$INSTALL_DIR/VERSION" 2>/dev/null || echo "unknown")
deployed_version=$(cat "$HOME/.aidevops/agents/VERSION" 2>/dev/null || echo "none")

if [[ "$setup_exit" -ne 0 ]]; then
print_warning "Setup exited with code $setup_exit"
fi

if [[ "$repo_version" != "$deployed_version" ]]; then
print_warning "Agent deployment incomplete: repo=$repo_version, deployed=$deployed_version"
print_info "Run 'bash $INSTALL_DIR/setup.sh' manually to deploy agents"
else
print_success "Updated to version $new_version (agents deployed)"
fi
Comment on lines +755 to +768
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

This block has a logic flaw and a redundant variable.

  1. Logic Flaw: If setup.sh fails (setup_exit != 0), but the deployed version happens to match the repo version, the else block is executed, incorrectly printing a "success" message. A failed setup should never result in a success message.
  2. Redundant Variable: repo_version is redundant. The new_version variable, defined on line 722, already holds the same value.

I suggest refactoring this block to fix the logic and remove the redundancy.

Suggested change
local repo_version deployed_version
repo_version=$(cat "$INSTALL_DIR/VERSION" 2>/dev/null || echo "unknown")
deployed_version=$(cat "$HOME/.aidevops/agents/VERSION" 2>/dev/null || echo "none")
if [[ "$setup_exit" -ne 0 ]]; then
print_warning "Setup exited with code $setup_exit"
fi
if [[ "$repo_version" != "$deployed_version" ]]; then
print_warning "Agent deployment incomplete: repo=$repo_version, deployed=$deployed_version"
print_info "Run 'bash $INSTALL_DIR/setup.sh' manually to deploy agents"
else
print_success "Updated to version $new_version (agents deployed)"
fi
local deployed_version
deployed_version=$(cat "$HOME/.aidevops/agents/VERSION" 2>/dev/null || echo "none")
if [[ "$setup_exit" -ne 0 ]] || [[ "$new_version" != "$deployed_version" ]]; then
if [[ "$setup_exit" -ne 0 ]]; then
print_warning "Setup exited with code $setup_exit"
fi
if [[ "$new_version" != "$deployed_version" ]]; then
print_warning "Agent deployment incomplete: repo=$new_version, deployed=$deployed_version"
fi
print_info "Run 'bash $INSTALL_DIR/setup.sh' manually to deploy agents"
else
print_success "Updated to version $new_version (agents deployed)"
fi

fi
else
print_warning "Repository not found, performing fresh install..."
Expand Down
Loading