Skip to content

Fix garbled PF_ConsoleLogs.txt when collecting Linux container logs#208

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-console-logs-formatting
Draft

Fix garbled PF_ConsoleLogs.txt when collecting Linux container logs#208
Copilot wants to merge 2 commits intomainfrom
copilot/fix-console-logs-formatting

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 30, 2026

Docker's GetContainerLogsAsync returns a multiplexed stream with 8-byte binary headers per frame (stream type, padding, big-endian uint32 payload size). The existing code reads this raw stream with StreamReader.ReadLine(), so those binary headers appear as �������� garbage in the log file.

Changes

  • DockerContainerEngine.CollectLogs: Replace StreamReader.ReadLine() with DemuxDockerStream, which parses the Docker multiplexed stream frame-by-frame, stripping headers and writing only UTF-8 payload content
  • DockerContainerEngine.DemuxDockerStream (new, internal static): Reads 8-byte header → extracts payload size → reads payload → invokes write callback. Loops until stream is exhausted.
  • DockerContainerEngine.ReadExactAsync (new, private static): Ensures exact byte counts are read from the stream, handling partial reads.
  • Unit tests: 4 tests covering single frame, multiple frames (stdout+stderr), empty stream, and zero-length payload frames.

Docker multiplexed stream format

┌──────────┬───────────┬────────────────┬─────────────────────┐
│ byte 0   │ bytes 1-3 │ bytes 4-7      │ N bytes             │
│ stream   │ padding   │ payload size   │ payload             │
│ (1=out,  │ (zeros)   │ (big-endian    │ (actual log text)   │
│  2=err)  │           │  uint32 = N)   │                     │
└──────────┴───────────┴────────────────┴─────────────────────┘

Also removed an unused StringBuilder allocation in the same code path.

…rbage characters in PF_ConsoleLogs.txt

The Docker API returns a multiplexed stream with 8-byte binary headers per frame
when the container is not running with TTY. The previous code read this stream
using StreamReader.ReadLine(), which treated the binary headers as text, producing
garbled characters (e.g., ��������) in the log file.

Added DemuxDockerStream method that properly parses the Docker multiplexed stream
format by reading and stripping the 8-byte headers (stream type + padding + payload
size) before extracting the UTF-8 payload content.

Agent-Logs-Url: https://github.com/PlayFab/MpsAgent/sessions/3632fce0-9338-4fa3-a907-6ada665fc04c

Co-authored-by: dgkanatsios <8256138+dgkanatsios@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix formatting of PF_ConsoleLogs.txt for linux containers Fix garbled PF_ConsoleLogs.txt when collecting Linux container logs Mar 30, 2026
Copilot AI requested a review from dgkanatsios March 30, 2026 20:45
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.

Bad PF_ConsoleLogs.txt when running linux containers

2 participants