Skip to content

Pooria/1024 railtracks folder#1110

Open
Pooria90 wants to merge 6 commits into
mainfrom
pooria/1024-railtracks-folder
Open

Pooria/1024 railtracks folder#1110
Pooria90 wants to merge 6 commits into
mainfrom
pooria/1024-railtracks-folder

Conversation

@Pooria90
Copy link
Copy Markdown
Contributor

Summary

Fixes inconsistent .railtracks directory placement when agents are run from different working directories (closes #1024).

Previously, each call site resolved the data directory independently — _session.py read RAILTRACKS_HOME but fell back to cwd(), while evaluations/utils.py, cli/__init__.py, and cli/viz_server.py hardcoded ".railtracks" relative to cwd(). Running scripts from a subdirectory silently created a second .railtracks folder, splitting session and evaluation data across locations.

The fix introduces a single resolve_railtracks_home() function in railtracks/paths.py used by all four sites. Resolution order:

  1. RAILTRACKS_HOME env var, if set
  2. Walk up from cwd() until an existing .railtracks directory is found (git-style traversal)
  3. Fall back to cwd()/.railtracks with a UserWarning prompting the user to run railtracks init from their project root

Type of change

  • Bug fix
  • Feature
  • Breaking change
  • Docs
  • Refactor / chore / build / tests

Checklist

  • Lint & format pass (ruff check . && ruff format .)
  • Tests added/updated and pass locally (pytest tests)
  • Docs updated if user-facing behavior changed
  • Breaking changes include migration notes

Notes

Migration: No breaking change for users who already set RAILTRACKS_HOME — that path takes priority and behaviour is unchanged. Users relying on the implicit cwd() fallback will see a UserWarning on first run until they run railtracks init from their project root; after that, traversal finds the directory and the warning is not emitted again.

railtracks init behaviour: If a .railtracks directory already exists in a parent folder, init reports the existing location rather than creating a second one. The .gitignore entry is now written adjacent to the .railtracks directory rather than always at cwd().

Removed: EVALS_DIR module-level constant from evaluations/utils.py and UI_VERSION_FILE constant from cli/constants.py — both are now computed at call time via resolve_railtracks_home(). Tests that patched EVALS_DIR directly have been updated to patch resolve_railtracks_home instead.

@Pooria90 Pooria90 linked an issue May 21, 2026 that may be closed by this pull request
@Pooria90 Pooria90 marked this pull request as ready for review May 21, 2026 19:09
if env:
return Path(env) / _DIRNAME

current = Path.cwd()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be fine in Windows too, right? (Cross-operating system file paths)

Copy link
Copy Markdown
Member

@jbueza-railtownai jbueza-railtownai left a comment

Choose a reason for hiding this comment

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

LGTM

lgtm


cli_name = "railtracks"
cli_directory = ".railtracks"
UI_VERSION_FILE = f"{cli_directory}/.ui_version"
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.

This constant is used by the CLI to detect the user's version of the visualizer UI vs the most recently published version and warns the user to update to get new features

def get_stored_ui_version():
"""Get the stored UI version (ETag) from disk"""
version_file = Path(UI_VERSION_FILE)
version_file = resolve_railtracks_home() / ".ui_version"
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.

Same comment here and below regarding UI_VERSION constant
it's a file inside .railtracks

return JSONResponse(content={"error": "Not Found"}, status_code=404)

ui_dir = Path(f"{cli_directory}/ui")
ui_dir = get_railtracks_dir() / "ui"
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.

will this make it dir/.railtracks/ui, or dir/ui cause only the first is correct, the second one will break the visualizer

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.

[Visualizer] .railtracks folder location

3 participants