Skip to content

fix(memos-local-plugin): episode lifecycle and noise filtering#1607

Open
Starfie1d1272 wants to merge 1 commit intoMemTensor:mainfrom
Starfie1d1272:fix/episode-lifecycle-noise
Open

fix(memos-local-plugin): episode lifecycle and noise filtering#1607
Starfie1d1272 wants to merge 1 commit intoMemTensor:mainfrom
Starfie1d1272:fix/episode-lifecycle-noise

Conversation

@Starfie1d1272
Copy link
Copy Markdown

Summary

Three related fixes targeting episode lifecycle correctness and trace noise reduction.

1. Remove adapter-initiated episode pre-creation

File: __init__.py

initialize() was calling episode.open to pre-create an episode before any real turn. The orchestrator's turn.start already creates a proper episode on the first real turn via openEpisodeIfNeeded(), so every Hermes session produced 2 episodes — one empty orphan always abandoned.

Fix: Remove the premature episode.open call.

2. Finalize idle-timeout episodes that have content

Files: memory-core.ts, episode-manager.ts, reward.ts

  • autoFinalizeStaleTasks() was unconditionally calling abandon() even when the episode had real conversation turns. Idle timeout != meaningless conversation.
  • abandon() was always setting closeReason: "abandoned" even when async reward scoring had already completed (rTask was set).
  • reward.ts updateMeta() was not syncing closeReason after writing rTask.

Fix: Check traceIds to decide finalize vs abandon. Check rTask in abandon() to preserve "finalized" status. Sync closeReason in reward's updateMeta().

3. Filter Hermes auto-skill evaluation prompts

File: __init__.py

Hermes injects a structured auto-skill eval prompt ("Review the conversation above and consider whether a skill should be saved or updated...") at task end. This system-level scaffolding was captured as conversation content, polluting memory search indices and downstream skill generation.

Fix: Strip auto-skill eval blocks from both assistant_content and user_content in _turn_end(). Skip turn.start prefetch for these prompts to avoid creating orphan traces.

🤖 Generated with Claude Code

Three related fixes:

- Remove adapter-initiated episode.open in initialize() — the orchestrator
  creates episodes on first real turn, avoiding empty orphan episodes.

- Check traceIds before deciding idle-timeout disposition — episodes with
  content get finalized (completed), truly empty episodes get abandoned
  (skipped). Previously all were abandoned regardless of content.

- Check rTask in abandon() — episodes that already received async reward
  scoring keep closeReason: "finalized" instead of being overwritten to
  "abandoned". Sync closeReason in reward.ts updateMeta().

- Filter Hermes auto-skill evaluation prompts from traces — strip the
  distinctive "Review the conversation above..." block from both
  assistant_content and user_content before writing turn.end, and skip
  turn.start prefetch for these prompts to avoid creating orphan traces.
Copilot AI review requested due to automatic review settings May 1, 2026 06:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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