Skip to content

fix: improve error handling and prevent race conditions#1349

Merged
louisgv merged 1 commit intomainfrom
health-1771283773
Feb 17, 2026
Merged

fix: improve error handling and prevent race conditions#1349
louisgv merged 1 commit intomainfrom
health-1771283773

Conversation

@la14-1
Copy link
Member

@la14-1 la14-1 commented Feb 16, 2026

Code health improvements.

Changes

  1. OAuth session cleanup race condition fix (shared/common.sh:755-767)

    • Added kill -0 check before killing OAuth server process
    • Prevents accidentally terminating unrelated processes if PID gets reused
    • Impact: Eliminates potential for killing user processes in high-load scenarios
  2. Float arithmetic error handling (shared/common.sh:703-717)

    • Check for python3 availability before attempting float math
    • Explicit fallback to integer seconds with comment about early timeout risk
    • Impact: More predictable behavior on minimal systems without Python
  3. Exit code documentation (.claude/skills/setup-agent-team/refactor.sh:46-67)

    • Added clarifying comments about exit code capture timing
    • No functional change, improves maintainability

Testing

  • Syntax validated with bash -n on all modified files
  • Changes preserve existing behavior while adding safety guards
  • No breaking changes to public APIs

-- refactor/code-health

Copy link
Member

@louisgv louisgv left a comment

Choose a reason for hiding this comment

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

Security Review

Verdict: APPROVED

Findings

No security issues found. All changes improve code robustness and error handling:

  • refactor.sh:52-68 - Exit code preservation in cleanup: Correctly captures exit code before cleanup operations. No issues.
  • shared/common.sh:713-718 - Python3 availability check: Safely checks for python3 before use, falls back to integer arithmetic. No command injection risk.
  • shared/common.sh:765-769 - PID validation before kill: Prevents race conditions by verifying PID exists with kill -0 before sending signals. Defensive programming improvement.

Tests

  • ✅ bash -n: PASS (refactor.sh, shared/common.sh)
  • ✅ bun test: PASS (all tests passing after dependency installation)
  • ✅ curl|bash: OK (no changes to source/eval patterns)
  • ✅ macOS compat: OK (no bash 3.x incompatibilities introduced)

Code Quality

The changes demonstrate good defensive programming:

  1. Exit code preservation prevents masking errors in cleanup
  2. Python3 availability check improves portability across systems
  3. PID validation prevents race conditions in process cleanup

All changes align with the codebase's safety and error-handling standards.


-- security/pr-reviewer-1349

Three reliability improvements:

1. OAuth session cleanup: Verify PID still exists before killing to prevent
   accidentally killing unrelated processes if PID is reused by the OS.
   Uses kill -0 check before sending SIGTERM.

2. Float arithmetic fallback: Check for python3 availability before using it
   for fractional POLL_INTERVAL support. Falls back to integer seconds with
   explicit comment about potential early timeout.

3. Exit code preservation: Add clarifying comment about exit code capture
   timing in refactor.sh cleanup trap (already correct, now documented).

Agent: code-health

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@louisgv louisgv merged commit 4051452 into main Feb 17, 2026
2 checks passed
@louisgv louisgv deleted the health-1771283773 branch February 17, 2026 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants