Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
test: classify owned Chrome startup syscalls without private registers (#9641)
[._.]/ Adam Eivy060925e23330
diff --git a/server/services/htmlComposition/testBrowserCleanup.js b/server/services/htmlComposition/testBrowserCleanup.jsindex f7dc8eb3f7..89d33d91c1 100644--- a/server/services/htmlComposition/testBrowserCleanup.js+++ b/server/services/htmlComposition/testBrowserCleanup.js@@ -25,8 +25,8 @@ export function _selectTestChrome(candidates) {}// Failure-only Linux observations of this owned child and its current worker.-// Never read cmdline, environ, links, stacks, or arbitrary process output. A-// At most 23 prefixes of 4096 bytes (92 KiB), 17 directory entries and one+// Never read cmdline, environ, links, stacks, or arbitrary process output.+// At most 40 prefixes of 4096 bytes (160 KiB), 17 directory entries and one// statfs call. These count/byte caps do not guarantee elapsed time. Samples// are non-atomic: wait categories and resource pressure do not prove a cause.function readProcPrefix(path) {@@ -64,6 +64,34 @@ const WAIT_CATEGORIES = new Map([const safeInteger = value => Number.isSafeInteger(value) && value >= 0 ? value : 'unavailable';const attemptObservation = fn => { try { return fn(); } catch { return 'unavailable'; } };+// Native Linux x86-64 syscall numbers, from arch/x86/entry/syscalls/syscall_64.tbl.+// This is a diagnostic for the native 64-bit CI browser, not a decoder for+// compatibility ABIs. Report unknown numbers as other; never keep arguments,+// stack/program counters, file descriptors or paths from /proc/*/syscall.+const X64_SYSCALL_CATEGORIES = new Map([+ ['read', [0, 17, 19]], ['write', [1, 18, 20]], ['open', [2, 257, 437]],+ ['metadata', [4, 5, 6, 21, 262, 332]], ['memory', [9, 10, 11, 12, 25, 28]],+ ['futex', [202, 449]], ['poll', [7, 23, 232, 270, 271, 281, 441]],+ ['process', [56, 57, 58, 59, 61, 247, 322, 435]], ['entropy', [318]], ['device', [16]],+].flatMap(([category, numbers]) => numbers.map(number => [String(number), category])));++function syscallFacts(pid, ids, { read, arch }) {+ if (arch !== 'x64') return '; syscalls: table=unsupported';+ const category = path => attemptObservation(() => {+ const text = read(path).slice(0, 4096).trim();+ if (text === 'running') return 'running';+ // Read only the first token. Everything after it is private register data.+ const number = text.match(/^(-1|0|[1-9]\d*)(?:\s|$)/)?.[1];+ if (!number) return 'unavailable';+ if (number === '-1') return 'outside';+ return X64_SYSCALL_CATEGORIES.get(number) ?? 'other';+ });+ const counts = Object.fromEntries(['running', 'outside', ...new Set(X64_SYSCALL_CATEGORIES.values()), 'other', 'unavailable'].map(name => [name, 0]));+ const lead = category(`/proc/${pid}/syscall`);+ for (const id of ids?.slice(0, 16) ?? []) counts[category(`/proc/${pid}/task/${id}/syscall`)]++;+ return `; syscalls: table=x64-native lead=${lead} threads=${ids ? Object.entries(counts).map(([name, count]) => `${name}:${count}`).join(',') : 'unavailable'}`;+}+function resourceFacts(child, { read, cpus, usage, disk }) {const worker = attemptObservation(usage);const fs = attemptObservation(disk);@@ -85,6 +113,7 @@ function resourceFacts(child, { read, cpus, usage, disk }) {export function _testChromeProcessFacts(proc, {platform = process.platform, workerPid = process.pid, read = readProcPrefix, threads = readThreadIds,+ arch = process.arch,cpus = availableParallelism, usage = () => process.resourceUsage(), disk = () => statfsSync(tmpdir()),} = {}) {if (platform !== 'linux') return 'os=unsupported';@@ -124,7 +153,8 @@ export function _testChromeProcessFacts(proc, {+ ` parent=${same(child?.parent, String(workerPid))} group=${same(child?.group, worker?.group)} session=${same(child?.session, worker?.session)}`+ ` leadWait=${leadWait} threads=${ids ? Math.min(ids.length, 16) : 'unavailable'} threadLimit=${ids ? ids.length > 16 : 'unavailable'}`+ ` waits=${Object.entries(waits).map(([name, count]) => `${name}:${count}`).join(',')}`- + `; resources: ${resourceFacts(child, { read, cpus, usage, disk })}`;+ + `; resources: ${resourceFacts(child, { read, cpus, usage, disk })}`+ + syscallFacts(proc.pid, ids, { read, arch });}function describeProcess(proc, observeProcess) {diff --git a/server/services/htmlComposition/testBrowserCleanup.test.js b/server/services/htmlComposition/testBrowserCleanup.test.jsindex 6282d7cb9d..de2dfa82d4 100644--- a/server/services/htmlComposition/testBrowserCleanup.test.js+++ b/server/services/htmlComposition/testBrowserCleanup.test.js@@ -27,6 +27,7 @@ function startingChild() {}const syntheticResources = {+ arch: 'unsupported',cpus: () => 4,usage: () => ({ userCPUTime: 0, systemCPUTime: 12, maxRSS: 34 }),disk: () => ({ bavail: 2, bsize: 4096, ffree: 5 }),@@ -38,7 +39,7 @@ const resourceText = {'/proc/meminfo': 'MemAvailable: 42 kB\n',};const resourceExpected = '; resources: cpus=4 workerUserMicros=0 workerSystemMicros=12 workerMaxRssKiB=34 childCpuTicks=23'- + ' cpuAvg10=1.25 memoryAvg10=0 ioAvg10=3.5 memAvailableKiB=42 tmpFreeBytes=8192 tmpFreeInodes=5';+ + ' cpuAvg10=1.25 memoryAvg10=0 ioAvg10=3.5 memAvailableKiB=42 tmpFreeBytes=8192 tmpFreeInodes=5; syscalls: table=unsupported';function expectStartupClean(proc) {expect(proc.listenerCount('spawn')).toBe(0);@@ -226,6 +227,54 @@ describe('test Chrome startup', () => {await expect(ready).rejects.not.toThrow('example-secret');expectStartupClean(proc);});++ it('captures capped syscall categories only at failure, without leaking registers or inventing denied observations', async () => {+ const proc = startingChild();+ proc.pid = 123;+ const registers = ' 0xexample-secret 456 777 /private/example-secret';+ const read = vi.fn(path => {+ if (path.endsWith('/stat')) return '123 (example-secret) D 456 777 888';+ if (path.endsWith('/wchan')) return 'folio_wait_bit_common';+ if (path === '/proc/123/syscall') return '9' + registers;+ if (path.endsWith('/syscall')) {+ const id = path.split('/').at(-2);+ if (id === '4') throw new Error('denied example-secret');+ return ({ 1: '202' + registers, 2: 'running', 3: '-1' + registers, 5: '257' + registers, 6: '318' + registers, 7: '999' + registers, 8: 'malformed example-secret', 9: '9'.padEnd(4096, ' ') + registers })[id] ?? '0' + registers;+ }+ return resourceText[path];+ });+ const observeProcess = owned => _testChromeProcessFacts(owned, {+ platform: 'linux', workerPid: 456, read, threads: () => Array.from({ length: 100 }, (_, i) => String(i + 1)),+ ...syntheticResources, arch: 'x64',+ });+ const ready = _waitForTestChrome(proc, 20000, undefined, { observeProcess });+ const rejected = expect(ready).rejects.toThrow('did not start within 20000ms');+ await vi.advanceTimersByTimeAsync(19999);+ expect(read).not.toHaveBeenCalled();+ await vi.advanceTimersByTimeAsync(1);+ await rejected;+ await expect(ready).rejects.toThrow('syscalls: table=x64-native lead=memory threads=running:1,outside:1,read:7,write:0,open:1,metadata:0,memory:1,futex:1,poll:0,process:0,entropy:1,device:0,other:1,unavailable:2');+ await expect(ready).rejects.not.toThrow(/example-secret|0x|\/private\/|456|777|888/);+ expect(read).toHaveBeenCalledTimes(40);+ expect(read.mock.calls.filter(([path]) => path.endsWith('/syscall'))).toHaveLength(17);+ expect(read.mock.calls.every(([path]) => /^\/proc\/(?:(123|456)\/(stat|wchan|syscall|task\/\d+\/(wchan|syscall))|pressure\/(cpu|memory|io)|meminfo)$/.test(path))).toBe(true);+ expectStartupClean(proc);+ });++ it('keeps denied leader syscalls and unavailable thread lists distinct from empty or unsupported samples', () => {+ const read = vi.fn(path => {+ if (path.endsWith('/syscall')) throw new Error('denied example-secret');+ return resourceText[path] ?? '0';+ });+ const options = { platform: 'linux', read, ...syntheticResources, arch: 'x64' };+ const denied = _testChromeProcessFacts({ pid: 123 }, { ...options, threads: () => { throw new Error('denied'); } });+ expect(denied).toContain('syscalls: table=x64-native lead=unavailable threads=unavailable');+ const empty = _testChromeProcessFacts({ pid: 123 }, { ...options, threads: () => [] });+ expect(empty).toContain('syscalls: table=x64-native lead=unavailable threads=running:0,outside:0');+ read.mockClear();+ expect(_testChromeProcessFacts({ pid: 123 }, { ...options, arch: 'arm64', threads: () => [] })).toContain('syscalls: table=unsupported');+ expect(read.mock.calls.some(([path]) => path.endsWith('/syscall'))).toBe(false);+ });});describe('real capture diagnostics boundary', () => {