Skip to content

feat: validate AUTHSOME_HOME against running daemon via health check to prevent directory mismatch errors#304

Closed
ankitranjan7 wants to merge 1 commit into
mainfrom
feature/daemon-home-mismatch
Closed

feat: validate AUTHSOME_HOME against running daemon via health check to prevent directory mismatch errors#304
ankitranjan7 wants to merge 1 commit into
mainfrom
feature/daemon-home-mismatch

Conversation

@ankitranjan7
Copy link
Copy Markdown
Collaborator

Description

Adds a daemon-home mismatch guard for the local managed daemon.

When Authsome is pointed at the default local daemon URL (127.0.0.1:7998), it now checks the running daemon’s home directory before reusing it. If the daemon is already running with a different home than the current AUTHSOME_HOME, Authsome fails fast with a clear error instead of silently talking to the wrong daemon.

This also adds the daemon home path to the unprotected /health response so the CLI can make that check safely.

Motivation and Context

This fixes a confusing local workflow bug when switching AUTHSOME_HOME, especially with ephemeral directories like mktemp -d.

Before this change:

  • authsome whoami could talk to an already-running daemon that was started from a different home directory
  • authsome daemon stop only looked for the PID file under the current AUTHSOME_HOME
  • the result was inconsistent behavior where commands appeared to disagree about which Authsome home was active

With this change, Authsome surfaces the mismatch explicitly and tells the user to stop the existing daemon or change/unset AUTHSOME_HOME.

How Has This Been Tested?

Tested with:

  • uv run ruff check src/authsome/cli/daemon_control.py src/authsome/server/routes/health.py src/authsome/server/schemas.py tests/cli/test_daemon_control.py
  • uv run ty check src/
  • uv run pytest
  • uv tool run pre-commit run --all-files

Added coverage for:

  • allowing reuse when the running daemon home matches the current AUTHSOME_HOME
  • rejecting reuse when the running daemon home differs from the current AUTHSOME_HOME

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • All new and existing tests passed.

Copy link
Copy Markdown
Collaborator

@manojbajaj95 manojbajaj95 left a comment

Choose a reason for hiding this comment

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

Need the movtivation behind these changes.

@ankitranjan7
Copy link
Copy Markdown
Collaborator Author

ankitranjan7 commented May 25, 2026

@manojbajaj95 If a daemon is running already (which is always true if authsome is being used), and then AUTHSOME_HOME is then set differently, "authsome whomai" prints the original Home directory since the daemon is still pointing to the original authsome_home directory and authsome daemon stop also does not work since it checks for the PID file in the new home directory path.

This PR just checks the where the currently running dameon is pointing to and make sure the AUTHSOME_HOME matches that . OR else it shows an appropriate error message something like :-

"Error: Authsome daemon at http://127.0.0.1:7998 is already running with home '/Users/ankitranjan/.authsome', but current AUTHSOME_HOME is '/var/folders/mv/cmf60kpj1g1cqsxsj_2bwjv40000gn/T/tmp.KtiWNOFTXA'. Stop the existing daemon or unset/change AUTHSOME_HOME before retrying."

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