server: GET /api/config first-paint directory selection diverges from launch resolution; GET mutates ServerState; phantom config_path for trials

Open
#126 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Start with routes/config.py, especially _config_response and _choose_active_directory, then read config_service.choose_active_directory in service.py and the trial handling in /load-content and /content. Trace how ServerState initializes its config and active directory before moving initialization out of the GET handler. Done when first paint follows launch directory selection, GET has no state mutations, and trial responses identify the session and return config_path: None.

Written by the indexing model from the issue text.

Description

bug

Problem

Two divergent selection algorithms coexist in routes/config.py:

  • _choose_active_directory (used by load/drop/create/reload) calls the core single-source-of-truth config_service.choose_active_directory ("Single source of truth shared by desktop launch resolution and the server's config load/drop endpoints", service.py:178-180).
  • But the first-paint fallback inside _config_response hand-rolls its own (config.py:99-116):
selected = config_service.auto_select_directory(cfg, hostname)  # display-name match, no search_dir preference
if selected and Path(selected).exists():
    state.active_directory = Path(selected)
elif available_dirs:
    state.active_directory = Path(available_dirs[0])

auto_select_directory returns a machine display name or first scan path (never search_dir first, no existence ranking), while choose_active_directory prefers search_dir then hostname-matched scan dirs. A config with search_dir=D1 and a hostname-matched machine scanning D2 launches on D1 but the web session's first GET /api/config activates D2 — session behavior diverges from launch behavior until a load/reload normalizes it.

Additionally:

  • GET /api/config (a read) mutates state.config_path, cfg.config_path and state.active_directory (side effects in a GET handler).
  • The response never includes session_trial (only /load-content appends it, config.py:277), so after a page refresh the UI cannot tell it is on a trial — yet the response still advertises "config_path": str(phantom) and "config_exists" for that phantom (config.py:131-132), contradicting GET /content's careful config_path: None for trials (config.py:390-396).

Suggested fix

  1. Replace the hand-rolled block with _choose_active_directory(cfg, None).
  2. Move the initial-state derivation into a ServerState/bootstrap method instead of a GET handler.
  3. Include session_trial (and config_path: None for trials) in _config_response.
Dominant language
Python
Stars
1
Forks
1
Avg merge
4h 46m
Merged PRs (30d)
55

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from falbany/ProFiles

All issues in falbany/ProFiles

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.