fix: stop re-paying for provider calls a provenance check discards - #302
Merged
Conversation
Owner
Author
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Bundle ReportBundle size has no change ✅ Affected Assets, Files, and Routes:view changes for bundle: engram-frontend-client-array-pushAssets Changed:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #302 +/- ##
==========================================
- Coverage 91.03% 91.03% -0.01%
==========================================
Files 222 222
Lines 23195 23196 +1
==========================================
Hits 21116 21116
- Misses 2079 2080 +1 ☔ View full report in Codecov by Harness. |
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.
A provenance check compared the model recorded for a provider call against
stage.policy.model. Since #296 the gateway resolves the effective model per response kind, so as soon as a policy carried a per-kind override the two disagreed — every distillation call succeeded, was billed, and was then thrown away.Measured on the stand before the revert: ~840 paid calls, zero useful output, 122 works climbing toward terminal at streak 7/12. All distill calls switched from
gpt-5-minitogpt-5-nanoat 05:00 UTC when the override was set, and every one after that failed.The failure was also invisible, which is why it ran for hours:
provider_call_record_missingis absent from_MODEL_POLICY_CODE_MAP, so it degraded tounexpected_exception— and UNEXPECTED retries, buying another call each time._classify_provider_errorrebuiltClassifiedWorkFailurefield by field and droppedredacted_detail, so every persistedfailure_reasonon this path was empty._call_providercaughtExceptionwith no logging at all.Same shape as the 402 outage this campaign started with: the specific failure class is discarded, the generic one retries, and each retry re-pays.
Changes
Parity compares the record against the result, not against policy config.
record.policy_idandrecord.policy_versionon the lines above already pin the record to this stage's policy; re-deriving "the model" a second time only created a way for two computations to disagree. Resolving viaresolve_model()would have worked too, but it stays time-dependent — if metadata changes between the call and the check it breaks again. The consistency check does not.provider_call_record_missing→ CONFIGURATION, so the stage goes BLOCKED. The call already succeeded and was billed; retrying cannot fix a configuration disagreement, it just buys another one. Blocked is visible and free. The distillation path already supplies a fingerprint (distillation_provider_stage.py:1237), so the CONFIGURATION contract is satisfied._classify_provider_errorreturns the translated failure whole, sofailure_reasonsurvives to the database._call_providerlogs the exception it catches, with stage and request id.One existing test asserted the old
retry/unexpected_exceptionbehaviour and now assertsblocked/provider_call_record_missingwith a non-empty detail — a deliberate behaviour change, not a test tweak.Not included
The stand was unblocked separately by removing the override with raw SQL, deliberately without bumping the policy version: stages pin
policy_versionand_refresh_live_policy(distillation_provider_stage.py:454) raisesmodel policy version is staleon mismatch, so editing through the console would have failed all 121 pending works with a different error. After the revert, a forced retry produced 133 completed stages and zero failures.Also unaddressed here: there is no cap on chunks per window.
ENGRAM_DISTILL_MAX_CHUNKSdoes not exist in the code — onlyENGRAM_DISTILL_CHUNK_CHAR_BUDGETbounds anything — and the largest window holds 701 real chunks, because each new window over a live session re-covers it from scratch. Legal today, but it means ~95 continuations for one work.Verification
pytest -q engram→ 3516 passed.ruff check engram→ clean.🤖 Generated with Claude Code