Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) · semantic ver

### Changed

- **fix(logs):** the console request line now tags a skipped conversion as
`savings:skip(<reason>)` instead of a bare reason word, so skip reasons are
greppable in `omniglyph` stdout and `wrangler tail`. Extracted to a pure
`skipReasonTag` helper shared by the Node and Worker hosts.

- **perf(render):** harden the rendered-page LRU with canonical full SHA-256
keys, race-safe byte accounting, smaller Worker defaults, runtime budget
control and cache-pressure counters in `/proxy-stats`. (thanks
Expand Down
8 changes: 8 additions & 0 deletions src/log-tags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** Console request-log formatting shared by the Node and Worker hosts. */

/** Tag a non-compressed outcome's skip reason for the stdout / `wrangler tail`
* request line. Empty string when there is no reason, so the caller can append
* it unconditionally without a spurious `savings:skip()`. */
export function skipReasonTag(reason: string | undefined): string {
return reason ? `savings:skip(${reason})` : '';
}
3 changes: 2 additions & 1 deletion src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from './core/safety-policy.js';
import type { TransformOptions } from './core/transform.js';
import { resolveOpenAIApiKey } from './node-auth.js';
import { skipReasonTag } from './log-tags.js';
import {
parseExportArgv,
runExportCore,
Expand Down Expand Up @@ -1018,7 +1019,7 @@ async function main(): Promise<void> {
const extraTag = extra.length > 0 ? ` (${extra.join(' ')})` : '';
const tag = e.info?.compressed
? `compressed ${e.info.origChars}ch → ${e.info.imageCount}img/${e.info.imageBytes}B${extraTag}`
: (e.info?.reason ?? '');
: skipReasonTag(e.info?.reason);
const cacheRead = e.usage?.cache_read_input_tokens ?? 0;
const inputTokens = e.usage?.input_tokens ?? 0;
const usageTag =
Expand Down
3 changes: 2 additions & 1 deletion src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import type { TransformOptions } from './core/transform.js';
import { toTrackEvent, JsonLogTracker, noopTracker, type Tracker } from './core/tracker.js';
import { setRenderCacheMaxBytes } from './core/render-cache.js';
import { skipReasonTag } from './log-tags.js';

export interface Env {
/** Optional single upstream base for every API family. Family-specific env vars override it. */
Expand Down Expand Up @@ -151,7 +152,7 @@ export default {
// shows up in `wrangler tail`).
const tag = e.info?.compressed
? `compressed ${e.info.origChars}ch → ${e.info.imageCount}img/${e.info.imageBytes}B`
: (e.info?.reason ?? '');
: skipReasonTag(e.info?.reason);
const cacheRead = e.usage?.cache_read_input_tokens ?? 0;
console.log(`${e.method} ${e.path} → ${e.status} (${e.durationMs}ms) ${tag} cache_read=${cacheRead}`);

Expand Down
16 changes: 16 additions & 0 deletions tests/log-tags.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, it } from 'vitest';
import { skipReasonTag } from '../src/log-tags.js';

/** The console request-log line tags a non-compressed outcome so skip reasons
* are greppable in `omniglyph` stdout / `wrangler tail` (e.g. savings:skip(not_profitable)). */
describe('skipReasonTag', () => {
it('wraps a skip reason as savings:skip(<reason>)', () => {
expect(skipReasonTag('not_profitable')).toBe('savings:skip(not_profitable)');
expect(skipReasonTag('below_threshold')).toBe('savings:skip(below_threshold)');
});

it('is empty when there is no reason (no spurious tag)', () => {
expect(skipReasonTag(undefined)).toBe('');
expect(skipReasonTag('')).toBe('');
});
});