-
-
Notifications
You must be signed in to change notification settings - Fork 819
fix(explorer): /api/decisions returns 422 — coerce decision timestamp to str #937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
logan-jl-cc
wants to merge
2
commits into
semantica-agi:main
Choose a base branch
from
logan-jl-cc:fix/explorer-decision-timestamp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+93
−1
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| """Unit tests for the explorer decision route adapter. | ||
|
|
||
| Regression coverage for the ``/api/decisions`` 422 bug: a decision node | ||
| whose ``timestamp`` is stored as a POSIX float (the format | ||
| ``ContextGraph.record_decision`` writes) must not break Pydantic | ||
| validation of ``DecisionResponse`` (typed ``Optional[str]``). | ||
| """ | ||
|
|
||
| import math | ||
|
|
||
| from semantica.explorer.routes.decisions import _node_to_decision | ||
| from semantica.explorer.schemas import DecisionResponse | ||
|
|
||
|
|
||
| def _decision_node(timestamp): | ||
| """Build a minimal decision node dict shaped like ContextGraph.to_dict().""" | ||
| return { | ||
| "id": "d-1", | ||
| "type": "decision", | ||
| "properties": { | ||
| "category": "loan_underwriting", | ||
| "scenario": "A-7291 review", | ||
| "reasoning": "DTI within policy", | ||
| "outcome": "approved", | ||
| "confidence": 0.94, | ||
| "timestamp": timestamp, | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| def test_timestamp_float_is_coerced_to_str(): | ||
| """A POSIX-float timestamp (what record_decision stores) must validate. | ||
|
|
||
| Before the fix this raised a ValidationError (422 on the endpoint). | ||
| """ | ||
| node = _decision_node(timestamp=1786513069.694965) | ||
|
|
||
| decision = _node_to_decision(node) | ||
|
|
||
| assert isinstance(decision, DecisionResponse) | ||
| assert decision.timestamp == "1786513069.694965" | ||
| # round-trips through Pydantic strict str validation | ||
| assert decision.confidence == 0.94 | ||
| assert decision.outcome == "approved" | ||
|
|
||
|
|
||
| def test_timestamp_int_is_coerced_to_str(): | ||
| """Integer timestamps (some stores serialize without sub-second precision) | ||
| are handled by the same coercion path.""" | ||
| decision = _node_to_decision(_decision_node(timestamp=1786513069)) | ||
|
|
||
| assert decision.timestamp == "1786513069" | ||
|
|
||
|
|
||
| def test_timestamp_none_is_preserved(): | ||
| """A missing timestamp must stay None, not become the string 'None'.""" | ||
| decision = _node_to_decision(_decision_node(timestamp=None)) | ||
|
|
||
| assert decision.timestamp is None | ||
|
|
||
|
|
||
| def test_timestamp_str_passes_through(): | ||
| """An already-string timestamp is left intact.""" | ||
| decision = _node_to_decision(_decision_node(timestamp="2026-08-12T10:04:20")) | ||
|
|
||
| assert decision.timestamp == "2026-08-12T10:04:20" | ||
|
|
||
|
|
||
| def test_timestamp_missing_key_defaults_to_none(): | ||
| """A decision node without a timestamp key at all should not raise.""" | ||
| node = { | ||
| "id": "d-2", | ||
| "type": "decision", | ||
| "properties": {"category": "x", "outcome": "y"}, | ||
| } | ||
|
|
||
| decision = _node_to_decision(node) | ||
|
|
||
| assert decision.timestamp is None | ||
|
|
||
|
|
||
| def test_float_timestamp_not_nan_or_inf(): | ||
| """Sanity guard: degenerate float values still coerce to a finite string | ||
| rather than crashing validation.""" | ||
| for value in (float("nan"), float("inf")): | ||
| node = _decision_node(timestamp=value) | ||
| decision = _node_to_decision(node) | ||
| assert isinstance(decision.timestamp, str) | ||
| if math.isnan(value): | ||
| assert "nan" in decision.timestamp.lower() | ||
| else: | ||
| assert "inf" in decision.timestamp.lower() |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Inconsistent timestamp in metadata
🐞 Bug≡ CorrectnessAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools