Repository navigation
fix: count only visible messages toward the session tail budget - #810
Merged
Merged
Conversation
The tail window was counted in raw entries, so toolResult and other non-rendering entries consumed the budget. In agent-heavy sessions the window starved user messages out of the chat: a real session with 15 user messages across 562 entries loaded exactly ONE user message; every earlier question needed manual "load earlier" paging. - countsTowardTail(): user / assistant messages plus the compaction divider consume the budget; toolResult and hidden custom entries ride along inside the span - regression test for the pagination path
cy7372
force-pushed
the
fix/session-tail-visible-messages
branch
from
September 13, 2026 01:25
9983363 to
a72e763
Compare
SameSite=Strict drops the session cookie on external top-level navigations (common on mobile), forcing a re-login while in-page XHR still works. Fixes agegr#806
Patches GHSA-2xp9-vwfh-vxw4 / GHSA-p293-qw3h-jr36 (unauthenticated RCE in [email protected]) and pulls sharp 0.35.4 for the libheif advisories via npm audit fix. next/image is only used for the static logo, so the /_next/image endpoint is turned off entirely with images.unoptimized. Co-authored-by: Cursor <[email protected]>
scrollIntoView({ block: "nearest" }) parked the keyboard-selected option flush
against the scroll container, where whole-pixel scroll snapping left it a
fraction of a pixel outside the viewport and overflow clipping cut off its
focus ring. Give options a scroll-margin equal to the container padding so
navigation always lands them fully visible; this also unblocks the e2e
"Keyboard selection must scroll into view" assertion.
Co-authored-by: Cursor <[email protected]>
Route handlers have no reliable client address, so a per-IP limiter would be spoofable via x-forwarded-for and empty for direct 127.0.0.1 access. Use one shared exponential backoff (1s doubling to 60s) for POST /api/web-auth instead; a success or five idle minutes resets it. Return 429 with Retry-After while blocked and surface the wait on the login page. Co-authored-by: Cursor <[email protected]>
…comment Co-authored-by: Cursor <[email protected]>
agegr
approved these changes
Sep 16, 2026
agegr
left a comment
Owner
There was a problem hiding this comment.
Confirmed: with tail counted in raw entries, a tool-heavy session (user → assistant+toolCall → toolResult → assistant, ×N) fits roughly one user turn into the default 50-entry page. Counting user/assistant messages plus the compaction divider is the right unit, and hasMore keeps paging working.
I merged main and pushed two adjustments:
- Raw cap lowered from
max(1500, tail·30)tomax(200, tail·6). Tool results can be large, and 1500 raw entries per page (45 000 attail=1000) undoes the payload bound this slice exists for. With a 1:1 assistant:toolResult ratiotail·6is still 3× headroom, and the search path (tail: 200) gets 1200. Added a test for the cap. - Restored the
sliceActiveBranchJSDoc (the new helper's comment had been inserted between the doc block and the function) and dropped the dated anecdote from the comment.
tsc, eslint, and lib/session-reader* + app/api/sessions/** tests pass. Approving.
agegr
added a commit
that referenced
this pull request
Sep 19, 2026
Co-authored-by: Cursor <[email protected]> #810 stopped counting toolResults toward the default page, so the old 24-turn compacted session no longer pushed the user prompt off the first page.
lclichen
pushed a commit
to lclichen/pi-web
that referenced
this pull request
Sep 22, 2026
…r#810) * fix: count only visible messages toward the session tail budget The tail window was counted in raw entries, so toolResult and other non-rendering entries consumed the budget. In agent-heavy sessions the window starved user messages out of the chat: a real session with 15 user messages across 562 entries loaded exactly ONE user message; every earlier question needed manual "load earlier" paging. - countsTowardTail(): user / assistant messages plus the compaction divider consume the budget; toolResult and hidden custom entries ride along inside the span - regression test for the pagination path * Align new session branding with chat input * fix: preserve UNC roots in file API paths * fix(auth): use SameSite=Lax for pi_web_session cookie (agegr#818) SameSite=Strict drops the session cookie on external top-level navigations (common on mobile), forcing a re-login while in-page XHR still works. Fixes agegr#806 * fix: preserve newlines in extension dialog titles like pi's TUI * fix(deps): upgrade Next.js to 16.3.5 and disable image optimizer Patches GHSA-2xp9-vwfh-vxw4 / GHSA-p293-qw3h-jr36 (unauthenticated RCE in [email protected]) and pulls sharp 0.35.4 for the libheif advisories via npm audit fix. next/image is only used for the static logo, so the /_next/image endpoint is turned off entirely with images.unoptimized. Co-authored-by: Cursor <[email protected]> * fix: keep focused extension select option clear of the scroller edge scrollIntoView({ block: "nearest" }) parked the keyboard-selected option flush against the scroll container, where whole-pixel scroll snapping left it a fraction of a pixel outside the viewport and overflow clipping cut off its focus ring. Give options a scroll-margin equal to the container padding so navigation always lands them fully visible; this also unblocks the e2e "Keyboard selection must scroll into view" assertion. Co-authored-by: Cursor <[email protected]> * fix(auth): throttle web password failures with global backoff Route handlers have no reliable client address, so a per-IP limiter would be spoofable via x-forwarded-for and empty for direct 127.0.0.1 access. Use one shared exponential backoff (1s doubling to 60s) for POST /api/web-auth instead; a success or five idle minutes resets it. Return 429 with Retry-After while blocked and surface the wait on the login page. Co-authored-by: Cursor <[email protected]> * Tighten the raw-entry page cap and restore the sliceActiveBranch doc comment Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Alex Yang <[email protected]> Co-authored-by: richardmilles <[email protected]> Co-authored-by: Cursor <[email protected]> (cherry picked from commit 50a2fd4)
lclichen
pushed a commit
to lclichen/pi-web
that referenced
this pull request
Sep 22, 2026
Co-authored-by: Cursor <[email protected]> agegr#810 stopped counting toolResults toward the default page, so the old 24-turn compacted session no longer pushed the user prompt off the first page. (cherry picked from commit eac6f14)
HeRockOne
pushed a commit
to HeRockOne/pi-web
that referenced
this pull request
Sep 30, 2026
…r#810) * fix: count only visible messages toward the session tail budget The tail window was counted in raw entries, so toolResult and other non-rendering entries consumed the budget. In agent-heavy sessions the window starved user messages out of the chat: a real session with 15 user messages across 562 entries loaded exactly ONE user message; every earlier question needed manual "load earlier" paging. - countsTowardTail(): user / assistant messages plus the compaction divider consume the budget; toolResult and hidden custom entries ride along inside the span - regression test for the pagination path * Align new session branding with chat input * fix: preserve UNC roots in file API paths * fix(auth): use SameSite=Lax for pi_web_session cookie (agegr#818) SameSite=Strict drops the session cookie on external top-level navigations (common on mobile), forcing a re-login while in-page XHR still works. Fixes agegr#806 * fix: preserve newlines in extension dialog titles like pi's TUI * fix(deps): upgrade Next.js to 16.3.5 and disable image optimizer Patches GHSA-2xp9-vwfh-vxw4 / GHSA-p293-qw3h-jr36 (unauthenticated RCE in [email protected]) and pulls sharp 0.35.4 for the libheif advisories via npm audit fix. next/image is only used for the static logo, so the /_next/image endpoint is turned off entirely with images.unoptimized. Co-authored-by: Cursor <[email protected]> * fix: keep focused extension select option clear of the scroller edge scrollIntoView({ block: "nearest" }) parked the keyboard-selected option flush against the scroll container, where whole-pixel scroll snapping left it a fraction of a pixel outside the viewport and overflow clipping cut off its focus ring. Give options a scroll-margin equal to the container padding so navigation always lands them fully visible; this also unblocks the e2e "Keyboard selection must scroll into view" assertion. Co-authored-by: Cursor <[email protected]> * fix(auth): throttle web password failures with global backoff Route handlers have no reliable client address, so a per-IP limiter would be spoofable via x-forwarded-for and empty for direct 127.0.0.1 access. Use one shared exponential backoff (1s doubling to 60s) for POST /api/web-auth instead; a success or five idle minutes resets it. Return 429 with Retry-After while blocked and surface the wait on the login page. Co-authored-by: Cursor <[email protected]> * Tighten the raw-entry page cap and restore the sliceActiveBranch doc comment Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Alex Yang <[email protected]> Co-authored-by: richardmilles <[email protected]> Co-authored-by: Cursor <[email protected]>
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 6, 2026
…r#810) * fix: count only visible messages toward the session tail budget The tail window was counted in raw entries, so toolResult and other non-rendering entries consumed the budget. In agent-heavy sessions the window starved user messages out of the chat: a real session with 15 user messages across 562 entries loaded exactly ONE user message; every earlier question needed manual "load earlier" paging. - countsTowardTail(): user / assistant messages plus the compaction divider consume the budget; toolResult and hidden custom entries ride along inside the span - regression test for the pagination path * Align new session branding with chat input * fix: preserve UNC roots in file API paths * fix(auth): use SameSite=Lax for pi_web_session cookie (agegr#818) SameSite=Strict drops the session cookie on external top-level navigations (common on mobile), forcing a re-login while in-page XHR still works. Fixes agegr#806 * fix: preserve newlines in extension dialog titles like pi's TUI * fix(deps): upgrade Next.js to 16.3.5 and disable image optimizer Patches GHSA-2xp9-vwfh-vxw4 / GHSA-p293-qw3h-jr36 (unauthenticated RCE in [email protected]) and pulls sharp 0.35.4 for the libheif advisories via npm audit fix. next/image is only used for the static logo, so the /_next/image endpoint is turned off entirely with images.unoptimized. Co-authored-by: Cursor <[email protected]> * fix: keep focused extension select option clear of the scroller edge scrollIntoView({ block: "nearest" }) parked the keyboard-selected option flush against the scroll container, where whole-pixel scroll snapping left it a fraction of a pixel outside the viewport and overflow clipping cut off its focus ring. Give options a scroll-margin equal to the container padding so navigation always lands them fully visible; this also unblocks the e2e "Keyboard selection must scroll into view" assertion. Co-authored-by: Cursor <[email protected]> * fix(auth): throttle web password failures with global backoff Route handlers have no reliable client address, so a per-IP limiter would be spoofable via x-forwarded-for and empty for direct 127.0.0.1 access. Use one shared exponential backoff (1s doubling to 60s) for POST /api/web-auth instead; a success or five idle minutes resets it. Return 429 with Retry-After while blocked and surface the wait on the login page. Co-authored-by: Cursor <[email protected]> * Tighten the raw-entry page cap and restore the sliceActiveBranch doc comment Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Alex Yang <[email protected]> Co-authored-by: richardmilles <[email protected]> Co-authored-by: Cursor <[email protected]>
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 6, 2026
Co-authored-by: Cursor <[email protected]> agegr#810 stopped counting toolResults toward the default page, so the old 24-turn compacted session no longer pushed the user prompt off the first page.
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 8, 2026
…r#810) * fix: count only visible messages toward the session tail budget The tail window was counted in raw entries, so toolResult and other non-rendering entries consumed the budget. In agent-heavy sessions the window starved user messages out of the chat: a real session with 15 user messages across 562 entries loaded exactly ONE user message; every earlier question needed manual "load earlier" paging. - countsTowardTail(): user / assistant messages plus the compaction divider consume the budget; toolResult and hidden custom entries ride along inside the span - regression test for the pagination path * Align new session branding with chat input * fix: preserve UNC roots in file API paths * fix(auth): use SameSite=Lax for pi_web_session cookie (agegr#818) SameSite=Strict drops the session cookie on external top-level navigations (common on mobile), forcing a re-login while in-page XHR still works. Fixes agegr#806 * fix: preserve newlines in extension dialog titles like pi's TUI * fix(deps): upgrade Next.js to 16.3.5 and disable image optimizer Patches GHSA-2xp9-vwfh-vxw4 / GHSA-p293-qw3h-jr36 (unauthenticated RCE in [email protected]) and pulls sharp 0.35.4 for the libheif advisories via npm audit fix. next/image is only used for the static logo, so the /_next/image endpoint is turned off entirely with images.unoptimized. Co-authored-by: Cursor <[email protected]> * fix: keep focused extension select option clear of the scroller edge scrollIntoView({ block: "nearest" }) parked the keyboard-selected option flush against the scroll container, where whole-pixel scroll snapping left it a fraction of a pixel outside the viewport and overflow clipping cut off its focus ring. Give options a scroll-margin equal to the container padding so navigation always lands them fully visible; this also unblocks the e2e "Keyboard selection must scroll into view" assertion. Co-authored-by: Cursor <[email protected]> * fix(auth): throttle web password failures with global backoff Route handlers have no reliable client address, so a per-IP limiter would be spoofable via x-forwarded-for and empty for direct 127.0.0.1 access. Use one shared exponential backoff (1s doubling to 60s) for POST /api/web-auth instead; a success or five idle minutes resets it. Return 429 with Retry-After while blocked and surface the wait on the login page. Co-authored-by: Cursor <[email protected]> * Tighten the raw-entry page cap and restore the sliceActiveBranch doc comment Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Alex Yang <[email protected]> Co-authored-by: richardmilles <[email protected]> Co-authored-by: Cursor <[email protected]>
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 8, 2026
Co-authored-by: Cursor <[email protected]> agegr#810 stopped counting toolResults toward the default page, so the old 24-turn compacted session no longer pushed the user prompt off the first page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The session tail window was counted in raw entries, so toolResult and other non-rendering entries consumed the budget. In agent-heavy sessions the window starved user messages out of the chat: a real session with 15 user messages across 562 entries loaded exactly one user message; every earlier question needed manual "load earlier" paging.
Fix
countsTowardTail(): only user / assistant messages plus the compaction divider consume the tail budget; toolResult entries, hidden custom messages and session meta ride along inside the span without consuming it. Older history still loads on demand via pagination.Includes a regression test for the pagination path.