The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Keep the companion runtime available for background learning (#613)
Dee4b506c872ef0
diff --git a/cli/src/cli.ts b/cli/src/cli.tsindex 88e24ad5a..58791c547 100644--- a/cli/src/cli.ts+++ b/cli/src/cli.ts@@ -4940,7 +4940,8 @@ async function runForeground(session: AuthSession | null): Promise<void> {})backend.pairControl = pairControl// THE PAIR HARNESS (pair/pairHarness.ts): the daemon as a conversation, started or resumed when you talk- // to it, stopped when idle. Automatic approvals, scoped harnessd MCP, a fresh token every launch.+ // to it, stopped when idle unless coding memory still uses it. Automatic approvals, scoped harnessd+ // MCP, a fresh token every launch.const pairHarness = new PairHarness({pairedDaemon: () => pairSensor.pairedDaemon(),pairedName: () => pairSensor.pairedName(),@@ -4994,6 +4995,7 @@ async function runForeground(session: AuthSession | null): Promise<void> {const sessionId = registry.resolve(agentId)?.sessionIdreturn !!sessionId && mirror.isBusy(sessionId)},+ backgroundInUse: (agentId): boolean => agentId === pairHarness.agentId() && !!codingMemory?.needsCompanion(),now: Date.now,})pairTalk = (text, uid) => pairHarness.talk(text, uid)diff --git a/cli/src/memory/runtime.spec.ts b/cli/src/memory/runtime.spec.tsindex 90e2fb734..43b17df38 100644--- a/cli/src/memory/runtime.spec.ts+++ b/cli/src/memory/runtime.spec.ts@@ -96,6 +96,29 @@ it('opens no store and invokes no model while experimental, watching consent orexpect(inference.run).not.toHaveBeenCalled()})+it('keeps the companion available between reviews only while this owner has enabled learning', async () => {+ sessions = []+ expect(runtime.needsCompanion()).toBe(false)+ await runtime.tick()+ await runtime.configure({ learn: true, recall: false })+ expect(runtime.needsCompanion()).toBe(true)+ expect(inference.target).not.toHaveBeenCalled()+ expect(inference.run).not.toHaveBeenCalled()+ await runtime.configure({ learn: false, recall: true })+ expect(runtime.needsCompanion()).toBe(false)+ await runtime.configure({ learn: true, recall: true })+ context.watching = false+ expect(runtime.needsCompanion()).toBe(false)+ context.watching = true; context.experimental = false+ expect(runtime.needsCompanion()).toBe(false)+ context.experimental = true; context.profileId = 'owner_b'+ expect(runtime.needsCompanion()).toBe(false)+ context.profileId = 'owner_a'+ expect(runtime.needsCompanion()).toBe(true)+ await runtime.pause()+ expect(runtime.needsCompanion()).toBe(false)+})+it.each(['replace', 'mutate'] as const)('binds activity to open host sessions and rejects a native-session %s during the read', async mode => {await learn()sessions[0].name = 'Parser fixes'diff --git a/cli/src/memory/runtime.ts b/cli/src/memory/runtime.tsindex 6b951c25f..64caf21b5 100644--- a/cli/src/memory/runtime.ts+++ b/cli/src/memory/runtime.ts@@ -116,6 +116,11 @@ export class CodingMemoryRuntime {return !this.stopped && context.experimental ? context.profileId : null}+ /** Learning is a continuing use of the collection's model, even with an empty or deferred queue. */+ needsCompanion(): boolean {+ return !!this.active?.ready && this.authorized(this.active) && this.active.preferences.learn+ }+/** Explicit owner controls remain usable with watching/learning/recall off. No capture is started. */async libraryStatus(owner: string) {return this.withOwner(owner, async port => ({ runtime: this.status(),diff --git a/cli/src/pair/pairHarness.spec.ts b/cli/src/pair/pairHarness.spec.tsindex 676532551..677afa006 100644--- a/cli/src/pair/pairHarness.spec.ts+++ b/cli/src/pair/pairHarness.spec.ts@@ -104,7 +104,8 @@ describe('the package', () => {})describe('talking to it', () => {- function world(opts: { engine?: 'claude' | 'codex' | 'opencode' | null; pair?: string | null } = {}) {+ function world(opts: { engine?: 'claude' | 'codex' | 'opencode' | null; pair?: string | null;+ backgroundInUse?: (agentId: string) => boolean } = {}) {let pair = opts.pair === undefined ? 'tim' : opts.pairconst rows: PairHarnessRow[] = []let working = false@@ -124,6 +125,7 @@ describe('talking to it', () => {stop: vi.fn<PairHarnessDeps['stop']>(async (agentId) => { rows.find((r) => r.agentId === agentId)!.status = 'stopped' }),send: vi.fn(),working: () => working,+ backgroundInUse: opts.backgroundInUse,now: Date.now,}const harness = new PairHarness(deps)@@ -239,6 +241,38 @@ describe('talking to it', () => {expect(w.deps.stop).toHaveBeenCalledWith('pair-1')})+ it.each(['claude', 'codex', 'opencode'] as const)('keeps the %s model connection available while background learning is enabled', async engine => {+ let learning = true+ const backgroundInUse = vi.fn((id: string) => id === 'pair-1' && learning)+ const w = world({ engine, backgroundInUse })+ expect(await w.harness.open(undefined, engine)).toMatchObject({ ok: true, started: true })+ w.rows[0]!.hasConversation = true+ await vi.advanceTimersByTimeAsync(PAIR_IDLE_MS * 3)+ expect(w.rows[0]!.status).toBe('live')+ expect(w.deps.stop).not.toHaveBeenCalled()+ expect(w.deps.send).not.toHaveBeenCalled()+ expect(w.deps.resume).not.toHaveBeenCalled()+ expect(w.deps.create).toHaveBeenCalledOnce()+ expect(w.deps.create.mock.calls[0]?.[0].prompt).toBe('')+ learning = false+ await vi.advanceTimersByTimeAsync(60_000)+ expect(w.rows[0]!.status).toBe('stopped')+ expect(w.deps.stop).toHaveBeenCalledExactlyOnceWith('pair-1')+ })++ it('still honors explicit off and never reopens a stopped companion for background learning', async () => {+ const w = world({ backgroundInUse: () => true })+ await w.harness.open()+ w.rows[0]!.hasConversation = true+ await w.harness.off()+ expect(w.rows[0]!.status).toBe('stopped')+ await vi.advanceTimersByTimeAsync(PAIR_IDLE_MS * 3)+ expect(await w.harness.idleCheck()).toBe(false)+ expect(w.deps.stop).toHaveBeenCalledOnce()+ expect(w.deps.resume).not.toHaveBeenCalled()+ expect(w.deps.send).not.toHaveBeenCalled()+ })+it('a new paired daemon keeps the collection conversation and does not interrupt its terminal', async () => {const w = world()await w.harness.talk('hi tim')diff --git a/cli/src/pair/pairHarness.ts b/cli/src/pair/pairHarness.tsindex fbd84df25..7da9be4a1 100644--- a/cli/src/pair/pairHarness.ts+++ b/cli/src/pair/pairHarness.ts@@ -5,8 +5,8 @@* paired daemon's voice (roster lore, first words, lines) and the floor.** On demand only. The window's `daemon_talk { text }` (never a tool: BRAIN.md "Security") forwards the words- * to it — starting it, or resuming it if it was paused. Paused when idle (the guarded stop: its- * conversation is kept; the next talk resumes it). Never a tile anyone picks (hidden from the catalog),+ * to it — starting it, or resuming it if it was paused. Paused when idle unless opted-in background+ * learning still uses it (the guarded stop keeps its conversation for the next talk). Hidden from the catalog,* never counted as a person's turn (zooTurns), never a notification, never watched by the sensor.** New conversations use the product's automatic approvals. The control interface still checks the@@ -219,6 +219,8 @@ export interface PairHarnessDeps {send: (agentId: string, text: string) => void/** A turn is open on it right now. */working: (agentId: string) => boolean+ /** Opted-in background learning still needs this runtime, even between review jobs. */+ backgroundInUse?: (agentId: string) => booleannow: () => numberidleMs?: number}@@ -388,7 +390,7 @@ export class PairHarness {if (agentId === this.saved()?.agentId) this.touch()}- /** Pause it when it has been idle long enough: its conversation is kept, the next talk resumes it. */+ /** Pause unused conversations; keep the learning runtime available without submitting a turn. */async idleCheck(): Promise<boolean> {const agentId = this.activeAgentId ?? this.saved()?.agentIdconst row = agentId ? this.deps.find().find((r) => r.agentId === agentId) : null@@ -396,6 +398,7 @@ export class PairHarness {// An empty/setup terminal has no conversation to resume. Pausing it discards its selected model// and strands a pending memory review; leave it open until a real conversation can be preserved.if (row.hasConversation === false) return false+ if (this.deps.backgroundInUse?.(agentId)) return falseif (this.deps.working(agentId) || this.deps.now() - this.lastActivity < (this.deps.idleMs ?? PAIR_IDLE_MS)) return falsetry {await this.deps.stop(agentId)diff --git a/docs/plans/2026-09-30-coding-memory-review-log.md b/docs/plans/2026-09-30-coding-memory-review-log.mdindex 8d57d40db..2d817528c 100644--- a/docs/plans/2026-09-30-coding-memory-review-log.md+++ b/docs/plans/2026-09-30-coding-memory-review-log.md@@ -775,3 +775,27 @@ type is now set without prematurely sending headers. No product device behaviorThis change prevents new duplicate capture; it does not rewrite previously saved evidence ormemories. No live memory, installed app, global plugin, provider setting or release was changed.The real-session quality sample still requires explicit approval for its external model destination.++### Keep the companion available for continuous learning++A read-only completion audit found a live memory service with Learn and Recall enabled, learning+waiting for a model, and capture at its bounded backlog limit. The selected collection conversation+was saved as stopped. This does not establish whether that specific stop was manual or automatic.+It exposed a reproducible lifecycle gap: the collection's ten-minute idle timer stops its native+runtime even when background coding-memory learning remains enabled. OpenCode requires that live+runtime for its observed account/model binding; cached names cannot replace that authority.++The collection now remains open while its current owner has authorized background learning. This+applies equally to Claude, Codex and OpenCode, including time between reviews or while work is+deferred. It does not send a keepalive prompt, launch a model request, reopen a stopped conversation,+switch engines, retain provider credentials on disk or enlarge the queue. Normal idle shutdown+resumes when learning is disabled. Explicit stop and experiment-off still take precedence, and+account or watching changes immediately revoke the memory runtime's keep-open requirement.++The regression first failed for all three engines: a synthetic idle collection was stopped despite+its background-use requirement. After the fix it stayed live for three idle intervals, with no+prompt or resume calls, and stopped on the next check after learning was disabled. Runtime checks+cover an empty queue, Recall-only mode, identity changes, watching/experimental-off and pause.+This is lifecycle validation with synthetic state. The live stopped conversation and its backlog+were left untouched; a fresh model connection and real-user extraction-quality validation remain+necessary before claiming end-to-end completion.