Skip to content

COG-6341 feat: Add --memory-only flag to cognee-cli forget - #4697

Open
goran-radonic wants to merge 4 commits into
devfrom
feature/cog-6341-add-memory-only-flag-to-cognee-cli-forget-local-api-url
Open

COG-6341 feat: Add --memory-only flag to cognee-cli forget#4697
goran-radonic wants to merge 4 commits into
devfrom
feature/cog-6341-add-memory-only-flag-to-cognee-cli-forget-local-api-url

Conversation

@goran-radonic

Copy link
Copy Markdown
Contributor

Description

Added --memory-only to cognee-cli forget, was missing even though the SDK already supports it (both locally and through --api-url). Also fixed --dataset getting silently dropped in --api-url mode (wrong arg name) and made --everything --memory-only error instead of just doing a full wipe.

Acceptance Criteria

  • --memory-only reaches forget() locally and via --api-url
  • --dataset works again in --api-url mode
  • --everything --memory-only errors instead of wiping everything

Type of Change

  • New feature (non-breaking change that adds functionality)
  • Bug fix (non-breaking change that fixes an issue)

Screenshots

CLI only, no UI. 164 passed.

Pre-submission Checklist

  • All new and existing tests pass
  • I have added tests that prove my fix is effective or that my feature works
  • My code follows the project's coding standards and style guidelines
  • I have tested my changes thoroughly before submitting this PR
  • This PR contains minimal changes necessary to address the issue/feature
  • I have searched existing PRs to ensure this change hasn't been submitted already
  • I have linked any relevant issues in the description
  • My commits have clear and descriptive messages

DCO Affirmation

I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin.

cognee.forget() and CogneeApiClient.forget() both accept a memory_only
parameter, but cognee-cli forget never exposed it in either the local
argparse configuration or the --api-url remote-dispatch path, making
memory-only forget entirely unreachable from the CLI. Adds the flag to
both paths.

Also fixes an unrelated bug found in the same function: --api-url
forget dispatch read args.dataset_name, a field the CLI parser never
sets (its flag is --dataset), silently dropping --dataset in that
mode. And adds a guard for --everything --memory-only, which
previously silently ignored --memory-only and did a full destructive
wipe instead (--everything has no confirmation prompt).

Split out of #4694 per reviewer feedback that PR bundled unrelated
concerns; extracted as its own change.
@Vasilije1990

Copy link
Copy Markdown
Contributor

@goran-radonic check tests please

return
if not everything and not dataset and not dataset_id and not data_id:
fmt.error("Specify --dataset or --dataset-id, --data-id with dataset, or --everything.")
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

minor — Validation gap: --data-id without a dataset passes through here but fails in the SDK with "data_id requires dataset or dataset_id." For consistency with the other validations added in this PR, check data_id and not dataset and not dataset_id and error with "Specify --dataset or --dataset-id when using --data-id."

@@ -56,13 +68,22 @@ def execute(self, args: argparse.Namespace) -> None:
)
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

minor — Same validation gap as in api_dispatch.py: data_id without a dataset reference should error here for better UX. Add a check after line 63: if data_id and not dataset and not dataset_id: fmt.error("Specify --dataset or --dataset-id when using --data-id.")

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

A 90-line diff to add one CLI flag, plus 180 lines of tests to prove it works — the ratio suggests either paranoia or prior trauma with silent flag-dropping. 🧪

🟢 No blocking issues found.

Top findings:

  • minorcognee/cli/api_dispatch.py:392 — CLI validation gap: --data-id without a dataset passes through but fails in SDK
  • minorcognee/cli/commands/forget_command.py:69 — Same gap in command layer; add validation for better UX

See inline comments for details.

Fix the review findings in PR #4697:
1. [minor] `cognee/cli/api_dispatch.py:392` — Add validation after line 389: check if `data_id and not dataset and not dataset_id`, error with "Specify --dataset or --dataset-id when using --data-id."
2. [minor] `cognee/cli/commands/forget_command.py:69` — Add validation after line 63: `if data_id and not dataset and not dataset_id: fmt.error("Specify --dataset or --dataset-id when using --data-id.")` and return early
Then run the test suite.

--data-id alone satisfied forget's "must specify something" check,
so it reached cognee.forget()/CogneeApiClient.forget() with no
dataset and failed there instead, with a less clear error message.
Add the same guard to both the local execute() path and the
--api-url dispatch path.
memory_only=False,
)
dispatch(args)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[blocker] Missing test for the main bug fix — --data-id without --dataset should error.

The PR title says "Require dataset when --data-id is used" and the commit message explains that --data-id alone used to pass validation and fail later. But there's no test exercising the new validation at api_dispatch.py:393-395.

Add a test:

@patch("cognee.cli.api_dispatch.CogneeApiClient")
def test_data_id_without_dataset_does_not_call_client(self, MockClient):
    """--data-id alone must error; requires --dataset or --dataset-id."""
    mock_instance = MagicMock()
    MockClient.return_value.__enter__ = MagicMock(return_value=mock_instance)
    MockClient.return_value.__exit__ = MagicMock(return_value=False)

    args = argparse.Namespace(
        api_url="http://localhost:8000",
        command="forget",
        user_id=None,
        dataset=None,
        dataset_id=None,
        data_id="11111111-1111-1111-1111-111111111111",
        everything=False,
        memory_only=False,
    )
    dispatch(args)

    mock_instance.forget.assert_not_called()

)

with pytest.raises(CliCommandException):
command.execute(args)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[blocker] Missing test for the main bug fix — --data-id without --dataset should error.

Add a test in this class to match the validation at forget_command.py:71-73:

def test_execute_data_id_without_dataset_errors(self):
    """--data-id alone must error; requires --dataset or --dataset-id."""
    mock_cognee = MagicMock()
    mock_cognee.forget = AsyncMock()

    with patch.dict(sys.modules, {"cognee": mock_cognee}):
        command = ForgetCommand()
        args = argparse.Namespace(
            dataset=None,
            dataset_id=None,
            data_id="11111111-1111-1111-1111-111111111111",
            everything=False,
            memory_only=False,
        )
        # Should not raise, just print an error and return without calling forget().
        command.execute(args)

    mock_cognee.forget.assert_not_awaited()

@@ -56,13 +68,26 @@ def execute(self, args: argparse.Namespace) -> None:
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[minor] Error message inconsistency.

This says --everything/--all but the equivalent message in api_dispatch.py:391 only says --everything. For consistency, either both should mention the --all alias or neither should.

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

A PR titled "Require dataset when --data-id is used" that adds validation for exactly that... then forgets to test it. 🎯

🔴 2 blockers, 1 minor — changes requested

  • blockercognee/tests/cli_tests/cli_unit_tests/test_api_dispatch.py:277 — Missing test for --data-id without --dataset (the main bug fix)
  • blockercognee/tests/cli_tests/cli_unit_tests/test_cli_commands.py:709 — Missing test for --data-id without --dataset in command path
  • minorcognee/cli/commands/forget_command.py:68 — Error message mentions --all alias inconsistently

See inline comments for details.

Fix the review findings in PR #4697:
1. [blocker] Add test_data_id_without_dataset_does_not_call_client to TestForgetDispatch in test_api_dispatch.py — verify that --data-id alone (without --dataset or --dataset-id) triggers the validation error at api_dispatch.py:393-395 and does not call client.forget()
2. [blocker] Add test_execute_data_id_without_dataset_errors to TestForgetCommand in test_cli_commands.py — verify that --data-id alone triggers the validation error at forget_command.py:71-73 and does not await cognee.forget()
3. [minor]   Remove "--all" from the error message at forget_command.py:68 to match api_dispatch.py:391, or add it to both for consistency
Then run the test suite.

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