MCPcopy
hub / github.com/dataelement/Clawith / workspace_locks

Function workspace_locks

backend/app/services/workspace_locking.py:57–80  ·  view source on GitHub ↗
(
    agent_id: uuid.UUID,
    paths: list[str],
    *,
    ttl_seconds: int = DEFAULT_LOCK_TTL_SECONDS,
)

Source from the content-addressed store, hash-verified

55
56@asynccontextmanager
57async def workspace_locks(
58 agent_id: uuid.UUID,
59 paths: list[str],
60 *,
61 ttl_seconds: int = DEFAULT_LOCK_TTL_SECONDS,
62):
63 normalized = sorted({_normalize_workspace_path(path) or "." for path in paths if path is not None})
64 owner_token = uuid.uuid4().hex
65 acquired: list[str] = []
66 try:
67 for path in normalized:
68 ok = await acquire_workspace_lock(
69 agent_id,
70 path,
71 owner_token=owner_token,
72 ttl_seconds=ttl_seconds,
73 )
74 if not ok:
75 raise RuntimeError(f"Workspace lock busy: {path}")
76 acquired.append(path)
77 yield
78 finally:
79 for path in reversed(acquired):
80 await release_workspace_lock(agent_id, path, owner_token=owner_token)

Callers 3

delete_workspace_fileFunction · 0.90
move_workspace_pathFunction · 0.90
flush_temp_workspaceFunction · 0.90

Calls 3

acquire_workspace_lockFunction · 0.85
release_workspace_lockFunction · 0.85

Tested by

no test coverage detected