Skip to content

[client] Fixes DisableAutoConnect semantics - #6409

Closed
riccardomanfrin wants to merge 2 commits into
mainfrom
disable_auto_connect_no_client_stop
Closed

riccardomanfrin wants to merge 2 commits into
mainfrom
disable_auto_connect_no_client_stop

Conversation

@riccardomanfrin

@riccardomanfrin riccardomanfrin commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes

Clarify the semantics of the DisableAutoConnect flag in the client
daemon. The flag previously short-circuited every code path that
considered spawning the connection goroutine — service Start, the Up
RPC handler, and future coming MDM-driven engine restart.

The flag's intent is narrower: it governs whether the daemon should
automatically connect at service start. An explicit user request,
or a policy refresh applied to an already-running engine, should not be
subordinated to the flag.

New semantics:

  1. Service Start + DisableAutoConnect=true → daemon stays
    idle, no connection goroutine spawned, clientRunning stays
    false. The state RPC reports StatusIdle.
  2. Service Start + DisableAutoConnect=false → daemon spawns
    connectWithRetryRuns, retry loop runs until ctx cancelled.
  3. Up RPC (any value of DisableAutoConnect) → flag ignored.
    The user explicitly asked to connect — by definition not "auto".
  4. MDM-triggered restart (any value of DisableAutoConnect) →
    flag ignored. An MDM policy change applies new config to an
    already-running engine; treated as an implicit Up.
  5. Down / Stop / Logout → cancels ctx; cleanupConnection
    clears clientRunning. DisableAutoConnect is not involved.

Code changes:

  • client/server/server.go: removed the DisableAutoConnect branch
    inside connectWithRetryRuns so the retry loop no longer
    collapses to a single-shot when the flag is set. The flag is now
    only consulted at the top of Start() (the early-return path that
    sets StatusIdle).

Issue ticket number and link

No public issue. Semantic divergence between the flag name and its
behaviour surfaced during the MDM integration review
(#6374) — DisableAutoConnect
was being read as a runtime kill switch in addition to a startup
gate. This PR confines it to its documented purpose so the MDM PR
does not have to choose between two reasonable but incompatible
interpretations.

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

The DisableAutoConnect flag is already documented as a
startup-only auto-connect gate (CLI help text and ConfigInput
field comment). The previous implementation diverged from the
documented intent; this PR aligns the implementation with the
existing docs, so no doc update is required. The behavioural
contract becomes: setting the flag prevents the boot-time
connection only — explicit Up requests and MDM-driven restarts
remain unaffected.

Docs PR URL (required if "docs added" is checked)

N/A

Summary by CodeRabbit

  • Bug Fixes
    • Updated connection retry behavior so connection attempts consistently follow the backoff-based retry flow.
    • Added improved debug logging when a client run exits with an error, making connection termination issues easier to diagnose.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3d4f883d-3046-41ee-a888-05817474ff16

📥 Commits

Reviewing files that changed from the base of the PR and between c2c23f6 and ab16673.

📒 Files selected for processing (1)
  • client/server/server.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/server/server.go

📝 Walkthrough

Walkthrough

The PR removes the DisableAutoConnect early-exit path from the retry loop in connectWithRetryRuns to ensure the function always enters the backoff-based retry mechanism, and adds debug error logging when client.Run exits to improve observability of connection failures.

Changes

Connection Lifecycle Improvements

Layer / File(s) Summary
Connection retry loop simplification
client/server/server.go
The DisableAutoConnect conditional early-return is removed; connectWithRetryRuns now always proceeds into the backoff retry loop with defer-based lifecycle cleanup, with a comment clarifying that retries are cancelled on stop/down commands.
Connection error logging
client/server/server.go
A debug log is added when client.Run exits with an error, improving observability of connection termination failures.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A rabbit hops through logs so clear,
Connection loops, no more to fear—
When retries fail, we'll see the light,
Errors logged both day and night. 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change—fixing DisableAutoConnect semantics by removing the flag's branch from the retry loop.
Description check ✅ Passed The description is comprehensive, covering changes, context, issue link, and documentation rationale. All required template sections are present and completed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch disable_auto_connect_no_client_stop

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

DisableAutoConnect semantics
============================

Scope: governs ONLY the service-Start auto-connect decision. Once the
connection goroutine has been spawned (by any path), the flag is never
consulted again — the retry loop keeps trying to connect until ctx is
cancelled by Down / Stop / Logout.

Cases
-----

1. Service Start + DisableAutoConnect = true
   - No connection goroutine spawned.
   - clientRunning stays false.
   - State set to StatusIdle.
   - Daemon stays passive until an explicit Up RPC.

2. Service Start + DisableAutoConnect = false
   - Spawn connectWithRetryRuns.
   - clientRunning = true.
   - Retry loop runs until ctx cancelled.

3. Up RPC (any value of DisableAutoConnect)
   - Flag ignored. The user / admin explicitly asked to connect — by
     definition not "auto".
   - Spawn connectWithRetryRuns.
   - clientRunning = true.

4. MDM-triggered restart (any value of DisableAutoConnect)
   - Flag ignored. An MDM policy change applies new config to an
     already-running engine; treated as an implicit Up.
   - Spawn connectWithRetryRuns.
   - clientRunning = true.

5. Down / Stop / Logout
   - Cancels ctx → connectWithRetryRuns exits → close(giveUpChan).
   - cleanupConnection clears clientRunning = false.
   - DisableAutoConnect not involved.
Prepare for next step

Collapse error log into s.connect and rename it to more explicit connectOnce
@riccardomanfrin
riccardomanfrin force-pushed the disable_auto_connect_no_client_stop branch from f60d315 to c2c23f6 Compare June 11, 2026 12:59
@github-actions

github-actions Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

Release artifacts

Built for PR head ab16673 in workflow run #15846.

Artifact Link
All release artifacts Download
Linux packages Download
Windows packages Download
macOS packages Download
UI artifacts Download
UI macOS artifacts Download

GHCR images (amd64)

This comment is updated by the Release workflow. Artifact links expire according to the workflow retention policy.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
client/server/server.go (1)

1657-1659: 💤 Low value

Duplicate logging with runOperation.

When client.Run() fails, this logs "run client connection exited with error: %v", then the error propagates to runOperation (line 253) which logs the same message with ". Will retry in the background" appended. Consider removing this log since the caller already logs with more context, or differentiate the messages if both are needed for distinct debugging purposes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@client/server/server.go` around lines 1657 - 1659, The log.Debugf in the
error branch of client.Run is duplicating a higher-level message in
runOperation; remove the duplicate logging inside the Run caller (the
log.Debugf("run client connection exited with error: %v", err) in the block
where client.Run(runningChan, s.logFile) returns an error) and simply return the
error so runOperation (which logs with ". Will retry in the background") is the
single source of that message; alternatively, if a lower-level log is still
desired, change it to a lower-severity/trace message or add distinct context
(e.g., include s.name or connection id) instead of mirroring runOperation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@client/server/server.go`:
- Around line 1657-1659: The log.Debugf in the error branch of client.Run is
duplicating a higher-level message in runOperation; remove the duplicate logging
inside the Run caller (the log.Debugf("run client connection exited with error:
%v", err) in the block where client.Run(runningChan, s.logFile) returns an
error) and simply return the error so runOperation (which logs with ". Will
retry in the background") is the single source of that message; alternatively,
if a lower-level log is still desired, change it to a lower-severity/trace
message or add distinct context (e.g., include s.name or connection id) instead
of mirroring runOperation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0797369e-594a-4333-9043-93975dadf89d

📥 Commits

Reviewing files that changed from the base of the PR and between d770376 and c2c23f6.

📒 Files selected for processing (1)
  • client/server/server.go

@riccardomanfrin riccardomanfrin changed the title Fixes DisableAutoConnect semantics [client] Fixes DisableAutoConnect semantics Jun 15, 2026
@sonarqubecloud

Copy link
Copy Markdown

@mlsmaycon mlsmaycon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we can probably leave it as is with more docs. But I don't see any harm in keeping it here. If we keep it, let's add some docs for it.

Comment thread client/server/server.go
@riccardomanfrin
riccardomanfrin deleted the disable_auto_connect_no_client_stop branch June 18, 2026 06:32
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.

2 participants