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.

fix(core): prevent same-millisecond pane name collisions (#1091)

Dee47d2f5a6bd6d
diff --git a/cli/src/lib/harnessSessionLabel.spec.ts b/cli/src/lib/harnessSessionLabel.spec.ts
index a6a0230c3..91a1fa4a3 100644
--- a/cli/src/lib/harnessSessionLabel.spec.ts
+++ b/cli/src/lib/harnessSessionLabel.spec.ts
@@ -2,12 +2,42 @@ import { mkdirSync, mkdtempSync, rmSync, symlinkSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
-import { harnessPaneOwner, ownedHere, ownerCommand, paneOwnerFormat, paneOwnerOf } from './harnessSessionLabel.js'
+import { buildHarnessSessionLabel, harnessPaneOwner, isHarnessSessionFor, ownedHere, ownerCommand, paneOwnerFormat, paneOwnerOf } from './harnessSessionLabel.js'
import { isolatedTmux } from '../testing/isolatedTmux.js'
const dirs: string[] = []
afterEach(() => { for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true }) })
+describe('panes created in the same millisecond', () => {
+ it('allocates distinct names for the same engine and keeps discovery recognition', () => {
+ const now = 1_700_000_000_000
+ const names = Array.from({ length: 128 }, () => buildHarnessSessionLabel('claude', now))
+ expect(new Set(names).size).toBe(names.length)
+ for (const name of names) {
+ expect(name).toMatch(/^harness-claude-1700000000000-/)
+ expect(name).toMatch(/^[A-Za-z0-9_-]+$/)
+ expect(isHarnessSessionFor(name, 'claude')).toBe(true)
+ expect(isHarnessSessionFor(name, 'codex')).toBe(false)
+ }
+ })
+
+ it('starts two real private panes concurrently with names allocated at the identical clock value', async () => {
+ const home = mkdtempSync(join(tmpdir(), 'pane-label-'))
+ dirs.push(home)
+ const tmux = await isolatedTmux({ ...process.env, HOME: home, ZDOTDIR: home, HISTFILE: join(home, 'history') })
+ try {
+ // Start the disposable server first: this tests name allocation, not a tmux startup race.
+ await tmux.run('new-session', '-d', '-s', 'fixture-bootstrap', '/bin/sh', '-c', 'sleep 60')
+ const names = Array.from({ length: 2 }, () => buildHarnessSessionLabel('codex', 1_700_000_000_000))
+ const panes = await Promise.all(names.map(name => tmux.run('new-session', '-d', '-P', '-F', '#{pane_id}',
+ '-s', name, '/bin/sh', '-c', 'sleep 60')))
+ expect(new Set(panes).size).toBe(2)
+ const sessions = (await tmux.run('list-sessions', '-F', '#{session_name}')).split('\n')
+ for (const name of names) expect(sessions).toContain(name)
+ } finally { await tmux.close() }
+ })
+})
+
describe('which daemon a pane belongs to', () => {
it('is one tag per data folder: the same for one daemon every time, another for a daemon beside it', () => {
const root = mkdtempSync(join(tmpdir(), 'pane-owner-'))
@@ -70,7 +100,9 @@ describe('the tag on a tmux before 3.0', () => {
it('reads the window\'s tag only in a session Harness named, on a real tmux', async () => {
// A pane the person split into an agent's window, once they had moved that window into their own
// session, carries no tag of its own: the window's was taken for it, and it was styled as an agent.
- const tmux = await isolatedTmux()
+ const home = mkdtempSync(join(tmpdir(), 'pane-owner-home-'))
+ dirs.push(home)
+ const tmux = await isolatedTmux({ ...process.env, HOME: home, ZDOTDIR: home, HISTFILE: join(home, 'history') })
try {
const tag = '0123456789abcdef'
await tmux.run('new-session', '-d', '-s', 'harness-claude-1', '-x', '80', '-y', '24')
diff --git a/cli/src/lib/harnessSessionLabel.ts b/cli/src/lib/harnessSessionLabel.ts
index 151c3404e..fe004337a 100644
--- a/cli/src/lib/harnessSessionLabel.ts
+++ b/cli/src/lib/harnessSessionLabel.ts
@@ -9,7 +9,7 @@
*
* The name says a pane is Harness's, not WHICH daemon's: see `HARNESS_OWNER_OPTION`.
*/
-import { createHash } from 'node:crypto'
+import { createHash, randomUUID } from 'node:crypto'
import { realpathSync } from 'node:fs'
import { basename, dirname, join, resolve } from 'node:path'
@@ -106,14 +106,15 @@ export function ownedHere(owner: string, sessionName: string, self: string): boo
}
export function buildHarnessSessionLabel(engine: string, now: number = Date.now()): string {
- return `${HARNESS_SESSION_PREFIX}${engine}-${now}`.replace(/[^A-Za-z0-9_-]/g, '-')
+ // Concurrent creates can share a millisecond, and separate daemons can share the tmux server.
+ return `${HARNESS_SESSION_PREFIX}${engine}-${now}-${randomUUID()}`.replace(/[^A-Za-z0-9_-]/g, '-')
}
export function isHarnessSession(sessionName: string): boolean {
return sessionName.startsWith(HARNESS_SESSION_PREFIX)
}
-/** Whether a harness session was created FOR this engine — `harness-<engine>-<ts>` — rather than another. */
+/** Whether a harness session was created FOR this engine; old and new creation suffixes both qualify. */
export function isHarnessSessionFor(sessionName: string, engine: string): boolean {
return sessionName.startsWith(`${HARNESS_SESSION_PREFIX}${engine}-`)
}
diff --git a/cli/src/lib/tmuxLegacySessions.spec.ts b/cli/src/lib/tmuxLegacySessions.spec.ts
index c546ea278..05d027684 100644
--- a/cli/src/lib/tmuxLegacySessions.spec.ts
+++ b/cli/src/lib/tmuxLegacySessions.spec.ts
@@ -71,13 +71,13 @@ describe('adoptLegacyHarnessSessions', () => {
const adopted = await adoptLegacyHarnessSessions(owned, 1_800_000_000_000)
expect(adopted).toEqual([
- { from: 'claude-1787912296587', to: 'harness-claude-1800000000000', paneId: '%13' },
- { from: 'codex-1787549944131', to: 'harness-codex-1800000000001', paneId: '%1' },
+ { from: 'claude-1787912296587', to: expect.stringMatching(/^harness-claude-1800000000000-[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/), paneId: '%13' },
+ { from: 'codex-1787549944131', to: expect.stringMatching(/^harness-codex-1800000000001-[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/), paneId: '%1' },
])
expect(readFileSync(calls, 'utf8').trim().split('\n')).toEqual([
'list-panes -a -F #{pane_id}|#{pane_pid}|#{session_name}|#{pane_current_path}|#{@harness_daemon}',
- 'rename-session -t =claude-1787912296587 harness-claude-1800000000000',
- 'rename-session -t =codex-1787549944131 harness-codex-1800000000001',
+ `rename-session -t =claude-1787912296587 ${adopted[0]!.to}`,
+ `rename-session -t =codex-1787549944131 ${adopted[1]!.to}`,
])
})
diff --git a/docs/research/2026-10-09-daemon-separation-progress.md b/docs/research/2026-10-09-daemon-separation-progress.md
index 2b104a063..f338f3376 100644
--- a/docs/research/2026-10-09-daemon-separation-progress.md
+++ b/docs/research/2026-10-09-daemon-separation-progress.md
@@ -144,9 +144,40 @@ times will be recorded after the CI correction is reviewed and validated.
## Added core follow-ups
+Item 6 completed as `a9895b02c` at 06:23:02 UTC. Independent review approved
+`3af878758` against `79c658faa`; [automatic CI](https://github.com/autonomous-ai/openharness/actions/runs/37892739470)
+passed all selected checks and `ci/required`. Final receipt
+`20261009T061719.342956Z-78031` passed typecheck, core/harnessd at per-file 100%,
+and 622 directly affected tests including architecture and both unchanged goldens.
+The broader preceding run passed 1,780 tests with seven existing skips. Full
+reader/model/lean/crash lanes passed 28 selected cases; the final rebuilt lean
+bundle passed its two cases. The final queue correction changes only dependent
+Command Code refresh ordering, covered by the real config and batch regressions.
+
+Matched final measurement `20261009T061834.097319Z-84262` passed in 69.7 seconds:
+empty/idle/active CPU 0.75/1.65/6.81%, mean RSS 81.2/95.7/98.9 MiB, event-loop
+p95 12.07/12.07/12.06 ms, and two-turn latency p95 6.979 seconds. The baseline
+above was 0.75/1.65/6.91%, 81.2/95.1/98.8 MiB and 6.976 seconds, on the same
+toolchain and workload. These are short core-only observations, not a new limit.
+
+Runtime timing: golden committed 05:26:02; implementation/review corrections
+continued through 06:16; final review approved at 06:17. Local checks ended about
+06:18. Measurement ran 06:18:47–06:19:44; CI finished 06:21:19. The merge helper
+ran 06:22:48–06:23:02 and verified the full tested tree. Golden commit through
+merge took 57 minutes; total request elapsed was 6 hours 56 minutes 21 seconds.
+Validation, implementation and review overlap; waiting and merge are separate.
+Publication remains zero.
+
Pane profile polling also needs a session/route snapshot taken before capture:
the entry-time check cannot reject an older screen if the same registry object
changed in place during the capture. This pre-existing limitation is independent
of the runtime extraction's config and staged-history publication checks.
-The owner reported that two panes of the same agent started in one millisecond fail. Onboarding avoids it today; the fix belongs in core. The current session-label generator contains only the engine and a millisecond timestamp, so concurrent same-engine creates can collide. Reproduce with a pinned clock, fix the shared label generation, and verify two isolated panes can start together. This is not blocking the completed usage separation.
+The owner reported that two panes of the same agent started in one millisecond
+fail. Onboarding avoids it today. Regressions committed in `be3ed36e1` reproduce
+both the duplicate label and a real tmux `duplicate session` failure with two
+concurrent private panes. The shared generator now appends a random UUID to the
+existing engine/timestamp prefix, avoiding same-clock collisions across calls,
+daemon processes and restarts. Discovery still accepts both old and new names;
+existing panes are neither renamed nor removed. All native fixtures use private
+homes, shell history and sockets. Final validation and review are pending.