Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/scripts/remote-shared-control-retirement-probe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@ function summarizeMemory(snapshot: MemorySnapshot): {
app: MemorySnapshot['app']
host: MemorySnapshot['host']
processMemoryMetric: MemorySnapshot['processMemoryMetric']
processCommitMetric: MemorySnapshot['processCommitMetric']
totalCpu: number
totalMemory: number
totalPrivateMemory: MemorySnapshot['totalPrivateMemory']
worktreeCount: number
sessionCount: number
worktreeMemory: number
Expand All @@ -208,8 +210,10 @@ function summarizeMemory(snapshot: MemorySnapshot): {
app: snapshot.app,
host: snapshot.host,
processMemoryMetric: snapshot.processMemoryMetric,
processCommitMetric: snapshot.processCommitMetric,
totalCpu: snapshot.totalCpu,
totalMemory: snapshot.totalMemory,
totalPrivateMemory: snapshot.totalPrivateMemory,
worktreeCount: snapshot.worktrees.length,
sessionCount: snapshot.worktrees.reduce(
(total, worktree) => total + worktree.sessions.length,
Expand Down
7 changes: 7 additions & 0 deletions docs/reference/windows-process-enumeration.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ time to prove a PID has not been recycled — daemon identity, managed-hook
ownership, and CPU accounting in the memory collector — still reads it through
its own query. Those callers are not migrated.

Committed private bytes have no equivalent either, and the one memory value the
snapshot does carry is unusable for the sizes Orca now sees: `process.cc` stores
`pmc.WorkingSetSize` into a `DWORD`, so anything above 4 GB wraps. That is the
second reason `windows-process-resource-collector.ts` still runs its own
`Get-CimInstance` sweep — it needs `PageFileUsage` (commit) and the CPU-time
counters in the same pass. Migrating it to the native table would cost both.

Start time is a proxy for identity, not identity. The durable answer for the
process trees Orca itself spawns is an inherited handle: a job object names the
tree Orca created, so no start-time comparison is needed. Those readers should
Expand Down
107 changes: 107 additions & 0 deletions src/cli/index-memory-diagnostics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,112 @@ describe('orca cli worktree awareness', () => {
expect(output).toContain('hostAvailable: 2.0 MB (free-memory)')
expect(output).toContain('app: 1.0 MB')
expect(output).toContain('- feature 1.0 MB 2.5% 1 session')
// Back-compat: a host that never heard of committed bytes prints none.
expect(output).not.toContain('totalPrivateMemory')
expect(output).not.toContain('processCommitMetric')
})

it('reports committed private bytes alongside the resident figure', async () => {
queueFixtures(
callMock,
okFixture('req_memory', {
app: {
cpu: 1.25,
memory: 1024 * 1024,
privateMemory: 2 * 1024 * 1024,
main: { cpu: 0.5, memory: 512 * 1024, privateMemory: 1024 * 1024 },
renderer: { cpu: 0.5, memory: 384 * 1024, privateMemory: 768 * 1024 },
other: { cpu: 0.25, memory: 128 * 1024, privateMemory: 256 * 1024 },
history: [1024 * 1024]
},
worktrees: [
{
worktreeId: 'repo::/tmp/repo/feature',
worktreeName: 'feature',
repoId: 'repo',
repoName: 'Orca',
cpu: 2.5,
memory: 1024 * 1024,
privateMemory: 14 * 1024 * 1024,
sessions: [
{
sessionId: 'pty-1',
paneKey: null,
pid: 123,
cpu: 2.5,
memory: 1024 * 1024,
privateMemory: 14 * 1024 * 1024
}
],
history: [1024 * 1024]
}
],
host: {
totalMemory: 8 * 1024 * 1024,
freeMemory: 2 * 1024 * 1024,
availableMemory: 2 * 1024 * 1024,
availableMemorySource: 'free-memory',
usedMemory: 6 * 1024 * 1024,
memoryUsagePercent: 75,
cpuCoreCount: 8,
loadAverage1m: 1.25
},
processMemoryMetric: 'working-set',
processCommitMetric: 'private-bytes',
totalCpu: 3.75,
totalMemory: 2 * 1024 * 1024,
totalPrivateMemory: 16 * 1024 * 1024,
collectedAt: 1000
})
)
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {})

await main(['diagnostics', 'memory'], '/tmp/repo')

const output = logSpy.mock.calls.flat().join('\n')
expect(output).toContain('totalMemory: 2.0 MB')
expect(output).toContain('processMemoryMetric: summed working set; shared pages may repeat')
expect(output).toContain('totalPrivateMemory: 16 MB')
expect(output).toContain(
'processCommitMetric: summed private bytes; committed memory, counted whether resident or paged out'
)
expect(output).toContain('- feature 1.0 MB 14 MB committed 2.5% 1 session')
})

it('passes committed bytes through --json untouched', async () => {
const snapshot = {
app: {
cpu: 0,
memory: 1024,
privateMemory: 4096,
main: { cpu: 0, memory: 1024, privateMemory: 4096 },
renderer: { cpu: 0, memory: 0, privateMemory: 0 },
other: { cpu: 0, memory: 0, privateMemory: 0 },
history: []
},
worktrees: [],
host: {
totalMemory: 16 * 1024,
freeMemory: 1024,
availableMemory: 1024,
availableMemorySource: 'free-memory',
usedMemory: 15 * 1024,
memoryUsagePercent: 93.75,
cpuCoreCount: 8,
loadAverage1m: 0
},
processMemoryMetric: 'working-set',
processCommitMetric: 'private-bytes',
totalCpu: 0,
totalMemory: 1024,
totalPrivateMemory: 4096,
collectedAt: 1000
}
queueFixtures(callMock, okFixture('req_memory', snapshot))
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {})

await main(['diagnostics', 'memory', '--json'], '/tmp/repo')

expect(JSON.parse(logSpy.mock.calls.flat().join('\n')).result).toEqual(snapshot)
})
})
22 changes: 22 additions & 0 deletions src/cli/workspace-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function formatMemorySnapshot(snapshot: MemorySnapshot): string {
`collectedAt: ${new Date(snapshot.collectedAt).toISOString()}`,
`totalMemory: ${formatByteCount(snapshot.totalMemory)}`,
`processMemoryMetric: ${formatProcessMemoryMetric(snapshot.processMemoryMetric)}`,
...formatCommitLines(snapshot),
`totalCpu: ${formatCpu(snapshot.totalCpu)}`,
[
`hostUsed: ${formatByteCount(snapshot.host.usedMemory)}`,
Expand Down Expand Up @@ -55,11 +56,32 @@ function formatWorktreeMemoryLine(worktree: WorktreeMemory): string {
return [
`- ${worktree.worktreeName}`,
`${formatByteCount(worktree.memory)}`,
...(worktree.privateMemory === undefined
? []
: [`${formatByteCount(worktree.privateMemory)} committed`]),
`${formatCpu(worktree.cpu)}`,
`${worktree.sessions.length} session${worktree.sessions.length === 1 ? '' : 's'}`
].join(' ')
}

// Why omitted rather than zeroed: a host that predates the field, or cannot read
// commit at all, must not be printed as agents committing nothing.
function formatCommitLines(snapshot: MemorySnapshot): string[] {
if (typeof snapshot.totalPrivateMemory !== 'number') {
return []
}
return [
`totalPrivateMemory: ${formatByteCount(snapshot.totalPrivateMemory)}`,
`processCommitMetric: ${formatProcessCommitMetric(snapshot.processCommitMetric)}`
]
}

function formatProcessCommitMetric(metric: MemorySnapshot['processCommitMetric']): string {
return metric === 'private-bytes'
? 'summed private bytes; committed memory, counted whether resident or paged out'
: `summed ${metric ?? 'unknown'}`
}

function formatCpu(cpu: number): string {
return `${cpu.toFixed(1)}%`
}
Expand Down
Loading
Loading