Skip to content

Render WSRF in step-summary token usage with progressive disclosure - #54591

Merged
pelikhan merged 2 commits into
mainfrom
copilot/add-javascript-wsrf-value
Aug 21, 2026
Merged

Render WSRF in step-summary token usage with progressive disclosure#54591
pelikhan merged 2 commits into
mainfrom
copilot/add-javascript-wsrf-value

Conversation

Copilot AI commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

This updates step-summary reporting to surface Working-Set Rebuild Factor (WSRF) directly in the existing token-usage section. WSRF is now visible at a glance, with detailed metric breakdown collapsed behind <details>/<summary>.

  • Summary UI integration

    • Extended parse_token_usage.cjs step-summary composition to include WSRF in the same token-usage block (no separate report path).
    • Preserved existing token table output and placement.
  • Progressive disclosure for WSRF

    • Added a nested details block that renders:
      • measurement state (measured / partial / unavailable)
      • rebuild factor (formatted as N.NN× when present)
      • cumulative input tokens
      • peak invocation input tokens
      • rebuild excess tokens
      • invocation count
  • Computation wiring

    • Reused existing working-set metric calculation (calculateWorkingSetFromJSONL) and fed its output into the step-summary renderer, keeping WSRF semantics aligned with existing usage-activity logic.
const workingSet = calculateWorkingSetFromJSONL(content).workingSet;
await appendStepSummarySection(getSummaryTitle(), markdown, workingSet);

// rendered inside summary:
<details>
  <summary>Working-Set Rebuild Factor (WSRF): 3.90× (measured)</summary>
  ...
</details>

Copilot AI and others added 2 commits August 21, 2026 18:33
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title Render WSRF in token usage step summary Render WSRF in step-summary token usage with progressive disclosure Aug 21, 2026
Copilot AI requested a review from pelikhan August 21, 2026 18:35
@pelikhan
pelikhan marked this pull request as ready for review August 21, 2026 18:38
Copilot AI balanced review requested due to automatic review settings August 21, 2026 18:38
@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel skipped because pre-fetch PR data was unavailable: unable to fetch test file diff

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #54591

@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR does not have the implementation label and has 0 new lines of code in business logic directories.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

reviewed_at: 2026-08-21T00:00:00Z
review_event: REQUEST_CHANGES
top_themes:
  - nested-details markdown rendering bug in step summary
files_reviewed:
  - actions/setup/js/parse_token_usage.cjs
  - actions/setup/js/parse_token_usage.test.cjs
comment_count: 1

Note

This comment is managed by comment memory.

It stores persistent context for this thread in the code block at the top of this comment.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 4.71 AIC · ⌖ 6.88 AIC · ⊞ 7K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Request changes

The new WSRF summary wiring introduces a markdown-structure bug in the step summary: it nests a <details> block inside the existing token-usage <details>, which GitHub does not render reliably.

Blocking theme
  • The progressive-disclosure UI is implemented with nested <details>, so the new summary can render malformed or lose its collapsed behavior depending on the GitHub surface.

🔎 Code quality review by PR Code Quality Reviewer · gpt54 · 4.71 AIC · ⌖ 6.88 AIC · ⊞ 7K
Comment /review to run again


return [
"<details>",
`<summary>Working-Set Rebuild Factor (WSRF): ${displayFactor} (${measurementState})</summary>`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This nests a <details> block inside another <details> block in the step summary, and GitHub’s markdown renderer does not handle nested disclosure widgets reliably, so the WSRF section can render as broken or permanently expanded instead of being progressively hidden.

💡 Why this blocks

The outer token-usage section is already a <details> element. buildWorkingSetDetailsSection() now injects a second <details> inside it, which is exactly the kind of nesting GitHub markdown tends to flatten or render inconsistently across summary surfaces. That means the new UX goal—“collapsed WSRF details inside collapsed token usage”—is not actually guaranteed, and in the worst case the summary becomes malformed.

Use a non-nested disclosure pattern here instead, e.g. keep the outer <details> and render the WSRF line plus bullets directly inside it, or split WSRF into a sibling section rather than a child <details>.

return [
  `**Working-Set Rebuild Factor (WSRF):** ${displayFactor} (${measurementState})`,
  "",
  `- State: \`${measurementState}\``,
  ...
].join("\n");

That preserves valid markdown structure and avoids renderer-dependent breakage.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The implementation is clean and correct. buildWorkingSetDetailsSection guards every numeric field with Number.isFinite, handles null/non-object input, and the new tests cover both the measured and unavailable states. No blocking issues found.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 28.2 AIC · ⌖ 8.76 AIC · ⊞ 5.7K

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ponytail review (over-engineering only): one small shrink opportunity noted inline (repeated formatting ternaries could be extracted into a helper). No other bloat found.

net: -3 lines possible.

Generated by ✂️ Ponytail Reviewer for #54591 · auto · 17.8 AIC · ⌖ 4.47 AIC · ⊞ 7.3K
Comment /ponytail to run again

Comments that could not be inline-anchored

actions/setup/js/parse_token_usage.cjs:19

shrink: four repeated Number.isFinite(x) ? x.toLocaleString() : &quot;0&quot; ternaries. Extract const fmt = n =&gt; Number.isFinite(n) ? n.toLocaleString() : &quot;0&quot;; and call it for each field, ~4 lines shorter.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Integrates WSRF metrics into the existing token-usage step summary using progressive disclosure.

Changes:

  • Computes WSRF from deduplicated token-usage records.
  • Renders measured and unavailable metric details.
  • Adds renderer and integration tests.
Show a summary per file
File Description
actions/setup/js/parse_token_usage.cjs Computes and renders WSRF in the step summary.
actions/setup/js/parse_token_usage.test.cjs Tests WSRF rendering and summary integration.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment on lines +137 to +138
"",
].join("\n");

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /tdd, /diagnosing-bugs, and /codebase-design — requesting changes on a correctness risk and minor test gaps.

📋 Key Themes & Highlights

Key Themes

  • Correctness risk: calculateWorkingSetFromJSONL is called outside the markdown.length > 0 guard; a throw there will silently abort the step-summary write. (See inline comment on line 202.)
  • Test coverage gaps: "partial" measurement state and null/undefined inputs for buildWorkingSetDetailsSection are unexercised by the new tests.
  • UI ordering: WSRF details are placed before the token table, reversing the information hierarchy implied by the PR description.

Positive Highlights

  • ✅ Clean extraction of buildWorkingSetDetailsSection — composable, independently testable, and null-safe.
  • Number.isFinite guards on all numeric fields prevent NaN/Infinity leaking into output.
  • toLocaleString() for token counts is a nice ergonomic touch.
  • ✅ Two meaningful unit tests (measured + unavailable) plus an integration assertion were added with the feature — good discipline.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 36.2 AIC · ⌖ 10.2 AIC · ⊞ 7.8K
Comment /matt to run again

@@ -168,9 +202,10 @@ async function main() {
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/diagnosing-bugs] calculateWorkingSetFromJSONL is called before the if (markdown.length > 0) guard — if it throws, the token-usage summary is silently lost.

💡 Suggested fix

Move the call inside the guard so a WSRF failure cannot suppress the token table:

const markdown = generateTokenUsageSummary(summary);
if (markdown.length > 0) {
  const workingSet = calculateWorkingSetFromJSONL(content).workingSet;
  core.info(renderTokenTableAsPlainText(getSummaryTitle(), markdown));
  await appendStepSummarySection(getSummaryTitle(), markdown, workingSet);
}

Alternatively, wrap the call in a try/catch and fall back to null so WSRF failures are non-fatal.

@copilot please address this.

});

test("renderTokenTableAsPlainText strips table separator lines and pipes", () => {
const markdown = ["| # | Alias | Input | Output |", "|--:|-------|------:|-------:|", "| 1 | sonnet46 | 100 | 200 |", "| **Total** | | **100** | **200** |", "", "Legend: `Alias` is the model shorthand.", ""].join("\n");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/tdd] The "partial" measurement state is mentioned in the PR body but has no dedicated test. Both buildWorkingSetDetailsSection tests cover "measured" and "unavailable"; a "partial" case would complete the contract.

💡 Suggested test
test("buildWorkingSetDetailsSection renders partial state", () => {
  const section = buildWorkingSetDetailsSection({
    measurement_state: "partial",
    rebuild_factor: 2.0,
    cumulative_input_tokens: 200000,
    peak_input_tokens: 100000,
    rebuild_excess_tokens: 100000,
    invocations: 2,
  });
  expect(section).toContain("Working-Set Rebuild Factor (WSRF): 2.00× (partial)");
  expect(section).toContain("- State: `partial`");
});

@copilot please address this.

@@ -549,6 +552,37 @@ describe("parse_token_usage", () => {
expect(section).toContain("Per-request AI credits and token totals");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/tdd] buildWorkingSetDetailsSection(null) and buildWorkingSetDetailsSection(undefined) are not explicitly tested — only the guard's early-return (return "") is implied. A test for falsy input would pin the contract.

💡 Suggested test
test("buildWorkingSetDetailsSection returns empty string for null or undefined", () => {
  expect(buildWorkingSetDetailsSection(null)).toBe("");
  expect(buildWorkingSetDetailsSection(undefined)).toBe("");
  expect(buildWorkingSetDetailsSection("string")).toBe("");
});

@copilot please address this.

function buildStepSummarySection(title, markdown) {
return `<details>\n<summary>${title}</summary>\n\nPer-request AI credits and token totals\n\n${markdown}</details>\n\n`;
function buildStepSummarySection(title, markdown, workingSet = null) {
const workingSetSection = buildWorkingSetDetailsSection(workingSet);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/codebase-design] The WSRF details block is rendered before the token table (${workingSetSection}${markdown}), but the PR description says "WSRF visible at a glance alongside the token table." Placing WSRF above the table inverts the information hierarchy — users land on WSRF first, then scroll to credits/totals.

Consider reversing the order (${markdown}${workingSetSection}) or adding a blank line between them to keep the token table as the primary surface.

@copilot please address this.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

  • Reviewer feedback is still blocking on this PR. Please address the newest unresolved review concern about the nested <details> step-summary rendering bug first.
  • After updating the branch, run the pr-finisher skill and leave a concise maintainer handoff with validation status and merge readiness.

Run: https://github.com/github/gh-aw/actions/runs/32515777962

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 6.29 AIC · ⌖ 8.15 AIC · ⊞ 6.9K ·
Comment /souschef to run again

@pelikhan
pelikhan merged commit ebca180 into main Aug 21, 2026
68 of 77 checks passed
@pelikhan
pelikhan deleted the copilot/add-javascript-wsrf-value branch August 21, 2026 19:04
Copilot stopped work on behalf of gh-aw-bot due to an error August 21, 2026 19:04
Copilot AI requested a review from gh-aw-bot August 21, 2026 19:04
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.87.4

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.

4 participants