Skip to content

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

fix: preserve OpenCode lifecycle event ordering

Cursor Agent0efeed764fb6
diff --git a/cli/beacon/internal/endpoint/hooks/assets/opencode/beacon.ts b/cli/beacon/internal/endpoint/hooks/assets/opencode/beacon.ts
index 0b4af3f4..da6593f4 100644
--- a/cli/beacon/internal/endpoint/hooks/assets/opencode/beacon.ts
+++ b/cli/beacon/internal/endpoint/hooks/assets/opencode/beacon.ts
@@ -208,7 +208,7 @@ export const BeaconEndpointPlugin = async ({ project, directory, worktree, clien
return {
"chat.message": async (input, output) => {
if (output?.message?.id) messageRoles.set(output.message.id, "user")
- await sendToBeacon(client, {
+ await enqueue({
type: "chat.message",
session_id: sessionID(input),
model: modelName(input),
@@ -218,8 +218,7 @@ export const BeaconEndpointPlugin = async ({ project, directory, worktree, clien
})
},
"command.execute.before": async (input, output) => {
- await sendToBeacon(
- client,
+ await enqueue(
payload("command.execute.before", {
session_id: sessionID(input),
command_name: input?.command,
@@ -237,8 +236,7 @@ export const BeaconEndpointPlugin = async ({ project, directory, worktree, clien
started_at: Date.now(),
})
rememberFilePath(input?.tool, output?.args || {}, sid, input?.callID)
- await sendToBeacon(
- client,
+ await enqueue(
payload("tool.execute.before", {
session_id: sessionID(input),
tool_name: input?.tool,
@@ -251,8 +249,7 @@ export const BeaconEndpointPlugin = async ({ project, directory, worktree, clien
const active = activeCalls.get(input?.callID)
const args = input?.args || active?.args || {}
rememberFilePath(input?.tool, args, sessionID(input), input?.callID)
- await sendToBeacon(
- client,
+ await enqueue(
payload("tool.execute.after", {
session_id: sessionID(input),
tool_name: input?.tool,
diff --git a/plugins/opencode-beacon/src/beacon.test.ts b/plugins/opencode-beacon/src/beacon.test.ts
index 6f40d4e9..c6bd1325 100644
--- a/plugins/opencode-beacon/src/beacon.test.ts
+++ b/plugins/opencode-beacon/src/beacon.test.ts
@@ -26,6 +26,9 @@ describe("BeaconEndpointPlugin", () => {
test("forwards prompts and correlated tool lifecycle payloads", async () => {
const hooks = await plugin()
+ await hooks.event!({
+ event: { type: "session.created", properties: { sessionID: "ses_1", info: { id: "ses_1" } } },
+ } as any)
await hooks["chat.message"]!(
{ sessionID: "ses_1", model: { providerID: "moonshotai", modelID: "kimi-k3" } } as any,
{ parts: [{ type: "text", text: "summarize" }] } as any,
@@ -40,11 +43,12 @@ describe("BeaconEndpointPlugin", () => {
)
expect(payloads.map((item) => item.type)).toEqual([
+ "session.created",
"chat.message",
"tool.execute.before",
"tool.execute.after",
])
- expect(payloads[2]).toMatchObject({
+ expect(payloads[3]).toMatchObject({
session_id: "ses_1",
call_id: "call_1",
tool_name: "bash",
diff --git a/plugins/opencode-beacon/src/beacon.ts b/plugins/opencode-beacon/src/beacon.ts
index 0b4af3f4..da6593f4 100644
--- a/plugins/opencode-beacon/src/beacon.ts
+++ b/plugins/opencode-beacon/src/beacon.ts
@@ -208,7 +208,7 @@ export const BeaconEndpointPlugin = async ({ project, directory, worktree, clien
return {
"chat.message": async (input, output) => {
if (output?.message?.id) messageRoles.set(output.message.id, "user")
- await sendToBeacon(client, {
+ await enqueue({
type: "chat.message",
session_id: sessionID(input),
model: modelName(input),
@@ -218,8 +218,7 @@ export const BeaconEndpointPlugin = async ({ project, directory, worktree, clien
})
},
"command.execute.before": async (input, output) => {
- await sendToBeacon(
- client,
+ await enqueue(
payload("command.execute.before", {
session_id: sessionID(input),
command_name: input?.command,
@@ -237,8 +236,7 @@ export const BeaconEndpointPlugin = async ({ project, directory, worktree, clien
started_at: Date.now(),
})
rememberFilePath(input?.tool, output?.args || {}, sid, input?.callID)
- await sendToBeacon(
- client,
+ await enqueue(
payload("tool.execute.before", {
session_id: sessionID(input),
tool_name: input?.tool,
@@ -251,8 +249,7 @@ export const BeaconEndpointPlugin = async ({ project, directory, worktree, clien
const active = activeCalls.get(input?.callID)
const args = input?.args || active?.args || {}
rememberFilePath(input?.tool, args, sessionID(input), input?.callID)
- await sendToBeacon(
- client,
+ await enqueue(
payload("tool.execute.after", {
session_id: sessionID(input),
tool_name: input?.tool,