unit-mesh / auto-dev

🧙‍AutoDev: The AI-powered coding wizard with multilingual support 🌐, auto code generation 🏗️, and a helpful bug-slaying assistant 🐞! Customizable prompts 🎨 and a magic Auto Dev/Testing/Document/Agent feature 🧪 included! 🚀
https://ide.unitmesh.cc/
Mozilla Public License 2.0
2.62k stars 303 forks source link

Agent回傳的 /write ,如果有指定行數會重複寫入 #177

Closed ymli0215 closed 2 months ago

ymli0215 commented 2 months ago

agent回傳/write 時,如果檔案後面加上#L1-L2 會變成 '''java ''' 內的內容會重複寫好幾次在檔案中

沒有#L1-L2就正常只寫一次

```devin
/write:src/main/java/com/ibmct/booking/business/sas/StockController.java#L1-L2

\`\`\`java
/*
* ===========================================================================
\`\`\`
```
phodal commented 2 months ago

如果只是上述的代码,我测试了一下,应该只会执行一次。估计,可能受什么代码影响 —— Agent 回传。

phodal commented 2 months ago

应该还是执行多次导致的,能提交一个复现的步骤吗。我这边除非手动点多次执行,要不无法复现。

ymli0215 commented 2 months ago

我目前測試起來,一樣的prompt,一樣的agent 剛開啟intellij的時候,就只寫一次 接著再跑一次相同的agent,就會重複寫了(這時候為了好分辨,我是把產生檔案的內容清空,再跳個幾行,比較清楚辨認)

感覺起來就像是前一次的資料還留著 跑第一次,就出現一次內容 跑第二次,會出現兩次內容 跑第三次,會出現三次內容 ...

phodal commented 2 months ago

应该是重复多次,执行的缘故。

ymli0215 commented 2 months ago

目前看起來是這樣,寫入資料的時候,intellij他會跳出 Writing to file:xxxx 的訊息 的確是執行多次就會跳出多次

ymli0215 commented 2 months ago

重複測試了一下,這應該就原本就有的問題 只是我加上了L1-L2這樣才比較明顯出現 原本沒有設定L1-L2,其實也是有重複執行,但是它就是取代整個檔案,所以就沒有感覺到重複的問題 但是intellij會跳出多個 Writing to file: 的訊息視窗,這其實就表示 WriteInsCommand 被執行多次

phodal commented 2 months ago

估计有可能是之前那个处理 Agent 返回继续处理引起的

ymli0215 commented 2 months ago

追蹤起來,好像是DevInsProgramRunner的

override fun runFinish(string: String, event: ProcessEvent, scriptPath: String) {
                environment.project.service<DevInsProcessProcessor>().process(string, event, scriptPath)
}

被執行好幾次....

這跟Agent的調整有關係嗎??

phodal commented 2 months ago

调用的地方应该是 DevInsRunConfigurationProfileState,看上去 processTerminated 被调用了多次?

ymli0215 commented 2 months ago

DevInsRunConfigurationProfileState的processTerminated只送了一次message 但是DevInsProgramRunner的connection.subscribe那邊收到多次message 因此觸發寫多次的寫入

我加了一個追蹤的參數來確認,DevInsProgramRunner收到的多次message都是由DevInsRunConfigurationProfileState發出來 ProcessEvent都是同一個...

phodal commented 2 months ago

你清空一下右下角的 idea 告警试试,我本地会出现一个错误:

java.lang.Exception: error when processing com.intellij.execution.process.ProcessEvent[source={processTerminatedListener=com.intellij.execution.process.ProcessTerminatedListener@325de1f6}] by class cc.unitmesh.devti.language.run.DevInsRunConfigurationProfileState$execute$1
    at com.intellij.execution.process.ProcessHandler$2.processTerminated(ProcessHandler.java:268)
    at com.intellij.execution.process.ProcessHandler.lambda$notifyTerminated$2(ProcessHandler.java:207)
    at com.intellij.execution.process.ProcessHandler$TasksRunner.execute(ProcessHandler.java:325)
    at com.intellij.execution.process.ProcessHandler.notifyTerminated(ProcessHandler.java:190)
    at com.intellij.execution.process.ProcessHandler.notifyProcessTerminated(ProcessHandler.java:186)
    at cc.unitmesh.devti.language.run.DevInsProcessHandler.detachProcessImpl(DevInsProcessHandler.kt:9)
    at com.intellij.execution.process.ProcessHandler.lambda$detachProcess$1(ProcessHandler.java:143)
    at com.intellij.execution.process.ProcessHandler$TasksRunner.execute(ProcessHandler.java:325)
    at com.intellij.execution.process.ProcessHandler.detachProcess(ProcessHandler.java:140)
    at cc.unitmesh.devti.language.run.DevInsRunConfigurationProfileState$agentRun$1$1.invokeSuspend(DevInsRunConfigurationProfileState.kt:152)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
Caused by: java.lang.RuntimeException: Cannot invoke (class=, method=runFinish, topic=DevInsRunListener)
    at com.intellij.util.messages.impl.MessageBusImplKt.invokeListener(MessageBusImpl.kt:677)
    at com.intellij.util.messages.impl.MessageBusImplKt.deliverMessage(MessageBusImpl.kt:423)
    at com.intellij.util.messages.impl.MessageBusImplKt.pumpWaiting(MessageBusImpl.kt:402)
    at com.intellij.util.messages.impl.MessageBusImplKt.access$pumpWaiting(MessageBusImpl.kt:1)
    at com.intellij.util.messages.impl.MessagePublisher.invoke(MessageBusImpl.kt:461)
    at jdk.proxy32/jdk.proxy32.$Proxy343.runFinish(Unknown Source)
    at cc.unitmesh.devti.language.run.DevInsRunConfigurationProfileState$execute$1.processTerminated(DevInsRunConfigurationProfileState.kt:57)
    at com.intellij.execution.process.ProcessHandler$2.processTerminated(ProcessHandler.java:262)
phodal commented 2 months ago

复现了,应该是 topic 没有 unsubscribe 导致的,只有多次执行 agent 才会出现。

ymli0215 commented 2 months ago

對 我剛剛也測試到這段,我是加了一個是否已經subscribe的判斷 如果有subscribe就不做原有的動作

phodal commented 2 months ago

哦,那我就不改了,你直接来 PR ?