ajuste no contas

This commit is contained in:
T3782834
2026-09-01 11:24:03 -03:00
parent 9ed4782f9d
commit 397b831fd3
428 changed files with 2294 additions and 4648 deletions

View File

@@ -423,8 +423,52 @@ class AgentWorkflow:
):
boundary_pending = bool(state.get("operational_context_boundary_pending"))
tx_status = str(state.get("transaction_status") or "").strip().upper()
terminal_interaction = tx_status in {"COMPLETED", "FAILED", "CANCELLED", "BLOCKED", "OUT_OF_SCOPE"}
reset_operational_context = boundary_pending or terminal_interaction
active_tx = state.get("active_transaction") if isinstance(state.get("active_transaction"), dict) else {}
active_tx_status = str(active_tx.get("status") or "").strip().upper()
nonterminal_tx_statuses = {
"COLLECTING_PARAMETERS",
"AWAITING_CONFIRMATION",
"EXECUTING",
"PAUSED",
"WAITING_INPUT",
}
# A new active transaction has precedence over terminal evidence from
# the previous transaction in the same session. Without this guard,
# a stale state["transaction_status"] == COMPLETED can tombstone an
# AWAITING_CONFIRMATION transaction that was just opened in the
# current turn.
active_transaction_pending = bool(active_tx) and active_tx_status in nonterminal_tx_statuses
# A confirmation latch is itself authoritative live transaction state.
# Depending on checkpoint serialization/order, active_transaction may
# not yet be rehydrated while pending_tool_call + confirmation_required
# are present. Never let terminal evidence from the previous transaction
# tombstone a valid confirmation for the new one.
pending_call = state.get("pending_tool_call") if isinstance(state.get("pending_tool_call"), dict) else {}
pending_confirmation = bool(
state.get("confirmation_required")
and pending_call.get("tool_name")
and isinstance(pending_call.get("arguments"), dict)
)
if pending_confirmation and not active_transaction_pending:
pending_args = dict(pending_call.get("arguments") or {})
active_tx = {
"transaction_id": str(pending_args.get("transaction_id") or state.get("transaction_id") or ""),
"tool_name": str(pending_call.get("tool_name") or ""),
"arguments": pending_args,
"status": "AWAITING_CONFIRMATION",
}
state["active_transaction"] = active_tx
state["transaction_status"] = "AWAITING_CONFIRMATION"
tx_status = "AWAITING_CONFIRMATION"
active_tx_status = "AWAITING_CONFIRMATION"
active_transaction_pending = True
terminal_interaction = (
tx_status in {"COMPLETED", "FAILED", "CANCELLED", "BLOCKED", "OUT_OF_SCOPE"}
and not active_transaction_pending
)
reset_operational_context = (boundary_pending or terminal_interaction) and not active_transaction_pending
# The durable history/checkpoint is preserved, but the first turn
# after a completed workflow must look operationally like a fresh