Skip to content

Commit 4a7e8f1

Browse files
gasolimagasser-mamdouhmanodnyab
authored
fix(AmazonQ FeatureDev): throws an error when the repo is bigger than 200 MB (#4471)
Problem: Backend can't handle repo size larger than 200 MB Solution: Throws an error to give the user better experience Co-authored-by: Gasser <gasser.mamdouh1@gmail.com> Co-authored-by: manodnyab <66754471+manodnyab@users.noreply.github.com>
1 parent d6ae1b2 commit 4a7e8f1

File tree

6 files changed

+31
-12
lines changed

6 files changed

+31
-12
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Amazon Q Feature Development: Update error message when repo size larger than 200 megabytes"
4+
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/FeatureDevConstants.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ const val CODE_GENERATION_RETRY_LIMIT = 3
1313

1414
// The default retry limit used when the session could not be found
1515
const val DEFAULT_RETRY_LIMIT = 0
16+
17+
// Max allowed size for a repository in bytes
18+
const val MAX_PROJECT_SIZE_BYTES: Long = 200 * 1024 * 1024

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/FeatureDevExceptions.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33

44
package software.aws.toolkits.jetbrains.services.amazonqFeatureDev
55

6+
import software.aws.toolkits.jetbrains.services.amazonq.RepoSizeError
67
import software.aws.toolkits.resources.message
78

89
open class FeatureDevException(override val message: String?, override val cause: Throwable? = null) : RuntimeException()
910

10-
class ContentLengthError(override val message: String, override val cause: Throwable?) : RuntimeException()
11+
class ContentLengthError(override val message: String, override val cause: Throwable?) : RepoSizeError, RuntimeException()
1112

1213
class PlanIterationLimitError(override val message: String, override val cause: Throwable?) : RuntimeException()
1314

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/controller/FeatureDevController.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ import software.aws.toolkits.core.utils.getLogger
2525
import software.aws.toolkits.core.utils.info
2626
import software.aws.toolkits.core.utils.warn
2727
import software.aws.toolkits.jetbrains.core.coroutines.EDT
28+
import software.aws.toolkits.jetbrains.services.amazonq.RepoSizeError
2829
import software.aws.toolkits.jetbrains.services.amazonq.apps.AmazonQAppInitContext
2930
import software.aws.toolkits.jetbrains.services.amazonq.auth.AuthController
3031
import software.aws.toolkits.jetbrains.services.amazonq.toolwindow.AmazonQToolWindowFactory
3132
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.CodeIterationLimitError
32-
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.ContentLengthError
3333
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.DEFAULT_RETRY_LIMIT
3434
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.FEATURE_NAME
3535
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.InboundAppMessagesHandler
@@ -435,7 +435,7 @@ class FeatureDevController(
435435
}
436436
} catch (err: Exception) {
437437
logger.warn(err) { "Encountered ${err.message} for tabId: $tabId" }
438-
if (err is ContentLengthError) {
438+
if (err is RepoSizeError) {
439439
messenger.sendError(
440440
tabId = tabId,
441441
errMessage = err.message,

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/session/Session.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import software.aws.toolkits.jetbrains.services.amazonq.FeatureDevSessionContext
99
import software.aws.toolkits.jetbrains.services.amazonq.messages.MessagePublisher
1010
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.APPROACH_RETRY_LIMIT
1111
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.CODE_GENERATION_RETRY_LIMIT
12+
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.MAX_PROJECT_SIZE_BYTES
1213
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.clients.FeatureDevClient
1314
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.conversationIdNotFound
1415
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.messages.sendAsyncEventProgress
@@ -39,7 +40,7 @@ class Session(val tabID: String, val project: Project) {
3940
var isAuthenticating: Boolean
4041

4142
init {
42-
context = FeatureDevSessionContext(project)
43+
context = FeatureDevSessionContext(project, MAX_PROJECT_SIZE_BYTES)
4344
proxyClient = FeatureDevClient.getInstance(project)
4445
featureDevService = FeatureDevService(proxyClient, project)
4546
_state = ConversationNotStartedState("", tabID)

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/FeatureDevSessionContext.kt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ import java.util.zip.ZipOutputStream
3131
import kotlin.io.path.Path
3232
import kotlin.io.path.relativeTo
3333

34-
class FeatureDevSessionContext(val project: Project) {
34+
interface RepoSizeError {
35+
val message: String
36+
}
37+
class RepoSizeLimitError(override val message: String) : RuntimeException(), RepoSizeError
38+
39+
class FeatureDevSessionContext(val project: Project, val maxProjectSizeBytes: Long? = null) {
3540
// TODO: Need to correct this class location in the modules going further to support both amazonq and codescan.
3641

3742
private val ignorePatterns = setOf(
@@ -92,16 +97,23 @@ class FeatureDevSessionContext(val project: Project) {
9297

9398
suspend fun zipFiles(projectRoot: VirtualFile): File = withContext(getCoroutineBgContext()) {
9499
val files = mutableListOf<VirtualFile>()
100+
var totalSize: Long = 0
101+
95102
VfsUtil.visitChildrenRecursively(
96103
projectRoot,
97104
object : VirtualFileVisitor<Unit>() {
98105
override fun visitFile(file: VirtualFile): Boolean {
99-
if (file.isFile) {
106+
val isFileIgnored = runBlocking { ignoreFile(file, this) }
107+
if (file.isFile && !isFileIgnored) {
108+
totalSize += file.length
100109
files.add(file)
110+
111+
if (maxProjectSizeBytes != null && totalSize > maxProjectSizeBytes) {
112+
throw RepoSizeLimitError(message("amazonqFeatureDev.content_length.error_text"))
113+
}
101114
return true
102-
}
103-
return runBlocking {
104-
!ignoreFile(file, this)
115+
} else {
116+
return !isFileIgnored
105117
}
106118
}
107119
}
@@ -113,9 +125,7 @@ class FeatureDevSessionContext(val project: Project) {
113125
files.chunked(50).forEach { chunk ->
114126
launch {
115127
for (file in chunk) {
116-
if (file.isFile && !ignoreFile(file, this)) {
117-
send(file)
118-
}
128+
send(file)
119129
}
120130
}
121131
}

0 commit comments

Comments
 (0)