Skip to content

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.

Let a pane survive the start marker its own CLI used to write (#60)

0xken1592d3b9ac5713
diff --git a/cli/hook/notify.mjs b/cli/hook/notify.mjs
index f13acde66..efd9c278e 100644
--- a/cli/hook/notify.mjs
+++ b/cli/hook/notify.mjs
@@ -372,17 +372,14 @@ function execFileText(cmd, args, timeout, env) {
}
/**
- * Mirrors ensureUtf8Locale in src/lib/childLocale.ts. Linux procps substitutes `?` for every byte it cannot print in the
- * current locale, and a hook child launched by an engine under systemd/docker/ssh usually has no locale
- * at all. Measured on Ubuntu 24.04 + procps-ng 4.0.4: `⌘ <title>` reads back as `??? <title>` in BOTH
- * comm and args, which kills both halves of the Command Code marker in processMatchScore. macOS never
- * substitutes, so this is Linux-only and cannot regress it.
- */
-/**
- * Mirrors lib/childLocale.ts. This process is spawned by the ENGINE, not by the daemon, so it inherits
- * the engine's environment and has to set its own — it shells out to both `tmux` and `ps`, and Linux
- * mangles both without a UTF-8 locale (tmux turns the -F TAB separator into `_`; ps turns `⌘` into
- * `???`). Only when nothing usable is configured.
+ * Mirrors ensureUtf8Locale in src/lib/childLocale.ts. This process is spawned by the ENGINE, not by the
+ * daemon, so it inherits the engine's environment and has to set its own — and a hook child launched by
+ * an engine under systemd/docker/ssh usually has no locale at all. It shells out to both `tmux` and
+ * `ps`, and Linux mangles both without a UTF-8 locale: tmux turns the `-F` TAB separator into `_`, and
+ * procps substitutes `?` for every byte it cannot print. Measured on Ubuntu 24.04 + procps-ng 4.0.4,
+ * `⌘ <title>` reads back as `??? <title>` in BOTH comm and args, which kills both halves of the Command
+ * Code marker in processMatchScore. macOS never substitutes, so this is Linux-only and cannot regress
+ * it. Applied only when nothing usable is configured.
*/
function ensureUtf8Locale(env = process.env) {
if (process.platform !== 'linux') return
diff --git a/cli/src/lib/tmuxBackend.ts b/cli/src/lib/tmuxBackend.ts
index 065465ec2..2565e856d 100644
--- a/cli/src/lib/tmuxBackend.ts
+++ b/cli/src/lib/tmuxBackend.ts
@@ -23,6 +23,7 @@ import { TmuxControlStream } from './tmuxStream.js'
import {
captureTmuxPane,
listPaneTitles,
+ LSTART_MARKER_RE,
resolvePaneEngineProcess,
sendKeyToTmux,
sendLiteralToTmux,
@@ -295,6 +296,18 @@ export class TmuxBackend implements TerminalBackend<TmuxRuntimeRef> {
try {
const live = await resolvePaneEngineProcess(runtime.paneId, expected.engine)
if (!live) return { state: 'gone', reason: `no ${expected.engine} process under tmux pane` }
+ // A saved marker that is not a C-locale `lstart` stamp was written either by the pre-fix parser,
+ // with its fields shifted, or by a `ps` that still inherited the user's LC_TIME (see psEnv in
+ // lib/childLocale.ts). Either way it can never equal the corrected stamp for the same live
+ // process, so comparing it would report a running engine as gone — once, on the upgrade that
+ // fixed the reading. The pane still has a matching engine process; take it.
+ //
+ // checkSessionRuntime makes the same allowance, but nothing calls that function today, so this
+ // is where the allowance has to live: coordinator.validate/acquireLease pass the PERSISTED
+ // identity straight through to here.
+ if (expected.processIdentity && !LSTART_MARKER_RE.test(expected.processIdentity.startMarker)) {
+ return { state: 'alive' }
+ }
if (expected.processIdentity
&& (expected.processIdentity.pid !== live.pid || expected.processIdentity.startMarker !== live.startMarker)) {
return { state: 'gone', reason: 'process changed under tmux pane' }
diff --git a/cli/src/lib/tmuxBackendValidate.spec.ts b/cli/src/lib/tmuxBackendValidate.spec.ts
new file mode 100644
index 000000000..982ff5f2c
--- /dev/null
+++ b/cli/src/lib/tmuxBackendValidate.spec.ts
@@ -0,0 +1,64 @@
+/**
+ * `validate` is the live path: `terminals.validate` / `acquireLease` hand it the identity PERSISTED in
+ * the registry, so it is the one place a marker written by an older CLI is compared against one read
+ * today. `checkSessionRuntime` makes the same allowance, but nothing calls it.
+ *
+ * Own file, and one narrowly-mocked import, because the sibling `tmuxBackend.spec.ts` drives the real
+ * binary through stub `tmux`/`ps` scripts on PATH — the wrong instrument for asserting which branch of
+ * one comparison ran.
+ */
+import { describe, expect, it, vi } from 'vitest'
+
+const resolvePaneEngineProcess = vi.hoisted(() => vi.fn())
+vi.mock('./tmux.js', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('./tmux.js')>()),
+ resolvePaneEngineProcess,
+}))
+
+const { TmuxBackend } = await import('./tmuxBackend.js')
+
+const PANE = { backend: 'tmux' as const, paneId: '%42' }
+/** The same process, read today, under the LC_TIME=C that psEnv now guarantees. */
+const LIVE = { pid: 15160, executable: '/Users/admin/.local/bin/claude', startMarker: 'Tue Sep 15 23:10:38 2026' }
+
+describe('TmuxBackend.validate and the pre-psEnv start marker', () => {
+ it('keeps a pane whose saved marker was written under the user own LC_TIME', async () => {
+ resolvePaneEngineProcess.mockResolvedValue(LIVE)
+ // hu_HU parsed fine before psEnv landed, so a marker like this is on disk for real users. It can
+ // never equal the C-locale stamp above, and comparing it would report a running engine as gone.
+ const saved = { ...LIVE, startMarker: 'K szept. 15 23:10:38 2026' }
+
+ const result = await new TmuxBackend().validate(PANE, { engine: 'claude', processIdentity: saved })
+
+ expect(result.state).toBe('alive')
+ })
+
+ it('keeps a pane whose saved marker came from the shifted pre-fix parser', async () => {
+ resolvePaneEngineProcess.mockResolvedValue(LIVE)
+ const saved = { ...LIVE, startMarker: 'Greeting Thu Jul 30 11:00:03 2026' }
+
+ expect((await new TmuxBackend().validate(PANE, { engine: 'claude', processIdentity: saved })).state)
+ .toBe('alive')
+ })
+
+ it('still evicts a pane whose engine really was replaced', async () => {
+ resolvePaneEngineProcess.mockResolvedValue(LIVE)
+ // A C-locale stamp IS comparable, so a genuine difference must still count — the allowance above
+ // must not become a hole in the PID-reuse guard.
+ const saved = { ...LIVE, pid: 999, startMarker: 'Mon Sep 14 08:00:00 2026' }
+
+ const result = await new TmuxBackend().validate(PANE, { engine: 'claude', processIdentity: saved })
+
+ // Narrow before reading `reason`: only the non-alive arms of RuntimeValidation carry one.
+ if (result.state !== 'gone') throw new Error(`expected gone, got ${result.state}`)
+ expect(result.reason).toContain('process changed')
+ })
+
+ it('reports an empty pane as gone, saved marker or not', async () => {
+ resolvePaneEngineProcess.mockResolvedValue(null)
+ const saved = { ...LIVE, startMarker: 'K szept. 15 23:10:38 2026' }
+
+ expect((await new TmuxBackend().validate(PANE, { engine: 'claude', processIdentity: saved })).state)
+ .toBe('gone')
+ })
+})