Skip to content

Conversation

@DevelopmentCats
Copy link
Contributor

Description

Brings session resumption up to speed with current claude-code capabilities, and should make session resumption less prone to errors across the board.

I am still testing this further to ensure that all logic path's are verified.

Type of Change

  • New module
  • New template
  • Bug fix
  • Feature/enhancement
  • Documentation
  • Other

Module Information

Path: registry/coder/modules/claude-code
New version: v4.2.3
Breaking change: [ ] Yes [ ] No

Testing & Validation

  • Tests pass (bun test)
  • Code formatted (bun fmt)
  • Changes tested locally

Related Issues

Copilot AI review requested due to automatic review settings December 3, 2025 20:37
Copilot finished reviewing on behalf of DevelopmentCats December 3, 2025 20:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the session resumption logic for the claude-code module to simplify and improve reliability across both standalone and task modes. The changes remove the problematic remove-last-session-id.sh script that attempted to manage stale session data, replacing it with more robust session validation and detection functions directly in the start script.

Key changes:

  • Introduces three new helper functions (task_session_exists, is_valid_session, has_any_sessions) to improve session state detection
  • Simplifies the session resumption decision tree by consolidating conditional logic and removing external script dependencies
  • Adds comprehensive test coverage for edge cases like partial initialization, session validation, and mode-specific behavior

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
registry/coder/modules/claude-code/scripts/start.sh Refactored session resumption logic with new validation functions; removed dependency on external session cleanup script; simplified conditional branches for task vs standalone modes
registry/coder/modules/claude-code/scripts/remove-last-session-id.sh Removed entirely - session cleanup logic no longer needed with improved validation approach
registry/coder/modules/claude-code/main.tf Removed references to remove-last-session-id.sh script; updated local variables to remove unused script encoding
registry/coder/modules/claude-code/main.test.ts Added four new test cases for partial initialization detection, first build scenarios, session continuation, and task mode isolation; updated existing test to create valid JSONL session files with proper content
registry/coder/modules/claude-code/README.md Updated module version to 4.2.3 across all examples; updated version pins in examples (claude_code_version, agentapi_version, boundary_version); removed cli_app from standalone mode example

@DevelopmentCats
Copy link
Contributor Author

@matifali @35C4n0r this should solve all of the session resumption issues, if you guys can test this too that would be cool 😸

Copy link
Collaborator

@35C4n0r 35C4n0r left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


if [ -d "$project_dir" ] && find "$project_dir" -type f -name "*${TASK_SESSION_ID}*" 2> /dev/null | grep -q .; then
printf "TASK_SESSION_ID: %s file found\n" "$TASK_SESSION_ID"
if [ -d "$project_dir" ] && find "$project_dir" -name "*.jsonl" 2> /dev/null | grep -q .; then
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

The find command with -name "*.jsonl" will match all files recursively in subdirectories, not just direct children. If the project directory structure includes nested directories with .jsonl files, this could incorrectly report sessions that aren't actually valid Claude session files. Consider adding -maxdepth 1 to restrict the search to immediate children only: find "$project_dir" -maxdepth 1 -name "*.jsonl"

Suggested change
if [ -d "$project_dir" ] && find "$project_dir" -name "*.jsonl" 2> /dev/null | grep -q .; then
if [ -d "$project_dir" ] && find "$project_dir" -maxdepth 1 -name "*.jsonl" 2> /dev/null | grep -q .; then

Copilot uses AI. Check for mistakes.
Comment on lines +124 to +134
if ! head -3 "$session_file" | jq empty 2> /dev/null; then
printf "Session validation failed: invalid JSONL format, removing corrupt file\n"
rm -f "$session_file"
return 1
fi

# Check for minimum session content
# Valid sessions need at least 2 lines: initial message and first response
local line_count
line_count=$(wc -l < "$session_file")
if [ "$line_count" -lt 2 ]; then
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

[nitpick] The JSONL validation (line 124) is performed before checking the minimum line count (line 134). For files with only 1 line, head -3 will successfully validate that single line as valid JSON, passing validation, and then fail on the line count check. This ordering works correctly, but for efficiency, consider checking the line count before running jq to avoid unnecessary JSON parsing for files that are too short.

Copilot uses AI. Check for mistakes.
agent_id = coder_agent.example.id
workdir = "/home/coder"
install_claude_code = true
claude_code_version = "4.2.2"
Copy link
Member

Choose a reason for hiding this comment

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

Looks like the version bump script is not foolproof.

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.

3 participants