Skip to content

Context._migrated attribute is unused and migration lacks idempotency guard #82

Description

@bjester

Observed Behavior

In Context.__init__, self._migrated = False is defined, but it is never checked, modified, or referenced anywhere else in context.py or the rest of the codebase. As a consequence, Context.migrate() repeats filesystem searches and checks on every runtime initialization without an idempotency guard.

Expected Behavior

Context._migrated should be used as a guard inside Context.migrate() so that migration logic runs at most once per Context instance.

Steps to Reproduce

  1. Inspect src/treefort/context.py:58.
  2. Observe self._migrated = False.
  3. Search for _migrated across src/ and tests/; note no other references exist.
  4. Calling context.migrate() repeatedly re-executes all directory lookups.

Minimal Reproduction Environment / Conditions

  • Version / Branch / Commit: release-v0.5.x@6d07c0c
  • Component: treefort.context.Context

Errors, Logs & Telemetry

In src/treefort/context.py:58:

class Context:
    def __init__(self):
        self.cwd = Path.cwd()
        self._cached_project_dir: Path | None = None
        self._migrated = False  # Never read or set to True
        self._config_manager = ConfigManager()

Deliverables & Testing Requirements

  • Use self._migrated in Context.migrate(): early-exit if already True, and set to True upon completion.
  • Regression Safety: Add a unit test in tests/test_migration.py verifying that repeated calls to context.migrate() do not perform redundant migrations.

Technical Pointers & Root Cause Clues

  • Suspected Components: src/treefort/context.py:58, 97-126
  • Related Commits: 226762e (Rename project to treefort)

Notes & Edge Cases

  • Ensures clean lifecycle state management and avoids unnecessary I/O overhead on repeated commands.

Metadata

Severity / Priority: P2 (Normal)
Area: bug, context, migration

AI Usage

Drafted with Gemini following the DEEP framework based on code review findings against release-v0.5.x. Reproduction conditions and code references were verified in the codebase.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2 - NormalShould fix but can waitbugSomething isn't working

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions