.NET: Fix render dupe and text input clear bugs, and improve guardrail error messaging#6136
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the .NET Harness console UI rendering logic to better handle terminal wrapping and bottom-panel mode switches.
Changes:
- Adds ANSI-aware visible string length measurement.
- Updates queued/scroll text height calculations to account for wrapping.
- Forces bottom-panel repaint when switching modes to avoid stale content.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
dotnet/samples/02-agents/Harness/ConsoleReactiveComponents/AnsiEscapes.cs |
Adds visible-length calculation for ANSI-styled strings. |
dotnet/samples/02-agents/Harness/ConsoleReactiveComponents/TextPanel.cs |
Updates queued panel height/rendering to account for wrapped physical rows. |
dotnet/samples/02-agents/Harness/ConsoleReactiveComponents/TextScrollPanel.cs |
Updates scroll-panel last-item offset calculation for wrapped rows. |
dotnet/samples/02-agents/Harness/Harness_Shared_Console/HarnessAppComponent.cs |
Passes console width into queued-panel measurement and invalidates bottom child on mode changes. |
Comments suppressed due to low confidence (1)
dotnet/samples/02-agents/Harness/ConsoleReactiveComponents/TextPanel.cs:58
- This loop compares the global
currentRowagainst the current item'slineCount, so after rendering a one-line itemcurrentRowis already 1 and subsequent one-line items are skipped entirely. It also advances only one row for a logical line that may wrap. Track rows rendered for the current item separately and advancecurrentRowby the physical rows occupied by each logical line/item.
for (int j = 0; j < lines.Length && currentRow < lineCount; j++)
{
Console.Write(AnsiEscapes.MoveAndEraseLine(props.Y + currentRow));
Console.Write(lines[j]);
currentRow++;
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
dotnet/samples/02-agents/Harness/ConsoleReactiveComponents/TextPanel.cs:58
lineCountnow includes wrapped terminal rows, butcurrentRowis still incremented only once per logical line. For a long line that wraps, the leftover-line cleanup starts too early and erases the wrapped continuation rows (and later items can be positioned over them); advancecurrentRowby the physical row count for each logical line instead.
int lineCount = CountPhysicalLines(text, props.Width);
for (int j = 0; j < lines.Length && currentRow < lineCount; j++)
{
Console.Write(AnsiEscapes.MoveAndEraseLine(props.Y + currentRow));
Console.Write(lines[j]);
currentRow++;
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 88%
✓ Correctness
The PR correctly addresses the stated bugs: line wrapping is now accounted for in physical line counting (using overflow-safe ceiling division), the bottom panel invalidation on mode change ensures proper repaint, and the shared static render lock prevents ANSI interleaving. The previously raised overflow and duplication concerns are properly resolved. No new correctness issues found.
✓ Security Reliability
The PR is sound from a security/reliability perspective. The shared static render lock uses C#'s rentrant Monitor, so nested acquisitions within RenderCore (e.g., calling child.Invalidate()) are safe on the same thread. The GetContentFilterDetails method properly disposes JsonDocument via 'using' and wraps all parsing in a catch-all since it's non-critical diagnostic output. The PlanningOutputObserver fallback gracefully renders unparseable responses as text rather than failing. The CountPhysicalLines math is overflow-safe with the ceiling-division formula for positive terminal widths.
✓ Test Coverage
This PR modifies console rendering logic in a sample/harness application that has no existing test infrastructure. The new
AnsiEscapes.VisibleLengthandAnsiEscapes.CountPhysicalLinesutility methods are pure functions with well-defined inputs/outputs that are highly testable and now serve as shared logic for correct rendering across multiple components. While this is sample code, these helpers are algorithmic in nature and could benefit from unit tests — especially given the prior review thread identifying edge cases (overflow, zero-width, emoji). The rendering, observer, and framework changes involve Console I/O and are harder to unit test without mocking infrastructure.
✗ Design Approach
The wrapped-height changes are headed in the right direction, but
TextPanelstill does not repaint wrapped content the same way it measures it. In the new render loop, wrapped logical lines advancecurrentRowby multiple rows without clearing those continuation rows first, so a rerender where content shrinks can still leave stale text on screen.
Flagged Issues
-
TextPanel.cs:59only erases the first physical row of a logical line even whenlinePhysicalRows > 1, so rerendering shorter wrapped content leaves stale continuation rows behind.
Automated review by westey-m's agents
Motivation and Context
Description
Contribution Checklist