Skip to content

.NET: [Bug]: Microsoft.Agents.AI.Tools.Shell.HeadTailBuffer can reorder and silently drop UTF-8 runes at the head/tail boundary #7112

Description

@Lightczx

Description

HeadTailBuffer may reorder UTF-8 characters and silently discard output when a multi-byte rune does not fit in the remaining head capacity.

The returned result can report Truncated == false even though data was removed.

This affects command output containing non-ASCII characters near the head/tail boundary.

Code Sample

HeadTailBuffer buffer = new(20);

buffer.AppendLine("aaaaaaa\U0001F600\U0001F600\U0001F600");

var (text, truncated) = buffer.ToFinalString();

The input, including the appended newline, is exactly 20 UTF-8 bytes:
aaaaaaa: 7 bytes
Three emoji runes: 12 bytes
Newline: 1 byte

Expect:
text == "aaaaaaa😀😀😀\n"
truncated == false

Actual:
text == "aaaaaaa\n😀😀"
truncated == false

The first emoji is silently discarded, and the newline is moved before the remaining emoji runes.

Package Versions

Microsoft.Agents.AI.Tools.Shell 1.12.0-preview.260629.1

.NET Version

.NET 10

Metadata

Metadata

Assignees

Labels

.NETUsage: [Issues, PRs], Target: .NetreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Fields

No fields configured for Bug.

Projects

Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions