Skip to content

Commit 35f0984

Browse files
authored
fix: retain async fails if timestamp is set (#251)
* fix: retain async fails if timestamp is set * fix: rename openclawd to openclaw
1 parent 5dc4519 commit 35f0984

File tree

85 files changed

+171
-86
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+171
-86
lines changed

hindsight-api/hindsight_api/engine/task_backend.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,16 @@ async def submit_task(self, task_dict: dict[str, Any]):
182182
operation_id = task_dict.get("operation_id")
183183
task_type = task_dict.get("type", "unknown")
184184
bank_id = task_dict.get("bank_id")
185-
payload_json = json.dumps(task_dict)
185+
186+
# Custom encoder to handle datetime objects
187+
from datetime import datetime
188+
189+
def datetime_encoder(obj):
190+
if isinstance(obj, datetime):
191+
return obj.isoformat()
192+
raise TypeError(f"Object of type {type(obj).__name__} is not JSON serializable")
193+
194+
payload_json = json.dumps(task_dict, default=datetime_encoder)
186195

187196
schema = self._schema_getter() if self._schema_getter else self._schema
188197
table = fq_table("async_operations", schema)

hindsight-api/tests/test_http_api_integration.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,3 +1098,79 @@ async def test_version_endpoint_returns_correct_version(api_client):
10981098
assert isinstance(features["worker"], bool)
10991099

11001100
print(f"Version endpoint returned: api_version={result['api_version']}, features={features}")
1101+
1102+
1103+
@pytest.mark.asyncio
1104+
async def test_retain_with_timestamp_async(api_client, test_bank_id):
1105+
"""Test that async retain accepts timestamp field and serializes correctly."""
1106+
response = await api_client.post(
1107+
f"/v1/default/banks/{test_bank_id}/memories",
1108+
json={
1109+
"items": [
1110+
{
1111+
"content": "Test memory with timestamp",
1112+
"context": "test",
1113+
"timestamp": "2026-01-30T11:45:00Z"
1114+
}
1115+
],
1116+
"async": True
1117+
}
1118+
)
1119+
1120+
assert response.status_code == 200, f"Expected 200, got {response.status_code}: {response.text}"
1121+
data = response.json()
1122+
assert data["success"] is True
1123+
assert data["async"] is True
1124+
assert "operation_id" in data
1125+
1126+
1127+
@pytest.mark.asyncio
1128+
async def test_retain_with_timestamp_sync(api_client, test_bank_id):
1129+
"""Test that sync retain accepts timestamp field."""
1130+
response = await api_client.post(
1131+
f"/v1/default/banks/{test_bank_id}/memories",
1132+
json={
1133+
"items": [
1134+
{
1135+
"content": "Test memory with timestamp sync",
1136+
"context": "test",
1137+
"timestamp": "2026-01-30T11:45:00Z"
1138+
}
1139+
],
1140+
"async": False
1141+
}
1142+
)
1143+
1144+
assert response.status_code == 200, f"Expected 200, got {response.status_code}: {response.text}"
1145+
data = response.json()
1146+
assert data["success"] is True
1147+
assert data["async"] is False
1148+
1149+
1150+
@pytest.mark.asyncio
1151+
async def test_retain_with_multiple_timestamps(api_client, test_bank_id):
1152+
"""Test that multiple items with different timestamp formats work."""
1153+
response = await api_client.post(
1154+
f"/v1/default/banks/{test_bank_id}/memories",
1155+
json={
1156+
"items": [
1157+
{
1158+
"content": "Event 1",
1159+
"timestamp": "2026-01-30T11:45:00Z" # With Z
1160+
},
1161+
{
1162+
"content": "Event 2",
1163+
"timestamp": "2026-01-30T12:00:00+00:00" # With timezone
1164+
},
1165+
{
1166+
"content": "Event 3" # No timestamp
1167+
}
1168+
],
1169+
"async": True
1170+
}
1171+
)
1172+
1173+
assert response.status_code == 200, f"Expected 200, got {response.status_code}: {response.text}"
1174+
data = response.json()
1175+
assert data["success"] is True
1176+
assert data["items_count"] == 3

hindsight-clients/python/hindsight_client_api/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
88
HTTP API for Hindsight
99
10-
The version of the OpenAPI document: 0.4.2
10+
The version of the OpenAPI document: 0.4.3
1111
Generated by OpenAPI Generator (https://openapi-generator.tech)
1212
1313
Do not edit the class manually.
1414
""" # noqa: E501
1515

1616

17-
__version__ = "0.4.3"
17+
__version__ = "0.0.7"
1818

1919
# import apis into sdk package
2020
from hindsight_client_api.api.banks_api import BanksApi

hindsight-clients/python/hindsight_client_api/api/banks_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
HTTP API for Hindsight
77
8-
The version of the OpenAPI document: 0.4.2
8+
The version of the OpenAPI document: 0.4.3
99
Generated by OpenAPI Generator (https://openapi-generator.tech)
1010
1111
Do not edit the class manually.

hindsight-clients/python/hindsight_client_api/api/directives_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
HTTP API for Hindsight
77
8-
The version of the OpenAPI document: 0.4.2
8+
The version of the OpenAPI document: 0.4.3
99
Generated by OpenAPI Generator (https://openapi-generator.tech)
1010
1111
Do not edit the class manually.

hindsight-clients/python/hindsight_client_api/api/documents_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
HTTP API for Hindsight
77
8-
The version of the OpenAPI document: 0.4.2
8+
The version of the OpenAPI document: 0.4.3
99
Generated by OpenAPI Generator (https://openapi-generator.tech)
1010
1111
Do not edit the class manually.

hindsight-clients/python/hindsight_client_api/api/entities_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
HTTP API for Hindsight
77
8-
The version of the OpenAPI document: 0.4.2
8+
The version of the OpenAPI document: 0.4.3
99
Generated by OpenAPI Generator (https://openapi-generator.tech)
1010
1111
Do not edit the class manually.

hindsight-clients/python/hindsight_client_api/api/memory_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
HTTP API for Hindsight
77
8-
The version of the OpenAPI document: 0.4.2
8+
The version of the OpenAPI document: 0.4.3
99
Generated by OpenAPI Generator (https://openapi-generator.tech)
1010
1111
Do not edit the class manually.

hindsight-clients/python/hindsight_client_api/api/mental_models_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
HTTP API for Hindsight
77
8-
The version of the OpenAPI document: 0.4.2
8+
The version of the OpenAPI document: 0.4.3
99
Generated by OpenAPI Generator (https://openapi-generator.tech)
1010
1111
Do not edit the class manually.

hindsight-clients/python/hindsight_client_api/api/monitoring_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
HTTP API for Hindsight
77
8-
The version of the OpenAPI document: 0.4.2
8+
The version of the OpenAPI document: 0.4.3
99
Generated by OpenAPI Generator (https://openapi-generator.tech)
1010
1111
Do not edit the class manually.

0 commit comments

Comments
 (0)