Skip to content

feat(newsletters): raise AI generation limits for long-form content#809

Merged
dealako merged 1 commit into
mainfrom
feat/newsletter-ai-limits
May 28, 2026
Merged

feat(newsletters): raise AI generation limits for long-form content#809
dealako merged 1 commit into
mainfrom
feat/newsletter-ai-limits

Conversation

@niravpatel27
Copy link
Copy Markdown
Contributor

Summary

  • Raise newsletter input ceilings: raw content 20k → 50k chars, system-prompt override 10k → 20k chars.
  • Add a newsletter-specific output cap (NEWSLETTER_AI_MAX_TOKENS = 12_000). Meeting-agenda generation keeps its 4k shared cap.
  • Heads-up: touches apps/lfx-one/src/server/services/ai.service.ts (protected). Change is a single max_tokens binding swap on the existing newsletter call — no structural change.

Test plan

  • Paste a long source draft (>20k chars) into the AI generator and confirm the form accepts it.
  • Generate a long newsletter and verify the output isn't truncated mid-body.
  • Generate a short meeting agenda and confirm it still respects the 4k cap.

Long source notes and longer generated newsletters were getting capped
before the AI could finish. Raise the input ceilings on raw content
(20k -> 50k chars) and system-prompt override (10k -> 20k chars), and
add a newsletter-specific output cap of 12k tokens so generation isn't
truncated mid-flow. Meeting-agenda generation keeps the shared 4k
ceiling -- agendas have a 2k character target and shouldn't drift
larger.

Signed-off-by: Nirav Patel <npatel@linuxfoundation.org>
@niravpatel27 niravpatel27 requested a review from a team as a code owner May 28, 2026 17:10
Copilot AI review requested due to automatic review settings May 28, 2026 17:10
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 05e19235-c520-416f-a69b-46a9d4ccf5e9

📥 Commits

Reviewing files that changed from the base of the PR and between efb80ae and d88b804.

📒 Files selected for processing (2)
  • apps/lfx-one/src/server/services/ai.service.ts
  • packages/shared/src/constants/newsletter.constants.ts

Walkthrough

Newsletter generation AI token limits are increased and centralized. Constants for raw content length, system prompt length, and a new AI output token ceiling are updated in the shared constants file. The AiService imports and applies the newsletter-specific token ceiling to newsletter generation requests.

Changes

Newsletter AI Token Limits

Layer / File(s) Summary
Newsletter token capacity constants
packages/shared/src/constants/newsletter.constants.ts
NEWSLETTER_RAW_CONTENT_MAX_LENGTH increases from 20,000 to 50,000 characters, NEWSLETTER_SYSTEM_PROMPT_MAX_LENGTH increases from 10,000 to 20,000 characters, and new NEWSLETTER_AI_MAX_TOKENS constant is set to 12,000 for AI generation output.
AiService newsletter token integration
apps/lfx-one/src/server/services/ai.service.ts
AiService imports NEWSLETTER_AI_MAX_TOKENS and applies it as the max_tokens cap in the OpenAI chat completion request for newsletter generation, replacing the shared AI_REQUEST_CONFIG.MAX_TOKENS with inline comments explaining the newsletter-specific ceiling.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: increasing AI generation limits for newsletter long-form content through updated constants and token ceiling configuration.
Description check ✅ Passed The description clearly explains the changes: increased input limits, new output token cap for newsletters, and preservation of meeting-agenda caps, directly aligned with the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/newsletter-ai-limits

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR raises newsletter AI generation limits to better support long-form source content and longer generated newsletter bodies, while preserving the existing shorter cap for meeting agenda generation.

Changes:

  • Increased newsletter raw content and system prompt override character limits.
  • Added a newsletter-specific AI output token cap.
  • Updated newsletter AI generation to use the new newsletter token cap instead of the shared agenda cap.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/shared/src/constants/newsletter.constants.ts Defines the higher newsletter input limits and newsletter-specific AI max token constant.
apps/lfx-one/src/server/services/ai.service.ts Uses the newsletter-specific max token cap for newsletter generation while leaving agenda generation unchanged.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

Copy link
Copy Markdown
Contributor

@dealako dealako left a comment

Choose a reason for hiding this comment

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

Code Review — PR #809

Independent review

Correctness

Every claim in the PR description and inline comments checks out against the code on disk:

  • AI_REQUEST_CONFIG.MAX_TOKENS = 4_000 is untouched; ai.service.ts still binds it to the meeting-agenda chat.completions call (line 84) — agendas keep the 4k ceiling exactly as stated.
  • NEWSLETTER_AI_MAX_TOKENS = 12_000 is bound only to the newsletter completion (line 138) — no blast radius to the agenda path.
  • The bodyHtml JSON schema cap in ai.service.ts:157 is 100_000 chars, so 12k output tokens (~48k chars at ≈4 chars/token) land well inside the schema before it would push back. The comment is accurate.
  • Claude Sonnet 4 supports up to 64k output tokens; 12k is safely within range.
  • Input-limit enforcement is symmetric: both constants are imported and validated server-side in newsletter.controller.ts:429,446 and used in the Angular form validators in newsletter-generate-drawer.component.ts:48,52,70. No client/server drift.

Security

The diff is pure numeric-constant adjustments — no new code paths, no new sinks, no new HTTP surface. The systemPromptOverride prompt-injection surface is pre-existing; this PR only raises its character cap from 10k to 20k. Not a new concern, but worth noting for awareness.

Performance / cost 💬 (nit)

Raising the output ceiling from 4k to 12k tokens (~3×) and the input from 20k to 50k chars (~2.5×) meaningfully increases per-generation spend. The /generate route currently relies on the shared API-level rate limiter and doesn't have a per-route budget. That's a pre-existing condition — this PR doesn't make it worse in a novel way — but a future ticket for a newsletter-specific rate limit (or per-user budget) would be worth filing once you see real usage data at the new limits. Not blocking.

Test coverage

No automated tests existed for these numeric caps before this PR, so there's nothing regressed. A future test that asserts newsletter.controller.ts rejects a rawContent > 50k chars and accepts one at exactly 50k would be a nice guard — worth a follow-up, not a blocker here.

Style / consistency

The numeric separator (12_000, 50_000, 20_000) matches the existing convention in ai.constants.ts. The NEWSLETTER_AI_MAX_TOKENS name follows the existing AI_REQUEST_CONFIG naming pattern. Comment quality is high — the inline rationale in both files explains the why clearly.

Documentation

The constant comment correctly cross-references the JSON schema cap and the shared agenda cap. The PR description's test plan covers the three meaningful scenarios. No doc gaps found.


AI comment reconciliation

CodeRabbit — zero actionable comments. Agreed: nothing to add from their pass.

Copilot — reviewed both files, zero comments. Agreed.

My independent pass adds one additional observation (cost/rate-limit nit above) that neither bot surfaced, but it's pre-existing context rather than a fault in this change.


Revision tracking

First review on this PR — d88b8040 is the only commit. No prior review rounds to track.


Summary

Hey Nirav! Clean, surgical change — you isolated the newsletter output cap from the shared agenda cap, verified the model's actual token ceiling, and matched the comment arithmetic to the schema constraints. The server-side validation symmetry with the Angular form validators is exactly right.

Blocking issues: 0 | Minor issues: 0 | Nits: 1 (cost/rate-limit awareness on the increased ceilings — pre-existing, not introduced here).

Approved. No blockers or merge conflicts. The one nit is worth a follow-up ticket when you have usage data at the new limits, but it doesn't need to hold this PR.

@dealako dealako merged commit d2b2840 into main May 28, 2026
11 checks passed
@dealako dealako deleted the feat/newsletter-ai-limits branch May 28, 2026 17:45
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.

3 participants