Skip to content

Fix AI Eval Log Entries crash on Input/Output display (AB#621544)#8506

Open
Groenbech96 wants to merge 2 commits into
mainfrom
private/magnushar/fix-aitlog-blob-text-621544
Open

Fix AI Eval Log Entries crash on Input/Output display (AB#621544)#8506
Groenbech96 wants to merge 2 commits into
mainfrom
private/magnushar/fix-aitlog-blob-text-621544

Conversation

@Groenbech96
Copy link
Copy Markdown
Contributor

@Groenbech96 Groenbech96 commented Jun 5, 2026

What & why

The AI Eval Log Entries page crashes when the user clicks Input or Output to view the captured content for an entry. The crash happens before any content is displayed, so test results cannot be inspected from the page.

Root cause

SetInputBlob / GetInputBlob and SetOutputBlob / GetOutputBlob in AITLogEntry.Table.al use the binary OutStream.Write(Text) / InStream.Read(var Text) overloads on the BLOB stream.

  • OutStream.Write(Text) prepends length metadata to the stream (and ends with a 0 byte for the text overload).
  • InStream.Read(var Text) reads until a 0 byte or the requested length; when the requested and available lengths differ it raises a runtime error.

When the AI Test Data Compare page calls GetInputBlob / GetOutputBlob to display the saved content, the mismatched read length raises that error and the page fails to open.

Fix

Switch the four affected calls in AITLogEntry.Table.al from Write / Read to WriteText / ReadText, matching the pattern already used by the sibling GetMessage / GetErrorCallStack procedures in the same table.

- OutStream.Write(NewInput);
+ OutStream.WriteText(NewInput);
- InStream.Read(InputContent);
+ InStream.ReadText(InputContent);
- OutStream.Write(NewOutput);
+ OutStream.WriteText(NewOutput);
- InStream.Read(OutputContent);
+ InStream.ReadText(OutputContent);

Linked work

Fixes AB#621544

How I validated this

  • I read the full diff and it contains only changes I intended.
  • I built the affected app(s) locally with no new analyzer warnings.
  • I ran the change in Business Central and confirmed it behaves as expected.
  • I added or updated tests for the new behavior, or explained below why none are needed.

What I tested and the outcome

Added a new test project AI Test Toolkit Tests (build/projects/AI Test Toolkit Tests/) following the same shape as Performance Toolkit Tests, with a new app src/Tools/AI Test Toolkit/Test/. The app contains codeunit 149060 "AIT Log Entry Blob Test" with seven tests for the Input/Output BLOB roundtrip:

  • InputBlobRoundtripSimpleText
  • OutputBlobRoundtripSimpleText
  • InputBlobRoundtripEmptyText
  • InputBlobRoundtripMultilineText
  • InputBlobRoundtripUnicodeText
  • InputBlobRoundtripJsonPayload (mirrors the AI Test Data Compare payload shape that triggers the page crash)
  • InputBlobRoundtripLargeText

Each test persists the record via Insert(false) and reloads it via Get(), so the CalcFields-based read path used by the page is exercised — not just an in-memory roundtrip.

I do not have a BC container available in this environment to execute the AL tests, so I am relying on CI to run them. They have been written so they fail against the previous binary Write/Read code and pass against the WriteText/ReadText fix.

Risk & compatibility

  • Behavior-only fix to two pairs of accessors on a tooling-only table (AIT Log Entry, 149034) inside the AI Test Toolkit. No schema change and no public API change.
  • Existing rows in the BLOB fields persisted by the previous binary Write code will still contain the leading length bytes. Reading them with ReadText returns the text including those leading bytes, which is what the page already mishandled — so no new data corruption, and any new entry written after this fix is read back cleanly. If preserving access to legacy rows is needed, a follow-up data-fix can be considered, but it is out of scope here.
  • Adds a new test app and test project. No impact on shipped apps.

@Groenbech96 Groenbech96 requested review from a team as code owners June 5, 2026 11:09
@github-actions github-actions Bot added Build: scripts & configs Build scripts and configuration files AL: Tools labels Jun 5, 2026
@github-actions github-actions Bot added this to the Version 29.0 milestone Jun 5, 2026
Comment thread src/Tools/AI Test Toolkit/Test/src/AITLogEntryBlobTest.Codeunit.al Outdated
Comment thread src/Tools/AI Test Toolkit/Test/app.json
The AI Eval Log Entries page crashes when the user clicks Input or Output to
view the captured content.

Root cause: SetInputBlob/GetInputBlob and SetOutputBlob/GetOutputBlob in
AITLogEntry.Table.al use binary Write()/Read() on the BLOB OutStream/InStream.
Binary Write(Text) prepends length metadata; Read(var Text) then reads until a
0 byte and errors when the requested length and available length differ. Calling
GetXxxBlob() from the AI Test Data Compare page therefore raises a runtime
error and the page fails to open.

Fix: switch the four affected calls to WriteText/ReadText, matching the pattern
already used by the sibling GetMessage/GetErrorCallStack procedures in the same
table.

Tests: add codeunit "AIT Log Entry Blob Test" (149060) with seven roundtrip
tests for SetXxxBlob/GetXxxBlob. Each test persists the record via Insert(false)
and reloads it via Get() so the CalcFields-based read path used by the page is
exercised. The tests fail against the binary Write/Read code and pass against
the WriteText/ReadText fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Groenbech96 Groenbech96 force-pushed the private/magnushar/fix-aitlog-blob-text-621544 branch from d47fffe to 8d05fd2 Compare June 5, 2026 12:54
Comment thread build/projects/AI Test Toolkit Tests/.AL-Go/settings.json
Comment thread src/Tools/AI Test Toolkit/src/Logs/AITLogEntry.Table.al
Comment thread src/Tools/AI Test Toolkit/src/Logs/AITLogEntry.Table.al
Avoids O(n^2) string concatenation flagged in PR review.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Groenbech96
Copy link
Copy Markdown
Contributor Author

Thanks for the review. Triage:

  1. Quadratic string concat in InputBlobRoundtripLargeText — adopted. Rewrote with TextBuilder + ToText() in d479b70.

  2. Test app target: "OnPrem" vs parent's Cloud — keeping as-is. This matches the established convention for sibling test apps in this repo (e.g. src/Tools/Performance Toolkit/App/app.json is Cloud while src/Tools/Performance Toolkit/Test/app.json is OnPrem). The same holds for System Application Tests and Business Foundation Tests. Test apps in BCApps are designed to run in CI containers, not SaaS sandboxes.

  3. installOnlyReferencedApps: false — keeping as-is. Same value used by every other test project's settings.json in this repo (Performance Toolkit Tests, System Application Tests, Business Foundation Tests, Test Stability Tools). Switching just this one project would deviate from the repo pattern; if true is desired it should be a separate, repo-wide change.

  4. Write→WriteText breaks pre-existing rows / 5. ReadText truncation on existing data — not in scope. AIT Log Entry (149034) is the AI eval log table populated each time a test suite runs in the AI Test Toolkit; it holds transient run history, not persistent user data. Pre-existing rows are already unreadable via the page (that is the bug). Adding an upgrade codeunit to migrate transient log rows would add risk and code without unblocking any user — the natural action is to rerun the suite, which writes new rows that read back cleanly. Also, the comment 5 claim that InStream.ReadText reads only "until the first newline" is not accurate: with no length parameter it reads the remaining stream content as text, which is exactly the behavior the new multiline test covers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AL: Tools Build: scripts & configs Build scripts and configuration files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant