Skip to content

fix: track() returns created Path on success (match Optional[Path] signature) - #2

Merged
seojoonkim merged 1 commit into
seojoonkim:mainfrom
lifrary:fix/track-return-path
Apr 17, 2026
Merged

seojoonkim merged 1 commit into
seojoonkim:mainfrom
lifrary:fix/track-return-path

Conversation

@lifrary

@lifrary lifrary commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Summary

MemKraft.track() declares -> Optional[Path] but the success path never returns the created Path — it falls off the end of the function and implicitly returns None. Callers that use the documented return type cannot distinguish success from failure. This PR adds the missing return filepath on success.

Problem

In src/memkraft/core.py the track() method declares:

def track(self, name: str, entity_type: str = "person", source: str = "") -> Optional[Path]:

All three failure paths return None explicitly:

Line Condition Return
78 empty name return None
87 already tracking return None
128 OSError writing file return None

But the success path ends at the print statement on line 125 and falls through, returning None implicitly — so the signature's promise of Optional[Path] is only ever a promise of None.

filepath.write_text(content, encoding="utf-8")
print(f"✅ Tracking: {filepath.relative_to(self.base_dir.parent)}")
# ← implicit None here; nothing differentiates success from failure
except OSError as e:
    ...
    return None

Fix

One line:

             filepath.write_text(content, encoding="utf-8")
             print(f"✅ Tracking: {filepath.relative_to(self.base_dir.parent)}")
+            return filepath
         except OSError as e:

Why it matters

  • Library users who want the created path currently have to recompute it from name (duplicating _slugify + live_notes_dir logic), or ignore the return entirely.
  • The type signature documents the intended behavior, so this is the smallest-surface fix — existing None returns on failure paths are preserved, so nothing downstream breaks.
  • Prior commit f407429 ("R11 hotfix — return values, …") already swept similar gaps elsewhere; this looks like one that slipped through.

Test plan

  • Added TestR16DuplicateEntities::test_track_new_returns_path which asserts the return value isinstance(result, Path), the file exists, and the path equals the expected live_notes_dir / slug.
  • Existing assertions that expect None on failure are unchanged and still pass (test_track_duplicate_returns_none, test_track_empty_name, test_track_whitespace_name).
  • Full suite: 278 passed locally (pytest tests/), up from 277.

Scope

This PR touches only track()'s success return and adds one test. No behavior change for any failure path, no refactor, no new dependencies.

🤖 Generated with Claude Code

The signature `-> Optional[Path]` promises a Path on success, but all
three failure paths return None explicitly while the success path falls
through, returning None implicitly. Library callers cannot distinguish
success from failure via the documented return type.

Adds `return filepath` on the success branch and a test asserting the
return is a valid Path. Failure-path None returns are preserved, so
existing assertions (empty name, whitespace name, duplicate tracking)
are unchanged.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@seojoonkim
seojoonkim merged commit 042c592 into seojoonkim:main Apr 17, 2026
seojoonkim added a commit that referenced this pull request Apr 17, 2026
- brief() returns text from MCP recall path (#3)
- track() returns Path correctly (#2)
- Korean josa stripping improvements (#1)
- 594 passed, 1 skipped
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.

2 participants