caelum0x 20193a0b8d fix(agent): a real, nil-error bridge-funding decline was misclassified as a grant in the audit trail
tools.go's handleRationBridgeFunding tagged EVERY nil-error gateway
response as AGENT_ACTION_RATION_BRIDGE, even when GrantedMinorUnits was
0. bridge.Service.RationBridgeFunding has three documented paths that
return exactly that shape (below the $5 minimum-useful-grant floor —
including its own independent, ledger-entry-based velocity check
disagreeing with this agent's decision-history-based
hasOpenGrantWithinWindow — a ledger-core-rechecked reserve-floor
violation, or "deposit already received"). None of those is a Go
error, so every one of them was recorded as if money had actually
moved.

This both corrupted the audit trail (a "granted $0" decision labeled
as a bridge grant) and fed hasOpenGrantWithinWindow's wasActuallyGranted
check a false "actually executed" signal, since the snapshot map always
carries a granted_minor_units key even at 0 — permanently
velocity-capping a tenant that was never actually granted anything, the
same fund-stranding-via-misclassification failure mode round 6 fixed
via a missing deposit_id, reached here instead via a wrong action tag.

Fix: tag the decision AGENT_ACTION_DECLINE whenever
GrantedMinorUnits <= 0, regardless of error.

Reproduced live against the real running stack (real auth + ledger-core,
real RecordAgentDecision/ListAgentDecisions, a stubbed gateway forcing
the exact zero-grant/nil-error response) before fixing, and confirmed
fixed the same way afterward. New regression tests in runner_test.go
cover both the misclassification itself and its downstream
velocity-cap consequence; both fail on the pre-fix code and pass after.
2026-10-29 19:28:51 +03:00
..