Skip to content

feat(settlement): add a cross-service agent settlement summary view - #322

Merged
mikewheeleer merged 1 commit into
Agentpay-Org:mainfrom
thlpkee20-wq:feature/settlement-01-view
Jul 28, 2026
Merged

feat(settlement): add a cross-service agent settlement summary view#322
mikewheeleer merged 1 commit into
Agentpay-Org:mainfrom
thlpkee20-wq:feature/settlement-01-view

Conversation

@thlpkee20-wq

Copy link
Copy Markdown
Contributor

Closes #298

`get_last_settlement` (per `(agent, service_id)`) and
`get_billing_summary` already exist as read views. Adds
`AgentSettlementSummary { total_settled, outstanding_services,
last_settlement }` and `get_agent_settlement_summary(agent)`, combining
the agent's lifetime settled total with one bounded pass over their
active-service index (capped at `MAX_AGENT_SERVICE_INDEX`) to count
outstanding services and find the most recent settlement stamp among
currently-indexed services. Pure read; defaults to zero/`None` for an
unseen agent, never panics.

Caveat documented on the struct: `settle()` deindexes a service once
drained, so `last_settlement` only reflects `settle_all()` sweeps
(which do not deindex) or services still carrying nonzero usage; use
`get_last_settlement` for the authoritative per-pair timestamp
regardless of index membership. (I initially assumed `last_settlement`
would reflect any settle call and had to correct both the doc comment
and the tests once I hit this — see the test names below.)

Adds 4 tests: defaults for an unseen agent, outstanding-count tracking
through an individual `settle()` (which deindexes and drops out of
`last_settlement`), and `last_settlement` correctly reflecting a
`settle_all()` timestamp.

Test plan

get_last_settlement (per (agent, service_id)) and get_billing_summary
already exist as read views. Adds AgentSettlementSummary { total_settled,
outstanding_services, last_settlement } and
get_agent_settlement_summary(agent), combining the agent's lifetime
settled total with one bounded pass over their active-service index
(capped at MAX_AGENT_SERVICE_INDEX) to count outstanding services and
find the most recent settlement stamp among currently-indexed services.
Pure read; defaults to zero/None for an unseen agent, never panics.

Caveat documented on the struct: settle() deindexes a service once
drained, so last_settlement only reflects settle_all() sweeps (which do
not deindex) or services still carrying nonzero usage; use
get_last_settlement for the authoritative per-pair timestamp regardless
of index membership.

Adds 4 tests covering: defaults for an unseen agent, outstanding-count
tracking through an individual settle() (which deindexes and drops out
of last_settlement), and last_settlement correctly reflecting a
settle_all() timestamp.
@mikewheeleer

Copy link
Copy Markdown
Contributor

well done @thlpkee20-wq, this reads well. merging in 🌟

@mikewheeleer
mikewheeleer merged commit 3d12463 into Agentpay-Org:main Jul 28, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a read-only view exposing the current settlement state

2 participants