Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3f8d194
refactor: replace redundant null-or guards with optional chaining
ding113 Jul 22, 2026
31bc3d6
feat(proxy): add stream gate, replay, affinity, and cache metrics
ding113 Jul 22, 2026
d46d113
Merge remote-tracking branch 'origin/dev' into cchp-gateway-porting
ding113 Jul 22, 2026
9cfcb72
style(probe-scheduler): reformat test.each array literals to multiline
ding113 Jul 22, 2026
4715c7e
fix(proxy): replace unsafe optional chaining in fingerprint test
ding113 Jul 22, 2026
fd2297d
chore: format code (cchp-gateway-porting-4715c7e)
github-actions[bot] Jul 22, 2026
785221b
Merge remote-tracking branch 'origin/dev' into cchp-gateway-porting
ding113 Jul 22, 2026
b84a336
feat(db): add cache effectiveness and replay payload tables
ding113 Jul 22, 2026
d70547c
Merge remote-tracking branch 'origin/dev' into cchp-gateway-porting
ding113 Jul 22, 2026
ac9a64e
feat(proxy): add stream content gate and affinity routing settings
ding113 Jul 23, 2026
6f73e6c
feat(leaderboard): add cache coefficient column to provider boards
ding113 Jul 23, 2026
4aba48a
refactor(providers): remove per-provider cache effectiveness card
ding113 Jul 23, 2026
8279178
Merge remote-tracking branch 'origin/dev' into cchp-gateway-porting
ding113 Jul 23, 2026
918cddb
feat(db): add cache effectiveness, batch apply, and replay schema
ding113 Jul 23, 2026
942d371
fix(proxy): align forwarder and affinity mocks with merged APIs
ding113 Jul 23, 2026
aec4c76
refactor(discovery): remove DISCOVERY_ROLLOUT_PERCENT env canary
ding113 Jul 23, 2026
9da2f69
refactor: replace explicit null guards with optional chaining and Obj…
ding113 Jul 23, 2026
1dd3cb6
test(auth): add DB-less auth chain and my-usage action unit coverage
ding113 Jul 23, 2026
bb72b8b
test(proxy): expand guard pipeline and session-id error coverage
ding113 Jul 23, 2026
7aa7857
test: expand dashboard logs, session binding, and clipboard coverage
ding113 Jul 23, 2026
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
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ ENABLE_API_KEY_REDIS_CACHE="true" # 是否启用 API Key Redis 缓存(
# 降低该值会按签发时间收紧已签发 ADMIN_TOKEN 签名 cookie 的剩余寿命,且不会延长其原始 exp。
AUTH_SESSION_TTL_SECONDS=604800 # Web UI 登录态过期时间(秒,默认 604800 = 7 天,范围 60-31536000)
SESSION_TTL=300 # 代理请求上下文缓存时间(秒,默认 300 = 5 分钟;不控制 Web UI 登录态)
DISCOVERY_ROLLOUT_PERCENT=100 # Discovery 运维灰度比例(0-100,按 API Key + Session 稳定分桶)
STORE_SESSION_MESSAGES=false # 会话消息存储模式(默认:false)
# - false:存储请求/响应体但对 message 内容脱敏 [REDACTED]
# - true:原样存储 message 内容(注意隐私和存储空间影响)
Expand Down
63 changes: 63 additions & 0 deletions drizzle/0112_complex_sabra.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
CREATE TABLE IF NOT EXISTS "provider_batch_apply_operations" (
"claim_key" varchar(256) PRIMARY KEY NOT NULL,
"preview_token" varchar(256) NOT NULL,
"payload_fingerprint" varchar(128) NOT NULL,
"operation_id" varchar(256) NOT NULL,
"undo_token" varchar(256) NOT NULL,
"undo_expires_at" timestamp with time zone,
"undo_consumed_at" timestamp with time zone,
"status" varchar(32) NOT NULL,
"result" jsonb,
"expires_at" timestamp with time zone NOT NULL,
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "provider_cache_effectiveness" (
"id" serial PRIMARY KEY NOT NULL,
"provider_id" integer NOT NULL,
"model" varchar(128) NOT NULL,
"cache_ttl_bucket" varchar(10) NOT NULL,
"window_start" timestamp with time zone NOT NULL,
"window_end" timestamp with time zone NOT NULL,
"sample_count" integer DEFAULT 0 NOT NULL,
"eligible_count" integer DEFAULT 0 NOT NULL,
"theoretical_cache_tokens" bigint DEFAULT 0 NOT NULL,
"observed_cache_read_tokens" bigint DEFAULT 0 NOT NULL,
"raw_effectiveness_bp" integer DEFAULT 0 NOT NULL,
"confidence_bp" integer DEFAULT 0 NOT NULL,
"effectiveness_bp" integer DEFAULT 0 NOT NULL,
"created_at" timestamp with time zone DEFAULT now()
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "replay_payloads" (
"replay_id" varchar(64) PRIMARY KEY NOT NULL,
"verifier" varchar(64) NOT NULL,
"scope_tag" varchar(16) NOT NULL,
"key_id" integer NOT NULL,
"user_id" integer NOT NULL,
"format" varchar(16) NOT NULL,
"model" varchar(128),
"status_code" integer NOT NULL,
"headers_json" jsonb,
"payload" text NOT NULL,
"byte_size" integer NOT NULL,
"source_message_request_id" integer,
"created_at" timestamp with time zone DEFAULT now(),
"expires_at" timestamp with time zone NOT NULL
);
--> statement-breakpoint
ALTER TABLE "message_request" ADD COLUMN "cache_compatibility_key" varchar(64);--> statement-breakpoint
ALTER TABLE "message_request" ADD COLUMN "cache_score_eligible" boolean;--> statement-breakpoint
ALTER TABLE "message_request" ADD COLUMN "cache_score_excluded_reason" varchar(32);--> statement-breakpoint
ALTER TABLE "message_request" ADD COLUMN "theoretical_cache_tokens" bigint;--> statement-breakpoint
ALTER TABLE "message_request" ADD COLUMN "cache_ttl_bucket" varchar(10);--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN "stream_gate_mode" varchar(10) DEFAULT 'enforce' NOT NULL;--> statement-breakpoint
ALTER TABLE "system_settings" ADD COLUMN "affinity_ignore_client_session_id" boolean DEFAULT true NOT NULL;--> statement-breakpoint
Comment on lines +55 to +56

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Migration defaults activate both features on all existing deployments immediately

When PostgreSQL ALTER TABLE … ADD COLUMN … DEFAULT 'enforce' NOT NULL runs, all existing rows in system_settings are immediately set to stream_gate_mode = 'enforce'. Because resolveStreamGateMode() reads the DB-cached value first (taking precedence over the STREAM_GATE_MODE env var whose default is 'off'), stream content gating in full enforce mode activates for every deployment the moment this migration runs. The same is true for affinity_ignore_client_session_id DEFAULT true. If the intent is a safe dark launch, both defaults should be 'off' / false to match the env-var defaults, with operators opting in by updating the system settings.

Prompt To Fix With AI
This is a comment left during a code review.
Path: drizzle/0112_complex_sabra.sql
Line: 55-56

Comment:
**Migration defaults activate both features on all existing deployments immediately**

When PostgreSQL `ALTER TABLE … ADD COLUMN … DEFAULT 'enforce' NOT NULL` runs, all existing rows in `system_settings` are immediately set to `stream_gate_mode = 'enforce'`. Because `resolveStreamGateMode()` reads the DB-cached value first (taking precedence over the `STREAM_GATE_MODE` env var whose default is `'off'`), stream content gating in full enforce mode activates for every deployment the moment this migration runs. The same is true for `affinity_ignore_client_session_id DEFAULT true`. If the intent is a safe dark launch, both defaults should be `'off'` / `false` to match the env-var defaults, with operators opting in by updating the system settings.

How can I resolve this? If you propose a fix, please make it concise.

CREATE UNIQUE INDEX IF NOT EXISTS "uniq_provider_batch_apply_operations_preview_token" ON "provider_batch_apply_operations" USING btree ("preview_token");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "uniq_provider_batch_apply_operations_operation_id" ON "provider_batch_apply_operations" USING btree ("operation_id");--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS "uniq_provider_batch_apply_operations_undo_token" ON "provider_batch_apply_operations" USING btree ("undo_token");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_provider_batch_apply_operations_expires_at" ON "provider_batch_apply_operations" USING btree ("expires_at");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_provider_cache_effectiveness_window" ON "provider_cache_effectiveness" USING btree ("provider_id","model","window_start" DESC NULLS LAST);--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_replay_payloads_key_id" ON "replay_payloads" USING btree ("key_id");--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "idx_replay_payloads_expires_at" ON "replay_payloads" USING btree ("expires_at");
2 changes: 1 addition & 1 deletion drizzle/meta/0110_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "b6b7996d-5b70-4a31-a1c7-3a318b3398a0",
"prevId": "c054c34a-98a4-4ae1-b0e5-0b663380f123",
"prevId": "60b89563-2169-4393-b823-ded5c410b455",
"version": "7",
"dialect": "postgresql",
"tables": {
Expand Down
Loading
Loading