Skip to content

Script hangs after "Configuration:" due to ((variable++)) with set -e #319

@dimitrystd

Description

@dimitrystd

Environment

  • OS: Ubuntu on WSL2 (Windows 11)
  • Bash: GNU bash 5.2.21
  • Agent OS: Latest from main branch

Steps to Reproduce

  1. Navigate to any project directory (not the agent-os base directory)
  2. Run: ~/agent-os/scripts/project-install.sh --verbose
  3. Script prints "Configuration:" and hangs indefinitely
  4. Never creates the agent-os/ directory structure

Observed Behavior

Script output stops after printing:

=== Agent OS Project Installation ===

[VERBOSE] Using profile: default
[VERBOSE] Inheritance chain: default 

Configuration:
[hangs here - no further output]

Root Cause

The script uses set -e (line 8) which exits on any non-zero return code. The bug occurs at line 450:

((chain_depth++))

In bash arithmetic:

  • ((chain_depth++)) increments the variable (0 → 1)
  • But the expression returns the old value (0)
  • Zero is falsy in arithmetic context, producing exit code 1
  • set -e interprets this as an error and terminates the script

Recommended Fix

Add || true to all ((variable++)) statements to prevent set -e from triggering:

Lines to fix:

  • Line 244: ((profile_file_count++))((profile_file_count++)) || true
  • Line 248: ((profiles_used++))((profiles_used++)) || true
  • Line 338: ((new_count++))((new_count++)) || true
  • Line 342: ((entry_count++))((entry_count++)) || true
  • Line 360: ((new_count++))((new_count++)) || true
  • Line 364: ((entry_count++))((entry_count++)) || true
  • Line 402: ((count++))((count++)) || true
  • Line 450: ((chain_depth++))((chain_depth++)) || true

Alternative: Use count=$((count + 1)) which always returns 0 exit code.

Tested Solution

After applying the fix, the script completes successfully and creates the expected directory structure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions