chore-shared-helper-duplication-hooks-services-2026-06-10: extract shared helpers#74
Merged
emp3thy merged 1 commit intoJun 13, 2026
Conversation
…-06-10 — extract shared session-id/clock/spool/timestamp helpers Create better_memory/_common.py (pure stdlib, no intra-package imports so hooks can import it cheaply) housing env_session_id, get_session_id, default_clock, resolve_home, default_spool_dir, and safe_timestamp. Replace the 7 drifting session-ID fallback copies, 8 _default_clock copies, and the duplicated _default_spool_dir/_safe_timestamp helpers in hooks with imports; delete the 'duplicated to avoid cross-module import' workaround in session_close.py. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Claude BugBot Analysis
No bugs found. The PR is a clean refactoring that centralizes duplicated utility functions (_default_clock, _default_spool_dir, _safe_timestamp, session-ID resolution) into a new better_memory._common module. All call sites are correctly updated, removed import os/import uuid/from pathlib import Path statements have no remaining usages in the affected files, the test monkeypatch target was correctly renamed from _default_spool_dir to default_spool_dir, and the extracted functions are behaviorally equivalent to the originals they replace.
No bugs were detected in this PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extracts the session-ID fallback, default clock, spool-dir, and safe-timestamp helpers — previously copy-pasted across hooks, services, storage, and the MCP layer (7 session-ID copies, 8 clock copies) — into a new lightweight
better_memory/_common.py. The module is pure stdlib with no intra-package imports so hooks can import it without paying for SQLite/boto3/config at invocation time; a test guards that property. All copies replaced with imports; the 'duplicated to avoid cross-module import' workaround in session_close.py is gone.Closes chore-shared-helper-duplication-hooks-services-2026-06-10.
Test plan:
pytest --ignore=tests/ui(playwright not installed): 946 passed, 17 skippedtests/test_common.py: helper behaviour + lightweight-import guardruff checkon changed files: only 6 pre-existing E501s also present on HEADPBI:
.ralph/current/chore-shared-helper-duplication-hooks-services-2026-06-10on ralph-queue.🤖 Generated with Claude Code