Skip to content

fix(finance): use frozen currency basis for fixed request costs - #807

Closed
LIghtJUNction wants to merge 60 commits into
wip/rust-core-go-extensionsfrom
fix/finance-frozen-currency-history-20261012
Closed

LIghtJUNction wants to merge 60 commits into
wip/rust-core-go-extensionsfrom
fix/finance-frozen-currency-history-20261012

Conversation

@LIghtJUNction

@LIghtJUNction LIghtJUNction commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

开发主线交接(2026-10-12)

开发默认主线现为 wip/rust-core-go-extensions;旧单体 main 与 traditional 冻结于 3948a0a1ee1cefdd016a7aa45a11851545bb4b85。分支交接不是发布、部署或验收通过。原问题、源码基线、测试与未完成项保留;旧单体路径仅作历史证据,后续先在微服务源码重新确认并按职责移植,不回灌旧数据库/权限/资金实现。

主线/S11 跟踪:#895。Extore 商品同步:#894,未验收,禁止部署,尤其禁止合并/推送 Extore main。

本 PR 原目标为旧单体 main,现转向微服务主线。只修改审查目标,尚未完成移植或验收,不可直接合并;须解决跨架构差异/冲突并完成本地验证,保留其他任务的改动。

变更说明 / Summary

The finance overview treated a fixed per-call model_price as a token rate whenever a consume log contained token counters. A charged call priced at USD 0.02 with 1,500 tokens produced 30 USD micros instead of 20,000. Tokenless calls also assumed that the raw historical price was already USD.

Estimate fixed prices once per charged request, independently of token counters. Accept explicit schema 2 USD prices or convert legacy prices with the log's frozen pricing_unit_credits_per_unit (Q) and pricing_credits_per_usd (K): price * Q / K. Use decimal arithmetic, round once to USD micros, and reject values outside int64. Unknown currency evidence, invalid modes, and ratio/tiered pricing remain unpriced; current FX and current credit anchors never fill missing historical evidence.

This changes the read-only finance estimate. Original logs, quota integers, wallet balances, payment settlement, and billing behavior are preserved. Expense/profit estimates can change where the previous projection used the wrong units. This focused repair does not add ratio/tiered cost reconstruction or resolve pre-existing aggregate accumulator overflow risks.

与上游的关系 / Upstream relationship

  • LMM API 独有变更 / LMM API-specific change
  • 上游尚未合并的修复或功能 / Change not yet merged upstream
  • 同步或移植上游变更 / Upstream sync or backport
  • 不适用(文档、CI、仓库维护等)/ Not applicable

上游参考 / Upstream reference: N/A; this repairs the project's finance projection against its existing fixed-price settlement and frozen pricing metadata contracts.

关联 Issue / Related issue

N/A. Related finance/frozen currency issues and PRs were searched before opening this focused repair.

变更类型 / Type of change

  • Bug 修复 / Bug fix
  • 新功能 / Feature
  • 重构或性能优化 / Refactor or performance
  • 前端或交互 / Frontend or UX
  • 部署、CI 或构建 / Deployment, CI, or build
  • 文档或仓库维护 / Documentation or maintenance

验证 / Verification

All checks ran locally on signed commit 8003a8909aa848b309044f61662630625904dacd, with a clean source tree before and after. From apps/api-go:

go test -json ./controller -run 'Test(Finance|SubscriptionFinance)' -count=1
PASS: 29 top-level tests and 43 subtests (72 passing checks), zero skips.

go vet ./controller
PASS

CGO_ENABLED=0 go build -trimpath -ldflags='-s -w' -o /home/lightjunction/.local/state/lmm-api/finance-currency-audit-20261012/lmm-api-go .
PASS

Changed-file gofmt -l and git diff --check HEAD^ HEAD also passed. Independent read-only source review passed.

Regression cases cover fixed prices with and without tokens; frozen old/current and fractional Q/K; missing or malformed currency evidence; unsupported or malformed billing modes; non-finite and overflowing values; half-micro rounding; zero/negative quota; independence from current K/Q/FX and an uninitialized current anchor; matching overview/user/daily expense totals; and unchanged historical logs and wallet credits. Existing finance export, payment-method filtering, refund, and subscription finance tests also passed.

Tests use local SQLite fixtures. Full repository/Web/deployment suites and CI were not rerun because the only changes are the finance controller's read-only projection and its tests. This PR does not claim PostgreSQL, browser, or production acceptance, and contains no production migration or write.

截图或日志 / Screenshots or logs

N/A; no UI or response schema changes. Local test results are recorded above.

提交检查 / Checklist

  • 我已搜索本仓库的 Issues 和 PRs,确认没有重复工作。
  • 此 PR 只包含与当前目标相关的改动,未混入格式化或其他无关变更。
  • 我已说明该变更对当前产品流程或兼容行为的影响,并保留必要的来源、版权和许可证信息。
  • 我已检查兼容性;如有破坏性变化,已在说明中明确列出迁移方式。
  • 我已补充或更新相关测试,并在上方记录实际验证结果;如未测试,已说明原因。
  • 我已更新受影响的文档、示例配置和多语言文案(如适用)。N/A: no documentation, configuration, or translation changes are needed for this projection repair.
  • 代码、日志、截图和提交记录中不包含 API Key、Cookie、Token、密码、DSN 或其他敏感信息。

LIghtJUNction and others added 30 commits October 10, 2026 22:25
Related to #711, RT14 partial work at 2f41649. Covers protocol structure only, not model injection resistance or executor authorization. Local selected-file baseline run reproduces 14 failing subcases. No remote CI.
…p ci]

Related to #711, RT14 partial work. Reuse the existing protocol validator for small contexts as well. Preserve valid conversations and existing compaction behavior. Selected-file offline regressions pass; full executor, confirmation, database and local-model testing remain unverified.
…ence [skip ci]

Pin source review to main@2f4164978cf27f6e0e605b0589fbe631aef2c441.
Add a loopback-only component runner, real Markdown observation entry,
URL-classification checks and runner-input tests. Keep private probes out.

Actual local evidence: URL classification 16 passed on the pinned function
excerpt; runner input validation 3 passed; TSX syntax transpilation passed.
Chromium localhost preflight was blocked by administrator policy (exit 2).
All four authenticated persisted-content paths remain NOT_RUN.

No production code changes or vulnerability-fix claim. No workflow dispatch,
release, deployment or merge. Refs #711.
Preserve manual deployment and exact Sigstore identity. Parse checksums and
archives only after verification, bind the exact published asset tuple and
resolved tag revision, and reject noncanonical checksums or duplicate members.

Add 14 offline tests executing actual workflow gate bodies with synthetic
artifacts and explicit GitHub/cosign doubles. These are not real signature,
PostgreSQL, systemd or production qualification.

Related #751. Native format1 to format2 migration in #757 remains unresolved.
* chore: export isolated refactor source for offline local validation

* chore: prepare public Go dependencies for offline local checks

* chore: export test tools for isolated local deployment verification

* chore: stage hash-bound locally tested refactor payload (1/3)

* chore: stage hash-bound locally tested refactor payload (2/3)

* chore: stage hash-bound locally tested refactor payload (3/3)

* chore: publish exact locally validated deployment refactor on isolated branch

* chore: normalize temporary gzip transport header without changing tested bytes

* refactor(deploy): remove embedded Go operator and ship separate signed deployment tool

Move deployment implementation/tests out of API linkage; bind separate backend and tool hashes across scripts, releases, packages and retained recovery. Local Go tests, race/vet, all-package compile, real executable smoke and Python regression checks completed. No release or production deployment. Remove all temporary transport workflows and payloads.

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…ed-ancestry-20261011

chore(release): record scoped OpenRouter hotfix source ancestry
…alect (#795)

Remove the startup-only commonGroupCol dependency from the public market and
routing visibility query. Add isolated SQLite regression coverage for empty
or stale legacy column metadata, bound group values, and availability filters.

Local evidence: gofmt and whitespace checks passed; SQL-only SQLite probe
passed. Go/GORM and application tests were not run: the local environment has
Go 1.23.2, no Bun/dependency cache, and no working network checkout. This is a
partial prerequisite fix, not the requested full public-relay lifecycle/UI
implementation. Keep the PR draft pending full local verification.
…e-20261011

fix(tool-market): guide setup prerequisites and next actions
…y-interaction

fix(web): 修复系统设置首次进入时目录误打开的初始化问题
…on-20261011

chore(web): stabilize generated route ordering
…ition

test(wallet): add RT-11 opt-in money composition scenarios (unverified)
…dance-ancestry-20261011

chore(release): qualify scoped tool market guidance source
…e-identity-20261012

fix(deploy): verify split tool holders with signed engine identity
…l-identity-20261012

fix(deploy): qualify per-start checker as the signed deployment engine
Copilot AI balanced review requested due to automatic review settings October 11, 2026 18:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-10-11T18:48:08.802166Z 8003a89 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copy link
Copy Markdown
Member Author

当前 head 8003a8909aa848b309044f61662630625904dacd 的 financeUsageCostMicros仍把所有固定价格视为整次请求总额,但图片路径的 model_price 是未乘 n 的单价:ImageRequest将数量单独放入计费倍率;实际结算再乘 OtherRatios,而日志仍保留原 ModelPrice。

由该 SHA 源码推导:Q=K、group=1 时,3 张 × $0.04 在财务投影中会成为 40,000 micros,而非 120,000,且 priced=true。这是财务估算修复尚缺数量维度,不是另一次钱包扣费或已证实生产损失。

建议补充图片结算日志到财务汇总的 n=1/n=3 回归,使用冻结的实际结算数量;历史记录缺少数量依据时保留 unpriced,避免默认一单位。本次只核对同一 SHA 源码,未独立执行测试。

@LIghtJUNction
LIghtJUNction changed the base branch from main to wip/rust-core-go-extensions October 12, 2026 11:02
@LIghtJUNction
LIghtJUNction marked this pull request as draft October 12, 2026 11:02
@LIghtJUNction

Copy link
Copy Markdown
Member Author

根据开发主线交接策略,旧单体 main / traditional 已冻结,相关财务/计费/测试/工具逻辑已由 wip/rust-core-go-extensions 对应微服务组件承接。关闭旧单体历史 PR,避免堆积。

@LIghtJUNction
LIghtJUNction deleted the fix/finance-frozen-currency-history-20261012 branch November 5, 2026 07:31
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.

2 participants