Skip to content

Commit 180e669

Browse files
thymikeeclaude
andcommitted
refactor(daemon): require identities for owner refusal errors
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 86dee15 commit 180e669

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

‎src/daemon-client/__tests__/daemon-client-embedded-lifecycle.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,19 @@ async function crashedStaleRegistration(ownership: 'embedded' | 'unrecognized' |
137137
return { stateDir, paths, ...registered };
138138
}
139139

140-
for (const [ownership, reason, hint] of [
140+
for (const [ownership, reason, message, hint] of [
141141
[
142142
'embedded',
143143
DAEMON_LIFECYCLE_REASONS.ownerEmbedded,
144+
'A host process owns this runtime, so it was not retired.',
144145
/owned by host process \d+\. Close it there/,
145146
],
146-
['sideways', 'daemon-owner-unrecognized', /Update agent-device/],
147+
[
148+
'sideways',
149+
'daemon-owner-unrecognized',
150+
'This daemon record states an owner this version cannot read, so this client did not replace it.',
151+
/Update agent-device/,
152+
],
147153
] as const)
148154
test(`a managed client preserves a ${ownership} owner`, async (t) => {
149155
if (await skipWhenLoopbackUnavailable(t)) return;
@@ -159,6 +165,7 @@ for (const [ownership, reason, hint] of [
159165
createDaemonTransport(createTestHostEnvironment())(request(stateDir)),
160166
);
161167
assert.equal(refusal.details?.reason, reason);
168+
assert.equal(refusal.message, message);
162169
assert.match(String(refusal.details?.hint), hint);
163170
assert.deepEqual(daemon.rpcCommands, [], 'the takeover was never attempted');
164171
assert.equal(spawn.mock.calls.length, 0);

‎src/daemon-client/daemon-lifecycle-errors.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,27 +162,27 @@ export function daemonBusyError(
162162
});
163163
}
164164

165-
/** Refuses stop or replacement when the record cannot prove a detached owner. */
165+
/** Refuses replacement when the record cannot prove a detached owner. */
166166
function daemonRecordOwnerUnrecognizedError(params: {
167-
info: DaemonIdentity | null;
167+
info: DaemonIdentity;
168168
stateDir: string;
169169
}): AppError {
170170
const { info, stateDir } = params;
171171
return new AppError(
172172
'COMMAND_FAILED',
173-
'This daemon record states an owner this version cannot read, so this client did not stop or replace it.',
173+
'This daemon record states an owner this version cannot read, so this client did not replace it.',
174174
{
175175
reason: DAEMON_RECORD_OWNER_UNRECOGNIZED_REASON,
176176
stateDir,
177-
...(info ? { daemon: daemonIdentityOf(info) } : {}),
178-
hint: `Update agent-device if the record comes from a newer build. Otherwise check what owns ${info ? `pid ${info.pid}` : 'this registration'}, then repair the record: stop that process by its own means and remove ${shellQuoteIfNeeded(stateDir)}/daemon.json so a daemon can register again.`,
177+
daemon: daemonIdentityOf(info),
178+
hint: `Update agent-device if the record comes from a newer build. Otherwise check what owns pid ${info.pid}, then repair the record: stop that process by its own means and remove ${shellQuoteIfNeeded(stateDir)}/daemon.json so a daemon can register again.`,
179179
},
180180
);
181181
}
182182

183183
/** The host that started an embedded runtime owns its close. */
184184
export function daemonNotRetirableError(params: {
185-
info: DaemonIdentity | null;
185+
info: DaemonIdentity;
186186
stateDir: string;
187187
}): AppError {
188188
const { info, stateDir } = params;
@@ -192,8 +192,8 @@ export function daemonNotRetirableError(params: {
192192
{
193193
reason: DAEMON_LIFECYCLE_REASONS.ownerEmbedded,
194194
stateDir,
195-
...(info ? { daemon: daemonIdentityOf(info) } : {}),
196-
hint: embeddedCloseHint(info?.pid),
195+
daemon: daemonIdentityOf(info),
196+
hint: embeddedCloseHint(info.pid),
197197
},
198198
);
199199
}

0 commit comments

Comments
 (0)