Skip to content

fix(offchain): warn on missing 'result' key in ok envelope; test coverage#100

Closed
DIvyaNautiyal07 wants to merge 1 commit into
feat/offchain-epicfrom
fix/offchain-response-schema-drift-warning
Closed

fix(offchain): warn on missing 'result' key in ok envelope; test coverage#100
DIvyaNautiyal07 wants to merge 1 commit into
feat/offchain-epicfrom
fix/offchain-response-schema-drift-warning

Conversation

@DIvyaNautiyal07

Copy link
Copy Markdown
Contributor

Summary

Two follow-ups to review nits on #98.

1. Missing result key silently yielded None

If the mech's response schema drifts (renamed field, truncated payload, added nesting), envelope.get("result") returned None, _PollSnapshot was constructed with result=None, and _apply_snapshot set target.result=None, target.error="Unknown". That is indistinguishable from a routine tool failure and lands in mech_responses as a fake failed prediction.

Now logs a warning citing the observed envelope keys so the drift is visible. Every other structural failure in _parse either returns processing or emits a warning; this one now matches the convention.

2. Restored _serialise_result JSON-coercion coverage

The removed test used {"answer": 1} (dict) as the response value, exercising the non-string fallback (json.dumps). The two new tests on #98 feed string results, so nothing pinned the coercion branch.

Added:

  • test_ok_status_serialises_non_string_inner_result_to_json — feeds result={"p_yes": 0.6, "p_no": 0.4} and asserts the snapshot result is the JSON-encoded string.
  • test_ok_status_envelope_missing_result_key_warns — asserts the schema-drift warning fires. Stub logger now captures warnings into a list so tests can assert on them.

Verification

  • 14 tests pass in test_offchain_response_poller.py (12 pre-existing + 2 new)
  • tomte tox -p -e black-check -e isort-check -e flake8 -e mypy -e pylint -e darglint all green
  • autonomy packages lock --check green

Follow-up to

Review comments on #98 (already merged into feat/offchain-epic).

🤖 Generated with Claude Code

…rage

Two follow-ups to review nits on #98:

1. Missing 'result' key silently yielded None: if the mech's response
   schema drifts (renamed field, truncated payload, new nesting),
   envelope.get("result") returned None, snapshot was constructed with
   result=None, and _apply_snapshot set target.result=None,
   target.error="Unknown". That is indistinguishable from a routine
   tool failure and lands in mech_responses as a fake failed
   prediction. Now logs a warning citing the observed envelope keys
   so the drift is visible.

   Every other structural failure in _parse either returns
   'processing' or emits a warning; this one now matches that
   convention.

2. _serialise_result JSON-coercion branch was uncovered: the removed
   test used {"answer": 1} (dict) as the response value, exercising
   the non-string fallback (json.dumps). The two new tests on #98 feed
   string results, so nothing pinned the coercion branch. Added
   test_ok_status_serialises_non_string_inner_result_to_json which
   feeds result={"p_yes": 0.6, "p_no": 0.4} and asserts the snapshot
   result is the JSON-encoded string.

   Also added test_ok_status_envelope_missing_result_key_warns which
   asserts the schema-drift warning fires. Stub logger now captures
   warnings into a list so tests can assert on them.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@DIvyaNautiyal07 DIvyaNautiyal07 deleted the fix/offchain-response-schema-drift-warning branch July 3, 2026 12:38
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