Repository navigation
Show session peak context, and keep a Thinking pair's tokens out of the next row #439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b693021
6f06a59
2135385
d99bac2
b37cb3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ | |
| get_project_display_name, | ||
| is_agent_session, | ||
| parse_date_bounds, | ||
| turn_context_tokens, | ||
| relative_href, | ||
| resident_bytes, | ||
| resident_transcript_bytes, | ||
|
|
@@ -2594,10 +2595,43 @@ def compute_session_data( | |
| cache.total_cache_read_tokens += ( | ||
| getattr(usage, "cache_read_input_tokens", 0) or 0 | ||
| ) | ||
| if not getattr(message, "isSidechain", False): | ||
| context = turn_context_tokens(usage) | ||
| if context > (cache.peak_context_tokens or 0): | ||
| cache.peak_context_tokens = context | ||
|
|
||
| return result | ||
|
|
||
|
|
||
| def session_token_fields(data: Optional[SessionCacheData]) -> Dict[str, Any]: | ||
| """A session's token figures for an index or nav row. | ||
|
|
||
| The minimal theme's meta lines read these (peak · new · out); the | ||
| classic theme reads none of them. | ||
| """ | ||
| if data is None: | ||
| return {} | ||
| return { | ||
| "total_input_tokens": data.total_input_tokens, | ||
| "total_output_tokens": data.total_output_tokens, | ||
| "total_cache_creation_tokens": data.total_cache_creation_tokens, | ||
| "peak_context_tokens": data.peak_context_tokens, | ||
| } | ||
|
|
||
|
|
||
| def _provider_session_token_fields( | ||
| totals: "Optional[ProviderTokenTotals]", | ||
| ) -> Dict[str, Any]: | ||
| """``session_token_fields`` for a provider that reports only cumulative | ||
| session totals (Codex): the same keys, the peak unknown.""" | ||
| return { | ||
| "total_input_tokens": totals.input_tokens if totals else 0, | ||
| "total_output_tokens": totals.output_tokens if totals else 0, | ||
| "total_cache_creation_tokens": 0, | ||
| "peak_context_tokens": None, | ||
| } | ||
|
|
||
|
|
||
| def compute_session_residuals(messages: List[TranscriptEntry]) -> Dict[str, int]: | ||
| """Per-session count of traversed entries ``compute_session_data`` skips. | ||
|
|
||
|
|
@@ -2741,6 +2775,7 @@ def _plan_page( | |
| total_output_tokens = 0 | ||
| total_cache_creation_tokens = 0 | ||
| total_cache_read_tokens = 0 | ||
| peak_context_tokens: Optional[int] = None | ||
| # The cached count must be the sessions-table sum, because | ||
| # is_page_stale() compares it against SUM(sessions.message_count) | ||
| # on the next run. len(page_messages) counts what's rendered | ||
|
|
@@ -2766,6 +2801,10 @@ def _plan_page( | |
| total_output_tokens += s.total_output_tokens | ||
| total_cache_creation_tokens += s.total_cache_creation_tokens | ||
| total_cache_read_tokens += s.total_cache_read_tokens | ||
| if s.peak_context_tokens is not None: | ||
| peak_context_tokens = max( | ||
| peak_context_tokens or 0, s.peak_context_tokens | ||
| ) | ||
|
|
||
| # Build page_info for navigation | ||
| has_prev = page_num > 1 | ||
|
|
@@ -2796,7 +2835,7 @@ def _plan_page( | |
| if total_output_tokens: | ||
| token_parts.append(f"Output: {total_output_tokens:,}") | ||
| if total_cache_creation_tokens: | ||
| token_parts.append(f"Cache Create: {total_cache_creation_tokens:,}") | ||
| token_parts.append(f"Cache Creation: {total_cache_creation_tokens:,}") | ||
| if total_cache_read_tokens: | ||
| token_parts.append(f"Cache Read: {total_cache_read_tokens:,}") | ||
| token_summary = " | ".join(token_parts) if token_parts else None | ||
|
|
@@ -2805,6 +2844,12 @@ def _plan_page( | |
| "message_count": page_message_count, | ||
| "date_range": date_range, | ||
| "token_summary": token_summary, | ||
| # The figures behind ``token_summary``, for the minimal theme's | ||
| # header (peak · new · out); the peak is the page's largest. | ||
| "total_input_tokens": total_input_tokens, | ||
| "total_output_tokens": total_output_tokens, | ||
| "total_cache_creation_tokens": total_cache_creation_tokens, | ||
| "peak_context_tokens": peak_context_tokens, | ||
| } | ||
|
|
||
| page_title = f"{title} - Page {page_num}" if page_num > 1 else title | ||
|
|
@@ -5240,6 +5285,7 @@ def _collect_project_sessions(messages: list[TranscriptEntry]) -> list[dict[str, | |
| "first_user_message": data.first_user_message | ||
| if data.first_user_message | ||
| else "[No user message found in session.]", | ||
| **session_token_fields(data), | ||
| } | ||
| ) | ||
|
|
||
|
|
@@ -5392,6 +5438,8 @@ def _project_window_view( | |
| "message_count": part.message_count if part else 0, | ||
| "first_user_message": row.first_user_message, | ||
| "team_name": row.team_name, | ||
| # The window's own figures, like its message count. | ||
| **session_token_fields(part), | ||
| } | ||
| ) | ||
| sessions.sort(key=lambda s: (s["first_timestamp"] or "", s["id"])) | ||
|
|
@@ -6406,12 +6454,12 @@ def render_provider_wholesale( | |
| "first_user_message": first_user | ||
| or "[No user message found in session.]", | ||
| "file": f"{rel_dest}/session-{session_key}{suffix}.{ext}", | ||
| # NOTE: no per-session token_summary key here — the Claude | ||
| # index project-card session list carries none either, and | ||
| # the drift pin (test_index_summary_dict_shape_matches_claude_path) | ||
| # locks the two session-dict shapes together. Per-session | ||
| # cumulative totals are stored on the session cache instead | ||
| # (durability); the project card shows the rolled-up total. | ||
| # The same token keys as the Claude path's session rows | ||
| # (``session_token_fields``) — the drift pin | ||
| # (test_index_summary_dict_shape_matches_claude_path) | ||
| # locks the two shapes together. From the cumulative | ||
| # session totals; no peak, which needs per-turn usage. | ||
| **_provider_session_token_fields(session_totals.get(session_key)), | ||
| } | ||
| ) | ||
|
|
||
|
|
@@ -7893,6 +7941,7 @@ def _convert_plan_inline( | |
| "message_count": session_data.message_count, | ||
| "first_user_message": session_data.first_user_message | ||
| or "[No user message found in session.]", | ||
| **session_token_fields(session_data), | ||
| # Per-session link relative to the index | ||
| # root. Used by the index renderer when | ||
| # `combined_suppressed` is True so the | ||
|
|
@@ -8124,6 +8173,7 @@ def _convert_plan_inline( | |
| "message_count": session_data.message_count, | ||
| "first_user_message": session_data.first_user_message | ||
| or "[No user message found in session.]", | ||
| **session_token_fields(session_data), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test gap: three of the four index builders aren't tested for the token fields. The cached, archived, fallback ( Suggested fix: an end-to-end
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 6f06a59. |
||
| # `{variant}` keeps the link in step with | ||
| # `_generate_individual_session_files`'s | ||
| # filename (`session-{id}{variant}.{ext}`). | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: stale comment.
It says
Nonecovers "a row written before the migration, an archived session whose source is gone". Since6f06a598the migration fills both frommessages, soNonenow means only a Codex session or a session with no usage, asapplication_model.mdalready says.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 2135385: the comment now says the migration fills the column for every cached session, and that
Nonemeans a session with no usage or a Codex session.