Skip to content

[PR] fix: read logger attribution tags in cache usage - #6742

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-14_usage-log-attribution-tags
Nov 14, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-14_usage-log-attribution-tags

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Closes #6740

Problem

Current logger.log() writes [v=<version>], preceded by [sess=<request-scope>] when the request has a bound context. parseUsageLog() still expects the explicit usage session immediately after the log level. As a result, current loop, relay and plugin usage lines contribute no samples to bili acp-cache diff.

This is observable through the real writer, without a fabricated logger format:

2026-11-14T12:00:00.000 [info] [sess=request-scope] [v=0.1.214] [actual-session] [plugin] [acp-usage] input=10000 cached=0

The parser returns an empty map. A real dump pair plus real scoped log output consequently loses its usage and calls a stable-prefix cache miss pure-append.

Change

Parse the bracketed prefix, remove the known current logger attribution prefix, then require the explicit usage session and optional plugin producer tag. Parsing these separately prevents an optional-prefix regex from backtracking and treating the version tag as a session when the actual session is absent.

The usage record's explicit session remains authoritative even when its request scope differs. Legacy untagged lines, local/UTC/offset timestamps, sanitized session IDs, sample ordering and numeric fields retain their behavior. A session literally named plugin remains valid. No logger output, wire behavior, cache policy, configuration or dependency changes.

Verification

  • 14 new regressions: 12 failures / 2 passing controls on unchanged master.
  • Four tests use real configureLogger → log → awaited closeLogger → parseUsageLog, covering scoped/unscoped and loop/plugin variants.
  • Two real dump-file tests carry those written logs through public runDiff, both default log discovery and explicit --log, and assert the correct session, usage values and prefix-stable-miss classification.
  • Mixed legacy/current formats, zero cached tokens, three timestamp formats, sort order, missing explicit session, a literal plugin session and malformed/noise lines are covered.
  • 60/60 related tests pass, including existing cache-diff, logger session-tag and log-retention suites.
  • Full npm run typecheck, npm run build and git diff --check pass. An initial typecheck attempt stopped while writing generated kernel declarations because the shared workspace ran out of disk space; after space was restored, both complete commands passed.
  • Independent read-only review checked the complete implementation, logger format and new cases; no blocker. The reviewer did not rerun tests.
node --import ./tests/preload-test-env.mjs --import ./tests/preload-storage-baseline.mjs --import tsx --test --test-concurrency=1 tests/acp-cache-diff-log-tags.test.ts tests/acp-cache-diff.test.ts tests/logger-session-tag.test.ts tests/log-retention.test.ts

Validation used Node 24.22.1, TZ=UTC and isolated temporary files. Full-suite results are left to hosted CI on the pushed head.

History check

Reviewed the complete indexed Afloat16 issue history and relevant actual PR patches. #6496 changes UTF-8 offset attribution; #6722 changes ordered sample-to-request alignment. Neither handles log prefixes. The actual #5487 patch streams retained logs while preserving this old regex; #4535 and its implementation only expand timestamp syntax. Focused all-state searches found no existing equivalent attribution-prefix correction.

Base: master a8bbb8d23108ba9148d09512927041364625d910 (0.1.214).

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.

Current logger attribution tags hide cache-usage samples from acp-cache diff

2 participants