Skip to content

Commit 817b6aa

Browse files
committed
fix(react-devtools): name the surviving companion when both faults fire
The precedence change dropped the stop verdict in the both-fail path: the action's fault is the right thing to throw, but an operator who saw only `devtools package failed` never learned a companion was still holding the bridge scope. It is now written to stderr beside the thrown fault, on the same channel the file already uses for its wait hint.
1 parent ce30ed9 commit 817b6aa

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

‎src/__tests__/cli-react-devtools.test.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,17 @@ test('react-devtools stop reports a companion whose stop could not be confirmed'
251251

252252
test('react-devtools stop keeps its own failure ahead of an unconfirmed companion stop', async () => {
253253
const actionFault = new Error('devtools package failed');
254+
const stopFault = new AppError('COMMAND_FAILED', 'companion pid 4322 is still running', {
255+
reason: 'signal-failed',
256+
pid: 4322,
257+
});
254258
vi.mocked(runCmdStreaming).mockRejectedValueOnce(actionFault);
255-
vi.mocked(stopReactDevtoolsCompanion).mockRejectedValueOnce(
256-
new AppError('COMMAND_FAILED', 'companion pid 4322 is still running'),
257-
);
259+
vi.mocked(stopReactDevtoolsCompanion).mockRejectedValueOnce(stopFault);
258260

259-
await assert.rejects(runRemoteStop, actionFault);
261+
const stderr = await withCapturedStderrAsync(() => assert.rejects(runRemoteStop(), actionFault));
260262
assert.equal(vi.mocked(stopReactDevtoolsCompanion).mock.calls.length, 1, 'cleanup still ran');
263+
// The action's fault is what the command reports, so the surviving companion has to be named here.
264+
assert.match(stderr, /companion pid 4322 is still running/);
261265
});
262266

263267
// The stop's own transport can reject with anything, and an unconfirmed exit may only ever be

‎src/cli/commands/react-devtools.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
ensureReactDevtoolsCompanion,
44
stopReactDevtoolsCompanion,
55
} from '../../client/client-react-devtools-companion.ts';
6-
import { AppError } from '@agent-device/kernel/errors';
6+
import { AppError, errorMessage } from '@agent-device/kernel/errors';
77
import { isRemoteBridgeBackend } from './remote-bridge.ts';
88
import type { CliFlags } from '@agent-device/contracts/command';
99
import { connectionProviderCapabilities } from '../connection/provider-policy.ts';
@@ -131,8 +131,8 @@ async function withRemoteDevtoolsCompanion<T>(
131131
flags?.remoteConfig ?? `${bridgeConfig.tenantId}:${bridgeConfig.runId}:${bridgeConfig.leaseId}`;
132132

133133
if (args[0] === 'stop') {
134-
// A companion that could not be confirmed stopped is this command's own verdict, so it is
135-
// reported — but never in place of the failure the stop was cleaning up after.
134+
// An unconfirmed companion stop fails this command, except when the action failed too: then the
135+
// action's fault is the verdict and the surviving companion is named on stderr beside it.
136136
const acted = await action().then(
137137
(value) => ({ value }) as const,
138138
(error: unknown) => ({ error }) as const,
@@ -146,7 +146,12 @@ async function withRemoteDevtoolsCompanion<T>(
146146
() => ({}) as const,
147147
(error: unknown) => ({ error }) as const,
148148
);
149-
if ('error' in acted) throw acted.error;
149+
if ('error' in acted) {
150+
if ('error' in stopped) {
151+
process.stderr.write(`Warning: ${errorMessage(stopped.error)}\n`);
152+
}
153+
throw acted.error;
154+
}
150155
if ('error' in stopped) throw stopped.error;
151156
return acted.value;
152157
}

0 commit comments

Comments
 (0)