Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(review): retain primary runtime session identity [V1,B3]
Corey Olson7e9e2180a70d
diff --git a/src/parent-session.js b/src/parent-session.jsindex d2ff1bfe..3d0f5948 100644--- a/src/parent-session.js+++ b/src/parent-session.js@@ -9,6 +9,7 @@ import { homedir } from 'node:os';import { join } from 'node:path';import { Refused } from './refused.js';import { createHash } from 'node:crypto';+import { AGENT_SESSION_IDS } from './person.js';/** Accept an opaque identity, never a path, whitespace, credential or arbitrary session metadata. */export function parentIdentity(value) {@@ -46,14 +47,19 @@ function ownSessionMetadata(file, session) {finally { if (descriptor !== undefined) closeSync(descriptor); }}-/** Discover only the invoking Codex session's metadata file, matching its runtime id before reading it. */+/** Keep the runtime's own identity; discover a parent only in its matching Codex metadata record. */export function runtimeSessionIdentity(environment = process.env, home = homedir()) {- const session = environment.CODEX_THREAD_ID || environment.CODEX_SESSION_ID;- if (!session || !/^[A-Za-z0-9-]+$/u.test(session)) return null;+ const key = AGENT_SESSION_IDS.find(name => Boolean(environment[name]));+ if (!key) return null;+ let session;+ try { session = parentIdentity(environment[key]); }+ catch { return null; }+ const own = { session, parent: null };+ if (key === 'CLAUDE_CODE_SESSION_ID') return own;const sessions = join(environment.CODEX_HOME || join(home, '.codex'), 'sessions');let entries;try { entries = readdirSync(sessions, { recursive: true, withFileTypes: true }); }- catch { return null; }+ catch { return own; }for (const entry of entries) {if (!entry.isFile() || !entry.name.endsWith(`-${session}.jsonl`)) continue;const metadata = ownSessionMetadata(join(entry.parentPath, entry.name), session);@@ -62,7 +68,7 @@ export function runtimeSessionIdentity(environment = process.env, home = homedirtry { return { session: parentIdentity(session), parent: parent ? parentIdentity(parent) : null }; }catch { /* An invalid runtime record cannot declare another identity. */ }}- return null;+ return own;}/** Read this runtime's parent, keeping a primary session's missing parent visible as unknown. */diff --git a/test/parent-session.test.js b/test/parent-session.test.jsindex 76aef7a6..ec5f314e 100644--- a/test/parent-session.test.js+++ b/test/parent-session.test.js@@ -13,6 +13,7 @@ import {joinParentSession,parentSessionDigest,runtimeParentSession,+ runtimeSessionIdentity,} from '../src/parent-session.js';import * as store from '../src/board.js';import { runFixtureGit } from './fixture-child.js';@@ -44,6 +45,10 @@ test('[V1,B3] parent discovery reads only matching own runtime metadata and agrewriteFileSync(own, JSON.stringify({ type: 'session_meta', payload: { id: 'other-session', parent_thread_id: 'foreign-parent' } }) + '\n');assert.equal(runtimeParentSession(environment), null, 'a filename alone cannot authenticate another session record');assert.equal(joinParentSession(undefined, {}), null, 'missing runtime metadata remains unknown');+ assert.deepEqual(runtimeSessionIdentity({ CODEX_SESSION_ID: 'unrecorded-own-session', CODEX_HOME: home }),+ { session: 'unrecorded-own-session', parent: null }, 'own runtime identity survives missing metadata');+ assert.deepEqual(runtimeSessionIdentity({ CLAUDE_CODE_SESSION_ID: 'claude-own-session', ...environment }),+ { session: 'claude-own-session', parent: null }, 'the native Claude session takes precedence over inherited Codex identity');assert.throws(() => joinParentSession('/private/session.jsonl'), { code: 'BAD_PARENT' });});