langgraph-runtime-inmem 0.2.1__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.
Files changed (16) hide show
  1. {langgraph_runtime_inmem-0.2.1 → langgraph_runtime_inmem-0.3.0}/.gitignore +0 -2
  2. {langgraph_runtime_inmem-0.2.1 → langgraph_runtime_inmem-0.3.0}/PKG-INFO +1 -1
  3. {langgraph_runtime_inmem-0.2.1 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/__init__.py +1 -1
  4. {langgraph_runtime_inmem-0.2.1 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/ops.py +115 -4
  5. {langgraph_runtime_inmem-0.2.1 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/queue.py +1 -1
  6. {langgraph_runtime_inmem-0.2.1 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/retry.py +4 -1
  7. {langgraph_runtime_inmem-0.2.1 → langgraph_runtime_inmem-0.3.0}/Makefile +0 -0
  8. {langgraph_runtime_inmem-0.2.1 → langgraph_runtime_inmem-0.3.0}/README.md +0 -0
  9. {langgraph_runtime_inmem-0.2.1 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/checkpoint.py +0 -0
  10. {langgraph_runtime_inmem-0.2.1 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/database.py +0 -0
  11. {langgraph_runtime_inmem-0.2.1 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/inmem_stream.py +0 -0
  12. {langgraph_runtime_inmem-0.2.1 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/lifespan.py +0 -0
  13. {langgraph_runtime_inmem-0.2.1 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/metrics.py +0 -0
  14. {langgraph_runtime_inmem-0.2.1 → langgraph_runtime_inmem-0.3.0}/langgraph_runtime_inmem/store.py +0 -0
  15. {langgraph_runtime_inmem-0.2.1 → langgraph_runtime_inmem-0.3.0}/pyproject.toml +0 -0
  16. {langgraph_runtime_inmem-0.2.1 → langgraph_runtime_inmem-0.3.0}/uv.lock +0 -0
@@ -2,7 +2,6 @@
2
2
  .env.gcp.yaml
3
3
  postgres-volume/
4
4
  redis-volume/
5
- backend/ui
6
5
 
7
6
  # Operating System generated files
8
7
  .DS_Store
@@ -63,5 +62,4 @@ pnpm-debug.log*
63
62
  .ipynb_checkpoints
64
63
  *.ipynb
65
64
  .editorconfig
66
- *.sql
67
65
  *.db
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langgraph-runtime-inmem
3
- Version: 0.2.1
3
+ Version: 0.3.0
4
4
  Summary: Inmem implementation for the LangGraph API server.
5
5
  Author-email: Will Fu-Hinthorn <will@langchain.dev>
6
6
  License: Elastic-2.0
@@ -9,7 +9,7 @@ from langgraph_runtime_inmem import (
9
9
  store,
10
10
  )
11
11
 
12
- __version__ = "0.2.1"
12
+ __version__ = "0.3.0"
13
13
  __all__ = [
14
14
  "ops",
15
15
  "database",
@@ -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(conn)
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(conn)
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(conn),
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(conn)
2364
+ checkpointer = Checkpointer()
2254
2365
  thread_id = str(thread_id)
2255
2366
  if thread_id not in checkpointer.storage:
2256
2367
  return
@@ -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("Sweeped runs", run_ids=run_ids)
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)
@@ -11,7 +11,10 @@ class RetryableException(Exception):
11
11
  pass
12
12
 
13
13
 
14
- RETRIABLE_EXCEPTIONS: tuple[type[BaseException], ...] = (RetryableException,)
14
+ RETRIABLE_EXCEPTIONS: tuple[type[BaseException], ...] = (
15
+ RetryableException,
16
+ asyncio.CancelledError,
17
+ )
15
18
  OVERLOADED_EXCEPTIONS: tuple[type[BaseException], ...] = ()
16
19
 
17
20