fix(plugin/event): bind team-idle-wake-hint client methods to SDK Session

The team-mode wiring at `createEventHandler` extracted
`pluginContext.client.session.promptAsync` and `.status` into a fresh
wrapper object. The methods were copied by reference, so the prompt-async
gate's `session.promptAsync.bind(session)` was binding to that plain
wrapper rather than the underlying SDK `Session` instance. The opencode
SDK's `promptAsync` reads `this._client.post(...)`, so production calls
threw `TypeError: undefined is not an object (evaluating 'this._client')`
on the very first dispatch — fingerprinted in /tmp/oh-my-opencode.log as
688 `background-agent-parent-wake`, 47 `model-suggestion-retry`, and 4
`team-idle-wake-hint` failures over the past three days.

Move the wrapper construction into `buildTeamIdleWakeHintClient`, which
preserves the narrow factory contract while binding both methods back to
the SDK `Session` so `_client` survives the dispatch. Cover the contract
with four BDD-style tests including the historical destructure-only
failure mode so any future regression is caught at unit-test time.
This commit is contained in:
YeonGyu-Kim
2026-05-17 02:06:14 +09:00
parent 271878bcea
commit a43215f24e
3 changed files with 128 additions and 7 deletions
+3 -7
View File
@@ -39,6 +39,7 @@ import { deleteSessionTools } from "../shared/session-tools-store";
import { lspManager } from "../tools";
import { dispatchOpenClawEvent } from "../openclaw/runtime-dispatch";
import { createTeamIdleWakeHint } from "../hooks/team-session-events/team-idle-wake-hint";
import { buildTeamIdleWakeHintClient } from "./build-team-idle-wake-hint-client";
import { createTeamLeadOrphanHandler } from "../hooks/team-session-events/team-lead-orphan-handler";
import { createTeamMemberErrorHandler } from "../hooks/team-session-events/team-member-error-handler";
import { createTeamMemberStatusHandler } from "../hooks/team-session-events/team-member-status-handler";
@@ -343,15 +344,10 @@ export function createEventHandler(args: {
const teamMemberStatusHandler = teamModeConfig
? createTeamMemberStatusHandler(teamModeConfig)
: undefined;
const teamIdleWakeHint = teamModeConfig && pluginContext.client.session?.promptAsync
const teamIdleWakeHint = teamModeConfig && typeof pluginContext.client.session?.promptAsync === "function"
? createTeamIdleWakeHint({
directory: pluginContext.directory,
client: {
session: {
promptAsync: pluginContext.client.session.promptAsync,
status: pluginContext.client.session.status,
},
},
client: buildTeamIdleWakeHintClient(pluginContext.client),
}, teamModeConfig)
: undefined;
const TMUX_ACTIVITY_EVENT_TYPES = new Set([