Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ymli0215 opened this issue May 6, 2024 · 14 comments
Closed

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

ymli0215 opened this issue May 6, 2024 · 14 comments
Assignees

Comments

@ymli0215
Copy link
Contributor

ymli0215 commented May 6, 2024

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

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

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

\`\`\`java
/*
* ===========================================================================
\`\`\`
```
@phodal
Copy link
Member

phodal commented May 6, 2024

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

@phodal
Copy link
Member

phodal commented May 7, 2024

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

@ymli0215
Copy link
Contributor Author

ymli0215 commented May 7, 2024

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

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

@phodal
Copy link
Member

phodal commented May 7, 2024

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

@ymli0215
Copy link
Contributor Author

ymli0215 commented May 7, 2024

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

@ymli0215
Copy link
Contributor Author

ymli0215 commented May 7, 2024

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

@phodal
Copy link
Member

phodal commented May 7, 2024

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

@ymli0215
Copy link
Contributor Author

ymli0215 commented May 7, 2024

追蹤起來,好像是DevInsProgramRunner的

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

被執行好幾次....

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

@phodal
Copy link
Member

phodal commented May 7, 2024

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

@ymli0215
Copy link
Contributor Author

ymli0215 commented May 8, 2024

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

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

@phodal
Copy link
Member

phodal commented May 8, 2024

你清空一下右下角的 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 phodal self-assigned this May 8, 2024
@phodal
Copy link
Member

phodal commented May 8, 2024

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

@ymli0215
Copy link
Contributor Author

ymli0215 commented May 8, 2024

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

@phodal
Copy link
Member

phodal commented May 8, 2024

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

phodal added a commit that referenced this issue May 8, 2024
@phodal phodal closed this as completed May 8, 2024
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

No branches or pull requests

2 participants