Skip to content

ADFA-2081 | Force Gradle sync when project cache is missing#655

Closed
jatezzz wants to merge 1 commit into
stagefrom
fix/ADFA-2081-force-sync-on-cache-miss
Closed

ADFA-2081 | Force Gradle sync when project cache is missing#655
jatezzz wants to merge 1 commit into
stagefrom
fix/ADFA-2081-force-sync-on-cache-miss

Conversation

@jatezzz
Copy link
Copy Markdown
Collaborator

@jatezzz jatezzz commented Nov 21, 2025

Description

This PR updates the project initialization flow to automatically trigger a Gradle sync when the project cache file is missing. This prevents initialization failures and ensures the IDE can recover gracefully without manual user intervention.

Details

The previous behavior treated the missing cache as a fatal error. Now, a forced initializeProject(true) is executed on the main thread, allowing the Gradle Tooling server to regenerate the required cache.

Screen.Recording.2025-11-21.at.4.57.42.PM.mov

Ticket

ADFA-2081

Observation

This improves robustness when opening newly created or externally modified projects.

prevents initialization failure by re-triggering project sync
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Nov 21, 2025

Greptile Overview

Greptile Summary

Changed project initialization error handling to automatically retry with forced Gradle sync when cache read fails, instead of showing error to user.

Key Changes:

  • Removed postProjectInit(false, CACHE_READ_ERROR) call that displayed error message
  • Added initializeProject(forceSync=true) retry when readGradleBuild() fails
  • Removed Sentry.captureException() call for cache read failures

Critical Issues:

  • Infinite recursion risk if forced sync succeeds but cache read continues to fail
  • Lost error telemetry by removing Sentry exception capture

Confidence Score: 1/5

  • This PR has critical regression risk due to infinite recursion potential
  • Score reflects two critical issues: (1) infinite recursion if cache read continues failing after forced sync, as onProjectInitialized will repeatedly call initializeProject(forceSync=true) with no retry limit, and (2) removed error tracking violates monitoring policy
  • ProjectHandlerActivity.kt:556 requires recursion protection before merge

Important Files Changed

File Analysis

Filename Score Overview
app/src/main/java/com/itsaky/androidide/activities/editor/ProjectHandlerActivity.kt 1/5 Changed cache read failure from error state to retry via forced sync. Critical infinite recursion risk and removed Sentry error tracking

Sequence Diagram

sequenceDiagram
    participant Activity as ProjectHandlerActivity
    participant Manager as ProjectManagerImpl
    participant BuildService as GradleBuildService
    
    Note over Activity: Initial project open
    Activity->>Activity: initializeProject(forceSync=false)
    Activity->>BuildService: initializeProject(needsSync)
    BuildService-->>Activity: InitializeResult.Success
    Activity->>Activity: onProjectInitialized()
    Activity->>Manager: readGradleBuild()
    
    alt Cache file exists
        Manager-->>Activity: Success(GradleBuild)
        Activity->>Manager: setup(gradleBuild)
        Activity->>Activity: postProjectInit(true)
    else Cache file missing
        Manager-->>Activity: Failure(error)
        Activity->>Activity: initializeProject(forceSync=true)
        Note over Activity: RISK: If cache still fails,<br/>infinite recursion occurs
        Activity->>BuildService: initializeProject(needsSync=true)
        BuildService-->>Activity: InitializeResult.Success
        Activity->>Activity: onProjectInitialized()
        Activity->>Manager: readGradleBuild()
        Note over Activity: Loop continues if cache<br/>read still fails
    end
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

}

withContext(Dispatchers.Main) { postProjectInit(false, CACHE_READ_ERROR) }
withContext(Dispatchers.Main) { initializeProject(forceSync = true) }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

logic: infinite recursion risk: if forced sync succeeds but cache read still fails, onProjectInitialized will call initializeProject(forceSync=true) again, creating infinite loop. need retry counter or max attempts check

Suggested change
withContext(Dispatchers.Main) { initializeProject(forceSync = true) }
// Prevent infinite retry loop - only retry once
if (forceSync) {
withContext(Dispatchers.Main) { postProjectInit(false, CACHE_READ_ERROR) }
} else {
withContext(Dispatchers.Main) { initializeProject(forceSync = true) }
}

@@ -552,11 +552,8 @@ abstract class ProjectHandlerActivity : BaseEditorActivity() {
if (gradleBuildResult.isFailure) {
val error = gradleBuildResult.exceptionOrNull()
log.error("Failed to read project cache", error)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

logic: removed error tracking: exception is no longer captured with Sentry.captureException(). cache read failures won't be tracked for monitoring

Context Used: Rule from dashboard - Use Sentry.captureException() to capture exceptions for error tracking and monitoring. (source)

@jatezzz jatezzz requested review from a team, Daniel-ADFA and itsaky-adfa November 21, 2025 22:26
@itsaky-adfa
Copy link
Copy Markdown
Contributor

DO NOT MERGE. This conflicts with #648

Copy link
Copy Markdown
Contributor

@dara-abijo-adfa dara-abijo-adfa left a comment

Choose a reason for hiding this comment

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

Check Greptile's comment about the infinite recursion risk.

@jatezzz
Copy link
Copy Markdown
Collaborator Author

jatezzz commented Nov 24, 2025

This PR will be closed, as it's a duplicate of #648

@jatezzz jatezzz closed this Nov 24, 2025
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