Skip to content

Conversation

@racimrl
Copy link
Contributor

@racimrl racimrl commented Oct 26, 2025

Change temporary directory path to './tmp' to avoid space issue on different partition

Description

Related Issue(s)

  • Closes #[issue number]

Type of Change

  • Feature (adding new functionality)
  • Fix (resolving a bug or issue)
  • Docs (documentation updates)
  • Refactor (code changes that don't affect functionality)
  • Maintenance (dependency updates or other maintenance)
  • Tests (adding or improving tests)
  • Breaking change (fix or feature with incompatible API changes)
  • Other: _____

Branch Naming

  • My branch follows the project's naming convention (e.g., feature/add-new-capability)

Commit Messages

  • My commits are small, atomic, and have proper commit messages
  • Commit messages are in imperative mood with a capitalized summary under 50 chars

Code Quality

  • I've performed a self-review of my code
  • I've added appropriate docstrings following the project's conventions
  • I've added proper logging where necessary (without trailing periods)
  • I've applied linting and formatting with Ruff
  • My code generates no new warnings

Testing

  • I've added tests for new functionality or bug fixes
  • All tests pass locally with my changes
  • Test coverage has not decreased

Documentation

  • I've updated documentation to reflect my changes
  • I've updated comments in hard-to-understand areas

If this is a breaking change

Screenshots/Examples

Additional Notes

Summary by CodeRabbit

  • New Features

    • Added support for per-UID directory handling in storage initialization.
  • Bug Fixes

    • Changed default temporary storage paths from absolute to relative directories for better portability and consistency across components.

Change temporary directory path to './tmp' to avoid space issue on different partition
@coderabbitai
Copy link

coderabbitai bot commented Oct 26, 2025

Walkthrough

This change updates storage path defaults from absolute /tmp to relative ./tmp throughout the comms module and adds a uid parameter to the constructor for per-UID directory handling. All storage operations now use consistent relative path prefixes.

Changes

Cohort / File(s) Summary
Path localization and UID parameter addition
src/tplr/comms.py
Updated LOCAL_TMP_DIR constant from /tmp/local_store to ./tmp/local_store; changed default save_location parameter in __init__ from /tmp to ./tmp; added uid: int | None parameter to constructor; updated instance temp directory paths (self.temp_dir, per-UID temp dirs, and hotkey-based save locations) to use ./tmp prefix instead of /tmp

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Changes follow a consistent, repetitive pattern (absolute to relative path conversion)
  • Single file affected with straightforward parameter and constant updates
  • No complex logic changes or interdependencies to trace
  • Minor attention: verify that relative ./tmp paths work correctly in all deployment environments

Poem

🐰 A rabbit hops through systems vast,
Where /tmp once ruled, now paths contrast!
From absolute roads to . we roam,
Relative paths lead data home. 🏡

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description is largely incomplete and fails to adequately fill the provided template. While the author provided a brief one-line description explaining the change and its motivation ("to avoid space issue on different partition"), the description is missing critical sections required by the template. Most notably, the "Type of Change" section is completely unchecked, providing no indication whether this is a feature, fix, refactor, or breaking change. Additionally, sections for Branch Naming, Commit Messages, Code Quality, and Testing are all left blank or unchecked, and no Related Issue number is provided. The description provides minimal context beyond the single-line summary and leaves most template guidance unaddressed. The author should complete the pull request description by filling out at least the Type of Change section (selecting the appropriate category—this appears to be a "Fix" addressing a storage space issue), confirming branch naming compliance, indicating whether code quality and testing checks have been performed, and providing any related issue numbers if applicable. At minimum, the Type of Change, Code Quality self-review, and Testing sections should be addressed to provide adequate context for reviewers.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "Change temporary directory path to './tmp'" is concise, clear, and directly summarizes the primary objective of the changeset. The title accurately captures the main change, which involves updating all temporary directory paths throughout the codebase from absolute "/tmp" to relative "./tmp" paths. While the changeset also includes adding a uid parameter to support this functionality, the title correctly prioritizes the core modification as the most important change from the developer's perspective. The title uses plain language without noise or vague terms and would be immediately understood by a teammate scanning the project history.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7641300 and 764ef27.

📒 Files selected for processing (1)
  • src/tplr/comms.py (6 hunks)
🔇 Additional comments (1)
src/tplr/comms.py (1)

120-122: Unrelated formatting change to type annotation.

The type annotation for _s3_clients has been reformatted across multiple lines. This change appears unrelated to the PR objective of changing temporary directory paths.

Is this formatting change intentional, or was it accidentally introduced by an IDE auto-formatter? If intentional, consider mentioning it in the PR description for clarity.

# Constants
CF_REGION_NAME: str = "enam"
LOCAL_TMP_DIR = "/tmp/local_store"
LOCAL_TMP_DIR = "./tmp/local_store"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Relative path creates working-directory dependency and potential data fragmentation.

Using "./tmp/local_store" instead of an absolute path means the storage location depends on the current working directory at runtime. This introduces several risks:

  • Data fragmentation: Multiple instances or runs from different directories will create separate tmp directories, leading to data inconsistency.
  • Cleanup issues: Stale data cleanup becomes unreliable when files are scattered across multiple locations.
  • Cross-partition: The PR objective of avoiding cross-partition issues may not be achieved—it depends on where the working directory is located.

Consider one of these solutions:

Solution 1 (Recommended): Use an absolute path with a configurable base directory:

+import pathlib
+
+# Allow configuration via environment variable, default to project root
+_BASE_DIR = os.getenv("TPLR_STORAGE_BASE", str(pathlib.Path(__file__).parent.parent.parent))
-LOCAL_TMP_DIR = "./tmp/local_store"
+LOCAL_TMP_DIR = os.path.join(_BASE_DIR, "tmp", "local_store")

Solution 2: Resolve to absolute path immediately:

-LOCAL_TMP_DIR = "./tmp/local_store"
+LOCAL_TMP_DIR = os.path.abspath("./tmp/local_store")

Solution 3: If space is the concern, use a dedicated disk mount:

-LOCAL_TMP_DIR = "./tmp/local_store"
+LOCAL_TMP_DIR = os.getenv("TPLR_TMP_DIR", "/var/lib/templar/local_store")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
LOCAL_TMP_DIR = "./tmp/local_store"
LOCAL_TMP_DIR = os.path.abspath("./tmp/local_store")
Suggested change
LOCAL_TMP_DIR = "./tmp/local_store"
LOCAL_TMP_DIR = os.getenv("TPLR_TMP_DIR", "/var/lib/templar/local_store")
🤖 Prompt for AI Agents
In src/tplr/comms.py around line 52, the LOCAL_TMP_DIR is a relative path
("./tmp/local_store") which ties storage to the current working directory and
risks fragmented/stale data and cross-partition issues; change it to an
absolute, configurable path (e.g., derive from an application config or
environment variable with a sensible default like the system temp dir or a
dedicated base directory), resolve it to an absolute path at module load time,
and ensure the directory is created with correct permissions so all runs use a
single well-known location; update any callers to use the resolved path rather
than the original relative constant.

self,
wallet: bt.wallet | None,
save_location: str = "/tmp",
save_location: str = "./tmp",
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Default parameter change introduces backward compatibility risk.

Changing the default from "/tmp" to "./tmp" could break existing deployments or scripts that expect files in /tmp. Additionally, the relative path inherits all the issues flagged for LOCAL_TMP_DIR.

Apply this diff to use a resolved absolute path:

+import pathlib
+
+# Constant for default storage base
+_DEFAULT_STORAGE = os.path.abspath(os.getenv("TPLR_STORAGE_BASE", "./tmp"))
+
 def __init__(
     self,
     wallet: bt.wallet | None,
-    save_location: str = "./tmp",
+    save_location: str = _DEFAULT_STORAGE,
     key_prefix: str = "model",
     config=None,
     hparams=None,
     uid: int | None = None,
     **kwargs,
 ):

Also update the docstring:

-        save_location (str, optional): The base directory for saving local files. Defaults to "./tmp".
+        save_location (str, optional): The base directory for saving local files. Defaults to resolved absolute path from TPLR_STORAGE_BASE or "./tmp".

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/tplr/comms.py around line 75, the default save_location was changed from
"/tmp" to "./tmp", which risks breaking deployments and inherits relative-path
issues; revert to an absolute resolved path by setting the default to a resolved
absolute temp directory (e.g., resolve the configured LOCAL_TMP_DIR or use
pathlib.Path("/tmp").resolve()) and ensure the function normalizes/creates the
directory before use; also update the function docstring to document that
save_location is an absolute path, how it is resolved, and that the directory
will be created if missing.

Comment on lines +99 to 100
self.temp_dir = os.path.join("./tmp", f"templar_{self.uid}")
os.makedirs(self.temp_dir, exist_ok=True)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Hardcoded path bypasses the save_location parameter.

The temp_dir is constructed using a hardcoded "./tmp" prefix instead of the save_location parameter that was just passed to __init__. This creates an inconsistency where the user's specified save_location is ignored for temp directory creation.

Apply this diff to respect the save_location parameter:

     # Create temp directory for this instance
-    self.temp_dir = os.path.join("./tmp", f"templar_{self.uid}")
+    self.temp_dir = os.path.join(os.path.abspath(save_location), f"templar_{self.uid}")
     os.makedirs(self.temp_dir, exist_ok=True)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self.temp_dir = os.path.join("./tmp", f"templar_{self.uid}")
os.makedirs(self.temp_dir, exist_ok=True)
self.temp_dir = os.path.join(os.path.abspath(save_location), f"templar_{self.uid}")
os.makedirs(self.temp_dir, exist_ok=True)
🤖 Prompt for AI Agents
In src/tplr/comms.py around lines 99 to 100, the temp_dir is created with a
hardcoded "./tmp" prefix which ignores the save_location parameter passed to
__init__; change the construction to join with the instance's save_location
(e.g., os.path.join(self.save_location, "tmp", f"templar_{self.uid}") or
os.path.join(self.save_location, f"templar_{self.uid}") depending on desired
structure) and keep os.makedirs(self.temp_dir, exist_ok=True) so the temp
directory is created under the provided save_location.

Comment on lines +114 to 115
self.save_location = os.path.join("./tmp", f"hotkey_{hotkey}")
os.makedirs(self.save_location, exist_ok=True)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

The save_location parameter is overridden and ignored.

Line 114 unconditionally overwrites self.save_location with a hardcoded "./tmp" prefix, ignoring the value passed by the caller in the save_location parameter. This makes the parameter misleading.

Apply this diff to respect the parameter:

     # Use the hotkey directly in the save_location
     if self.wallet is not None:
         hotkey = self.wallet.hotkey.ss58_address
-        self.save_location = os.path.join("./tmp", f"hotkey_{hotkey}")
+        self.save_location = os.path.join(os.path.abspath(save_location), f"hotkey_{hotkey}")
         os.makedirs(self.save_location, exist_ok=True)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self.save_location = os.path.join("./tmp", f"hotkey_{hotkey}")
os.makedirs(self.save_location, exist_ok=True)
self.save_location = os.path.join(os.path.abspath(save_location), f"hotkey_{hotkey}")
os.makedirs(self.save_location, exist_ok=True)
🤖 Prompt for AI Agents
In src/tplr/comms.py around lines 114-115, the code currently overwrites the
caller-provided save_location with a hardcoded "./tmp" prefix; instead use the
incoming save_location value (or default) as the base directory when
constructing self.save_location so the parameter is respected: set base =
save_location if provided (fall back to "./tmp" only when None/empty), then do
self.save_location = os.path.join(base, f"hotkey_{hotkey}") and call
os.makedirs(self.save_location, exist_ok=True); ensure you do not
unconditionally assign "./tmp" before this logic.

Comment on lines +1302 to 1303
temp_dir = os.path.join("./tmp", str(self.uid))
os.makedirs(temp_dir, exist_ok=True)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Duplicates temp directory creation instead of reusing self.temp_dir.

The put() method creates its own temp directory with os.path.join("./tmp", str(self.uid)) instead of reusing self.temp_dir that was already created in __init__. This creates potential for inconsistency and file fragmentation.

Apply this diff to reuse the existing temp directory:

     put_start = tplr.T()
 
-    # Create per-uid temp directory
-    temp_dir = os.path.join("./tmp", str(self.uid))
-    os.makedirs(temp_dir, exist_ok=True)
+    # Use the instance's temp directory
+    temp_dir = self.temp_dir
     temp_file_path = os.path.join(temp_dir, f"temp_{filename}")

This ensures all temporary files for an instance are stored in a single location, simplifying cleanup and improving consistency.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
temp_dir = os.path.join("./tmp", str(self.uid))
os.makedirs(temp_dir, exist_ok=True)
# Use the instance's temp directory
temp_dir = self.temp_dir
🤖 Prompt for AI Agents
In src/tplr/comms.py around lines 1302 to 1303, the put() method creates a new
temp_dir with os.path.join("./tmp", str(self.uid)) instead of reusing the
instance's existing self.temp_dir; change the code to use self.temp_dir (which
was created in __init__) for all temporary file operations so all temp files
live in the same directory and avoid fragmentation—replace the local temp_dir
creation with a reference to self.temp_dir and ensure os.makedirs is called only
if needed or removed if already created in __init__.

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.

1 participant