Commit graph

157 commits

Author SHA1 Message Date
Codeflash Bot
0b87fa0e12 Refactor GitHub App installation error handling in code context hash endpoints. Introduced a dedicated assertion function to streamline error validation and improve logging for installation issues. 2026-04-28 15:55:21 +00:00
Codeflash Bot
8d19be486e Enhance error handling for GitHub App installation checks in code context hash endpoints. Added specific exceptions for installation not found and installation errors, improving logging and user guidance for installation issues. 2026-04-28 15:41:54 +00:00
Kevin Turcios
d7a8b8f227
perf: fix CI build + lazy-load heavy libs + parallelize DB queries (#2601)
## Summary
- **Fix CI build failure**: Auth0Client crashes during Next.js
prerendering when env vars aren't set. Returns a no-op stub (`getSession
→ null`) when domain is missing — semantically correct for static
generation
- **Lazy-load markdown libs (~260kb)**: ReactMarkdown, remarkGfm, and
react-syntax-highlighter were eagerly imported in monaco-diff-viewer but
only rendered when user expands "Generated Tests". Extracted into a
dynamic component
- **Parallelize repo detail query**: `getRepositoryById` ran the
activity count sequentially after the repo lookup. Since `repoId` is
already available, all three queries now run in parallel

## Test plan
- [ ] CI `build` check passes (was failing since #2598)
- [ ] Trace page still renders generated tests correctly when expanded
- [ ] Repository detail page loads correctly with activity status
2026-04-13 11:03:05 -05:00
Kevin Turcios
3b1398973e
perf: Sentry-driven optimizations across all services (#2593)
## Summary

Comprehensive performance and reliability fixes driven by Sentry trace
data and error monitoring across aiservice, cf-api, and cf-webapp.

### Error Reduction
- **UUID validation (1,459 errors/month)**: Add `normalize_trace_id()`
to handle EXP0/EXP1 experiment suffixes instead of crashing. Add
`validate_trace_id` checks to 4 endpoints that were missing them. Fix
bare `UUID()` call in `log_event.py` (960 errors/month). Return 400
instead of 500 for invalid trace IDs in `log_features`.
- **CodeValidationError (1,068 errors/month)**: Add `repair_preamble()`
to fix broken LLM-generated test preambles that were causing all tests
to be discarded. 9 new tests.

### Speed Improvements
- **create-pr (11.8s → ~6s)**: Parallelize auth lookups and
post-PR-creation work (DB updates + GitHub API calls) with
`Promise.all`.
- **apikeys LCP (5,084ms → ~2s)**: Replace 5 sequential client-side
server actions with a single server-side `getDashboardInitData()` that
runs queries in parallel. Context providers accept initial data props to
skip client fetches.
- **optimization-prs (7.2s → ~3s)**: Replace `LEFT JOIN COUNT` on huge
JSONB table with `EXISTS` semi-join. Add composite indexes on
`optimization_events` for org-scoped and user-scoped queries.

### Web Vitals
- **Dashboard CLS (2.114 → ~0)**: Add matching skeleton for
OptimizationPRsTable, add `min-h-[420px]` to prevent layout shift.
- **Onboarding LCP (11.9s → ~6s)**: Reduce intro animation from 2400ms
to 1200ms, add `optimizePackageImports` for 12 heavy packages.
- **Trace page CLS (0.463 → ~0)**: Add `flex-shrink-0` to Monaco diff
viewer headers.
- Lazy-load Intercom/Crisp scripts, swap font display, reduce font
weights.

### Files Changed (19)
**aiservice (8):** common_utils.py, optimization_review.py,
code_validator.py, log_event.py, log_features.py, repair.py, review.py,
test_validate_code.py
**cf-api (1):** create-pr.ts
**cf-webapp (9):** layout.tsx, init-data-action.ts,
PrivacyModeContext.tsx, ViewModeContext.tsx, sidebar.tsx,
conditional-layout.tsx, action.ts, OptimizationPRsTable.tsx,
OptimizationsTable.tsx
**common (1):** schema.prisma

## Test plan
- [ ] Run aiservice tests: `cd django/aiservice && uv run pytest
tests/testgen_postprocessing/test_validate_code.py -v`
- [ ] Run aiservice type check: `cd django/aiservice && uv run mypy .`
- [ ] Verify cf-webapp builds: `cd js/cf-webapp && npm run build`
- [ ] Verify cf-api builds: `cd js/cf-api && npm run build`
- [ ] Run Prisma migration for new composite indexes
- [ ] Verify dashboard loads without CLS regression
- [ ] Verify create-pr endpoint still works end-to-end
- [ ] Monitor Sentry for UUID and CodeValidationError reduction after
deploy

---------

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
2026-04-10 15:39:44 -05:00
Aseem Saxena
960401e2d4
Merge branch 'main' into add/close_pr_end_point 2026-03-18 12:08:35 -07:00
Sarthak Agarwal
7deb16819e
[Fix] Suppress slack for codeflash employees (#2466)
Co-authored-by: Aseem Saxena <aseem.bits@gmail.com>
Co-authored-by: Kevin Turcios <106575910+KRRT7@users.noreply.github.com>
2026-03-08 02:54:32 +05:30
Sarthak Agarwal
2cb3d51ddb
fix issue with closed and merged PRs raising suggestion (#2436) 2026-02-21 01:23:55 +05:30
HeshamHM28
ad1cb9f032
[Fix] Fallback to staging if we fail to create PR (#2332)
Fixes CF-1037
2026-02-09 20:08:47 +02:00
HeshamHM28
1e8010c1ce fix tests 2026-01-29 18:40:45 +02:00
Sarthak Agarwal
a7b9333321
Merge branch 'main' into add/close_pr_end_point 2026-01-28 22:15:28 +05:30
HeshamHM28
f909642ce1
feat: Add Line Profiler visualization to webapp (#2268)
## Summary
Adds a line-by-line performance profiler visualization to the webapp,
allowing users to compare execution times between original and optimized
code.

  ## Changes

  ### New Line Profiler View
- **`LineProfilerView.tsx`**: Side-by-side comparison component showing:
    - Line-by-line execution times with heat map visualization
    - Syntax highlighting using `prism-react-renderer`
    - Collapsible function blocks
    - Light/dark mode support
    - Heat legend (cold → hot based on % time)

- **`lineProfilerParser.ts`**: Parser utilities for line profiler data:
- `parseLineProfilerResults()` - parses markdown table output from
Python's line_profiler
- `formatTime()` - converts timer units to human-readable format (ns,
µs, ms, s)
    - `getHeatLevel()` - determines heat coloring based on % time

- **`/review-optimizations/[traceId]/profiler/page.tsx`**: New route for
the profiler view

  ### API Changes
- **`create-pr.ts`**: Adds "📊 Performance Profile" link to PR
description when profiler data exists
- **`github-app.ts`**: Removes line profiler data from metadata when PR
is closed/merged
- **`create-staging.ts`**, **`suggest-pr-changes.ts`**: Handle line
profiler data in staging
- **`staging-storage-strategy.ts`**: Interface updates for line profiler
fields

  ### Webapp Integration
- **`page.tsx`**: Added "Performance Profile" button (only visible when
profiler data exists)
- **`action.ts`**: Sends line profiler data when creating PR from webapp
  Fixes CF-1018
  


https://codeflash-ai.slack.com/files/U08MSR1UN6L/F0A9YVDJY75/screen_recording_2026-01-21_at_10.03.18___pm.mov
https://github.com/HeshamHM28/my-best-repo/pull/21

linked to https://github.com/codeflash-ai/codeflash/pull/1139

---------

Co-authored-by: Aseem Saxena <aseem.bits@gmail.com>
2026-01-28 08:36:54 -08:00
Sarthak Agarwal
dd4510b254 new endpoint for close pr 2026-01-28 16:47:43 +05:30
HeshamHM28
548fcacff7
refactor: remove roboflow repository check from suggestPrChanges and … (#2311)
## Summary
- Remove the hardcoded check that blocked PR suggestions for roboflow
repositories
- Remove the corresponding unit test that validated the roboflow
restriction
2026-01-26 17:15:45 -08:00
HeshamHM28
11532147ea
fix: improve review comment handling for single and multi-line changes in suggestPrChanges (#2309)
Fixes CF-967
samples https://github.com/codeflash-ai/my-best-repo/pull/461 
  ## Summary
- Fix review comment creation to properly handle single-line changes by
only
  using `line` parameter (without `start_line`)
  - Fix condition to allow single-line hunks where `oldStart === oldEnd`
  (changed from `<` to `<=`)
2026-01-26 21:20:16 +05:30
HeshamHM28
45e22e0f94
Cf-api Refactor (#2131)
Fixes CF-833
2026-01-19 23:03:57 +05:30
HeshamHM28
60a3c0694c
[FEAT] Privacy Mode (#2092)
Fixes CF-690

  Pull Request Checklist

  Description

  - Description of PR:

  Privacy Mode Feature for Pro Users

This PR introduces a Privacy Mode feature that allows paid users
(Pro/Enterprise) to control how their code is stored during the
optimization review process.

  Key Changes:

  1. Privacy Mode Toggle in Sidebar
    - Added a new toggle in the dashboard sidebar for Privacy Mode
- Only available for Pro/Enterprise users (disabled with upgrade prompt
for free users)
- Persists user preference in database with localStorage fallback for
fast UI
  2. Storage Strategy Based on Privacy Setting
- Privacy Mode ON: Code is stored exclusively in GitHub branches (never
cached in database)
- Privacy Mode OFF: Code is temporarily cached in database for faster
loading, cleaned up when PR is created
  3. Database Changes
    - Added privacy_mode boolean field to users table (default: false)
    - Added staging_storage_type field to track storage method
  4. API Updates
- cf-api now checks user's privacy mode when determining storage
strategy
- StagingStorageStrategyFactory considers privacy mode alongside tier
eligibility
- Added getUserPrivacyMode, setUserPrivacyMode, and isUserPaid functions


  User Experience

  - Free users see the toggle disabled with "Upgrade to Pro" messaging
  - Tooltip explains the trade-off: privacy vs. loading speed
- Toggle state syncs between localStorage (for instant UI) and database
(for persistence)

  Storage Flow

  User Request → Check Privacy Mode
├─ Privacy ON + Paid + Valid Repo → Git Branch Storage (GitHub only)
      └─ Privacy OFF or Free → Plain Text Storage (Database cache)

---------

Co-authored-by: ali <mohammed18200118@gmail.com>
Co-authored-by: Mohamed Ashraf <ashraf@codeflash.ai>
2026-01-07 12:23:45 -08:00
Kevin Turcios
a7c0d896b7
Merge branch 'main' into cf-webapp/add--prs-list-on-dashboard 2026-01-06 18:03:16 -05:00
Mohamed Ashraf
ffa2224a24 git commit -m "fix: resolve merge conflicts with main branch" 2026-01-06 18:45:55 +02:00
mashraf-222
d0d2fb6fc6
Merge branch 'main' into disable-telemetry-flag-dev 2026-01-06 18:01:31 +02:00
HeshamHM28
e28d968fad
[CHORE] add trace_id to the pull request description comment (#2190)
Fixes cf-975
output:
https://github.com/HeshamHM28/my-best-repo/pull/15
2026-01-06 00:15:48 +00:00
Mohamed Ashraf
568b70a609 add telemetry flag to be disabled in dev 2025-12-31 02:29:06 +02:00
Mohamed Ashraf
7e9bc74237 FIX create PR test after update 2025-12-26 18:14:48 +02:00
Mohamed Ashraf
375d968d25 Add speedup value parsing and optimize update logic in create-pr and suggest-pr-changes endpoints
- Introduced a helper function to parse speedup values consistently across both endpoints.
- Enhanced the update logic to check for existing data before adding new optimization details, preserving staging data.
- Updated the `updateOptimizationEvent` function to accept `prCommentFields` for more granular updates based on provided data.
2025-12-24 16:59:17 +02:00
Mohamed Ashraf
16d71b9153 If the requested base branch reference returns 404, fetch the repository info to fallback to the default branch 2025-12-18 13:15:11 +02:00
Mohamed Ashraf
f3c04ae5ff update the PR body 2025-12-16 17:03:45 +02:00
Mohamed Ashraf
b1d9381f51 remove depricated endpoint 2025-12-16 12:53:16 +02:00
Mohamed Ashraf
04cf698845 adding installation_url target for github app 2025-12-16 12:41:53 +02:00
Mohamed Ashraf
46e98e9c3f revert the secret cf api key while setup of github workflow file 2025-12-16 11:24:50 +02:00
mashraf-222
b85ff4a5c2
adding global exception handler and logger for dev and production (#1927)
Co-authored-by: HeshamHM28 <HeshamMohamedFathy@outlook.com>
Co-authored-by: Sarthak Agarwal <sarthak.saga@gmail.com>
2025-12-15 21:32:20 +05:30
mashraf-222
d4ddff44df
Github action setup with PR for CLI user (#2009)
Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com>
Co-authored-by: Kevin Turcios <106575910+KRRT7@users.noreply.github.com>
2025-12-08 23:18:13 +05:30
Aseem Saxena
a22153572f todo 2025-11-24 17:03:25 -08:00
HeshamHM28
977aa9c212
[Chore] Add staging link to PR comment (#2001)
Fixes CF-764
Description:
This PR checks if the optimization is medium. If yes, it creates a
staging PR; if not, it creates a dependent PR.

How to test:
	1.	Open Insomnia.
2. Try hitting the “Suggest PR” endpoint with medium and high
optimizationReview.
	•	For high, it should create a dependent PR.
• For medium, it should create a staging PR and comment on the original
PR.https://github.com/codeflash-ai/my-best-repo/pull/437#issuecomment-3518024107

---------

Co-authored-by: Aseem Saxena <aseem.bits@gmail.com>
Co-authored-by: Sarthak Agarwal <sarthak.saga@gmail.com>
2025-11-19 13:39:02 -08:00
HeshamHM28
0f6ecb8e16 Merge branch 'main' into feat/allow-user-change-base-branch 2025-11-10 16:00:43 +02:00
HeshamHM28
333a5dbc43 Remove getBranches endpoint 2025-11-10 14:59:40 +02:00
HeshamHM28
48f2d15ded
[Fix] Create staging Broken access (#1835)
Co-authored-by: Kevin Turcios <106575910+KRRT7@users.noreply.github.com>
Co-authored-by: Sarthak Agarwal <sarthak.saga@gmail.com>
2025-10-31 16:28:15 -07:00
HeshamHM28
b1584a5d12
[Feat] Organization (#1888)
## Organization Feature

This PR introduces a new **Organization** feature that allows users to:
- Create organizations and add members  
- Manage repositories within organizations  
- Allow organization members to access and view shared repository data  

---

##  How to Test

### 1. Setup
- Apply the latest **database migrations**.  
- Build the **common** package, then **pack** and **install** it in
both:
  - `cf-webapp`
  - `cf-api`

### 2. Create an Organization
- You can create an organization **manually** in the database, **or**
- Use the **GitHub webhook** to add it automatically.

### 3. Test Scenarios
Prepare the following:
- **Two users:**
  - **User A** – has access to the organization and its repositories.
  - **User B** – a regular user.
- **Two repositories:**
  - One under the **organization**.
  - One under **User A’s personal account**.

### 4. Verification Steps
1. Log in to **cf-webapp** as **User A**.  
2. Confirm both the **personal account** and **organization** appear.  
3. Try optimizing code and ensure **statistics** display correctly.  
4. Switch between **personal** and **organization** accounts to verify
data accuracy.
5. From the **personal account**:
   - Open a specific repository.  
   - Add a new member by **GitHub username**.  
   - Log in as that member (**User B**) and verify access.  
6. From the **organization**:
   - Add members to the organization by **GitHub username**.  
- Log in as the added member and confirm they have access to
organization repositories.
- Update the member’s **role** and ensure changes are applied correctly.

---

---------

Co-authored-by: ali <mohammed18200118@gmail.com>
Co-authored-by: Sarthak Agarwal <sarthak.saga@gmail.com>
2025-10-29 13:05:40 -07:00
Aseem Saxena
6f25848185
Add optimization review badge to dependent pr comment and pr comment body (#1938)
Co-authored-by: Sarthak Agarwal <sarthak.saga@gmail.com>
2025-10-29 00:22:41 -07:00
HeshamHM28
5015a6b114 Refactor getBranches endpoint to remove pagination parameters and simplify branch listing logic 2025-10-27 14:57:53 +03:00
HeshamHM28
75b14c9ac8 Add getBranches endpoint 2025-10-27 14:39:41 +03:00
HeshamHM28
2bce026cfc Add branch existence check and pagination for listing branches in GitHub 2025-10-27 14:39:23 +03:00
Aseem Saxena
797e184e82
correct payload with optimization review info for approval pr / dependent pr creation (#1930) 2025-10-24 16:56:25 -07:00
Aseem Saxena
184bffbd8f
Feat/add optimization review details (#1910)
Co-authored-by: HeshamHM28 <HeshamMohamedFathy@outlook.com>
Co-authored-by: Sarthak Agarwal <sarthak.saga@gmail.com>
2025-10-21 22:06:12 -07:00
mashraf-222
445e2830f2
Bypass approval mechanism if request comes from cf-webapp (#1909)
- Added source parameter to track request origin to bypass approval
logic for source === "webapp"
- Also I saw that we have `dependencies.requiresApproval(owner, repo)`
so I used it

---------

Co-authored-by: Mohamed Ashraf <mohamedashrraf222@gmail.com>
Co-authored-by: Sarthak Agarwal <sarthak.saga@gmail.com>
2025-10-20 17:27:44 -07:00
Sarthak Agarwal
007b077b53
Add error logging and fix multiple errors (#1905)
Co-authored-by: saga4 <saga4@codeflashs-MacBook-Air.local>
2025-10-17 22:41:59 -07:00
HeshamHM28
37dbe55316
[Feat] add Create PR sentry logs (#1899)
Co-authored-by: Sarthak Agarwal <sarthak.saga@gmail.com>
2025-10-17 15:53:31 -07:00
Aseem Saxena
2082998386
Different UX for Optimization Impact (#1886)
At the moment, show it only for single hunk existing PR comments.
Changes made in a way to ensure ease in adding for new PRs too. Details
of optimization hidden from user at the moment.

---------

Co-authored-by: HeshamHM28 <HeshamMohamedFathy@outlook.com>
2025-10-14 17:43:07 -07:00
HeshamHM28
8fe910ba73
Fix PR creation: approval handling, error mapping, and save logic (#1873)
1. Allowed refresh token by adding scope permission and using
getAccessToken with force refresh.
2. Fixed approval and save logic by checking if the user is a member of
a repo.
	3.	Mapped errors correctly by creating type templates.
How to Test:
	1.	Manually add the user as a member of a repository.
2. Log in with this user and check if you can approve or save code and
access the repository.

---------

Co-authored-by: Sarthak Agarwal <sarthak.saga@gmail.com>
2025-10-09 11:59:07 -07:00
Aseem Saxena
3a54fa9487 fix test 2025-10-07 00:21:18 -07:00
aseembits93
2d2a6c38da bug fixes 2025-10-03 12:37:34 -07:00
aseembits93
126e1210aa almost ready 2025-09-30 10:40:41 -07:00