-
Notifications
You must be signed in to change notification settings - Fork 58
LCORE-625: Check if transcript directory is writable #602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LCORE-625: Check if transcript directory is writable #602
Conversation
|
Warning Rate limit exceeded@tisnik has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 20 minutes and 14 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
WalkthroughAdds a new directory_check(...) in Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller as ConfigCheck
participant Config as models.config:UserDataCollection
participant Checks as utils.checks:directory_check
participant FS as Filesystem/OS
Config->>Checks: directory_check(path, must_exists=True, must_be_writable=..., desc)
Checks->>FS: stat(path) / isdir(path)
alt Path missing & must_exists == True
Checks-->>Config: raise InvalidConfigurationError ("{desc} must be set")
else Path exists
alt Not a directory
Checks-->>Config: raise InvalidConfigurationError ("{desc} is not a directory")
else Is a directory
alt must_be_writable == True
Checks->>FS: access(path, WRITE)
alt Not writable
Checks-->>Config: raise InvalidConfigurationError ("{desc} is not writable")
else Writable
Checks-->>Config: return None
end
else
Checks-->>Config: return None
end
end
end
Note over Config,Checks: Called for feedback and transcripts when enabled
sequenceDiagram
autonumber
actor Caller as StoreTranscriptCaller
participant Transcripts as utils.transcripts:store_transcript
participant FS as Filesystem/OS
participant Logger as logs
Caller->>Transcripts: store_transcript(path, payload)
Transcripts->>FS: open(path, "w") / write(payload)
alt Write succeeds
Transcripts->>Logger: log success
Transcripts-->>Caller: return
else Write raises IOError/OSError
Transcripts->>Logger: log error with path
Transcripts-->>Caller: re-raise exception
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
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. 🧪 Early access (Sonnet 4.5): enabledWe are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience. Note:
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/utils/checks.py (1)
60-60: Consider reordering parameters for consistency.For consistency with similar validation functions, consider placing
descbeforeshould_be_writable, as descriptive parameters typically precede behavioral flags in the codebase.Apply this diff if you choose to reorder:
-def directory_check(path: FilePath, should_be_writable: bool, desc: str) -> None: +def directory_check(path: FilePath, desc: str, should_be_writable: bool = False) -> None:Note: This would require updating all call sites, so only consider if you haven't integrated this function yet.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/utils/checks.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
Use absolute imports for internal modules (e.g., from auth import get_auth_dependency)
Files:
src/utils/checks.py
**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.py: All modules start with descriptive module-level docstrings explaining purpose
Use logger = logging.getLogger(name) for module logging after import logging
Define type aliases at module level for clarity
All functions require docstrings with brief descriptions
Provide complete type annotations for all function parameters and return types
Use typing_extensions.Self in model validators where appropriate
Use modern union syntax (str | int) and Optional[T] or T | None consistently
Function names use snake_case with descriptive, action-oriented prefixes (get_, validate_, check_)
Avoid in-place parameter modification; return new data structures instead of mutating arguments
Use appropriate logging levels: debug, info, warning, error with clear messages
All classes require descriptive docstrings explaining purpose
Class names use PascalCase with conventional suffixes (Configuration, Error/Exception, Resolver, Interface)
Abstract base classes should use abc.ABC and @AbstractMethod for interfaces
Provide complete type annotations for all class attributes
Follow Google Python docstring style for modules, classes, and functions, including Args, Returns, Raises, Attributes sections as needed
Files:
src/utils/checks.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build-pr
- GitHub Check: e2e_tests
🔇 Additional comments (1)
src/utils/checks.py (1)
77-82: LGTM - Implementation is correct.The implementation correctly:
- Validates directory existence using
os.path.isdir()- Conditionally checks writability with
os.access(path, os.W_OK)- Raises appropriate errors with clear messages
- Follows the same pattern as
file_check
|
Note Unit test generation is an Early Access feature. Expect some limitations and changes as we gather feedback and continue to improve it. Generating unit tests... This may take up to 20 minutes. |
2fa47aa to
86115f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/models/config.py(1 hunks)src/utils/checks.py(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/utils/checks.py
🧰 Additional context used
📓 Path-based instructions (5)
src/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
Use absolute imports for internal modules (e.g., from auth import get_auth_dependency)
Files:
src/models/config.py
**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.py: All modules start with descriptive module-level docstrings explaining purpose
Use logger = logging.getLogger(name) for module logging after import logging
Define type aliases at module level for clarity
All functions require docstrings with brief descriptions
Provide complete type annotations for all function parameters and return types
Use typing_extensions.Self in model validators where appropriate
Use modern union syntax (str | int) and Optional[T] or T | None consistently
Function names use snake_case with descriptive, action-oriented prefixes (get_, validate_, check_)
Avoid in-place parameter modification; return new data structures instead of mutating arguments
Use appropriate logging levels: debug, info, warning, error with clear messages
All classes require descriptive docstrings explaining purpose
Class names use PascalCase with conventional suffixes (Configuration, Error/Exception, Resolver, Interface)
Abstract base classes should use abc.ABC and @AbstractMethod for interfaces
Provide complete type annotations for all class attributes
Follow Google Python docstring style for modules, classes, and functions, including Args, Returns, Raises, Attributes sections as needed
Files:
src/models/config.py
src/{models/config.py,configuration.py}
📄 CodeRabbit inference engine (CLAUDE.md)
src/{models/config.py,configuration.py}: All configuration uses Pydantic models extending ConfigurationBase
Configuration base models must set model_config with extra="forbid" to reject unknown fields
Files:
src/models/config.py
src/{models/**/*.py,configuration.py}
📄 CodeRabbit inference engine (CLAUDE.md)
src/{models/**/*.py,configuration.py}: Use @field_validator and @model_validator for custom validation in Pydantic models
Use precise type hints in configuration (e.g., Optional[FilePath], PositiveInt, SecretStr)
Files:
src/models/config.py
src/models/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
src/models/**/*.py: Pydantic models: use BaseModel for data models and extend ConfigurationBase for configuration
Use @model_validator and @field_validator for Pydantic model validation
Files:
src/models/config.py
🧬 Code graph analysis (1)
src/models/config.py (1)
src/utils/checks.py (1)
directory_check(60-87)
🪛 GitHub Actions: Pyright
src/models/config.py
[error] 238-238: pyright: Argument of type "str" cannot be assigned to parameter "path" of type "FilePath" in function "directory_check". "str" is not assignable to "Path".
[error] 249-249: pyright: Argument of type "str" cannot be assigned to parameter "path" of type "FilePath" in function "directory_check". "str" is not assignable to "Path".
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build-pr
- GitHub Check: e2e_tests
🔇 Additional comments (2)
src/models/config.py (2)
237-242: Incorrect parameter order in directory_check call.The
descparameter is passed in the wrong position. According to the function signature insrc/utils/checks.py,descis the fourth parameter, not the second.Apply this diff to fix the parameter order:
checks.directory_check( self.feedback_storage, - desc="Check directory to store feedback", must_exists=False, must_be_writable=True, + desc="Check directory to store feedback", )Likely an incorrect or invalid review comment.
248-253: Incorrect parameter order in directory_check call.The
descparameter is passed in the wrong position. According to the function signature insrc/utils/checks.py,descis the fourth parameter, not the second.Apply this diff to fix the parameter order:
checks.directory_check( self.transcripts_storage, - must_exists=False, - desc="Check directory to store transcripts", + must_exists=False, must_be_writable=True, + desc="Check directory to store transcripts", )Likely an incorrect or invalid review comment.
745e06d to
e4194f1
Compare
e4194f1 to
93828af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/utils/checks.py (1)
70-70: Fix grammatical error in docstring.The parameter description has a grammatical error: "Should the directory exists?" should be "Should the directory exist?"
Apply this diff:
- must_exists (bool): Should the directory exists? + must_exists (bool): Should the directory exist?src/utils/transcripts.py (2)
83-88: LGTM! Error handling for file write is appropriate.The try/except block correctly catches I/O errors, logs them with context, and re-raises to propagate the failure. This provides a runtime safety net complementing the upfront directory writability check.
Minor note: In Python 3,
IOErroris an alias forOSError, making the tuple redundant (though harmless).Optionally simplify to:
- except (IOError, OSError) as e: + except OSError as e:
60-60: Consider wrapping directory creation in error handling for clearer diagnostics.The
mkdircall could fail due to runtime issues (disk full, permission changes, path conflicts). While the try/except around the file write will catch these failures, wrappingmkdirseparately would provide clearer error messages distinguishing directory creation failures from file write failures.transcripts_path = construct_transcripts_path(user_id, conversation_id) - transcripts_path.mkdir(parents=True, exist_ok=True) + try: + transcripts_path.mkdir(parents=True, exist_ok=True) + except OSError as e: + logger.error("Failed to create transcript directory %s: %s", transcripts_path, e) + raise
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/models/config.py(1 hunks)src/utils/checks.py(1 hunks)src/utils/transcripts.py(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/models/config.py
🧰 Additional context used
📓 Path-based instructions (2)
src/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
Use absolute imports for internal modules (e.g., from auth import get_auth_dependency)
Files:
src/utils/checks.pysrc/utils/transcripts.py
**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.py: All modules start with descriptive module-level docstrings explaining purpose
Use logger = logging.getLogger(name) for module logging after import logging
Define type aliases at module level for clarity
All functions require docstrings with brief descriptions
Provide complete type annotations for all function parameters and return types
Use typing_extensions.Self in model validators where appropriate
Use modern union syntax (str | int) and Optional[T] or T | None consistently
Function names use snake_case with descriptive, action-oriented prefixes (get_, validate_, check_)
Avoid in-place parameter modification; return new data structures instead of mutating arguments
Use appropriate logging levels: debug, info, warning, error with clear messages
All classes require descriptive docstrings explaining purpose
Class names use PascalCase with conventional suffixes (Configuration, Error/Exception, Resolver, Interface)
Abstract base classes should use abc.ABC and @AbstractMethod for interfaces
Provide complete type annotations for all class attributes
Follow Google Python docstring style for modules, classes, and functions, including Args, Returns, Raises, Attributes sections as needed
Files:
src/utils/checks.pysrc/utils/transcripts.py
🧬 Code graph analysis (1)
src/utils/transcripts.py (1)
src/models/config.py (1)
dump(565-568)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build-pr
- GitHub Check: e2e_tests
🔇 Additional comments (1)
src/utils/checks.py (1)
79-87: LGTM! Logic correctly handles conditional existence and writability checks.The implementation correctly handles all valid parameter combinations:
- Early return when path doesn't exist and
must_exists=Falseis appropriate- Subsequent checks (directory type, writability) only run when the path exists
- Error messages are clear and include the description context
Description
LCORE-625: Check if transcript directory is writable
Type of change
Related Tickets & Documents
Summary by CodeRabbit