Skip to content
This repository was archived by the owner on Apr 24, 2026. It is now read-only.

Commit edb0c14

Browse files
lanmowerclaude
andcommitted
Fix PM2 logs: echo child output to exec-process stdout/stderr so pm2 monit shows real task output
- exec-process.js: pipe child stdout/stderr to process.stdout/stderr (in addition to RPC appendOutput) - runtime.js: nodejs/typescript spawn with stdin='ignore' to prevent bun exit on empty pipe Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c58163b commit edb0c14

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/exec-process.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ async function runChild(child, cleanup) {
3838
child.stdout?.on('data', async (d) => {
3939
const str = d.toString('utf8');
4040
stdout += str;
41+
process.stdout.write(str);
4142
await rpc('appendOutput', { taskId, type: 'stdout', data: str });
4243
});
4344
child.stderr?.on('data', async (d) => {
4445
const str = d.toString('utf8');
4546
stderr += str;
47+
process.stderr.write(str);
4648
await rpc('appendOutput', { taskId, type: 'stderr', data: str });
4749
});
4850
return new Promise((resolve) => {
@@ -83,13 +85,16 @@ async function runCompiled(spawnResult) {
8385
: { taskId, error: result.stderr || 'Execution failed' });
8486
}
8587

88+
process.stderr.write('[exec-process] task=' + taskId + ' runtime=' + RUNTIME + ' starting\n');
8689
const spawnResult = spawnProcess(RUNTIME, code, CWD);
8790
if (spawnResult.isCompile) {
8891
await runCompiled(spawnResult);
8992
} else {
9093
const result = await runChild(spawnResult.child, spawnResult.cleanup);
94+
process.stderr.write('[exec-process] task=' + taskId + ' child exited code=' + result.exitCode + '\n');
9195
await rpc(result.ok ? 'completeTask' : 'failTask', result.ok
9296
? { taskId, result: { success: true, exitCode: result.exitCode, stdout: result.stdout, stderr: result.stderr } }
9397
: { taskId, error: result.error || result.stderr || 'Execution failed' });
9498
}
99+
process.stderr.write('[exec-process] task=' + taskId + ' done\n');
95100
process.exit(0);

src/runtime.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ function makeTmp(ext, content) {
3939
return { dir, file };
4040
}
4141

42-
function spawnOpts(cwd) {
43-
return { cwd: cwd || process.cwd(), stdio: ['pipe', 'pipe', 'pipe'], detached: false };
42+
function spawnOpts(cwd, stdin = 'pipe') {
43+
return { cwd: cwd || process.cwd(), stdio: [stdin, 'pipe', 'pipe'], detached: false };
4444
}
4545

4646
export function spawnProcess(runtime, code, cwd) {
4747
let tmpDir = null;
4848
const cleanup = () => { if (tmpDir) { try { rmSync(tmpDir, { recursive: true, force: true }); } catch {} tmpDir = null; } };
4949

5050
if (runtime === 'nodejs' || runtime === 'typescript') {
51-
const child = spawn('bun', ['-e', code], spawnOpts(cwd));
51+
const child = spawn('bun', ['-e', code], spawnOpts(cwd, 'ignore'));
5252
return { child, cleanup };
5353
}
5454
if (runtime === 'python') {

0 commit comments

Comments
 (0)