Skip to content

bug(cli): soft-deleted observation still counted by 'delete session', blocking cleanup of session_project_directory_mismatch findings #1150

Description

@terracenter

Summary

engram doctor's session_project_directory_mismatch check flags a session by its
recorded session_project. After correcting the underlying content (soft-delete the
mistagged observation, re-save it under the correct project), the check keeps firing
forever because the original session row is never cleanable: delete session refuses
it as "still has observations" even though the observation is already soft-deleted and
projects list shows 0 active observations for that project, and hard-deleting the
original observation by ID fails as "not found" once it's already soft-deleted.

Version: 1.20.0 (precompiled binary). Have not verified against 2.0.0-rc.10 — noticed
while filing this that the installed binary is far behind current pre-release, and that
2.0 introduced an ownership_mode concept (#1030) that may be relevant to this same
class of problem, so this may already be partially addressed upstream. Filing as-is
since I could not reproduce on rc.10 in this environment.

Repro (literal commands, 1.20.0)

$ engram doctor --json --check session_project_directory_mismatch
...
"findings": [
  {"evidence": {"directory": "/home/freddy/Workspace/.agents", "directory_project": "agents",
    "directory_project_source": "git_remote", "session_id": "manual-save-.agents",
    "session_project": ".agents"}},
  {"evidence": {"directory": "/home/freddy/Workspace/.agents", "directory_project": "agents",
    "directory_project_source": "git_remote", "session_id": "manual-save-vault",
    "session_project": "vault"}}
]

Corrected the content: found the 2 flagged observations (#170, #85), read full content via
mem_get_observation, soft-deleted each (engram delete 170, engram delete 85 — both
succeeded), then re-saved the same content under the correct project (agents for #170's
content, obsidian for #85's content, since #85's actual content was vault/Obsidian work
despite the session's stale vault project tag).

After that:

$ engram projects list
  obsidian    80 obs  2 sessions  0 prompts
  agents       1 obs  1 session   0 prompts
  .agents      0 obs  1 session   0 prompts   <- correctly shows 0 obs now
  vault        0 obs  1 session   0 prompts   <- correctly shows 0 obs now

But cleanup of the stale sessions is impossible via any exposed command:

$ engram delete 170 --hard
engram: observation not found

$ engram delete session manual-save-.agents
engram: session still has observations: session "manual-save-.agents" has 1 observation(s)

$ engram delete session manual-save-vault
engram: session still has observations: session "manual-save-vault" has 1 observation(s)

And engram doctor still reports the original 2 findings, unchanged, even though the
content-level problem is fully fixed and projects list agrees the projects are empty.

Why it matters

There is no way to fully resolve a session_project_directory_mismatch finding once its
observation has been soft-deleted (the normal, non-destructive way to correct mistagged
content) — delete session and delete <id> --hard disagree with each other and with
projects list about whether the session still "has" an observation. The doctor check
never clears, permanently, for any session that goes through the soft-delete correction
path — the only way it seems to.

Expected

Either:

  • delete session and delete <id> --hard should agree with projects list's definition
    of "has observations" (i.e. count only active, non-soft-deleted rows), so a session with
    only soft-deleted observations can be deleted; or
  • session_project_directory_mismatch should not re-fire for sessions whose only
    observations are soft-deleted.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions