Skip to content

Keep Mentor profiles separate by lookback window - #1754

Merged
zlareb1 merged 3 commits into
ClickHouse:mainfrom
yorkhellen:fix/mentor-lookback-cache
Nov 30, 2026
Merged

zlareb1 merged 3 commits into
ClickHouse:mainfrom
yorkhellen:fix/mentor-lookback-cache

Conversation

@yorkhellen

@yorkhellen yorkhellen commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Keep Mentor profiles separate by lookback window

Closes: #1753

Changelog category (leave one):

  • Bug Fix

Changelog entry:

mentor.brief uses the requested lookback window even when a brief for a different window is cached.

Why

A seven-day brief followed by a one-hour brief returned the seven-day result twice. The profile cache used the same entry for both requests.

Scope and risk

The cache keys include the requested window. Automatic hints still read the default window. Both kinds of profile share the existing cache size limit.

Compatibility, rollout and rollback

  • Wire: no request or response shape changes.
  • Operator steps: none.
  • Rollback: revert the server change. The cache is in process memory.

Tests

  • A regression test reproduces the wrong window and checks that one-hour, seven-day, and thirty-day profiles keep separate cache entries.
  • Mentor unit tests and all four Guide and Mentor integration tests passed. A live client received 604800 and 3600 seconds on consecutive requests.

AI assistance in the code

  • AI-generated: TRAE authored the change and ran the checks above.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass.
  • Commits are signed off.

Note

Medium Risk
In-memory cache behavior changes for mentor profiles; incorrect caching could misreport usage windows until TTL, though wire shapes are unchanged and hints still use the default window.

Overview
Fixes a cache bug where mentor.brief (and mentor_profile) could return a profile computed for one lookback window when a different window_seconds was requested — e.g. a 7-day brief served again after asking for 1 hour.

Profile cache keys now include window_seconds as a fourth tuple element. _cache_put and mentor_profile store and look up by (org, namespace, agent, window). cached_profile, warm_profile, pack sections, and per-call hints still use only the default 7-day window; non-default windows are cached separately and do not update _profile_shown (that map stays on the 3-tuple identity and is evicted only when a default-window entry is dropped).

A regression test asserts 1h, 7d, and 30d profiles stay distinct with no extra store reads on cache hits; eviction and mirror tests were adjusted for the new _cache_put API.

Reviewed by Cursor Bugbot for commit 858e12e. Bugbot is set up for automated code reviews on this repo. Configure here.

Use the requested window in the profile cache key so a cached brief cannot answer a request for a different window. Keep automatic hints on the default profile.

Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>
@vercel

vercel Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Nov 30, 2026 12:51am UTC
loom-telemetry Ready Ready Preview Nov 30, 2026 12:51am UTC

Request Review

@zlareb1 zlareb1 self-assigned this Nov 29, 2026

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The cache keeps a separate entry for each lookback window, and automatic hints still use the default profile. The regression covers three windows, repeated cache hits, and default-window eviction.

@zlareb1 zlareb1 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Biome rejects the same assignment in docs/pages/adoption.astro on this head and clean main. The pinned formatter passes with the tracked repair. PR format job · Main format job · Repair #1706

The extraction classification test also fails on clean main because changed_files has no content classification. The same assertion passes with the tracked repair. PR unit job · Main unit job · Repair #1747

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The new CI attempt found a cache fixture outside the Mentor unit tests that still uses the old key. The ordinary cached case passes on clean main and fails with this diff. The private-request assertions still pass.

Comment thread server/insights/app/mentor.py Resolved

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The sender census reports the same stale plugin client fingerprints on this CI merge and on clean main. The test passes locally with both fingerprint repairs. PR job · Main job · Plugin repair #1773 · SDK repair #1706

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The tunable-constant gate flags the same duplicate coverage limit on this head and on clean main. The coverage repair keeps the store's existing bounds. PR job · Main job · Coverage repair #1722

The adoption directory test fails on this head and on clean main because ClickHouse expires its fixed snapshot rows. The repair derives fixture dates from UTC. PR job · Main job · Adoption repair #1740

Use the same cache key as production so the privacy test can verify an ordinary request reuses its profile without warming it.

Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>
Signed-off-by: zhangxiaoyu.york <zhangxiaoyu.york@bytedance.com>

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The cache keeps each requested lookback window separate, and automatic hints use the default window. The mirror advice fixture uses the new cache key and still checks that private requests leave advice state untouched. The nine focused cache and mirror advice tests pass on this head.

@zlareb1 zlareb1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The resolver attestation test fails at the same superseder assertion on this CI merge and on clean main with ClickHouse 26.11.5.8. The fixture needs a successor of equal standing to exercise the timestamp assertion. The integration shard passes on the repair. PR job · Main job · Repair #1781 · Passing shard

@zlareb1
zlareb1 merged commit adea421 into ClickHouse:main Nov 30, 2026
72 of 77 checks passed
@yorkhellen yorkhellen mentioned this pull request Nov 30, 2026
3 of 5 tasks
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.

Mentor returns a cached report for the wrong time window

2 participants