Skip to content

fix(accountant): Fix the filter, keep-alive and TTL gates (#911, #912, #919) - #924

Closed
boazdavid wants to merge 4 commits into
feat/reland-accountantfrom
fix/accountant-gates
Closed

boazdavid wants to merge 4 commits into
feat/reland-accountantfrom
fix/accountant-gates

Conversation

@boazdavid

Copy link
Copy Markdown
Collaborator

Summary

This draft fixes three accountant gate bugs. It stacks on #923.

Behavior change (needs a human yes before merge): figures change. Filter requests and reads return for accountant-priced rows (dollars stay 0). Keep-alive rescue returns for keep-alive-only setups. A downgraded 1h tier now makes a 5-60 minute gap cold. Old rows keep the old gate.

What changed

Issue Problem Cause Fix Before / after
#911 Realized block missing. Items can sum to more than the total. declFilterNotPriced removed the whole row from the scan. An EXISTS flag column (declFilterInBaseline). accumulateDeclFilterRow(..., skipUSD) skips only the dollars. carriedCost does the same for items. Harness run_b2: decl_filter_requests 0 -> 3, decl_filter_reads 0 -> 7587, USD stays 0. Net unchanged (0.0030792).
#912 A keep-alive-only setup loses the rescue. kaSavedGate needed a request_components row with priced_by='accountant'. New column requests.acc_priced (additive, default 0), set when the override applied. The gate trusts the stored keepalive_saved_usd for those rows. The credited-row guard stays first. Harness (preset off, keep-alive on, expired entry): rescue $0 -> $0.0367, net -$0.0400 -> -$0.0033.
#919 The library credits the rescue and SQL re-gates it with a second model. Two definitions of "reachable". Same marker as #912. Rows with acc_priced = 0 (old rows, fallbacks) keep the SQL gate. See above.
#919 TTL A gateway that bills 5m for a 1h ask makes a 5-60 minute gap look hot. entryFacts ran before the billed tier was known. capture.accBilledTTL runs after the usage arrives and before Compute. It lowers the TTL and the breakpoint TTLs to 5m when the response billed a 5m write. A request that wrote nothing keeps the asked tier. Unit test: billed 5m, gap 20m is not hot. Billed 1h is hot.

Limit: SharedWarm is still judged with the asked TTL at accEnd. It matters only when another thread of the session touched the entry.

Docs: docs/dashboard.md and docs/data-dependence.md (new flag column acc_priced, a yes or no, no text).

How it was tested

  • Each fix has a test written first and seen to fail without the fix:
    • TestFilterCreditKeepsFactsAndSkipsDollarsForAccountantPricedRows
    • TestTheGateKeepsTheRescueOfALibraryPricedRequestWithNoComponentRows
    • TestTheGateTrustsTheLibraryForPricedRowsAndKeepsSQLForLegacyRows
    • TestKaSavedGateKeepsTheCreditGuardFirst (guard order and idx_requests_tenant_session)
    • TestAccountantPricedIsSetOnOverrideAndStored
    • TestTheEntryTTLFollowsTheBilledTier
  • TestDeclCreditSkipsRequestsTheAccountantPriced now expects 3 requests and 3000 reads (the priced row keeps its facts).
  • go test -count=1 ./dash/... ./proxy/... ./apply/... ./keepalive/... ./components/... passes. gofmt -l, go vet ./..., go build ./..., go mod tidy -diff are clean.
  • End to end with the fake upstream: base binary against this branch, same scenarios.

Assisted-By: Claude (Anthropic AI) [email protected]

…ws (#911)

The B2 double-count fix dropped a whole request from DeclFilterSavings when the
accountant priced its toolfilter removal. That also dropped Requests, Reads and
Since, so ToolFilterDocFor lost its Realized block and the item list in
adaptToolsSaved could sum to more than the total.

Now the row stays in the scan. An EXISTS flag column marks it and
accumulateDeclFilterRow skips only the USD. carriedCost does the same for the
items, so items and total agree.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: DAVID BOAZ <[email protected]>
…TTL by the billed tier (#912, #919)

kaSavedGate needed a request_components row with priced_by='accountant' to
accept a rescue the ping only wrote. A keep-alive-only setup stores no
component rows, so the rescue was zeroed again.

The request row now stores acc_priced (additive column, default 0), set when the
accountant override applied. The gate trusts keepalive_saved_usd of such a row
as the library's own decision. It is a plain column read placed after the
credited-row guard, so the probe order is unchanged. Rows with acc_priced = 0
keep the SQL gate.

The entry TTL given to the library was 1h when every breakpoint asked for it,
before the billed tier was known. accBilledTTL now lowers the TTL (and the
breakpoint TTLs) to 5m after the usage arrives, when the response billed a
5m write, before Compute runs.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: DAVID BOAZ <[email protected]>
@boazdavid

Copy link
Copy Markdown
Collaborator Author

Closed in favour of #930, the combined PR for the accountant integration. The commits of this PR are in #930. Nothing is lost: the branch stays. Assisted-By: Claude (Anthropic AI) [email protected]

@boazdavid boazdavid closed this Nov 8, 2026
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant