Skip to content

feat(custom-engine): validate and persist engine-reported measurements - #459

Open
BiBoyang wants to merge 2 commits into
alibaba:mainfrom
BiBoyang:feat/engine-measurements
Open

BiBoyang wants to merge 2 commits into
alibaba:mainfrom
BiBoyang:feat/engine-measurements

Conversation

@BiBoyang

Copy link
Copy Markdown
Contributor

Summary

A custom engine can report four fixed numbers about a run: duration_ms, turns, input_tokens and output_tokens. Any other runtime measurement, such as decode speed at given context lengths or time to first token, had to go into an artifact file that skill-up archived without reading.

This PR is slice 1 of #422. SessionResult accepts an optional measurements object on both the local and http transports: named scalars and series, each with a unit, plus the engine's own provenance. skill-up validates it strictly, masks it, and writes it to result.json and report.json. It does nothing else with it: measurements never change a verdict, a pass rate, the benchmark or a named-metric state, and an invalid object never fails the case.

Related issues

Refs #422 (slice 1: contract and persistence). Background in #296.

Changes

  • internal/measurement (new, no internal dependencies): the stored form and the strict parser. A whole-object defect (unsupported schema_version, a duplicated JSON key, an unknown field, missing or invalid provenance, a size limit) rejects the object. An entry defect (invalid id or unit, a duplicated id, a non-finite value, a bad point, a series over its point limit) rejects only that scalar or series. Every rejection leaves a diagnostic with a scope, a code and a path. Nothing is truncated, and a missing value stays MISSING with its reason.
  • internal/agent: parseSessionResult keeps measurements as a raw field and validates it on its own, so a defect there cannot fail the decode of the fields grading depends on. Engine-supplied text goes through maskAPIKey, like stderr and final_message.
  • internal/evaluator: buildAggregateResult copies the last turn's SessionResult. It now clears the measurements, which would otherwise be presented as the whole case's.
  • internal/report, internal/runner: CaseResult and CaseTurnResult gain engine_measurements and engine_measurement_diagnostics, both omitempty. A single-turn case carries them on the case; a multi-turn case carries them on the turn that reported them.
  • internal/report/html.go: the HTML report converted each turn result to its embedded form with a struct conversion, which the new turn fields would break. It now copies the fields it embeds. The HTML output is unchanged.
  • Docs: a Measurements contract section in docs/design/custom-engine.md with the Eval scenario: long-context decode TPS decay — half-speed point as a compaction-threshold anchor #296 decode-speed sweep as the worked example, a short section in both writing-evals guides, and a CHANGELOG entry.

Following the review on #422:

  • The lists are named scalars and series.
  • The worked example's axis is requested_context_tokens, and the observed input-token count is a second series on that axis, so a timed-out step is MISSING in both.
  • Units are a validated free-form label, with a table of recommended spellings in the design doc.
  • Report tables and OTel Metrics export are left to later slices.

Test plan

  • make test passes
  • make verify passes (fmt + vet + lint)
  • make e2e passes (94 passed; 41 skipped as LLM-dependent in quick mode)
  • Manual testing steps (if applicable):
    • Ran the CLI against a local custom engine that reports one valid scalar, one scalar with an invalid unit, and one series with a missing point. The case passes, result.json carries the valid entries and one invalid_unit diagnostic, and the missing point has no value.
    • Compared a build of main with this branch on the same result without measurements: the report.json, JUnit, HTML and Markdown output is byte-identical.

How the acceptance criteria of #422 map to tests:

Criterion Tests
local and http both persist a scalar and a series TestPipeline_CustomEngine_Measurements_LocalTransport, TestPipeline_CustomEngine_Measurements_HTTPTransport
No measurements: result.json and report.json unchanged TestWriteResults_MeasurementsChangeNothingElse, TestPipeline_CustomEngine_NoMeasurementsLeavesTheOutputsUntouched
Verdicts, benchmark and metric states identical, also when invalid TestWriteResults_MeasurementsChangeNothingElse, TestCustomAgent_MeasurementsNeverChangeTheRunOutcome, TestPipeline_CustomEngine_Measurements_InvalidNeverChangesTheVerdict
MISSING keeps its reason; nothing becomes 0 TestParseKeepsMissingValuesMissing, TestWriteResults_MissingMeasurementIsWrittenWithoutAValue
Whole-object and entry defects, each with a diagnostic TestParseRejectsTheWholeObject, TestParseRejectsOnlyTheDefectiveScalar, TestParseRejectsOnlyTheDefectiveSeries, TestParseRejectsEveryEntryCarryingADuplicatedID
Every limit at the boundary and one past it TestParseAcceptsEveryLimitAtItsBoundary, TestParseRejectsOnePastEachWholeObjectLimit, TestParseRejectsOnePastEachEntryLimit
Free text masked; ids, units and reasons outside their patterns rejected TestParseMasksEngineText, TestCustomAgent_MasksMeasurementText, TestDiagnosticsNeverEchoRejectedText
Multi-turn: measurements stay on their turn TestExecuteMultiTurn_MeasurementsStayOnTheTurnThatReportedThem, TestPipeline_CustomEngine_Measurements_StayOnTheirTurn
Docs use the #296 sweep as the worked example docs/design/custom-engine.md; the same document is the fixture of TestParseWorkedExample

Notes for reviewers

Three things the proposal did not settle:

  • Bare NaN / Infinity. They make the whole SessionResult invalid JSON, so the case is a result error, and Python's json.dumps writes them by default. "Invalid measurements never change the verdict" cannot hold for that input. The docs tell engines to serialize with allow_nan=False and report such a value as MISSING. A number that is valid JSON but out of float64 range, such as 1e999, rejects only its own entry.
  • null. It is read as an omitted field, for measurements itself and for the optional fields inside it.
  • Diagnostics. Each one gives the path of the defect and the entry id when that id is valid. They never repeat text that failed validation, because it is engine-controlled.

Smaller choices, all written down in the design doc:

  • The per-result point limit counts points as sent, before any series is rejected.
  • Length limits apply to text as sent, before masking.
  • A custom engine that runs as an agent_judge engine has its measurements validated but not stored.

Two naming choices I'd like your view on:

A custom engine could report four fixed numbers about a run: duration,
turns, and input and output tokens. Anything else, such as decode speed
at given context lengths or time to first token, had to go into an
artifact file that skill-up archived without reading.

SessionResult now accepts an optional measurements object on both the
local and http transports: named scalars and series, each with a unit,
plus the engine's account of how they were produced. The new
internal/measurement package validates it strictly. A defect in the
object as a whole (an unsupported schema version, a duplicated JSON key,
an unknown field, missing provenance, a size limit) rejects all of it. A
defect in one entry rejects only that entry and keeps its siblings.
Every rejection leaves a diagnostic, nothing is truncated, and a value
that could not be measured stays MISSING with its reason instead of
becoming 0. Engine-supplied text is masked like stderr and
final_message.

The validated measurements are written to result.json and report.json
as engine_measurements and engine_measurement_diagnostics: on the case
for a single-turn case, and on the turn that reported them for a
multi-turn one. buildAggregateResult copies the last turn's
SessionResult, so it now clears them; otherwise the last turn's
measurements would be presented as the whole case's.

Measurements are informational. They never change a verdict, a pass
rate, the benchmark or a named-metric state, and an invalid object never
fails the case. Results without measurements are unchanged, and
grading.json, benchmark.json, the JUnit, HTML and Markdown reports, OTel
attributes and the JSONL event stream do not carry them. The HTML report
converted each turn result to its embedded form with a struct
conversion, which the new turn fields would break, so it now copies the
fields it embeds.

The custom engine design doc gains the Measurements contract, with the
decode-speed sweep from alibaba#296 as the worked example. The writing-evals
guides and the CHANGELOG describe the field.

Refs alibaba#422
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T18:30:19.435004Z aebd578 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aebd578054

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

previous := math.Inf(-1)
for index, item := range rawPoints {
point, at, defect := p.parsePoint(item)
if defect == nil && at <= previous {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve distinct decimal positions when validating series

When an engine sends a valid series with adjacent JSON decimals that are distinct but map to the same float64 (for example 9007199254740992 followed by 9007199254740993), parsePoint preserves each literal but this comparison sees equal rounded positions and rejects the entire series as non-increasing. Since the contract accepts finite JSON numbers and retains their spelling, compare positions without losing decimal precision or explicitly reject non-representable coordinates.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The comparison does read positions as float64 while the stored point keeps the literal. I kept the float64 comparison and stated it, rather than comparing decimals exactly: most readers of the stored JSON see at as a double, so two such points could not be told apart downstream either. 1669242 documents the rule in the design doc and the code, and adds a test for an integer pair, a decimal pair and the neighboring float64 that is accepted.

A series is rejected when a point's position does not increase. The
comparison reads each position as a float64, while the stored point
keeps the engine's literal. Two literals that are distinct as decimals
but convert to the same float64, such as 9007199254740992 and
9007199254740993, therefore reject the series, and nothing said so.

Keep that behavior and state it. Most readers of the stored JSON see
positions as doubles, so two such points could not be told apart
downstream either. The design doc, the Point and parsePoints comments
and the diagnostic hint now give the rule. A test pins it for an integer
pair and a decimal pair, together with the neighboring float64 that is
accepted.

Refs alibaba#422

This branch has not been deployed

No deployments
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.

1 participant