Skip to content

fix(jobs): report byte counts for returned observation output - #1332

Merged
yyjeqhc merged 1 commit into
yyjeqhc:mainfrom
skygunner:contrib/jobs-returned-bytes-20261028
Oct 28, 2026
Merged

yyjeqhc merged 1 commit into
yyjeqhc:mainfrom
skygunner:contrib/jobs-returned-bytes-20261028

Conversation

@skygunner

Copy link
Copy Markdown
Contributor

Problem

observe_jobs already aggregates a returned-byte metric from each successful observation's output.stdout_returned_bytes and output.stderr_returned_bytes (src/tool_runtime/observe_jobs.rs), but the bounded observation producer in src/tool_runtime/jobs.rs never populated either field. Both lookups therefore fell back to zero, so job_observation_items_total reported returned_bytes = 0 for every batch regardless of how much stdout/stderr was actually returned to the caller.

Change

The producer now reports the UTF-8 byte length of the stdout and stderr fragments it actually returns after output limiting (stdout.len(), stderr.len()). This is the returned fragment, not the Job's cumulative log volume and not the serialized JSON size. Job lifecycle, wait/update semantics, reconciliation and recovery are untouched, and no new statistics path is added: the existing consumer is simply given the facts it already expects.

Compatibility

  • Two additive fields on the canonical Job observation. The observation object schema is already open (additionalProperties: true), so no schema tightening or migration is involved.
  • No configuration, persistence or protocol change.

Validation

Test: observe_jobs_metrics_sum_utf8_bytes_of_returned_producer_output in src/tool_runtime/tests/observe_jobs.rs. It drives the real producer (a test runtime with runner registry Job updates) and the real consumer (a recording RuntimeMetrics sink), covering stdout-only, stderr-only, both, empty output, and one failed item in the same batch:

  • byte counts equal the UTF-8 byte length of each returned tail, and the multibyte fixture keeps bytes != character count;
  • the observation metric equals the sum of the successful items' stdout + stderr byte counts, and the failed item contributes nothing;
  • with tail_lines = 1 the reported bytes describe only the returned truncated fragment.

Commands (Linux x86_64, Rust 1.99.1):

cargo test --locked -p webcodex --lib observe_jobs_metrics_sum_utf8_bytes
  -> 1 passed; 3835 filtered out

With the producer fields removed (fix stashed), the same test fails:
  assertion failed: stdout bytes must count returned UTF-8 bytes, not characters (left: None, right: Some(18))

Not run here: Windows/macOS/ARM64 lanes (no environment available).

Job observations already feed a returned-byte metric, but the bounded output producer never populated stdout_returned_bytes or stderr_returned_bytes, so the metric silently fell back to zero.

Report the UTF-8 byte length of the stdout and stderr fragments actually returned after output limiting. The Job and observation lifecycle are unchanged.

@yyjeqhc yyjeqhc left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the scoped implementation and regression coverage against its source baseline; CI and diff checks pass. No blocking issue identified.

@yyjeqhc
yyjeqhc merged commit 1393308 into yyjeqhc:main Oct 28, 2026
18 checks passed
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.

2 participants