cog_revenue() offers expenditure recipes as suggestions: scope the candidate query by category_type #34
Closed
opened 2026-08-05 08:23:05 -04:00 by jared
·
1 comment
No Branch/Tag Specified
main
ci/mirror-canonical-tags
chore/release-47-badges-mirror-pr
docs/readme-perf-remeasure-56
feat/pagination-search-balances-57
feat/duckdb-threads-60
feat/cohort-predicates-58
fix/windows-backslash-paths
ci/mirror-to-github
ci/github-actions-matrix
feat/public-release-0.3.0
chore/fixture-sb203
ci/apt-https
fix/pushdown-pagination
feat/all-categories-37
fix/partial-coverage-signposting-9
fix/schema-v7
fix/cog-categories-balance-subtype
feat/cog-balances-25
feat/revenue-concepts-12
feat/expenditure-concepts-11
feat/coverage-disclosure-13
feat/complete-argument-18
fix/kodor-batch-14-15-16
fix/all-scoped-series-breaks-19
fix/regen-fixture-corpus-18
test/walkthrough-findings
feat/expenditure-concept
fix/3-url-trailing-slash
feat/phase-r3-signposting
fix/fixture-option-b-aggregates
feat/phase-r2-harmonization
feat/phase-r1-forward
feat/cog-gov-search-basket-mode
v0.4.0
Labels
Clear labels
kodor
kodor/feature-proposal
kodor/fix
kodor/needs-review
kodor/triaged
madison-walkthrough
severity/high
severity/low
severity/medium
south-guide
verdict/defect
verdict/definitional
kodor
kodor/feature-proposal
kodor/fix
kodor/needs-review
kodor/triaged
Kodor should process this issue
Kodor has written a feature proposal
Kodor should implement a fix (assigned to Kodor)
Kodor's work or failure needs Jared's review
Kodor has already triaged this issue (skip)
Surfaced while building the client-facing Southern API guide
needs
human
Cannot move without a person -- a decision, a check an agent cannot make, something outside the repo
origin
client
Came from a client ask
origin
obligation
Created by a change elsewhere
origin
review
Came from human review
origin
roborev
Promoted from a roborev finding
type
chore
Maintenance with no behaviour change
type
debt
Owed work -- docs, tests, cleanup a change obligated
type
decision
Needs a decision before work can proceed
type
defect
Something is wrong
type
feature
New capability
ws
api
Query verbs and results
ws
corpus
Corpus, mirror, provenance
ws
docs
Vignettes and guides
Assign a task to kodor
Kodor thinks this needs a feature.
Kodor should fix this
Kodor thinks the user is ready to review this.
Kodor is done with this issue.
Milestone
No items
No Milestone
Projects
Clear projects
No projects
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: Civilytics/uscogdata#34
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Deferred half of finding I1 from the uscogdata#9 final review (PR #32). Owner ruled: ship the minimal flow-prefix fix in #9, track the principled fix here.
What #9 fixed
.suppressed_components()measured every component of a candidate recipe against the calling verb's own view. Candidates were filtered only for M/L recipes, never for flow family, so a component belonging to the other verb was always absent from this verb's view and got reported as suppressed. Measured before the fix:Those dollars are fully reachable —
cog_spending()for the same gov/years/category returns $3,691,029,000. Nothing was suppressed. #9 fixed the fabricated dollar figure by filtering the measurement onLEFT(r.component_code, 1) IN (<verb flow_prefixes>).What is still wrong
The suggestion itself still fires.
cog_revenue(category = "Corrections")still surfaces the three corrections recipes astrigger = "empty_year", because the candidate query atR/suggestions.Rselects recipes bysummary_categoriesmembership without regard tocategory_type. A revenue verb should never have offered an expenditure category in the first place.This is pre-existing behavior, older than #9.
The fix
Scope the candidate query's
summary_categorieslookup by the verb's owncategory_type.Why it was deferred
It changes behavior beyond the #9 bug, and it breaks assertions in
tests/testthat/test-expenditure-concept.Rthat deliberately use a mis-scopedcog_spending(category = "IG Federal")to exercise the M/L counterpart logic (ig_federal_b47_widefiring for real in the fixture is what makes those tests non-theoretical). Those tests need rethinking as part of this change, not as a side effect of a bug fix.Also worth folding in:
suppressed_codesunder spending currently excludesJ67/J68as a side effect of the flow-prefix filter. Harmless today (they are in the view in every year they exist), but it is a wart the category_type approach would not have.Re-scoping, not closing: the performance framing is dead, the defect is not
#56 step 3 asked that this be absorbed if profiling confirmed it, or closed as speculative
if not. Neither is quite right, because #56 mis-files what this issue is.
The performance framing is retired. #56 lists this under "performance findings filed
before anyone was measuring." The measurement is now in: the whole R-side verb pipeline
sums to tens of milliseconds against seconds of remote HTTP, so a too-broad candidate
query is not on anyone's critical path. Do not do this for speed. (#35 was the genuinely
perf-shaped sibling and has been closed on the same evidence.)
The defect is untouched by any of that. The body of this issue is a correctness
problem:
A revenue verb should never offer an expenditure category's recipes. #9 fixed the
fabricated dollar figure by filtering the measurement on the verb's
flow_prefixes;the suggestion itself still fires, because the candidate query selects recipes by
summary_categoriesmembership without regard tocategory_type. That is pre-existingbehaviour, older than #9, and it is wrong regardless of how fast it is.
It is also a trust problem more than a latency one, which is the real reason to keep
it open: a suggestion block that names categories from the wrong flow teaches a user that
provenance output is noise to skim past. That costs more than 12 ms.
Retitling accordingly
Scope the suggestion candidate query by the verb's category_type→ the fix is unchanged,but the justification is correctness, so it is not re-triaged as a performance nice-to-have
and dropped next time someone sorts by impact.
The deferral reason recorded here still stands and is the actual work: it breaks
assertions in
tests/testthat/test-expenditure-concept.Rthat deliberately use amis-scoped
cog_spending(category = "IG Federal")to exercise the M/L counterpart logic.Those tests need rethinking as part of this change, which is why it was not folded into a
bug fix.
Scope the suggestion candidate query by the verb's category_typeto cog_revenue() offers expenditure recipes as suggestions: scope the candidate query by category_typejared referenced this issue2026-08-23 16:14:53 -04:00