Skip to content

refactor(client): remove managed daemon lifecycle - #4614

Merged
thymikee merged 7 commits into
0.22from
feat/0.22-attach-only-clients
Nov 16, 2026
Merged

thymikee merged 7 commits into
0.22from
feat/0.22-attach-only-clients

Conversation

@thymikee

@thymikee thymikee commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

For #3759 section 2, library clients attach to an existing daemon and no longer start, replace or retire it after timeouts. Remove daemonLifecycle: 'managed' and start the daemon explicitly:

import { createAgentDeviceClient, ensureDaemon } from 'agent-device';

await ensureDaemon({ stateDir });
const client = createAgentDeviceClient({ stateDir });

This includes client.replay.run() and client.replay.test(). Use startAgentDevice({ stateDir }) to own an in-process daemon. CLI/MCP ensuring and their private one-shot replay/test startup and cleanup remain supported.

Scope: 35 files, including migration docs, examples, regressions and a changeset. Remote health-recovery budgets and cancellation are preserved. Review fixes cover explicit startup, state-directory migration, cancellation-context identity and RPC race coverage. The final three-file documentation correction clarifies library replay startup and cancellation.

Validation

Head: 3a1ff5fa4ddef9e26553be6a99fe5c2133293f1d.

  • Full format and lint/typecheck passed.
  • Exact check:affected --run --head <SHA>: 42 passed, 25 skipped; exactCommit=true, checkoutChanged=false.
  • At runtime head a882478, full pnpm check passed 41 checks with 25 skipped, wire compatibility against v0.21.38 passed, and all 16 hosted checks were nonfailing.
  • Independent source reviews at d4c9997 and 28e37ef found no actionable regressions. The final documentation delta was cold-read against 0.22: remove superseded plugin, client and environment APIs #3759; runtime tests and another full gate were unnecessary for that delta.

Hosted checks at the new head remain required. No new live-device result or merge clearance is claimed.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff Turn on auto-fix

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.14 MB 6.14 MB +443 B
Package (unpacked) 6.14 MB 6.14 MB +443 B
Package (download) 1.86 MB 1.86 MB +180 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 51.0 ms 47.6 ms -3.5 ms
CLI --help 85.7 ms 93.9 ms +8.2 ms

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 35 files

You’re at about 97% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread examples/sdk/client-session.ts Resolved
Comment thread website/docs/docs/eve.md Resolved
Comment thread website/docs/docs/client-api.md Resolved
Comment thread examples/sdk/contracts-result.ts Resolved
Comment thread packages/client/src/index.ts Resolved
Comment thread examples/sdk/client-session.ts Resolved
@apex-sentinel-staging

apex-sentinel-staging Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve

Since the last review: 0 new · 0 still open · 1 no longer raised (1 marked fixed)

No open findings.

1 finding below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (a30accf38081).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

Earlier reviews

Review of a882478c · 16.11.2026 21:20 UTC

Apex Sentinel · ✅ Approve

Since the last review: 1 new · 0 still open · 1 no longer raised (1 marked fixed)

1 finding(s): 1 minor.

🟡 Minor (1)

Where Finding
packages/daemon-client/src/daemon-client-lifecycle.ts:103 🆕 Library client replay/test silently lost its private daemon and now needs a shared one

Reviewed with this repository's own Sentinel configuration (b13b016e9bc1).

Review of d4c99975 · 16.11.2026 20:38 UTC

Apex Sentinel · ✅ Approve

1 finding(s): 1 minor.

🟡 Minor (1)

Where Finding
packages/daemon-client/src/__tests__/daemon-client-startup-race.test.ts:644 Startup-race row no longer asserts how many RPCs the winner received

Reviewed with this repository's own Sentinel configuration (ea414582b7fa).

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on d4c9997. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

I found no new blocking problems in the code at d4c9997, but the open review threads below still need fixes before this can merge. All 17 checks pass at this head, and there are no conflicts.

Not blocking, and you can take or leave these: (1) The migration note in client-api.md:95 tells every managed client to call ensureDaemon() once. A detached daemon idle-exits after 5 minutes with no open session (daemon-idle-reap.ts:39-57), and an attach client never restarts it. A long-lived host then fails with daemon-not-running on the first request after an idle gap. The note could say this once: re-call ensureDaemon({ stateDir }) on details.reason 'daemon-not-running', or own the daemon with startAgentDevice(). eve.md can then follow the same rule. (2) The guard in cleanupDaemonAfterRequest still checks !daemon.startedByClient, but startedByClient is now never true without ownedStateDir. It can shrink to !settings.ownedStateDir, and the shared-dir teardown wording in that doc block and at client-api.md:238 can go. (3) .changeset/ is gitignored and maintainers do not use changeset entries, so this file can be dropped. The migration note already covers 0.22. (4) In daemon-client-lifecycle-embedded.test.ts:59, ownerRequest composes ensureStartedDaemon with an attach, and no client request takes that path. These rows prove the startup helper, not the CLI route that cli-help.ts:426 describes. Driving them through createEnsuredDaemonTransport or ensureDaemon would test the real route.

These open threads still apply: example error handling, eve.md idle exit, test-local sendToDaemon wrapper, migration note stateDir, and stale teardown wording. For the last one, the stale side is client-api.md:238, not :93. Seven lower-priority threads still apply as well. One thread does not need a change, so please resolve it: client-connection.ts:26. The sentence is not false, only possibly understated.

Please fix these threads first: put ensureDaemon inside the example's try, make the migration note pass stateDir and cover idle exit for long-lived hosts including eve.md, correct client-api.md:238, and route the test-local wrapper through createEnsuredDaemonTransport. Then resolve the lower-priority threads.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on a882478. The verdict and the full list are in the summary comment.

@thymikee
thymikee merged commit 31fc8df into 0.22 Nov 16, 2026
16 checks passed
@thymikee
thymikee deleted the feat/0.22-attach-only-clients branch November 16, 2026 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant