fix(daemon): report failed close/disconnect, cancel shutdown timers, scope daemon diagnostics
Summary
Fixes 2026-11-10 audit findings DCORE-1 (= DSESS-3), SRC2-5, DSRV-1, DSRV-2, DCORE-2, DSESS-2, SRC2-6 and SRC2-3. Each was reproduced with a failing test before the fix.
closeanddisconnectno longer report false success:closenow reports a script write that failed with a filesystem error, usingreason: script_write_failedand the target path.disconnectnames a lease it could not release. JSON output addsleaseIdandreleaseError.
- Shutdown timers are cancelled. There is no false "teardown timed out" line, and an embedded runtime no longer stays alive after close.
- Daemon diagnostics emitted outside a request now reach
daemon.log. This covers the shutdown summary, the lease sweep and its retries, and startup recovery. - Late binds and suite leases are cleaned up. A late ordinary bind is now disposed. Suite test-session close releases provider leases through the provider.
connect limrunis idempotent per session.disconnectremoves generated profiles that no session uses.app.logrotates while a sink is open, as the docs already said.network dumpreadsapp.login blocks instead of holding the whole file as one string.- Deferred: DSESS-7, required dependencies typed as optional. It needs a wide type change of its own.
29 files changed, +1266/−194. This is over the 1,000-line guideline because it batches one audit slice (daemon lifecycle, CLI connection and app log) whose fixes share the shutdown and diagnostics-scope seams. Future slices of this size will be split.
Validation
- Tested SHA
d2689cb: CI passes 19/19 checks, including the non-root unit suite and integration. Earlier localcheck:affected --run --head b8cf1bb(exactCommit=true): format, lint, typecheck, layering, fallow, build and related tests pass. - Unit suite: 8 failures. 7 are the known root-only chmod tests. The 8th is a 5 s timeout in
src/daemon-entrypoint.test.ts. That test passes 3 of 3 runs alone, and base code takes the same 2.5–3.4 s on this host. The cause is likely host load but not proven. - CI obligation: the non-root unit suite must confirm that test.
- Risks:
- Teardown no longer gets a thrown no-clobber error from the script writer. Before, that throw skipped
retire. - The shutdown scope logs more claim and lease events.
- Teardown no longer gets a thrown no-clobber error from the script writer. Before, that throw skipped
Generated by Claude Code
<a href="https://backend.blacksmith.sh/track/enable-autofix?expires=1796918559&installation_model_id=447842&pr_number=4357&ref=codesmith_pr_footer&repository=callstack%2Fagent-device&return_to=https%3A%2F%2Fgithub.com%2Fcallstack%2Fagent-device%2Fpull%2F4357&signature=4724adad9f194f249ea3a1e247e732fccf9ac502fee6836f2c74ca01d16ac93b"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-light.svg"><img alt="Autofix with [code]smith" src="https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png" width="190" height="28">
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.
<a href="https://www.cubic.dev/action/auto-fix/pr/callstack/agent-device/4357?returnTo=https%3A%2F%2Fgithub.com%2Fcallstack%2Fagent-device%2Fpull%2F4357&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg">
Generated by Claude Code