Skip to content

fix(workflow): escape control characters in file-sink JSON - #640

Merged
0xShug0 merged 4 commits into
0xShug0:mainfrom
DivyamTalwar:fix/workflow-json-control-escaping-779
Sep 23, 2026
Merged

0xShug0 merged 4 commits into
0xShug0:mainfrom
DivyamTalwar:fix/workflow-json-control-escaping-779

Conversation

@DivyamTalwar

@DivyamTalwar DivyamTalwar commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #639.

Use the existing engine::io::json::stringify_string() helper for workflow file-sink strings instead of emitting unescaped control characters. The implementation now delegates to the framework serializer rather than maintaining another custom JSON escaper.

Following maintainer feedback, the unsupported embedded-NUL expansion has been removed. Regression inputs cover realistic multiline text, carriage returns, tabs, quotes, backslashes and UTF-8. Framework serializer behavior is unchanged.

Executed validation

Exact updated commit: 0a79fb68e3154449299b4221dfd9a55101fb836d.

The registered file_sink_json_test exercises the actual word-timestamp helper, speech-segment/speaker-turn output files, artifact metadata and batch manifests. Parsed values are compared with the input text, not merely checked for escape substrings. Temporary output directories are created exclusively and cleaned up only when owned by the test.

  • Linux: the real CMake target passes three consecutive CTest executions with AddressSanitizer and UndefinedBehaviorSanitizer, no failures or skips.
  • macOS arm64: the actual file-sink and supporting sources compile warning-clean with C++17 and pass the updated test under UndefinedBehaviorSanitizer.
  • The same narrowed regression linked against the original file-sink source fails with newline must be escaped; the framework-helper implementation passes.

Exact Linux build/run commands and retained logs, job framework-file-sink-json. The gate checks this updated commit independently. Sanitizers halt on error; leak detection is disabled.

Scope and limits

No concrete normal-workflow producer requiring embedded-NUL preservation was established, so this PR no longer adds or claims that behavior. It does not change the framework JSON layer, inference, file naming or model outputs beyond valid string escaping at the file-output boundary.

No model weights or inference are used by the regression tests. No quality, performance, GPU-memory, leak-safety or native Windows execution claim is made. Apple ASan execution is not claimed. No dependency, release or package-version changes are requested.

Workflow and CLI artifact serializers used a local quote helper that escaped only quotes and backslashes. Reuse the framework JSON stringifier so transcript words, speaker labels, artifact metadata, and request identifiers remain valid JSON when they contain control characters.\n\nConstraint: Preserve the existing output schema while fixing JSON string encoding\nRejected: Add more cases to the local escaper | The framework serializer already owns the JSON rules\nConfidence: high\nScope-risk: narrow\nReversibility: clean\nDirective: Route future JSON string output through the framework serializer\nTested: clang++ warning-clean baseline fails and patched native harness passes; patched UBSan harness passes\nNot-tested: AddressSanitizer runtime cannot start in this sandbox; full CMake workflow target not run locally
File-sink serializers now emit JSON escapes directly, retaining embedded NUL and other control bytes while preserving the existing object and numeric schema. The expanded production-path test covers words, segments, speaker turns, artifact metadata, and batch request IDs, and the missing CTest registration is added through the standard engine unittest target.\n\nConstraint: The framework stringify helper truncates embedded NUL through cJSON's C-string API\nRejected: Keep delegating all file-sink strings to framework stringify_string | It loses bytes after embedded NUL in reachable file outputs\nConfidence: high\nScope-risk: narrow\nReversibility: clean\nDirective: Keep file-output JSON fields routed through quote_json and preserve its control-byte coverage when adding serializers\nTested: warning-clean patched production-path harness; authorized baseline failure; patched UBSan harness pass\nNot-tested: full CMake target unavailable locally; Apple ASan deadlocked before main
@0xShug0

0xShug0 commented Sep 22, 2026

Copy link
Copy Markdown
Owner

@DivyamTalwar Thanks. The issue is real, but the embedded-NUL case looks synthetic. Could you demonstrate a real producer that supplies embedded NULs in the normal workflows? That synthetic case leads to another custom JSON serializer even though the framework already provides JSON string escaping engine::io::json::stringify_string().

I suggest narrowing the PR to use the existing framework JSON serializer and adding regression tests for realistic inputs such as newlines, tabs, and carriage returns. Embedded-NUL support should only be added if there is a concrete production path that requires it.

@DivyamTalwar

Copy link
Copy Markdown
Contributor Author

Agreed. I could not establish a normal-workflow producer requiring embedded-NUL support, so I removed that expansion and the custom serializer. Updated head 0a79fb6 delegates to engine::io::json::stringify_string(). Tests now cover multiline text, carriage returns, tabs, quotes, backslashes and UTF-8, with exact parsed-value checks across real file-output paths. The narrowed regression fails against the original source and passes locally under UBSan; the actual CMake target also passes three Linux ASan/UBSan runs. Validation: https://github.com/DivyamTalwar/audio.cpp/actions/runs/35772230575 (framework-file-sink-json). The description and limitations have been updated accordingly.

@0xShug0
0xShug0 merged commit c40e781 into 0xShug0:main Sep 23, 2026
6 checks passed
@0xShug0

0xShug0 commented Sep 23, 2026

Copy link
Copy Markdown
Owner

PR merged. Thanks!

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.

Workflow file outputs contain invalid JSON when text includes control characters

2 participants