Skip to content

Conversation

@rushilpatel0
Copy link
Contributor

Motivation

Content

Testing

Please check the following before marking your PR as ready for review

  • I have added tests for my changes
  • I have updated the documentation or added new documentation as needed

@rushilpatel0 rushilpatel0 requested review from a team and codegen-team as code owners August 19, 2025 19:14
@codecov
Copy link

codecov bot commented Aug 19, 2025

Codecov Report

❌ Patch coverage is 12.50000% with 7 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/codegen/cli/commands/claude/main.py 12.50% 7 Missing ⚠️

@rushilpatel0 rushilpatel0 merged commit 1678fa8 into develop Aug 19, 2025
17 of 18 checks passed
@rushilpatel0 rushilpatel0 deleted the rpatel/create-session-on-claude branch August 19, 2025 19:17

# Proactively create the backend session as a fallback in case hooks fail
try:
agent_run_id = create_claude_session(session_id, resolved_org_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Logic error: Potential duplicate session creation leading to multiple agent runs

The proactive create_claude_session call runs before hooks are installed, but the SessionStart hook also creates the session. This can cause duplicate sessions or noisy errors if the backend isn’t strictly idempotent on session_id.

Suggested change
agent_run_id = create_claude_session(session_id, resolved_org_id)
# Set up Claude hook for session tracking first
hook_ready = ensure_claude_hook()
if not hook_ready:
console.print("⚠️ Failed to set up session tracking hook", style="yellow")
# Fallback: proactively create the backend session only if hooks failed
try:
agent_run_id = create_claude_session(session_id, resolved_org_id)
if agent_run_id:
console.print("✅ Backend session created", style="green")
else:
console.print("⚠️ Could not create backend session at startup (will rely on hooks)", style="yellow")
except Exception as e:
console.print(f"⚠️ Session creation error at startup: {e}", style="yellow")

This preserves your fallback while avoiding duplicate creation when hooks succeed.

@codegen-sh
Copy link
Contributor

codegen-sh bot commented Aug 19, 2025

Found 0 critical and 1 important issue. Please review my inline comment above.

🔍 View my analysis: https://codegen.com/agent/trace/77640

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