Skip to content

Commit 274f496

Browse files
author
Test User
committed
fix(session): address code review feedback
- Add init_session_tracking() call in main() before loop starts - Use literal escape codes for color in --reset-session output - Remove conditional in reset_session() to always create file - Remove unused old_session_id variable - Remove duplicate SESSION_EXPIRATION_SECONDS (keep in response_analyzer.sh) - Add clarifying comments for RALPH_SESSION_FILE vs CLAUDE_SESSION_FILE All 265 tests pass.
1 parent d3310d1 commit 274f496

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

ralph_loop.sh

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ CLAUDE_SESSION_FILE=".claude_session_id" # Session ID persistence file
3434
CLAUDE_MIN_VERSION="2.0.76" # Minimum required Claude CLI version
3535

3636
# Session management configuration (Phase 1.2)
37-
RALPH_SESSION_FILE=".ralph_session" # Ralph-specific session tracking
37+
# Note: SESSION_EXPIRATION_SECONDS is defined in lib/response_analyzer.sh (86400 = 24 hours)
38+
RALPH_SESSION_FILE=".ralph_session" # Ralph-specific session tracking (lifecycle)
3839
RALPH_SESSION_HISTORY_FILE=".ralph_session_history" # Session transition history
39-
SESSION_EXPIRATION_SECONDS=86400 # 24 hours in seconds
4040

4141
# Valid tool patterns for --allowed-tools validation
4242
# Tools can be exact matches or pattern matches with wildcards in parentheses
@@ -508,12 +508,8 @@ get_session_id() {
508508
reset_session() {
509509
local reason=${1:-"manual_reset"}
510510

511-
# Log the transition before clearing
512-
local old_session_id=$(get_session_id)
513-
514-
# Clear the session file
515-
if [[ -f "$RALPH_SESSION_FILE" ]]; then
516-
cat > "$RALPH_SESSION_FILE" << EOF
511+
# Always create/overwrite the session file to ensure consistent state
512+
cat > "$RALPH_SESSION_FILE" << EOF
517513
{
518514
"session_id": "",
519515
"created_at": "",
@@ -522,12 +518,9 @@ reset_session() {
522518
"reset_reason": "$reason"
523519
}
524520
EOF
525-
fi
526521

527522
# Also clear the Claude session file for consistency
528-
if [[ -f "$CLAUDE_SESSION_FILE" ]]; then
529-
rm -f "$CLAUDE_SESSION_FILE"
530-
fi
523+
rm -f "$CLAUDE_SESSION_FILE" 2>/dev/null
531524

532525
# Log the session transition
533526
log_session_transition "active" "reset" "$reason" "${loop_count:-0}"
@@ -896,7 +889,10 @@ main() {
896889
echo "Ralph projects should contain: PROMPT.md, @fix_plan.md, specs/, src/, etc."
897890
exit 1
898891
fi
899-
892+
893+
# Initialize session tracking before entering the loop
894+
init_session_tracking
895+
900896
log_status "INFO" "Starting main loop..."
901897
log_status "INFO" "DEBUG: About to enter while loop, loop_count=$loop_count"
902898

@@ -1107,7 +1103,7 @@ while [[ $# -gt 0 ]]; do
11071103
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
11081104
source "$SCRIPT_DIR/lib/date_utils.sh"
11091105
reset_session "manual_reset_flag"
1110-
echo -e "${GREEN}✅ Session state reset successfully${NC}"
1106+
echo -e "\033[0;32m✅ Session state reset successfully\033[0m"
11111107
exit 0
11121108
;;
11131109
--circuit-status)

0 commit comments

Comments
 (0)