Skip to content

bug(core): microcompaction keepRecent accepts fractional counts #5648

Description

@tt-a1i

microcompactHistory accepts fractional values for the QWEN_MC_KEEP_RECENT override because it parses the env var with Number(...) and only checks finiteness.

That value is later used as a count. JavaScript array slicing coerces a fractional keepRecent differently from the metadata calculation:

  • slice(-1.5) behaves like keeping 1 item
  • Math.min(count, 1.5) can report 1.5 in mediaKept
  • meta.keepRecent also exposes the fractional value

So QWEN_MC_KEEP_RECENT=1.5 can produce inconsistent diagnostic metadata even though retention counts should be integers.

Expected behavior: QWEN_MC_KEEP_RECENT and settings.toolResultsNumToKeep should resolve to positive safe integers. Fractional, unsafe, and non-finite values should fall back to the next source/default before keepRecent is used for slicing and metadata.

I can send a small fix with tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    category/coreCore engine and logicpriority/P2Medium - Moderately impactful, noticeable problemscope/memoryMemory and context managementscope/settingsSettings and preferencestype/bugSomething isn't working as expectedwelcome-pr

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions