Skip to content

Commit 12e47f5

Browse files
committed
fix(workspace): address harness-bot round 8 — Event.Status + clear() on install fail
Two findings on packages/opencode/src/altimate/plugin/onboarding-telemetry.ts: 1. Subscribe to Event.Status with status.type === "idle" instead of the deprecated Event.Idle. session/status.ts:49 marks Event.Idle as `// deprecated`; the non-deprecated path is Event.Status filtered on the idle status shape (matching what session/status.ts:176 uses for the legacy Bus SSE mirror). Replaces the earlier NOTE that only asserted "not the deprecated LegacyEvent" — the NOTE was technically correct but deflected from the fact that Event.Idle itself is deprecated too. (altimate-harness-bot #1099 comment 3837907427.) 2. Drain the pending set with pendingWorkspacePromptSessions.clear() on install failure instead of iterating an install-time snapshot. A second scan calling armWorkspacePromptOnSessionIdle after the snapshot but before the install fails would otherwise leave its sessionID as a permanent orphan in the pending set — no listener would ever fire for it, so its post-scan workspace prompt would silently never arm. (altimate-harness-bot #1099 comment 3837907105, P2.)
1 parent 3427b2c commit 12e47f5

1 file changed

Lines changed: 19 additions & 22 deletions

File tree

‎packages/opencode/src/altimate/plugin/onboarding-telemetry.ts‎

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,25 @@ async function armWorkspacePromptOnSessionIdle(sessionID: string): Promise<void>
6161
if (workspacePromptUnsubscribe) return
6262
if (workspacePromptInstall) return workspacePromptInstall
6363

64-
// Capture the set of pending sessions at install-time so an install
65-
// failure drains EVERY caller that awaited this install, not just the
66-
// one whose sessionID we happen to be handling. Later waiters would
67-
// otherwise see success from the shared promise and stop retrying,
68-
// leaving permanently-stale entries in the pending set. (cubic round 3.)
69-
const armingSessions = new Set(pendingWorkspacePromptSessions)
70-
7164
workspacePromptInstall = (async () => {
7265
try {
7366
const unsubscribe = await AppRuntime.runPromise(
7467
EventV2Bridge.Service.use((events) =>
7568
events.listen((event) =>
7669
Effect.gen(function* () {
77-
// NOTE: ``SessionEvent`` here is the module-local alias for
78-
// ``Event`` imported from ``@/session/status`` (see imports
79-
// above) — the MODERN ``EventV2.define`` API, not the
80-
// deprecated ``LegacyEvent.Idle`` under ``BusEvent.define``.
81-
// Grep the file for ``import { Event as SessionEvent }`` to
82-
// confirm. Bots flagging this as "deprecated API" are
83-
// false-positive matching on the token ``SessionEvent``.
84-
if (event.type !== SessionEvent.Idle.type) return
85-
const sid = (event.data as { sessionID?: string } | undefined)?.sessionID
70+
// Subscribe to ``Event.Status`` (session/status.ts:42, defined
71+
// via ``EventV2.define``) rather than ``Event.Idle`` — the
72+
// latter is marked ``// deprecated`` at session/status.ts:49
73+
// and is only kept around for the legacy Bus SSE mirror at
74+
// session/status.ts:176. Filtering ``event.data.status.type
75+
// === "idle"`` gives us the same trigger without riding the
76+
// deprecated event. (harness-bot round 8.)
77+
if (event.type !== SessionEvent.Status.type) return
78+
const data = event.data as
79+
| { sessionID?: string; status?: { type?: string } }
80+
| undefined
81+
if (data?.status?.type !== "idle") return
82+
const sid = data.sessionID
8683
if (!sid || !pendingWorkspacePromptSessions.has(sid)) return
8784
pendingWorkspacePromptSessions.delete(sid)
8885
yield* events.publish(TuiEvent.CommandExecute, {
@@ -107,12 +104,12 @@ async function armWorkspacePromptOnSessionIdle(sessionID: string): Promise<void>
107104
)
108105
workspacePromptUnsubscribe = unsubscribe
109106
} catch (err) {
110-
// Install failed — drop every session that was waiting on this install
111-
// so the next scan retries from scratch. Dropping only the current
112-
// caller's ID would leave later waiters (already resolved by the
113-
// shared install promise) with permanently-stale pending entries.
114-
// (cubic round 3.)
115-
for (const sid of armingSessions) pendingWorkspacePromptSessions.delete(sid)
107+
// Install failed — drain EVERY pending session, not just the ones
108+
// snapshotted at install-time. A late-arriving ``armWorkspacePromptOn
109+
// SessionIdle`` between the snapshot and the failure would otherwise
110+
// be a permanent orphan (its sessionID stays in the pending set but
111+
// no listener will ever fire for it). (harness-bot round 8.)
112+
pendingWorkspacePromptSessions.clear()
116113
workspaceLog.warn("session-idle listener install failed", { err: String(err) })
117114
} finally {
118115
workspacePromptInstall = null

0 commit comments

Comments
 (0)