Skip to content

obs-output: swap output last-error query to safe Rust (Refs #5308) - #5339

Merged
rdoupe merged 2 commits into
masterfrom
port/5308-output-get-last-error
Nov 20, 2026
Merged

rdoupe merged 2 commits into
masterfrom
port/5308-output-get-last-error

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #5308.

Swap only obs_output_get_last_error into obs-output. After obs_output_valid()'s exact NULL diagnostic (LOG_DEBUG, obs_output_get_last_error: Null 'output' parameter), the safe query returns the output's own last_error_message, else the first non-NULL error of the video encoder slots in ascending order, else of the audio slots, else NULL. Each field is read lazily, so nothing below a hit is read. The pointer is borrowed unchanged; empty and non-UTF-8 strings are errors like any other. No copy, cache, reference change or lock (the encoder error mutex is never taken).

The shim reads through production adapters that already exist: obs_output_last_error_fields, obs_output_video_encoder_getter_at, obs_output_encoder_getters_audio_at and obs_encoder_last_error_fields. No new private layout crosses the ABI. The original libobs/obs-output-get-last-error.c.h moves whole into libobs.ported-output-get-last-error, which only the C reference builds. The hybrid core-output group drops it and rust-exports.d exports the Rust symbol, so the export set stays identical (1769 symbols).

Shared Rust-static link support (#5246): two of those adapters had no support member, so output-encoder-getters-link-support.c and encoder-last-error-link-support.c join test/cmocka/build/rust-static-support.json as lazy members. No per-consumer fragment, stub or fake global was added.

Tests:

  • Tier 1 mirrors every assertion of the unchanged test_output_get_last_error.c on a recording model: result identity across independent equal-byte allocations, empty and non-UTF-8 errors, every hole and fallback step, the NULL diagnostic, and a read trace checked for priority order with nothing read after a hit.
  • Tier 3 runs the extracted original and the shim on real-header obs_output/obs_encoder fixtures. It checks the returned pointer identity (never a copy), untouched output, encoder and message bytes, the exact NULL diagnostic on both sides, no allocation, slot counts against the C build, and that each adapter addresses exactly the field the original reads. Coverage includes characterized shapes and a proptest. Five query mutants are caught: skipped own error, audio before video, descending slots, empty treated as missing, and a copy. A core mutant (descending video slots) failed Tier 1 and Tier 3 locally.
  • Tier 2: the unchanged C characterization runs against the hybrid libobs and the C reference. Tier 4 does not apply.

Test cost: new tests run in 0.02 s at most (OBS_PARITY_CASES=reduced), peak RSS 11.7 MB over 25 runs, and they start no threads of their own. The isolated child test spawns one process.

Evidence

RED (dad8841c2, the safe query is a stub that returns None):

soldr cargo test -p obs-data --test obs-tests-core -- output::output_get_last_error
test result: FAILED. 2 passed; 6 failed

GREEN (789c03913, on 5d0944dfd):

soldr cargo test -p obs-data --test obs-tests-core -- output::output_get_last_error
test result: ok. 8 passed; 0 failed

soldr cargo test -p obs-data --test obs-tests-core
test result: ok. 6182 passed; 0 failed; 5 ignored

soldr cargo test -p obs-studio-rust --test obs-tests-app -- native_build::
test result: ok. 326 passed; 0 failed

OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 2 --tests output_get_last_error
libobs exported symbols, C vs Rust: IDENTICAL (1769 symbols)
100% tests passed, 0 tests failed out of 1046   (C reference and hybrid libobs, each)
100% tests passed, 0 tests failed out of 1      (repeat of test_output_get_last_error, OFF and ON)

test_output_get_last_error run directly in the kept build volume, hybrid and C reference:
[ OK ] null_diagnostic, [ OK ] fallback_order_and_borrowing, 2 test(s) run, no skips
(the hybrid libobs.so defines obs_output_get_last_error; the ported C object is excluded)

uv run --no-project ci/windows_link_check.py      exit 0
Windows MSVC and Darwin arm64: hybrid libobs and 71 Rust-static fixtures linked

uv run ci/test_rust_static_link_support.py         OK (6 tests)
uv run ci/test_native_b2_portability.py            OK (29 tests)
./lint                                             lane lint: ok

./push passed the client lint and test lanes (9283 workspace tests). Its optional Swift lane exited 75 on this host, so nothing was attested and ordinary PR CI runs. This change has no user-visible effect, so it adds no line to the features ledger. Native Windows and macOS execution is not claimed.

🤖 Generated with Claude Code

@rdoupe
rdoupe requested a review from zackees as a code owner November 20, 2026 03:50
@rdoupe
rdoupe force-pushed the port/5308-output-get-last-error branch from 789c039 to c51128b Compare November 20, 2026 04:12
@rdoupe

rdoupe commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto 0f5f3e10e (master had added obs-output-get-name.c.h to libobs.core-output; kept it, dropped only the moved last-error file). Rechecked on the rebased head:

  • ./lint: ok
  • soldr cargo test -p obs-data --test obs-tests-core -- output::output_get_last_error: 8 passed, 0 failed
  • soldr cargo test -p obs-studio-rust --test obs-tests-app -- native_build::: 326 passed
  • OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 1 --tests output_get_last_error: 100% passed

rdoupe and others added 2 commits November 19, 2026 23:32
Tier 1 mirrors every assertion of the unchanged
test_output_get_last_error.c against the safe query on a recording model
of the output's fields: result identity, the NULL diagnostic, and every
field read once in priority order with nothing read after a hit. Tier 3
runs the extracted original and the shim on one real-layout output and
encoder fixture through the production field adapters, checks those
adapters address the original's fields, and shows five mutants caught.

The safe query is a stub that returns None:

    soldr cargo test -p obs-data --test obs-tests-core -- output::output_get_last_error
    test result: FAILED. 2 passed; 6 failed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After obs_output_valid()'s exact NULL diagnostic, the safe query returns
the output's own last_error_message, else the first error of the video
encoder slots in ascending order, else of the audio slots, else NULL.
Each field is read lazily, so nothing below a hit is read. The pointer is
borrowed unchanged, empty and non-UTF-8 strings included: no copy, cache,
reference or lock. The shim reads through the existing production
adapters of the output error slot, the video and audio slots and the
encoder error field, so no new layout crosses the ABI.

The output-encoder-getters and encoder-last-error adapters join the shared
Rust-static support manifest (#5246) as lazy members, so a standalone
Rust-static fixture that pulls this query links their real C.

The original moves whole into libobs.ported-output-get-last-error, which
only the C reference builds; the hybrid core-output group drops it and
the Rust symbol is exported in its place.

    soldr cargo test -p obs-data --test obs-tests-core -- output::output_get_last_error
    test result: ok. 8 passed; 0 failed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Ci-Attestation: {"at":1795149547,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":93,"stamp":"cc0cd657d7bd1a832cfc96f2dc28d417","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149547,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":93,"stamp":"f6ef1480ab57055cf2eb5938dc182649","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149547,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":93,"stamp":"40b0d2ef6e67b6332883a22ad8c155ae","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149547,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":93,"stamp":"383b71a2930be42bfa75281b5a6156d1","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149454,"gate":"general/all/client-lint","host":"linux-x86_64","key":"22f3ed3edbceb7d08607215a5ec8c77f09ba0aaeab3ffa0b387d1c022d6fe2ff","lane":"client-lint","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":55,"stamp":"1e4ae35a2c5d8884e2ba11338b059ebe","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149547,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":93,"stamp":"2c756a19935b9720f35cc6a389059f03","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149454,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"22f3ed3edbceb7d08607215a5ec8c77f09ba0aaeab3ffa0b387d1c022d6fe2ff","lane":"client-lint","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":55,"stamp":"638955ddd09abed3ebe2ffeb6494fe23","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149454,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"22f3ed3edbceb7d08607215a5ec8c77f09ba0aaeab3ffa0b387d1c022d6fe2ff","lane":"client-lint","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":55,"stamp":"8db470d3a2ee442b21a5b018b1e39d11","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149454,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"22f3ed3edbceb7d08607215a5ec8c77f09ba0aaeab3ffa0b387d1c022d6fe2ff","lane":"client-lint","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":55,"stamp":"dd2cc8b0c804e63b750e59a79b4f291d","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149454,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"22f3ed3edbceb7d08607215a5ec8c77f09ba0aaeab3ffa0b387d1c022d6fe2ff","lane":"client-lint","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":55,"stamp":"2f33d6b2c2d916f6820bee9e6e31e187","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149454,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"22f3ed3edbceb7d08607215a5ec8c77f09ba0aaeab3ffa0b387d1c022d6fe2ff","lane":"client-lint","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":55,"stamp":"3482edd14b020d82ce754814f83d174b","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149454,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"22f3ed3edbceb7d08607215a5ec8c77f09ba0aaeab3ffa0b387d1c022d6fe2ff","lane":"client-lint","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":55,"stamp":"eda5d3a091a9bbe839be2b3f40bb1bc0","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149454,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"22f3ed3edbceb7d08607215a5ec8c77f09ba0aaeab3ffa0b387d1c022d6fe2ff","lane":"client-lint","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":55,"stamp":"1252c0da17a78d0e1cfc2c1505d7d6c1","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149454,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"22f3ed3edbceb7d08607215a5ec8c77f09ba0aaeab3ffa0b387d1c022d6fe2ff","lane":"client-lint","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":55,"stamp":"9dd71355a58432db86bef1f67493b585","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149454,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"22f3ed3edbceb7d08607215a5ec8c77f09ba0aaeab3ffa0b387d1c022d6fe2ff","lane":"client-lint","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":55,"stamp":"fc366cfada738139ce20209a99ba0f4d","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149454,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"22f3ed3edbceb7d08607215a5ec8c77f09ba0aaeab3ffa0b387d1c022d6fe2ff","lane":"client-lint","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":55,"stamp":"4d0bf2cbe88e7d37683d2c17ac0c3e5a","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149454,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"22f3ed3edbceb7d08607215a5ec8c77f09ba0aaeab3ffa0b387d1c022d6fe2ff","lane":"client-lint","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":55,"stamp":"f6d107f0810c75e6470168f50046593c","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149454,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"22f3ed3edbceb7d08607215a5ec8c77f09ba0aaeab3ffa0b387d1c022d6fe2ff","lane":"client-lint","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":55,"stamp":"b9b38f958b396e356a67b9934d5c7736","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}
Ci-Attestation: {"at":1795149699,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"4439d6bfffcb54359f4819d9b4b3f50919a8bfaf34620c5dc8ae6ae704514203","lane":"client-test-x86_64-unknown-linux-gnu","parents":["0b1d7bc235da7d53ac0e185f89fe2dd0de41e3cd"],"secs":150,"stamp":"7f77e2922b55ebb951c101d3af11ff10","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d","v":1,"via":"run"}

Client-Checks: {"checks":{"base":"5bc3cf493a27ddbc58ca0609a1e3eba587201586","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.core+.h.c","libobs/build/libobs.core-output+.h.c","libobs/build/libobs.ported-hotkey-combination-background-id+.h.c","libobs/build/libobs.ported-output-get-last-error+.h.c","libobs/build/ported-source-sets/hotkey-combination-background-id.json","libobs/build/ported-source-sets/output-get-last-error.json","libobs/cmake/rust-exports.d/obs-hotkey-combination_background_id.txt","libobs/cmake/rust-exports.d/obs-output-output_get_last_error.txt","libobs/obs-hotkey-combination-background-id-fields.c.h","libobs/obs-hotkey-combination-background-id-lock.c.h","libobs/obs-hotkey-combination-background-id.c.h","rust/README.md","rust/obs-build/tests/native.rs","rust/obs-build/tests/native/registration/canonical_hotkey_combination_background_id_swap_is_registered.rs","rust/obs-build/tests/native/registration/canonical_output_get_last_error_swap_is_registered.rs","rust/obs-c-oracle/oracle/hotkey_combination_background_id.c","rust/obs-c-oracle/oracle/output_get_last_error.c","rust/obs-hotkey/src/combination_background_id.rs","rust/obs-hotkey/src/ffi/combination_background_id.rs","rust/obs-hotkey/src/ffi/mod.rs","rust/obs-hotkey/src/lib.rs","rust/obs-hotkey/tests/hotkey/background_query_parity.rs","rust/obs-hotkey/tests/hotkey/combination_background_id.rs","rust/obs-hotkey/tests/hotkey/combination_background_id_parity.rs","rust/obs-hotkey/tests/hotkey/main.rs","rust/obs-output/src/ffi/mod.rs","rust/obs-output/src/ffi/output_get_last_error.rs","rust/obs-output/src/lib.rs","rust/obs-output/src/output_get_last_error.rs","rust/obs-output/tests/output/main.rs","rust/obs-output/tests/output/output_get_last_error.rs","rust/obs-output/tests/output/output_get_last_error_parity.rs","test/cmocka/build/rust-static-support.json","test/cmocka/encoder-last-error-link-support.c","test/cmocka/output-encoder-getters-link-support.c"],"head":"7b338f3317cc2ef668b938b8306cd42595f75000","tools":{"orchestrator-python":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]","schema-dependencies":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]\n{'jsonschema': '4.26.0', 'json_source_map': '1.0.5'}","uv":"uv 0.13.5 (x86_64-unknown-linux-gnu)","xmllint":"xmllint: using libxml version 21504-GITv2.15.4\n   compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ICU ISO8859X Regexps Automata RelaxNG Schemas Schematron Modules Debug Zlib"},"tracked-digest":"e2c4b173bfe783cdb6381a80c8edc19b42f2bb916108a6c8f6744a1e42df042e","tree":"08e72356b48064abd5621b74739e9cf9dc45ec8d"}}
@rdoupe
rdoupe force-pushed the port/5308-output-get-last-error branch from c51128b to 624e649 Compare November 20, 2026 04:41
@rdoupe

rdoupe commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator Author

Windows Rust Tests failed building the oracle: MSVC C4310 ("cast truncates constant value", warnings as errors) on (char)0xff in rust/obs-c-oracle/oracle/output_get_last_error.c:45. Replaced the cast array with the equivalent literal "\xff\x80x" (same 4 bytes) in the RED commit. Rechecked: ./lint ok; soldr cargo test -p obs-data --test obs-tests-core -- output::output_get_last_error 8 passed. Auto-merge stays on, so it enters the queue when CI is green.

@rdoupe
rdoupe added this pull request to the merge queue Nov 20, 2026
Merged via the queue into master with commit f9e071f Nov 20, 2026
44 checks passed
@rdoupe
rdoupe deleted the port/5308-output-get-last-error branch November 20, 2026 05:56
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In review to Done in obs-rust Multiview Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant