MCPcopy
hub / github.com/arc53/DocsGPT / _mark_executed

Function _mark_executed

application/agents/tool_executor.py:84–135  ·  view source on GitHub ↗

Flip the row to ``executed``. If ``proposed_ok`` is False (the proposed write failed earlier), upsert a fresh row in ``executed`` so the reconciler can still see the attempt — without this, the side effect would be invisible to the journal. Both paths are scoped to the owning ``user_

(
    call_id: str,
    result: Any,
    *,
    message_id: Optional[str] = None,
    artifact_id: Optional[str] = None,
    proposed_ok: bool = True,
    tool_name: Optional[str] = None,
    action_name: Optional[str] = None,
    arguments: Any = None,
    tool_id: Optional[str] = None,
    user_id: Optional[str] = None,
    agent_id: Optional[str] = None,
)

Source from the content-addressed store, hash-verified

82
83
84def _mark_executed(
85 call_id: str,
86 result: Any,
87 *,
88 message_id: Optional[str] = None,
89 artifact_id: Optional[str] = None,
90 proposed_ok: bool = True,
91 tool_name: Optional[str] = None,
92 action_name: Optional[str] = None,
93 arguments: Any = None,
94 tool_id: Optional[str] = None,
95 user_id: Optional[str] = None,
96 agent_id: Optional[str] = None,
97) -> None:
98 """Flip the row to ``executed``. If ``proposed_ok`` is False (the
99 proposed write failed earlier), upsert a fresh row in ``executed`` so
100 the reconciler can still see the attempt — without this, the side
101 effect would be invisible to the journal. Both paths are scoped to
102 the owning ``user_id`` so a reused ``call_id`` can't cross tenants.
103 """
104 try:
105 with db_session() as conn:
106 repo = ToolCallAttemptsRepository(conn)
107 if proposed_ok:
108 updated = repo.mark_executed(
109 call_id,
110 result,
111 message_id=message_id,
112 artifact_id=artifact_id,
113 user_id=user_id,
114 )
115 if updated:
116 return
117 # Fallback synthesizes the row so the journal isn't lost.
118 repo.upsert_executed(
119 call_id,
120 tool_name=tool_name or "unknown",
121 action_name=action_name or "",
122 arguments=arguments if arguments is not None else {},
123 result=result,
124 tool_id=tool_id if tool_id and looks_like_uuid(tool_id) else None,
125 message_id=message_id,
126 artifact_id=artifact_id,
127 user_id=user_id,
128 agent_id=(
129 str(agent_id)
130 if agent_id and looks_like_uuid(str(agent_id))
131 else None
132 ),
133 )
134 except Exception:
135 logger.exception("tool_call_attempts executed write failed for %s", call_id)
136
137
138def _mark_failed(call_id: str, error: str, *, user_id: Optional[str] = None) -> None:

Callers 1

executeMethod · 0.85

Calls 5

mark_executedMethod · 0.95
upsert_executedMethod · 0.95
db_sessionFunction · 0.90
looks_like_uuidFunction · 0.90

Tested by

no test coverage detected