Skip to content

Complete 0083 with the token-budget failure path#238

Merged
chris-colinsky merged 2 commits into
mainfrom
feature/0083-token-budget-failure-path
Jul 25, 2026
Merged

Complete 0083 with the token-budget failure path#238
chris-colinsky merged 2 commits into
mainfrom
feature/0083-token-budget-failure-path

Conversation

@chris-colinsky

Copy link
Copy Markdown
Member

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:

  • A structured_output_invalid failure carries usage (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 carries metadata.token_budget.
  • A no-usage failure (provider_unavailable) populates token_budget on 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; add expected_error handling (pytest.raises + raised_from, with the §7 category riding the span status_description); make the exact-metrics assertion conditional on a declared metrics: block (a failure still records the baseline operation.duration); implement the two without-usage invariants; and fail loudly on an unmapped invariant name.
  • test_fixture_parsing.py — un-defer 131.
  • conformance.toml0083 → 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: getattr parity 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, the PromptManager.renderPromptResult.token_budget propagation, the langfuse extra-key tolerate case, and the filesystem unified malformed-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.

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.
Copilot AI review requested due to automatic review settings July 25, 2026 01:06

Copilot AI 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.

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_error handling and new “without usage” invariants.
  • Add unit coverage for PromptManager.render token-budget propagation/copy semantics, unified-backend malformed-budget fallback eligibility, and Langfuse failure-path WARNING-vs-ERROR precedence.
  • Mark proposal 0083 as implemented in conformance.toml and 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.

@chris-colinsky
chris-colinsky merged commit ab875e9 into main Jul 25, 2026
7 checks passed
@chris-colinsky
chris-colinsky deleted the feature/0083-token-budget-failure-path branch July 25, 2026 01:09
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