Repository navigation
feat(accounting): report client compaction to the accountant (#2137) - #2145
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 43 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
…l#2137) The context-guru thread tracker marks the first request after a client compaction (thread.Result.AfterCompaction), but Cortex never told the accountant. RequestMeta.Compaction was always empty, so Result.Compaction was always nil. - pipeline: add pctx.SetClientCompaction and ClientCompaction. - contextguru: resolveThread sets "unknown" when AfterCompaction is set. It does not use IsClientCompaction: that is true on the compaction request itself, and R55 wants the request after it. - accounting: RequestEnd copies the verdict into RequestMeta.Compaction. Host.Savings copies Result.Compaction into Extras.Compaction. - cost/event: add Event.Compaction (trigger, ended ChangeIDs). The inference parser writes it on the cost record. A compaction alone is a reason to publish a record. No figure or total reads it. - docs: describe the verdict and the record field in the integration design (sections 5.4 and 5.5). Fixes rossoctl#2137 Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: DAVID BOAZ <DAVIDBO@il.ibm.com>
9be934f to
7637f3d
Compare
clawgenti
left a comment
There was a problem hiding this comment.
Summary
This wires the client-compaction verdict through to the accountant: context-guru's resolveThread sets unknown on the request thread.Result.AfterCompaction marks, the host passes it as RequestMeta.Compaction, and Result.Compaction comes back on the cost record as event.Event.Compaction. That is the same rule context-guru's proxy uses. Using AfterCompaction instead of IsClientCompaction, as the issue proposed, is correct, because R55 wants the request that holds the summary. I found no must-fix issues.
What I checked locally on head 7637f3d:
go build ./...passes incore,cmd/cortexandcmd/agentop.go vetis clean on the touched packages, andgofmt -lprints nothing.core/accounting,core/cost/event,core/pipeline,core/plugins/contextguruandcore/plugins/inferenceparserpass.core/cost/ledgerandcore/cost/usagefail only in theAmerica/HavanaDST tests, which depend on the machine's tzdata and have nothing to do with this diff. That matches the PR description.- The claimed fix works. With the
res.AfterCompactionblock removed fromthread.go,TestOnRequest_ReportsTheRequestAfterAClientCompactionfails (first request after: ClientCompaction = "", want "unknown"). With it, the test passes. - Decoder safety:
Compactionis a new optional pointer field (omitempty). Older records have nocompactionkey and still decode. No consumer decodes cost events withDisallowUnknownFields, and no other producer writes acompactionkey in another shape. The pinned-wire and field-count tests are updated.Endedis copied into a non-nil slice, so it serializes as[]. SetClientCompactionignores an empty value, so a later plugin cannot clear the verdict. With no context-guru plugin, nothing is set and nothing changes.
Not a blocker: no view shows the record yet. As the PR says, that can be a follow-up (the issue's proposal 2).
Author: boazdavid (CONTRIBUTOR association, repo admin permission: maintainer)
Areas reviewed: Go (accounting host, pipeline context, context-guru plugin, inference parser, cost event wire format), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: pending at review time (DCO, Trivy, Dependency Review, YAML Lint, Hadolint, CodeQL python and action pinning pass; Go CI still running). Verified locally as above.
clawgenti
left a comment
There was a problem hiding this comment.
Summary
Follow-up to review 6071652911 at this same head (7637f3d), which a concurrent run of this program posted while this run was drafting; the two reviews are independent and I found no distinct finding to add to it. This body is here for two reasons: to record that the second review at this head is a duplicate rather than a second opinion, and to carry the <!-- reviewed --> marker the program needs so the PR stops being re-queued every cycle (the earlier review has none).
For completeness, what I verified myself before seeing the other review: go test on core/accounting, core/pipeline and core/cost/event at head; and a positive control — deleting Compaction: pctx.ClientCompaction(), from Host.RequestEnd fails both TestHost_ReportsClientCompaction and TestHost_SavingsCarriesTheCompactionRecord (RequestMeta.Compaction = "", want "unknown"), so the tests do catch the wiring. The line was restored. I also confirmed compactionRecord copies Ended into a fresh slice, so a nil Ended serialises as [] and never null, and that the publish gate in settleCost only adds a reason to publish.
Author: boazdavid (CONTRIBUTOR — returning external)
Areas reviewed: Go (accounting host, pipeline context, cost/event wire format, inferenceparser), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: Go CI mostly green at this head, with a few jobs still in progress at review time (DCO pass, CodeRabbit skipped)
Not checked:
core/plugins/contextgurutests —github.com/rossoctl/context-guru v0.7.9is not in this sandbox's module cache and the module proxy is unreachable, soTestOnRequest_ReportsTheRequestAfterAClientCompactioncould not be run here; theaccountingside of the wiring was run.cmd/cortexbuild — same missing module.
Generated by repoman github-pr-review@af425c8.
Summary
Cortex now tells the accountant when a request is the first one after a client compaction (
/compactor auto). The accountant then lists the savings that the compaction ended, and Cortex writes that list on the cost record. Before this change,Result.Compactionwas always nil.Fixes #2137.
What changed
core/pipeline: newpctx.SetClientCompactionandClientCompaction. They work likeSetAccountingThread. An empty value does not erase a set one.core/plugins/contextguru:resolveThreadsetsunknownwhen the thread tracker setsAfterCompaction. This is the rule of context-guru's proxy (compactionVerdict).core/accounting:RequestEndcopies the verdict intoRequestMeta.Compaction.Host.SavingscopiesResult.CompactionintoExtras.Compaction.core/cost/event: newEvent.Compaction, for example"compaction":{"trigger":"unknown","ended":["test:big"]}. It is omitted when there was no compaction. No figure or total reads it.core/plugins/inferenceparser: writesExtras.Compactionon the cost record. A compaction alone is a reason to publish a record, as a spend is.The fix does not use
agentall.IsClientCompaction, as the issue proposes.thread.Result.AfterCompactionmarks that request.How it was tested
TestOnRequest_ReportsTheRequestAfterAClientCompactionruns 4 requests through the plugin: a first turn, the compaction request, the first request after, and a next turn. Only the first request after getsunknown. Without the change inresolveThread, the test fails.TestHost_ReportsClientCompaction: the verdict reachesRequestMeta.Compaction, and the accountant answers withResult.Compaction. A plain request gets neither.TestHost_SavingsCarriesTheCompactionRecord: request 1 removes a tool (test:big). Request 2 comes after a compaction without that tool.Extras.Compactionis{unknown, [test:big]}.TestSettleCost_PublishesTheCompactionRecord: a request with only a compaction record still gets a cost record.TestEvent_CompactionWireandTestEventJSONTagsArePinned_EveryFieldfix the JSON shape.endedis[], notnull.gofmt -l core cmdprints nothing.go vetis clean incore,cmd/agentopandcmd/cortex.go test ./...:cmd/cortexandcmd/agentoppass. Thecmd/agentoproot package takes about 985 s on this Mac, so it needs-timeout 30m.corepasses exceptcore/cost/ledgerandcore/cost/usage. Both fail onmaintoo, because the DST tests forAmerica/Havanado not match this Mac's time-zone data.Open questions
usage.Countsfields, and that can be a follow-up.Technical notes
unknown. The wire does not tell a manual/compactfrom an auto compaction.Assisted-By: Claude (Anthropic AI) noreply@anthropic.com