Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix: bound OpenCode pending part flushes

Cursor Agentf68eb343eaa4
diff --git a/cli/beacon/internal/endpoint/hooks/assets/opencode/beacon.ts b/cli/beacon/internal/endpoint/hooks/assets/opencode/beacon.ts
index e107aca0..ca19640c 100644
--- a/cli/beacon/internal/endpoint/hooks/assets/opencode/beacon.ts
+++ b/cli/beacon/internal/endpoint/hooks/assets/opencode/beacon.ts
@@ -200,7 +200,7 @@ export const BeaconEndpointPlugin = async ({ project, directory, worktree, clien
void enqueue(payload("message.part.updated", { session_id: sid, model, part: next }))
}
const flushParts = (sid) => {
- for (const [key, item] of pendingParts) {
+ for (const [key, item] of [...pendingParts]) {
if (item.session_id !== sid) continue
const part = { ...item.part, time: { ...(item.part.time || {}), end: Date.now() } }
pendingParts.delete(key)
@@ -208,7 +208,7 @@ export const BeaconEndpointPlugin = async ({ project, directory, worktree, clien
}
}
const flushMessageParts = (messageID, sid, model, completedAt) => {
- for (const [key, item] of pendingParts) {
+ for (const [key, item] of [...pendingParts]) {
if (item.part?.messageID !== messageID) continue
const part = { ...item.part, time: { ...(item.part.time || {}), end: completedAt || Date.now() } }
pendingParts.delete(key)
diff --git a/plugins/opencode-beacon/src/beacon.test.ts b/plugins/opencode-beacon/src/beacon.test.ts
index 5803e423..c7c70dbe 100644
--- a/plugins/opencode-beacon/src/beacon.test.ts
+++ b/plugins/opencode-beacon/src/beacon.test.ts
@@ -261,6 +261,31 @@ describe("BeaconEndpointPlugin", () => {
expect(payloads[0].part.text).toBe("late role")
})
+ test("idle flush does not loop when a pending part still has no role", async () => {
+ const hooks = await plugin()
+ await hooks.event!({
+ event: {
+ type: "message.part.updated",
+ properties: {
+ sessionID: "ses_1",
+ part: {
+ id: "prt_unknown",
+ messageID: "msg_unknown",
+ sessionID: "ses_1",
+ type: "text",
+ text: "pending",
+ },
+ },
+ },
+ } as any)
+ await hooks.event!({
+ event: { type: "session.status", properties: { sessionID: "ses_1", status: { type: "idle" } } },
+ } as any)
+ await Bun.sleep(20)
+
+ expect(payloads.map((item) => item.type)).toEqual(["session.status"])
+ })
+
test("cleans session state after deletion", async () => {
const hooks = await plugin()
const completed = (sessionID: string) => ({
diff --git a/plugins/opencode-beacon/src/beacon.ts b/plugins/opencode-beacon/src/beacon.ts
index e107aca0..ca19640c 100644
--- a/plugins/opencode-beacon/src/beacon.ts
+++ b/plugins/opencode-beacon/src/beacon.ts
@@ -200,7 +200,7 @@ export const BeaconEndpointPlugin = async ({ project, directory, worktree, clien
void enqueue(payload("message.part.updated", { session_id: sid, model, part: next }))
}
const flushParts = (sid) => {
- for (const [key, item] of pendingParts) {
+ for (const [key, item] of [...pendingParts]) {
if (item.session_id !== sid) continue
const part = { ...item.part, time: { ...(item.part.time || {}), end: Date.now() } }
pendingParts.delete(key)
@@ -208,7 +208,7 @@ export const BeaconEndpointPlugin = async ({ project, directory, worktree, clien
}
}
const flushMessageParts = (messageID, sid, model, completedAt) => {
- for (const [key, item] of pendingParts) {
+ for (const [key, item] of [...pendingParts]) {
if (item.part?.messageID !== messageID) continue
const part = { ...item.part, time: { ...(item.part.time || {}), end: completedAt || Date.now() } }
pendingParts.delete(key)