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(cli): accept the NPOLICY descriptor so native Codex agents bind again (#1336)

0xdiego253c66149371ca
diff --git a/cli/src/engines/kit/nativeDescriptors.spec.ts b/cli/src/engines/kit/nativeDescriptors.spec.ts
index 58460485b..4e6fcf733 100644
--- a/cli/src/engines/kit/nativeDescriptors.spec.ts
+++ b/cli/src/engines/kit/nativeDescriptors.spec.ts
@@ -11,6 +11,11 @@ it('retains exact device/inode numbers, repeated library maps and complete empty
expect(parse('p42\0\n')).toEqual([])
expect(parse('p42\0\nf4\0tPIPE\0n->pipe\0\n')).toEqual([{ fd: '4', kind: 'PIPE', path: '->pipe' }])
})
+it('accepts a nameless NPOLICY descriptor but never a nameless file', () => {
+ expect(parse('p42\0\nf33\0tNPOLICY\0n\0\n')).toEqual([{ fd: '33', kind: 'NPOLICY', path: '' }])
+ expect(() => parse('p42\0\nf33\0tREG\0D0x1\0i5\0n\0\n')).toThrow('identity is held')
+ expect(() => parse('p42\0\nf4\0tPIPE\0n\0\n')).toThrow('identity is held')
+})
it.each([
'', 'p42\n', 'p42\0\n' + file().slice(0, -1), 'p41\0\n' + file(),
file(), 'p42\0\np42\0\n', 'p42\0xextra\0\n',
diff --git a/cli/src/engines/kit/nativeDescriptors.ts b/cli/src/engines/kit/nativeDescriptors.ts
index d779a3b8a..499133372 100644
--- a/cli/src/engines/kit/nativeDescriptors.ts
+++ b/cli/src/engines/kit/nativeDescriptors.ts
@@ -17,7 +17,9 @@ export interface DescriptorEvidence {
export const descriptorKey = (row: NativeDescriptor) => `${row.device}:${row.inode}`
const signature = (rows: readonly NativeDescriptor[]) => rows.map(row =>
JSON.stringify([row.fd, row.path, row.kind, String(row.device), String(row.inode)])).sort().join('\n')
-const knownKinds = new Set(['REG', 'DIR', 'CHR', 'BLK', 'FIFO', 'PIPE', 'unix', 'IPv4', 'IPv6', 'KQUEUE', 'FSEVENT', 'PSXSEM', 'PSXSHM', 'systm', 'NDRV', 'LINK'])
+const knownKinds = new Set(['REG', 'DIR', 'CHR', 'BLK', 'FIFO', 'PIPE', 'unix', 'IPv4', 'IPv6', 'KQUEUE', 'FSEVENT', 'PSXSEM', 'PSXSHM', 'systm', 'NDRV', 'LINK', 'NPOLICY'])
+/** lsof prints these kernel objects with an empty name; every file-like kind still needs a path. */
+const nameless = new Set(['NPOLICY'])
/** -F0 still terminates each process/file set with NL after its final NUL field. */
export function parseDescriptors(output: string, pid: number, budget: NativeEvidenceBudget): NativeDescriptor[] {
@@ -40,7 +42,7 @@ export function parseDescriptors(output: string, pid: number, budget: NativeEvid
continue
}
const fd = fields.get('f'), kind = fields.get('t'), path = fields.get('n')
- if (!processSeen || !fd || !kind || !path || rows.length >= 4096) {
+ if (!processSeen || !fd || !kind || path === undefined || (!path && !nameless.has(kind)) || rows.length >= 4096) {
return nativeUnavailable('the native descriptor pool is incomplete or exceeds its limit')
}
if (!/^(?:\d{1,10}|cwd|rtd|txt|mem)$/.test(fd) || !knownKinds.has(kind)) return nativeUnavailable('a native descriptor is unreadable or has an unknown type')
diff --git a/cli/src/lib/nativeConversation.spec.ts b/cli/src/lib/nativeConversation.spec.ts
index ea774d1eb..a7745c957 100644
--- a/cli/src/lib/nativeConversation.spec.ts
+++ b/cli/src/lib/nativeConversation.spec.ts
@@ -46,6 +46,15 @@ it('deduplicates multiple descriptors, aliases and hard links for the same open
symlinkSync(own, alias); linkSync(own, link); held = [own, own, alias, link]
await expect(find()).resolves.toEqual({ sessionId: id(), transcriptPath: own })
})
+it('resolves the rollout of a process that also holds the nameless NPOLICY descriptor', async () => {
+ const own = rollout(); held = [own]
+ const base = sources.descriptors
+ sources.descriptors = async (pid, budget) => {
+ const evidence = await base(pid, budget)
+ return { ...evidence, descriptors: [...evidence.descriptors, { fd: '33', path: '', kind: 'NPOLICY' }] }
+ }
+ await expect(find()).resolves.toEqual({ sessionId: id(), transcriptPath: own })
+})
it('holds two eligible files rather than letting Stop accept an empty identity', async () => {
held = [rollout(1), rollout(2)]
await expect(find()).rejects.toMatchObject({ code: 'IDENTITY_UNAVAILABLE' })
diff --git a/cli/src/lib/nativeProcessControl.spec.ts b/cli/src/lib/nativeProcessControl.spec.ts
index 8bc6d7e62..2b4d618b8 100644
--- a/cli/src/lib/nativeProcessControl.spec.ts
+++ b/cli/src/lib/nativeProcessControl.spec.ts
@@ -3,6 +3,7 @@ import { createHash } from 'node:crypto'
import { tmpdir } from 'node:os'
import { dirname, join } from 'node:path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { parseDescriptors } from '../engines/kit/nativeDescriptors.js'
import { NativeEvidenceBudget } from '../engines/kit/nativeEvidence.js'
import { controlDescriptors, nativeProcessControl, parseNativeProcessControl } from './nativeProcessControl.js'
import { env } from '../config/env.js'
@@ -69,6 +70,9 @@ describe('strict Darwin control protocol', () => {
output({ ...record(), fds: [{ ...regular, type: 8 }] }),
output({ ...record(), fds: [{ ...regular, mode: 0 }] }),
output({ ...record(), fds: [{ ...regular, type: 2 }] }),
+ output({ ...record(), fds: [{ fd: 33, type: 9, mode: 1, device: '0', inode: '0' }] }),
+ output({ ...record(), fds: [{ fd: 33, type: 9, mode: 0, device: '1', inode: '0' }] }),
+ output({ ...record(), fds: [{ fd: 33, type: 9, mode: 0, device: '0', inode: '5' }] }),
])('holds incomplete or invalid native output', text => { expect(() => parse(text)).toThrow('identity is held') })
it('requires the entire requested pool, including unique child enumeration and all descriptor slots', () => {
const text = output(record(), { schema: 2, mode: 'control', parent: 42, children: [43, 43] })
@@ -79,6 +83,14 @@ describe('strict Darwin control protocol', () => {
it.each(['unix', 'IPv4', 'IPv6', 'systm', 'NDRV', 'LINK'])('matches the proven lsof socket family %s', kind => {
expect(controlDescriptors([{ fd: '7', path: 'irrelevant', kind }])).toBe(controlDescriptors([{ fd: '7', path: '', kind: 'SOCKET' }]))
})
+ it('accepts the network-policy descriptor every native Codex holds and joins it with the lsof pool', () => {
+ const netpolicy = { fd: 33, type: 9, mode: 0, device: '0', inode: '0' }
+ const row = parse(output({ ...record(), fds: [regular, netpolicy] })).rows.get(42)!
+ expect(row.fds[1]).toEqual({ fd: '33', path: '', kind: 'NPOLICY' })
+ const lsof = parseDescriptors('p42\0\nf3\0tREG\0D0x11\0i9007199254740993\0n/x\0\nf33\0tNPOLICY\0n\0\n', 42, budget())
+ expect(controlDescriptors(lsof.filter(d => d.fd === '33'))).toBe(controlDescriptors([row.fds[1]]))
+ expect(controlDescriptors(row.fds.filter(d => d.fd === '3'))).toBe(controlDescriptors([{ ...lsof[0], path: '' }]))
+ })
it('rejects error or stderr even when the helper returned a complete plausible reply', async () => {
for (const failure of ['exit', 'stderr']) {
host.exec.mockImplementationOnce((_path, _args, _options, callback) => callback(failure === 'exit' ? Error('failed') : null,
diff --git a/cli/src/lib/nativeProcessControl.ts b/cli/src/lib/nativeProcessControl.ts
index 91fecd725..dda25e527 100644
--- a/cli/src/lib/nativeProcessControl.ts
+++ b/cli/src/lib/nativeProcessControl.ts
@@ -81,7 +81,7 @@ export function parseNativeProcessControl(output: string, pids: readonly number[
|| BigInt(fd.device) > 0xffffffffn || typeof fd.inode !== 'string' || !/^\d{1,20}$/.test(fd.inode)
|| BigInt(fd.inode) > 0xffffffffffffffffn) return nativeUnavailable('the native control descriptor is invalid')
seen.add(fd.fd)
- const kinds: Record<number, string> = { 2: 'SOCKET', 3: 'PSXSHM', 4: 'PSXSEM', 5: 'KQUEUE', 6: 'PIPE', 7: 'FSEVENT' }
+ const kinds: Record<number, string> = { 2: 'SOCKET', 3: 'PSXSHM', 4: 'PSXSEM', 5: 'KQUEUE', 6: 'PIPE', 7: 'FSEVENT', 9: 'NPOLICY' }
const modes: Record<number, string> = { [0o100000]: 'REG', [0o040000]: 'DIR', [0o020000]: 'CHR', [0o060000]: 'BLK', [0o010000]: 'FIFO' }
const kind = fd.type === 1 ? modes[fd.mode] : kinds[fd.type]
if (!kind || (fd.type === 1 ? fd.inode === '0' : fd.mode !== 0 || fd.device !== '0' || fd.inode !== '0')) {