Complete 0083 with the token-budget failure path#238
Merged
Conversation
Complete proposal 0083 (per-prompt token-budget observability) with the structured-output-failure path. No source change was needed: the budget already evaluates on any usage-bearing per-attempt event, so a structured_output_invalid failure (which carries usage, proposal 0082) drives the span, metrics, and section 7 log via the generic path, and a no-usage provider_unavailable failure records nothing token-budget. - conformance harness: route fixture 131 to the token-budget runner; add expected_error handling (raises + raised_from), make the exact metric assertion conditional on a declared metrics block (a failure still records the baseline operation.duration), and implement the two without-usage invariants. - conformance.toml: mark 0083 implemented (all fixtures 126-131 run).
Address the six findings from the whole-proposal adversarial review (0 blockers): cross-surface robustness plus the end-to-end coverage the per-PR reviews could not see. - langfuse: read token_budget via getattr in the metadata block, matching the OTel span + shared helper, so a non-TokenBudget value degrades instead of crashing the Generation. - harness: fail loudly on an unmapped token-budget invariant name (no more vacuous pass) and handle exception_propagates. - tests: a structured_output_invalid over-budget failure through Langfuse (ERROR wins, metadata.token_budget present, no WARNING); the PromptManager.render -> PromptResult.token_budget propagation; the langfuse extra-key tolerate case; and the filesystem unified malformed-budget fallback-eligible path.
There was a problem hiding this comment.
Pull request overview
Completes proposal 0083 (per-prompt token-budget observability) by wiring and asserting the failure-path behavior in the conformance harness, and flipping the conformance registry status to implemented. This rounds out token-budget signals across both successful completions and usage-bearing failures, while explicitly asserting “no usage, no evaluation” semantics.
Changes:
- Extend the conformance observability runner to execute fixture 131 (token-budget on structured-output failure), including
expected_errorhandling and new “without usage” invariants. - Add unit coverage for
PromptManager.rendertoken-budget propagation/copy semantics, unified-backend malformed-budget fallback eligibility, and Langfuse failure-path WARNING-vs-ERROR precedence. - Mark proposal 0083 as
implementedinconformance.tomland remove the 131 parsing deferral.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_prompts.py | Adds unit tests for token-budget propagation and unified malformed-budget fallback behavior. |
| tests/unit/test_observability_langfuse.py | Adds Langfuse test asserting structured-output over-budget failures stay ERROR (no WARNING override) while preserving token_budget metadata. |
| tests/conformance/test_observability.py | Routes fixture 131 through the token-budget runner; adds expected_error handling, conditional metrics assertions, and invariant-name guarding. |
| tests/conformance/test_fixture_parsing.py | Removes the deferral for fixture 131 now that the harness supports it. |
| src/openarmature/observability/langfuse/observer.py | Makes token_budget metadata extraction defensive via getattr, matching existing OTel/helper behavior. |
| conformance.toml | Flips proposal 0083 to implemented and documents the completed A/B/C rollout. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Third and final PR for proposal 0083 (per-prompt token-budget observability). Adds the structured-output-failure path and marks 0083
implemented. Follows PR A (completion path) and PR B (WARNING surfaces).The failure path needed no source change
The budget already evaluates on any usage-bearing per-attempt event, so the failure path falls out of the generic handling from PR A/B:
structured_output_invalidfailure carriesusage(proposal 0082), so it drives the OTel span attribute, the two §11 metrics, and the §7 WARNING log exactly like a completion, and the Langfuse ERROR Generation carriesmetadata.token_budget.provider_unavailable) populatestoken_budgeton the event but records nothing token-budget (there is nothing to compare against).PR C is therefore harness wiring plus the conformance flip:
test_observability.py— route fixture 131 to the token-budget runner; addexpected_errorhandling (pytest.raises+raised_from, with the §7 category riding the spanstatus_description); make the exact-metrics assertion conditional on a declaredmetrics:block (a failure still records the baselineoperation.duration); implement the two without-usage invariants; and fail loudly on an unmapped invariant name.test_fixture_parsing.py— un-defer 131.conformance.toml— 0083 →implemented(all six fixtures 126-131 run).Whole-proposal review
Ran a final multi-agent adversarial review over the complete A+B+C impl (0 blockers). Folded in:
getattrparity in the Langfuse metadata block, the invariant-name guard, and end-to-end coverage the per-PR reviews could not reach — a structured-over-budget failure through Langfuse, thePromptManager.render→PromptResult.token_budgetpropagation, the langfuse extra-key tolerate case, and the filesystemunifiedmalformed-budget path. Two non-blocking spec questions (Langfuse failure-path exceedance discoverability; the extra-key policy divergence) are with spec.Tests
Fixture 131 (both cases) plus the folded-in unit coverage. Full suite green; ruff and pyright clean.