Skip to content

Fix #2370: [Bug] meta.rewardDirty is re-set on episode reopen and never cleared when the ep - #2578

Open
syzsunshine219 wants to merge 2 commits into
MemTensor:mainfrom
Memtensor-AI:bugfix/autodev-2370-20260915213740784
Open

syzsunshine219 wants to merge 2 commits into
MemTensor:mainfrom
Memtensor-AI:bugfix/autodev-2370-20260915213740784

Conversation

@syzsunshine219

@syzsunshine219 syzsunshine219 commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Restores the change proposed in #2371 for review against main after its former base branch, dev-v2.0.34, was deleted. The source commits and authors are preserved.

Source head: 78c784798f20219d89139e5115e66252b80e7bde

This PR is open for review. Review and CI against the current base are pending; validation claims in the original description below refer to the earlier snapshot. The original discussion and evidence remain in #2371.


Original change description

Description

Fixed a permanent meta.rewardDirty marker on episodes that were terminal-skipped and then reopened (issue #2370).

Root cause: episode-manager.ts reopen() correctly sets rewardDirty: {reason:"episode_reopened",...} on the episode meta, but left meta.reward.skipped: true untouched from the earlier heuristic-skip scoring pass. episodeRewardIsDirty() in memory-core.ts evaluates rewardWasSkipped() before hasRewardDirtyMarker(), so the skip flag permanently short-circuited the function to false, making the episode invisible to every rescore scan path (init recovery loop, periodic dirty-closed scan, backoff filter). The marker was therefore never cleared.

Fix: In episode-manager.ts reopen(), when setting rewardDirty, also spread reward.skipped: undefined into the reward object if the episode had previously been terminal-skipped. This is a targeted one-shot patch to the object written to meta; it does not change any other reward fields. The existing collectDirtyClosedEpisodes bounded-page cleanup already handles any persisted rows that have the contradictory marker pair from before this fix.

Tests: Added two regression tests to tests/unit/session/episode-manager.test.ts: one asserting that reward.skipped is cleared and rewardDirty is set correctly after reopen on a previously-skipped episode, and one asserting that rewardDirty is not set when the episode was never scored. All 176 tests across 13 files pass.

Related Issue (Required): Fixes #2370

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • Documentation update

How Has This Been Tested?

Not run; documentation-only change.

  • Unit Test
  • Test Script Or Test Steps (please provide)
  • Pipeline Automated API Test (please provide)

Checklist

  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have created related documentation issue/PR in MemOS-Docs (if applicable)
  • I have linked the issue to this PR (if applicable)
  • I have mentioned the person who will review this PR

@whipser030, @hijzy please review this PR.

Reviewer Checklist

AutoDev added 2 commits September 16, 2026 06:16
…MemTensor#2370)

When an episode is terminal-skipped (meta.reward.skipped=true) and then
reopened, episode-manager.ts correctly sets rewardDirty but leaves
reward.skipped untouched. episodeRewardIsDirty() in memory-core.ts calls
rewardWasSkipped() before hasRewardDirtyMarker(), short-circuiting to false
and making the episode permanently invisible to every rescore scan.

Fix: in reopen(), when setting rewardDirty, also clear reward.skipped so
the marker is evaluated and the episode is queued for rescoring.

The collectDirtyClosedEpisodes bounded-page cleanup already handles existing
persisted rows with the contradictory marker pair; this fix closes the
write-path gap so new reopens don't produce the stale state in the first
place.

Regression test: reopen clears reward.skipped when setting rewardDirty (MemTensor#2370)
…emTensor#2370)

reopen() re-sets meta.rewardDirty, but EpisodeManager.finalize() and
abandon() passed snap.meta through to the repo without clearing it. Any
terminal path that did not happen to run the reward write — e.g. the
episode resumed with rTask != null, so the reward fallback was skipped —
left the marker on a fully resolved episode. episodeRewardIsDirty() and
consistency checks built on json_type(meta_json,'$.rewardDirty') then
reported the row as dirty indefinitely (reporter saw 17 days), which is
the durable half of MemTensor#2370 that clearing reward.skipped on reopen does
not address on its own.

Overwrite the key with `undefined` rather than dropping it or setting
`null`: the repo merges the patch into the existing meta_json (so an
omitted key would leave the stale value), and toJsonText uses
JSON.stringify, which omits undefined-valued keys — leaving the key
absent instead of present-and-null, which would still satisfy
`IS NOT NULL`.

Regression tests cover both terminal paths and assert on the
JSON-round-tripped meta, i.e. the shape the reporter's watchdog reads.
@syzsunshine219
syzsunshine219 marked this pull request as ready for review November 9, 2026 15:47
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.

[Bug] meta.rewardDirty is re-set on episode reopen and never cleared when the episode later reaches a terminal state

1 participant