Skip to content

Prod fixes#68

Merged
khaliqgant merged 5 commits intomainfrom
prod-fixes
Jan 5, 2026
Merged

Prod fixes#68
khaliqgant merged 5 commits intomainfrom
prod-fixes

Conversation

@khaliqgant
Copy link
Copy Markdown
Member

@khaliqgant khaliqgant commented Jan 5, 2026

Summary

Production fixes for routing issues and WebSocket stability.

1. Fix /api/repos/accessible and /api/repos/search returning 404

Problem: Express was matching /accessible and /search as the :id parameter in the /:id wildcard route, returning 404.

Solution: Moved specific routes (/accessible, /search) before the /:id wildcard in repos.ts. Added clear comment marking the wildcard routes section.

Files: src/cloud/api/repos.ts

2. Fix user presence constantly flipping online/offline

Problem: Users were rapidly cycling between online/offline status every second.

Root cause: In App.tsx, the currentUser object passed to usePresence was recreated on every render, causing callbacks to be recreated and effects to re-run (disconnect/reconnect).

Solution:

  • Memoized the presenceUser object in App.tsx using useMemo
  • Refactored usePresence hook to use refs instead of direct state in callbacks

Files: src/dashboard/react-components/App.tsx, src/dashboard/react-components/hooks/usePresence.ts

3. Fix /api/workspaces/:id/members and /api/invites returning 404

Problem: teamsRouter was mounted at /api/teams, but its routes define full paths like /workspaces/:workspaceId/members.

Solution: Changed mount path from /api/teams to /api.

Files: src/cloud/server.ts

4. Connected providers checkmarks on onboarding page

Shows checkmarks next to already-authenticated providers.

Files: src/dashboard/app/app/page.tsx

Test plan

  • Verify /api/repos/accessible returns repository list
  • Verify /api/repos/search?q=test returns search results
  • Verify user presence is stable (no rapid online/offline cycling)
  • Verify /api/workspaces/:id/members returns member list
  • Verify /api/invites returns pending invitations

🤖 Generated with Claude Code

khaliqgant and others added 5 commits January 5, 2026 23:51
- Move /accessible and /search routes before /:id wildcard in repos.ts
  to prevent Express matching them as :id parameter (fixes 404)
- Add clear comment marking wildcard routes section
- Memoize presenceUser object in App.tsx to prevent new object on each render
- Refactor usePresence hook to use refs instead of direct state in callbacks
  to prevent reconnection loops (fixes constant online/offline flapping)
- Add connected providers checkmarks to onboarding page

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…invites

The teamsRouter has routes like /workspaces/:workspaceId/members and /invites
but was mounted at /api/teams, making them inaccessible at the expected paths.
Changed mount from /api/teams to /api so routes work correctly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Changed billing routes from checking req.session.user (doesn't exist) to
  req.session.userId with DB lookup
- Added stripeCustomerId column to users table
- Added migration 0008_stripe_customer_id for the new column
- Updated all billing routes: subscription, checkout, portal, change,
  cancel, resume, invoices, upcoming

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Consolidate settings to use only SettingsPage (which has Billing tab)
instead of having two separate settings panels.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@khaliqgant khaliqgant requested a review from Copilot January 5, 2026 23:21
Copy link
Copy Markdown

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 fixes critical production issues affecting routing, WebSocket stability, and database schema updates for billing integration.

Key Changes:

  • Fixed Express route matching issues causing 404 errors for specific API endpoints
  • Resolved WebSocket reconnection loops by memoizing user objects and using refs in hooks
  • Updated database schema to support Stripe customer IDs for billing

Reviewed changes

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

Show a summary per file
File Description
src/cloud/api/repos.ts Relocated /accessible and /search routes before wildcard /:id route to fix 404 errors
src/cloud/server.ts Changed teams router mount point from /api/teams to /api to match route definitions
src/dashboard/react-components/hooks/usePresence.ts Refactored to use refs instead of direct state dependencies to prevent reconnection loops
src/dashboard/react-components/App.tsx Memoized presence user object to prevent unnecessary re-renders and WebSocket reconnections
src/dashboard/app/app/page.tsx Added connected provider checkmarks on onboarding page
src/cloud/db/schema.ts Added stripeCustomerId column to users table
src/cloud/db/migrations/* Migration files for adding Stripe customer ID and dropping SSH fields
src/cloud/api/billing.ts Updated billing endpoints to use database-stored user data instead of session
.trajectories/* Trajectory tracking files for completed work
Comments suppressed due to low confidence (1)

src/cloud/db/migrations/0008_stripe_customer_id.sql:1

  • The migration drops SSH-related columns from workspaces table, but the migration name only references 'stripe_customer_id'. Consider either splitting this into separate migrations or updating the migration name to reflect all changes (e.g., '0008_add_stripe_customer_id_drop_ssh').
ALTER TABLE "users" ADD COLUMN "stripe_customer_id" varchar(255);--> statement-breakpoint

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const typingTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const isConnectingRef = useRef(false); // Prevent race conditions
const currentUserRef = useRef(currentUser);
currentUserRef.current = currentUser; // Keep ref in sync with prop
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

The ref initialization and update are separated, which could lead to subtle bugs. Consider moving the ref declaration closer to where it's used (around line 276) or adding a comment explaining why it's declared early but also updated later in the hook.

Suggested change
currentUserRef.current = currentUser; // Keep ref in sync with prop
// Keep a mutable reference to the latest `currentUser` so that callbacks
// defined later in this hook (e.g. the WebSocket connect handler) can read
// the up-to-date value without needing to be recreated on every render.
currentUserRef.current = currentUser;

Copilot uses AI. Check for mistakes.
{/* Special expanded section for Codex with CLI auth flow */}
{provider.id === 'codex' ? (
<div className="p-4 bg-bg-tertiary rounded-xl border border-border-subtle space-y-4">
<div className={`p-4 bg-bg-tertiary rounded-xl border space-y-4 ${connectedProviders.includes(provider.id) || connectedProviders.includes('openai') ? 'border-green-500/50' : 'border-border-subtle'}`}>
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

The condition connectedProviders.includes('openai') appears twice in this file (lines 551, 558-559, 570, 575, and 604) specifically for the 'codex' provider. This hardcoded relationship between codex and openai should be extracted into a helper function or constant to improve maintainability and make the relationship explicit.

Copilot uses AI. Check for mistakes.
@khaliqgant khaliqgant merged commit bd45d41 into main Jan 5, 2026
6 checks passed
@khaliqgant khaliqgant deleted the prod-fixes branch January 5, 2026 23:24
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