Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(stations): "already told" reads what the opener heard, not the previous record

review22853b26b1dd
diff --git a/CLAUDE.md b/CLAUDE.md
index 2deabbc84..c3d3d6894 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -5752,8 +5752,11 @@ command-bearing opens; this does not add a human-confirm dialog or change mobile
headless factory, and the renderer's launch loop, so the two shells cannot disagree about when a
dependent starts. `report-outcome --notify-opener` (#1356) also sends the opener one app-written
notice through `deliverStationNotice`, to the recipient the failure monitor uses (each shell passes
- the same `opener` pair to both); a shell that passes none refuses the flag. Rules a refactor must
- not undo:
+ the same `opener` pair to both); a shell that passes none refuses the flag. It speaks only when
+ the outcome the opener last HEARD changes (`StationOutcomeStore.openerHeard` — process-local,
+ dropped with the report), never when the previous RECORD had the same outcome: a report made
+ without the flag, or whose notice was not sent, told the opener nothing, and a flagged repeat of
+ it must still wake the orchestrator. Rules a refactor must not undo:
- **A success wait is `--after` plus the report.** Every `--after-success` id is FOLDED INTO
`pendingLaunch.after` (renderer: once, right after `prWaitPre`; server: before `resolveAfter`),
so the existing rules apply unchanged — the station must exist and report status, the wait rope
diff --git a/src/core/canvas-control-core.ts b/src/core/canvas-control-core.ts
index 0036fde47..4d6ac26d9 100644
--- a/src/core/canvas-control-core.ts
+++ b/src/core/canvas-control-core.ts
@@ -337,10 +337,11 @@ function reportOutcomeDocLines(): string[] {
' are unsure: that is `failed`, with the reason in `--note`. Report last, when nothing is left to do.',
' You report only about yourself — `--node` naming another node is refused — and a later report',
` replaces the earlier one. The note (one line, at most ${OUTCOME_NOTE_MAX} characters) is shown in \`list\`, on your`,
- " card and on the waiting node; it is never typed into anyone's session unless you pass",
- ' `--notify-opener`, which also sends the agent that opened you one nodeterm-written notice with',
- ' your outcome (not your note), once per outcome change. Reporting does not end your session or your turn,',
- ' and it moves no kanban card.'
+ " card and on the waiting node; it is never typed into anyone's session. `--notify-opener` also",
+ ' sends the agent that opened you ONE notice written by nodeterm carrying your outcome — never',
+ ' your note — and only when the outcome it last heard changes; without an opener the flag',
+ ' tells you so and sends nothing. Reporting does not end your session or your turn, and it',
+ ' moves no kanban card.'
]
}
diff --git a/src/core/station-outcome-store.test.ts b/src/core/station-outcome-store.test.ts
index 5d46b4736..974d32e31 100644
--- a/src/core/station-outcome-store.test.ts
+++ b/src/core/station-outcome-store.test.ts
@@ -91,6 +91,59 @@ describe('handleReportOutcome', () => {
expect(refused.ok).toBe(false)
})
+ it('"already told" is read from what the opener HEARD, not from the previous record (#1356)', async () => {
+ const deliver = vi.fn(async () => ({ kind: 'delivered' }) as never)
+ const opener = {
+ recipientFor: () => ({ projectId: 'p1', recipientNodeId: 'orch', stationTitle: 'Tests' }),
+ deliver
+ }
+ const d = deps({ opener })
+ // A report made WITHOUT the flag told the opener nothing: a flagged repeat of the same outcome
+ // must still speak, or the orchestrator sleeps through a station that was done all along.
+ await handleReportOutcome({ nodeId: 'st1', args: { outcome: 'succeeded' }, verified: true }, d)
+ const r = await handleReportOutcome(
+ { nodeId: 'st1', args: { outcome: 'succeeded', 'notify-opener': '' }, verified: true },
+ d
+ )
+ expect(r.message).toContain('Your opener orch was told.')
+ expect(deliver).toHaveBeenCalledTimes(1)
+
+ // A notice that could NOT be sent (the project's switch off, say) is not "told": once it can
+ // be sent, the same outcome goes out.
+ deliver.mockResolvedValueOnce({ kind: 'notPermitted', reason: 'switch-off' } as never)
+ const args = { outcome: 'failed', 'notify-opener': '' }
+ const off = await handleReportOutcome({ nodeId: 'st2', args, verified: true }, d)
+ expect(off.message).toContain('could not be told (notPermitted:switch-off)')
+ const on = await handleReportOutcome({ nodeId: 'st2', args, verified: true }, d)
+ expect(on.message).toContain('Your opener orch was told.')
+ expect(deliver).toHaveBeenCalledTimes(3)
+
+ // Queued counts as told (the queue delivers it on the opener's next idle).
+ deliver.mockResolvedValueOnce({ kind: 'queued' } as never)
+ const q = await handleReportOutcome({ nodeId: 'st3', args, verified: true }, d)
+ expect(q.message).toContain('is told when it next goes idle')
+ const qAgain = await handleReportOutcome({ nodeId: 'st3', args, verified: true }, d)
+ expect(qAgain.message).toContain('already told')
+ expect(deliver).toHaveBeenCalledTimes(4)
+
+ // New work reaching the station withdraws its report AND what the opener heard about it: the
+ // report on the next task notifies again, even with the same outcome.
+ d.store.onHandover({ phase: 'landed', verb: 'send', targetNodeId: 'st3', at: 5_000 })
+ expect(d.store.get('st3')).toBeUndefined()
+ const next = await handleReportOutcome({ nodeId: 'st3', args, verified: true }, d)
+ expect(next.message).toContain('Your opener orch was told.')
+ expect(deliver).toHaveBeenCalledTimes(5)
+
+ // A station nobody opened through canvas control: the flag says so and sends nothing.
+ const alone = await handleReportOutcome(
+ { nodeId: 'st4', args, verified: true },
+ deps({ opener: { recipientFor: () => undefined, deliver } })
+ )
+ expect(alone.ok).toBe(true)
+ expect(alone.message).toContain('No opener to tell')
+ expect(deliver).toHaveBeenCalledTimes(5)
+ })
+
it('refuses an unverified caller and records nothing — a forgeable success is not evidence', async () => {
const d = deps()
const r = await handleReportOutcome({ nodeId: 'st1', args: { outcome: 'succeeded' }, verified: false }, d)
diff --git a/src/core/station-outcome-store.ts b/src/core/station-outcome-store.ts
index b50b234d7..5157809a7 100644
--- a/src/core/station-outcome-store.ts
+++ b/src/core/station-outcome-store.ts
@@ -141,6 +141,11 @@ export class StationOutcomeStore {
private readonly pending = new Map<string, number>()
/** Which conversation each report was made in (persisted beside it, never published). */
private readonly bindings = new Map<string, OutcomeBinding>()
+ /** The outcome the station's OPENER last heard through `--notify-opener` (#1356), kept while the
+ * report it was about stands. Not the report itself: a report made without the flag, or whose
+ * notice could not be sent, told the opener nothing — so "already told" is read from here, never
+ * from `byId`. Process-local like the Server Edition's creator ledger (never persisted). */
+ private readonly openerHeard = new Map<string, StationOutcome>()
private readonly durable: StationOutcomeStoreOptions['durable']
private readonly sessionOf: StationOutcomeStoreOptions['sessionOf']
@@ -199,12 +204,31 @@ export class StationOutcomeStore {
/** Withdraw a station's report. `true` when there was one. */
clear(nodeId: string): boolean {
- if (!this.byId.delete(nodeId)) return false
- this.bindings.delete(nodeId)
+ if (!this.drop(nodeId)) return false
this.changed()
return true
}
+ /** Every way a report leaves the store goes through here, so what the opener heard about it
+ * leaves with it: the next report after new work is a new task, and it notifies again. */
+ private drop(nodeId: string): boolean {
+ this.openerHeard.delete(nodeId)
+ this.bindings.delete(nodeId)
+ return this.byId.delete(nodeId)
+ }
+
+ /** `--notify-opener`: the outcome the opener last heard about this station's standing report, or
+ * `undefined` when it heard nothing (no flag yet, notice not sent, report withdrawn since). */
+ openerHeardOutcome(nodeId: string): StationOutcome | undefined {
+ return this.openerHeard.get(nodeId)
+ }
+
+ /** The opener was told (delivered, or queued for its next idle) this outcome. Only for a station
+ * whose report stands — a notice about a withdrawn report is not knowledge of the next one. */
+ markOpenerHeard(nodeId: string, outcome: StationOutcome): void {
+ if (this.byId.has(nodeId)) this.openerHeard.set(nodeId, outcome)
+ }
+
/**
* One normalized agent event. Only a session START matters: a node that begins a DIFFERENT
* session (or now runs a different agent) than the one its report was made in no longer speaks
@@ -233,8 +257,7 @@ export class StationOutcomeStore {
while (this.byId.size > STATION_OUTCOME_MAX_RECORDS) {
const oldest = this.byId.keys().next().value
if (oldest === undefined) break
- this.byId.delete(oldest)
- this.bindings.delete(oldest)
+ this.drop(oldest)
}
}
@@ -290,10 +313,7 @@ export class StationOutcomeStore {
const left = (this.pending.get(id) ?? 1) - 1
if (left > 0) this.pending.set(id, left)
else this.pending.delete(id)
- if (!ev.landed && this.byId.delete(id)) {
- this.bindings.delete(id)
- this.persist()
- }
+ if (!ev.landed && this.drop(id)) this.persist()
this.publish(this.list())
}
@@ -406,9 +426,12 @@ export async function handleReportOutcome(
at,
...(parsed.note ? { note: parsed.note } : {})
}
- // `--notify-opener` speaks only when the outcome CHANGES: repeating the same report cannot keep
- // waking the opener. New work reaching the station withdraws its report, so a new task notifies.
- const repeated = deps.store.get(req.nodeId)?.outcome === parsed.outcome
+ // `--notify-opener` speaks only when the outcome the opener HEARD changes: repeating the same
+ // report cannot keep waking it. Read before the record lands, and from what was actually told —
+ // not from the previous record: a report made without the flag, or whose notice was not sent, told
+ // the opener nothing, and a flagged repeat of it must still speak. New work reaching the station
+ // withdraws its report (and what was heard about it), so the next task notifies again.
+ const heard = deps.store.openerHeardOutcome(req.nodeId)
deps.store.record(record)
const projectId = deps.projectIdOfNode(req.nodeId)
let logged = false
@@ -433,9 +456,9 @@ export async function handleReportOutcome(
// `done` if openers start reading half-finished transcripts.
const told = !parsed.notifyOpener || !deps.opener
? undefined
- : repeated
+ : heard === parsed.outcome
? 'Your opener was already told this outcome; it is not told again.'
- : await tellOpener(record, deps.opener)
+ : await tellOpener(record, deps.store, deps.opener)
const message = [
`recorded: your task ${parsed.outcome}${parsed.note ? ` — "${parsed.note}"` : ''}.`,
RELEASE_TEXT[parsed.outcome],
@@ -451,9 +474,12 @@ export async function handleReportOutcome(
}
/** `--notify-opener`: one notice to the node that opened the station. Returns the line the station
- * is told, so it knows whether its opener heard. */
+ * is told, so it knows whether its opener heard — and records in the store what it heard, which
+ * is what silences a flagged repeat of the same outcome. A notice that was not sent records
+ * nothing, so the next flagged report tries again (the switch may have been turned on since). */
async function tellOpener(
record: StationOutcomeRecord,
+ store: Pick<StationOutcomeStore, 'markOpenerHeard'>,
opener: NonNullable<ReportOutcomeDeps['opener']>
): Promise<string> {
const recipient = opener.recipientFor(record.nodeId)
@@ -463,6 +489,9 @@ async function tellOpener(
.deliver({ stationNodeId: record.nodeId, recipientNodeId: recipient.recipientNodeId, body })
.catch(() => null)
const { pane, paneDetail } = outcome ? paneResult(outcome) : { pane: 'not-sent', paneDetail: 'error' }
+ // Queued counts as heard: the queue delivers it on the opener's next idle. A queued notice that
+ // then expires is the one case this cannot see — the opener reads `list` as it always could.
+ if (pane === 'told' || pane === 'queued') store.markOpenerHeard(record.nodeId, record.outcome)
if (pane === 'told') return `Your opener ${recipient.recipientNodeId} was told.`
if (pane === 'queued') return `Your opener ${recipient.recipientNodeId} is told when it next goes idle.`
return `Your opener could not be told (${paneDetail ?? 'not sent'}).`
diff --git a/src/shared/control-verbs.test.ts b/src/shared/control-verbs.test.ts
index 68e549273..0559e8069 100644
--- a/src/shared/control-verbs.test.ts
+++ b/src/shared/control-verbs.test.ts
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
-import { DRY_RUN_VERBS, dryRunRequested, dryRunRefusal, runNowRequested } from './control-verbs'
+import { DRY_RUN_VERBS, dryRunRequested, dryRunRefusal, flagRequested, runNowRequested } from './control-verbs'
describe('dryRunRequested', () => {
it('absent means no dry run', () => {
@@ -61,3 +61,19 @@ describe('runNowRequested (#925)', () => {
for (const v of ['false', 'NO', '0', ' 0 ']) expect(runNowRequested({ 'run-now': v })).toBe(false)
})
})
+
+describe('flagRequested — one reader for every presence flag', () => {
+ it('presence (the shim\'s empty string) is on; only an explicit false|no|0 is off', () => {
+ expect(flagRequested({}, 'notify-opener')).toBe(false)
+ expect(flagRequested({ 'notify-opener': '' }, 'notify-opener')).toBe(true)
+ expect(flagRequested({ 'notify-opener': 'true' }, 'notify-opener')).toBe(true)
+ expect(flagRequested({ 'notify-opener': ' No ' }, 'notify-opener')).toBe(false)
+ expect(flagRequested({ 'notify-opener': '0' }, 'notify-opener')).toBe(false)
+ expect(flagRequested({ 'run-now': '' }, 'notify-opener')).toBe(false)
+ })
+
+ it('runNowRequested is the same rule', () => {
+ for (const v of [undefined, '', 'yes', 'false', 'NO', '0'])
+ expect(runNowRequested({ 'run-now': v })).toBe(flagRequested({ 'run-now': v }, 'run-now'))
+ })
+})
diff --git a/src/shared/control-verbs.ts b/src/shared/control-verbs.ts
index 4c68dff9b..26023d810 100644
--- a/src/shared/control-verbs.ts
+++ b/src/shared/control-verbs.ts
@@ -112,7 +112,16 @@ export function dryRunRequested(args: Record<string, string | undefined>): boole
* valueless flag as an empty string, and only an explicit false|no|0 turns it off.
*/
export function runNowRequested(args: Record<string, string | undefined>): boolean {
- const v = args['run-now']
+ return flagRequested(args, 'run-now')
+}
+
+/**
+ * Is a presence flag (`--run-now`, `--notify-opener`) on? The shim encodes a valueless flag as an
+ * empty string, so presence means yes; only an explicit `false|no|0` turns it off. ONE reader for
+ * every such flag, so two verbs cannot disagree about what `--flag no` means.
+ */
+export function flagRequested(args: Record<string, string | undefined>, name: string): boolean {
+ const v = args[name]
if (v === undefined) return false
return !/^(false|no|0)$/i.test(v.trim())
}
diff --git a/src/shared/station-outcome.ts b/src/shared/station-outcome.ts
index 23986c050..576ef35da 100644
--- a/src/shared/station-outcome.ts
+++ b/src/shared/station-outcome.ts
@@ -25,7 +25,7 @@
import { oneLine } from './one-line'
import { parseWaitDeadlineArg } from './pr-wait'
-import { runNowRequested } from './control-verbs'
+import { flagRequested, runNowRequested } from './control-verbs'
import { isSafeNodeId } from './safe-id'
export type StationOutcome = 'succeeded' | 'failed'
@@ -110,9 +110,7 @@ export function parseReportOutcome(
}
}
const note = sanitizeOutcomeNote(args.note)
- // Read like `--run-now`: present and not false/no/0.
- const notify = args['notify-opener']
- const notifyOpener = notify !== undefined && !/^(false|no|0)$/i.test(notify.trim())
+ const notifyOpener = flagRequested(args, 'notify-opener')
return { ok: true, outcome, ...(note ? { note } : {}), ...(notifyOpener ? { notifyOpener } : {}) }
}