Skip to content

🔊 fix: warn when summarization.trigger.type is unrecognized#108

Merged
danny-avila merged 2 commits intomainfrom
fix/summarization-unrecognized-trigger-warning
Apr 19, 2026
Merged

🔊 fix: warn when summarization.trigger.type is unrecognized#108
danny-avila merged 2 commits intomainfrom
fix/summarization-unrecognized-trigger-warning

Conversation

@danny-avila
Copy link
Copy Markdown
Owner

Summary

Defense-in-depth companion to LibreChat#12735, which fixes an upstream Zod schema that was rejecting all three documented summarization.trigger.type values.

Today, shouldTriggerSummarization silently returns false for any trigger.type that isn't one of token_ratio, remaining_tokens, or messages_to_refine. That turned the recent LibreChat schema/docs/runtime drift into a silent no-op — summarization just never fired, with no signal to the operator.

This PR emits a one-time console.warn per unrecognized type so the misconfiguration surfaces in logs without spamming every agent turn:

[shouldTriggerSummarization] Unrecognized trigger.type: "token_count". Summarization will not fire. Valid values: token_ratio, remaining_tokens, messages_to_refine.

Behavior is unchanged for every valid trigger type and for the no-trigger-configured default.

The helper is deduped via a module-level Set<string> so an admin who deploys a typo doesn't get one warning per LLM round-trip. An internal _resetUnrecognizedTriggerWarnings export is provided for test reset.

Test plan

  • New unit test in src/summarization/__tests__/trigger.test.ts covers:
    • unrecognized type returns false
    • warning is emitted once per unrecognized type
    • duplicate unrecognized types do not warn again
    • a different unrecognized type warns once more
    • warning text mentions the offending type and all three valid values
  • npx jest src/summarization/__tests__/trigger.test.ts — 5 passed.
  • npx tsc --noEmit — clean.
  • npx eslint src/summarization/index.ts src/summarization/__tests__/trigger.test.ts — 0 errors (1 expected no-console warning, consistent with existing console.warn usage in src/graphs/Graph.ts).

`shouldTriggerSummarization` silently returned `false` whenever the
configured `trigger.type` was not one of the three it implements
(`token_ratio`, `remaining_tokens`, `messages_to_refine`). That turned
any upstream schema/SDK drift into a silent no-op — summarization just
never fired, with no signal to the operator.

Emit a one-time `console.warn` per unrecognized type so the
misconfiguration surfaces in logs without spamming every agent turn.

Behavior is unchanged for all valid trigger types and for the
no-trigger-configured default.
@danny-avila
Copy link
Copy Markdown
Owner Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 52ee91ac74

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (warnedUnrecognizedTriggerTypes.has(type)) {
return;
}
warnedUnrecognizedTriggerTypes.add(type);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Cap unknown-trigger cache growth

warnedUnrecognizedTriggerTypes is process-global and every previously unseen trigger.type is retained forever via warnedUnrecognizedTriggerTypes.add(type). Because SummarizationTrigger.type accepts arbitrary strings and this path runs on normal request flow, deployments that ingest dynamic or user-provided agent configs can accumulate unbounded unique keys over time, creating a memory-growth vector in long-lived workers. Consider bounding this cache (size cap/LRU) or using a time-based eviction policy.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Addressed in d60ec1e — the dedup set is now capped at 32 entries with FIFO eviction of the oldest key on overflow (Set preserves insertion order). Added a regression test that floods the function with 500 unique unrecognized types and verifies the dedup contract still holds.

Per Codex review: the dedup `Set` for warned trigger types was
process-global and grew unboundedly. Consumers that thread dynamic or
user-provided values through `trigger.type` could accumulate unique
keys in long-lived workers — a minor but real memory vector.

Cap the set at 32 entries and evict the oldest on overflow (Set
preserves insertion order, so this is FIFO-ish). 32 is well above the
handful of typos a legitimate deployment would ever see, and the dedup
contract still holds: we never warn twice for a type that is currently
in the set.
@danny-avila
Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila
Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila danny-avila merged commit f54b118 into main Apr 19, 2026
4 checks passed
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.

1 participant