feat(targets,management): instrument adapter spawn lifecycle and instance manager

Each target adapter (claude, codex, droid) now emits dispatch on child
spawn and respond on child exit with latencyMs. instance-manager emits
lifecycle events for instance create / start / stop so multi-instance flows
are traceable per requestId.

Refs #1141, #1138
This commit is contained in:
Tam Nhu Tran committed 2026-04-30 13:00:49 -04:00
1 parent 1ff4329ee4
commit 8afee344e1
4 files changed
+70

No files matched your search

+20
View File
@@ -23,6 +23,9 @@ import {
getCodexBinaryInfo,
readCodexVersion,
} from './codex-detector';
import { createLogger } from '../services/logging';
const adapterLogger = createLogger('targets:codex');
const CODEX_RUNTIME_PROVIDER_ID = 'ccs_runtime';
const CODEX_RUNTIME_ENV_KEY = 'CCS_CODEX_API_KEY';
@@ -310,6 +313,13 @@ export class CodexAdapter implements TargetAdapter {
const isPowerShellScript = isWindows && /\.ps1$/i.test(codexPath);
const needsShell = isWindows && /\.(cmd|bat)$/i.test(codexPath);
const spawnStartedAt = Date.now();
adapterLogger.stage('dispatch', 'target.spawn', 'Spawning Codex CLI child process', {
target: 'codex',
codexPath,
argCount: args.length,
});
let child: ChildProcess;
if (isPowerShellScript) {
child = spawn(
@@ -329,6 +339,16 @@ export class CodexAdapter implements TargetAdapter {
child = spawn(codexPath, args, { stdio: 'inherit', windowsHide: true, env: launchEnv });
}
child.on('exit', (code, signal) => {
adapterLogger.stage(
'respond',
'target.exit',
'Codex CLI child process exited',
{ target: 'codex', exitCode: code, signal },
{ latencyMs: Date.now() - spawnStartedAt }
);
});
wireChildProcessSignals(child, (err: NodeJS.ErrnoException) => {
if (err.code === 'EACCES') {
console.error(`[X] Codex CLI is not executable: ${codexPath}`);