Repository navigation
refactor(client): remove managed daemon lifecycle #4614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6329204
refactor(client): remove managed daemon lifecycle
thymikee 193c687
refactor(daemon-client): keep remote ensuring internal
thymikee cbb9c78
docs(client): start daemons explicitly in Node examples
thymikee d4c9997
fix(daemon-client): retain remote health recovery
thymikee 28e37ef
fix(client): address lifecycle examples and review clarity
thymikee a882478
test(daemon-client): retain RPC coverage after startup races
thymikee 3a1ff5f
docs(client): clarify replay daemon startup after migration
thymikee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'agent-device': minor | ||
| --- | ||
|
|
||
| Clients attach to an existing daemon and no longer start, replace, or retire it on timeout. This also applies to `client.replay.run()` and `client.replay.test()`; they no longer start a private daemon. Remove `daemonLifecycle: 'managed'` and call `ensureDaemon({ stateDir })` before creating a client for a detached daemon. To own a daemon in your process, call `startAgentDevice({ stateDir })` from `agent-device` and close its returned handle. CLI and MCP commands continue to ensure their daemon, including private one-shot replay/test startup and cleanup. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 30 additions & 20 deletions
50
packages/client/src/__tests__/index-daemon-lifecycle.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,47 +1,57 @@ | ||
| import { test } from 'vitest'; | ||
| import assert from 'node:assert/strict'; | ||
| import type { | ||
| AgentDeviceDaemonTransport, | ||
| AgentDeviceDaemonTransportContext, | ||
| DaemonLifecycle, | ||
| } from '@agent-device/contracts/client'; | ||
| import type { AgentDeviceDaemonTransport } from '@agent-device/contracts/client'; | ||
| import { createAgentDeviceClient } from '../index.ts'; | ||
|
|
||
| // `daemonLifecycle` is a client choice that only the transport can act on, so the client's job is to | ||
| // hand it over exactly and to refuse a value it does not know. | ||
| // A client always attaches, so `daemonLifecycle` is no longer a choice the transport acts on. The | ||
| // client's job is to accept `'attach'` (the only value, and the default) and to refuse any value that | ||
| // would mean managing a daemon, naming the explicit owners instead. | ||
|
|
||
| function recordingTransport() { | ||
| const contexts: Array<AgentDeviceDaemonTransportContext | undefined> = []; | ||
| const seen: Array<Record<string, unknown>> = []; | ||
| const transport: AgentDeviceDaemonTransport = async (_request, context) => { | ||
| contexts.push(context); | ||
| seen.push({ ...(context ?? {}) }); | ||
| return { ok: true, data: { devices: [] } }; | ||
| }; | ||
| return { contexts, transport }; | ||
| return { seen, transport }; | ||
| } | ||
|
|
||
| test('the configured daemon lifecycle reaches the transport', async () => { | ||
| const { contexts, transport } = recordingTransport(); | ||
| test('a client sends no daemon-management knob to its transport', async () => { | ||
| const { seen, transport } = recordingTransport(); | ||
| const attached = createAgentDeviceClient({ daemonLifecycle: 'attach' }, { transport }); | ||
| const plain = createAgentDeviceClient({}, { transport }); | ||
|
|
||
| const managed = createAgentDeviceClient({ daemonLifecycle: 'managed' }, { transport }); | ||
|
|
||
| await attached.devices.list(); | ||
| await managed.devices.list(); | ||
| await plain.devices.list(); | ||
|
|
||
| // `'attach'` is what every request does, so it is not a per-request option either: the transport | ||
| // gets the caller's cancellation and pin, and nothing about who owns the daemon. | ||
| assert.deepEqual( | ||
| contexts.map((context) => context?.daemonLifecycle), | ||
| ['attach', 'managed', undefined], | ||
| seen.map((context) => 'daemonLifecycle' in context), | ||
| [false, false], | ||
| ); | ||
| }); | ||
|
|
||
| test('the removed managed lifecycle is refused where the config is read', () => { | ||
| const { transport } = recordingTransport(); | ||
|
|
||
| assert.throws( | ||
| () => createAgentDeviceClient({ daemonLifecycle: 'managed' as never }, { transport }), | ||
| (error: { code?: string; details?: { daemonLifecycle?: unknown; hint?: unknown } }) => { | ||
| assert.equal(error.code, 'INVALID_ARGS'); | ||
| assert.equal(error.details?.daemonLifecycle, 'managed'); | ||
| assert.match(String(error.details?.hint), /ensureDaemon\(\{ stateDir \}\)/); | ||
| assert.match(String(error.details?.hint), /startAgentDevice\(\{ stateDir \}\)/); | ||
| return true; | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| test('an unknown daemon lifecycle is refused instead of becoming managed', () => { | ||
| test('an unknown daemon lifecycle is refused instead of attaching blindly', () => { | ||
| const { transport } = recordingTransport(); | ||
| const mistyped = 'Attach' as DaemonLifecycle; | ||
|
|
||
| assert.throws( | ||
| () => createAgentDeviceClient({ daemonLifecycle: mistyped }, { transport }), | ||
| () => createAgentDeviceClient({ daemonLifecycle: 'Attach' as never }, { transport }), | ||
| (error: { code?: string }) => error.code === 'INVALID_ARGS', | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.