🩹 fix: Codex review on context projection (G1 guard, IDOR, recount, summary)

- Guard `currentActive` against a stale window: a model/window switch on the
  current branch left the live snapshot outranking the projection (G1 didn't
  fire). Now defers to the projection unless streaming or the window matches.
- Scope branch lookups to the authenticated user (`getMessages` filter +
  injected `userId`) — was loading any conversation by id (IDOR).
- Recount messages with no stored `tokenCount` via the tokenizer instead of
  charging 0, so snapshot-less/imported histories don't under-report.
- Fall back (null) for already-summarized branches rather than projecting from
  the full raw parent chain (the next call would send summary + tail); the
  client's summary-baseline-aware estimate handles them until a follow-up
  replays the summary boundary.
This commit is contained in:
Danny Avila 2026-06-16 15:29:50 -04:00
parent e2310c9433
commit 5701a9da9c
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
3 changed files with 38 additions and 12 deletions

View file

@ -18,7 +18,7 @@ async function contextProjectionController(req, res) {
return;
}
const projection = await resolveContextProjection(
{ getMessages: db.getMessages, getAgent: db.getAgent },
{ userId: req.user?.id, getMessages: db.getMessages, getAgent: db.getAgent },
params,
);
res.json(projection ?? null);