langgraph-runtime-inmem 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/.gitignore +0 -2
- {langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/PKG-INFO +1 -1
- {langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/__init__.py +1 -1
- {langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/lifespan.py +4 -1
- {langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/ops.py +115 -4
- {langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/queue.py +1 -1
- {langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/retry.py +4 -1
- {langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/Makefile +0 -0
- {langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/README.md +0 -0
- {langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/checkpoint.py +0 -0
- {langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/database.py +0 -0
- {langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/inmem_stream.py +0 -0
- {langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/metrics.py +0 -0
- {langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/store.py +0 -0
- {langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/pyproject.toml +0 -0
- {langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/uv.lock +0 -0
{langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/lifespan.py
RENAMED
|
@@ -28,9 +28,12 @@ async def lifespan(
|
|
|
28
28
|
from langgraph_api.js.ui import start_ui_bundler, stop_ui_bundler
|
|
29
29
|
from langgraph_api.metadata import metadata_loop
|
|
30
30
|
|
|
31
|
+
from langgraph_runtime_inmem import __version__ as langgraph_runtime_inmem_version
|
|
32
|
+
|
|
31
33
|
await logger.ainfo(
|
|
32
|
-
f"Starting In-Memory runtime with langgraph-api={__version__}",
|
|
34
|
+
f"Starting In-Memory runtime with langgraph-api={__version__} and in-memory runtime={langgraph_runtime_inmem_version}",
|
|
33
35
|
version=__version__,
|
|
36
|
+
langgraph_runtime_inmem_version=langgraph_runtime_inmem_version,
|
|
34
37
|
)
|
|
35
38
|
try:
|
|
36
39
|
current_loop = asyncio.get_running_loop()
|
{langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/ops.py
RENAMED
|
@@ -910,6 +910,117 @@ class Threads(Authenticated):
|
|
|
910
910
|
}
|
|
911
911
|
)
|
|
912
912
|
|
|
913
|
+
@staticmethod
|
|
914
|
+
async def set_joint_status(
|
|
915
|
+
conn: InMemConnectionProto,
|
|
916
|
+
thread_id: UUID,
|
|
917
|
+
run_id: UUID,
|
|
918
|
+
run_status: RunStatus | Literal["rollback"],
|
|
919
|
+
checkpoint: CheckpointPayload | None = None,
|
|
920
|
+
exception: BaseException | None = None,
|
|
921
|
+
) -> None:
|
|
922
|
+
"""Set the status of both thread and run atomically in a single query.
|
|
923
|
+
|
|
924
|
+
This is an optimized version that combines the logic from Threads.set_status
|
|
925
|
+
and Runs.set_status to minimize database round trips and ensure atomicity.
|
|
926
|
+
|
|
927
|
+
Args:
|
|
928
|
+
conn: Database connection
|
|
929
|
+
thread_id: Thread ID to update
|
|
930
|
+
run_id: Run ID to update
|
|
931
|
+
run_status: New status for the run (or "rollback" to delete the run)
|
|
932
|
+
checkpoint: Checkpoint payload for thread status calculation
|
|
933
|
+
exception: Exception that occurred (affects thread status)
|
|
934
|
+
"""
|
|
935
|
+
# No auth since it's internal
|
|
936
|
+
from langgraph_api.errors import UserInterrupt, UserRollback
|
|
937
|
+
|
|
938
|
+
thread_id = _ensure_uuid(thread_id)
|
|
939
|
+
run_id = _ensure_uuid(run_id)
|
|
940
|
+
|
|
941
|
+
def _thread_has_active_runs() -> bool:
|
|
942
|
+
return any(
|
|
943
|
+
r["thread_id"] == thread_id and r["status"] in ("pending", "running")
|
|
944
|
+
for r in conn.store["runs"]
|
|
945
|
+
)
|
|
946
|
+
|
|
947
|
+
thread = next(
|
|
948
|
+
(t for t in conn.store["threads"] if t["thread_id"] == thread_id), None
|
|
949
|
+
)
|
|
950
|
+
if thread is None:
|
|
951
|
+
raise HTTPException(status_code=404, detail=f"Thread {thread_id} not found")
|
|
952
|
+
|
|
953
|
+
run = next(
|
|
954
|
+
(
|
|
955
|
+
r
|
|
956
|
+
for r in conn.store["runs"]
|
|
957
|
+
if r["run_id"] == run_id and r["thread_id"] == thread_id
|
|
958
|
+
),
|
|
959
|
+
None,
|
|
960
|
+
)
|
|
961
|
+
if run is None:
|
|
962
|
+
raise HTTPException(status_code=404, detail=f"Run {run_id} not found")
|
|
963
|
+
|
|
964
|
+
has_next = bool(checkpoint and checkpoint["next"])
|
|
965
|
+
if exception and not isinstance(exception, UserInterrupt | UserRollback):
|
|
966
|
+
base_thread_status: ThreadStatus = "error"
|
|
967
|
+
elif has_next:
|
|
968
|
+
base_thread_status = "interrupted"
|
|
969
|
+
else:
|
|
970
|
+
base_thread_status = "idle"
|
|
971
|
+
|
|
972
|
+
interrupts = (
|
|
973
|
+
{
|
|
974
|
+
t["id"]: t["interrupts"]
|
|
975
|
+
for t in checkpoint["tasks"]
|
|
976
|
+
if t.get("interrupts")
|
|
977
|
+
}
|
|
978
|
+
if checkpoint
|
|
979
|
+
else {}
|
|
980
|
+
)
|
|
981
|
+
|
|
982
|
+
now = datetime.now(UTC)
|
|
983
|
+
|
|
984
|
+
if run_status == "rollback":
|
|
985
|
+
if "checkpoints" in conn.store:
|
|
986
|
+
cpts_to_del = [
|
|
987
|
+
c for c in conn.store["checkpoints"] if c["run_id"] == run_id
|
|
988
|
+
]
|
|
989
|
+
conn.store["checkpoints"] = [
|
|
990
|
+
c for c in conn.store["checkpoints"] if c["run_id"] != run_id
|
|
991
|
+
]
|
|
992
|
+
|
|
993
|
+
if "checkpoint_writes" in conn.store and cpts_to_del:
|
|
994
|
+
cpt_ids = {c["checkpoint_id"] for c in cpts_to_del}
|
|
995
|
+
conn.store["checkpoint_writes"] = [
|
|
996
|
+
cw
|
|
997
|
+
for cw in conn.store["checkpoint_writes"]
|
|
998
|
+
if cw["checkpoint_id"] not in cpt_ids
|
|
999
|
+
]
|
|
1000
|
+
|
|
1001
|
+
conn.store["runs"].remove(run)
|
|
1002
|
+
|
|
1003
|
+
final_thread_status: ThreadStatus = (
|
|
1004
|
+
"busy" if _thread_has_active_runs() else base_thread_status
|
|
1005
|
+
)
|
|
1006
|
+
|
|
1007
|
+
else:
|
|
1008
|
+
run.update({"status": run_status, "updated_at": now})
|
|
1009
|
+
|
|
1010
|
+
if run_status in ("pending", "running") or _thread_has_active_runs():
|
|
1011
|
+
final_thread_status = "busy"
|
|
1012
|
+
else:
|
|
1013
|
+
final_thread_status = base_thread_status
|
|
1014
|
+
|
|
1015
|
+
thread.update(
|
|
1016
|
+
{
|
|
1017
|
+
"updated_at": now,
|
|
1018
|
+
"values": checkpoint["values"] if checkpoint else None,
|
|
1019
|
+
"interrupts": interrupts,
|
|
1020
|
+
"status": final_thread_status,
|
|
1021
|
+
}
|
|
1022
|
+
)
|
|
1023
|
+
|
|
913
1024
|
@staticmethod
|
|
914
1025
|
async def delete(
|
|
915
1026
|
conn: InMemConnectionProto,
|
|
@@ -1002,7 +1113,7 @@ class Threads(Authenticated):
|
|
|
1002
1113
|
# Add new thread to store
|
|
1003
1114
|
conn.store["threads"].append(new_thread)
|
|
1004
1115
|
|
|
1005
|
-
checkpointer = Checkpointer(
|
|
1116
|
+
checkpointer = Checkpointer()
|
|
1006
1117
|
copied_storage = _replace_thread_id(
|
|
1007
1118
|
checkpointer.storage[str(thread_id)], new_thread_id, thread_id
|
|
1008
1119
|
)
|
|
@@ -1133,7 +1244,7 @@ class Threads(Authenticated):
|
|
|
1133
1244
|
Auth.types.ThreadsUpdate(thread_id=thread_id),
|
|
1134
1245
|
)
|
|
1135
1246
|
|
|
1136
|
-
checkpointer = Checkpointer(
|
|
1247
|
+
checkpointer = Checkpointer()
|
|
1137
1248
|
|
|
1138
1249
|
thread_iter = await Threads.get(conn, thread_id, ctx=ctx)
|
|
1139
1250
|
thread = await fetchone(
|
|
@@ -1246,7 +1357,7 @@ class Threads(Authenticated):
|
|
|
1246
1357
|
async with get_graph(
|
|
1247
1358
|
graph_id,
|
|
1248
1359
|
thread_config,
|
|
1249
|
-
checkpointer=Checkpointer(
|
|
1360
|
+
checkpointer=Checkpointer(),
|
|
1250
1361
|
store=(await get_store()),
|
|
1251
1362
|
) as graph:
|
|
1252
1363
|
next_config = await graph.abulk_update_state(
|
|
@@ -2250,7 +2361,7 @@ def _delete_checkpoints_for_thread(
|
|
|
2250
2361
|
conn: InMemConnectionProto,
|
|
2251
2362
|
run_id: str | UUID | None = None,
|
|
2252
2363
|
):
|
|
2253
|
-
checkpointer = Checkpointer(
|
|
2364
|
+
checkpointer = Checkpointer()
|
|
2254
2365
|
thread_id = str(thread_id)
|
|
2255
2366
|
if thread_id not in checkpointer.storage:
|
|
2256
2367
|
return
|
{langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/queue.py
RENAMED
|
@@ -129,7 +129,7 @@ async def queue():
|
|
|
129
129
|
if do_sweep:
|
|
130
130
|
last_sweep_secs = loop.time()
|
|
131
131
|
run_ids = await ops.Runs.sweep(conn)
|
|
132
|
-
logger.info("
|
|
132
|
+
logger.info("Swept runs", run_ids=run_ids)
|
|
133
133
|
except Exception as exc:
|
|
134
134
|
# keep trying to run the scheduler indefinitely
|
|
135
135
|
logger.exception("Background worker scheduler failed", exc_info=exc)
|
{langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/retry.py
RENAMED
|
@@ -11,7 +11,10 @@ class RetryableException(Exception):
|
|
|
11
11
|
pass
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
RETRIABLE_EXCEPTIONS: tuple[type[BaseException], ...] = (
|
|
14
|
+
RETRIABLE_EXCEPTIONS: tuple[type[BaseException], ...] = (
|
|
15
|
+
RetryableException,
|
|
16
|
+
asyncio.CancelledError,
|
|
17
|
+
)
|
|
15
18
|
OVERLOADED_EXCEPTIONS: tuple[type[BaseException], ...] = ()
|
|
16
19
|
|
|
17
20
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/database.py
RENAMED
|
File without changes
|
|
File without changes
|
{langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/metrics.py
RENAMED
|
File without changes
|
{langgraph_runtime_inmem-0.2.0 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/store.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|