Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
974d7a0
docs(openspec): propose thread-chat prompt cache optimization
hifizz Aug 29, 2026
8743869
docs: add plain-language prompt cache research
hifizz Aug 29, 2026
e33d538
docs(openspec): define multi-quote backend and cache contracts
hifizz Aug 31, 2026
4dece00
docs(openspec): align cache contracts with latest backend
hifizz Aug 31, 2026
1bfbc40
docs(openspec): unify quote drafts and cache policy
hifizz Aug 31, 2026
725fec4
docs(openspec): narrow quote scope to current thread
hifizz Aug 31, 2026
4db552f
docs(openspec): define current-thread quote and cost-first cache design
hifizz Aug 31, 2026
afd7756
docs(openspec): restrict message quotes to current thread
hifizz Aug 31, 2026
6ffda97
docs(openspec): simplify composer quotes to current thread
hifizz Aug 31, 2026
672ee3d
docs(openspec): make cache policy quality-gated and cost-first
hifizz Aug 31, 2026
65c6421
docs(openspec): align tasks with current-thread quote scope
hifizz Aug 31, 2026
9ea9662
docs: explain current-thread quote and cheapest-safe cache policy
hifizz Aug 31, 2026
7561193
docs(openspec): make composer frontend boundary normative
hifizz Aug 31, 2026
7bb9ddf
feat(thread-chat): add quote and prompt cache contracts
hifizz Aug 31, 2026
052261e
feat(thread-chat): define versioned quote protocol
hifizz Aug 31, 2026
7feebed
feat(thread-chat): type quote message parts
hifizz Aug 31, 2026
3cf01da
feat(thread-chat): accept current-thread quote selections
hifizz Aug 31, 2026
dbd58a8
feat(thread-chat): add input budget error
hifizz Aug 31, 2026
43734a6
feat(thread-chat): enforce quote and input budgets
hifizz Aug 31, 2026
210f932
feat(thread-chat): resolve and authorize quote selections
hifizz Aug 31, 2026
29a943b
feat(thread-chat): add deterministic quote model serialization
hifizz Aug 31, 2026
e43b17a
feat(thread-chat): build ordered quote user parts
hifizz Aug 31, 2026
109f830
refactor(thread-chat): use structured user parts
hifizz Aug 31, 2026
717b6b1
feat(thread-chat): materialize quote parts on send
hifizz Aug 31, 2026
76df8f9
feat(thread-chat): persist branch origin quote on first turn
hifizz Aug 31, 2026
aa8cdbd
feat(thread-chat): preserve quotes across user edits
hifizz Aug 31, 2026
795981d
fix(thread-chat): map input budget errors to 400
hifizz Aug 31, 2026
ef1c92b
fix(thread-chat): keep new quote fields client-compatible
hifizz Aug 31, 2026
e610bd8
fix(thread-chat): default legacy send quote list
hifizz Aug 31, 2026
2b9310f
fix(thread-chat): default legacy fork quote list
hifizz Aug 31, 2026
10c354e
feat(thread-chat): define multi-quote composer draft model
hifizz Aug 31, 2026
0616490
feat(thread-chat): add prompt cache manifest primitives
hifizz Aug 31, 2026
5a666e1
feat(thread-chat): add two-phase prompt compiler
hifizz Aug 31, 2026
3a61bda
refactor(thread-chat): delegate context compilation to prompt compiler
hifizz Aug 31, 2026
933b76a
feat(thread-chat): introduce stable tool profiles
hifizz Aug 31, 2026
13e5914
feat(ai): expose resolved model route and cache capability
hifizz Aug 31, 2026
4048d2e
feat(ai): add route-scoped prompt cache controls
hifizz Aug 31, 2026
7be4af1
feat(thread-chat): compile cache-safe generation prompts
hifizz Aug 31, 2026
0e1f3c9
feat(observability): add prompt cache metadata keys
hifizz Aug 31, 2026
08bbac6
feat(thread-chat): run generation through prompt compiler
hifizz Aug 31, 2026
8fcc8a1
test(thread-chat): add quote and prompt cache contracts
hifizz Aug 31, 2026
49f6d2c
test(thread-chat): add prompt cache verification scripts
hifizz Aug 31, 2026
0a85886
fix(thread-chat): preserve locked package versions
hifizz Aug 31, 2026
349ba25
ci: verify prompt cache implementation
hifizz Aug 31, 2026
1a8e4f3
feat(chat): make stable attachment resolution deterministic
hifizz Aug 31, 2026
19b081a
fix(thread-chat): isolate dynamic attachment retrieval from stable hi…
hifizz Aug 31, 2026
391fac7
refactor(chat): keep thread system prompt stable
hifizz Aug 31, 2026
78e1dcf
feat(ai): normalize prompt cache usage per model step
hifizz Aug 31, 2026
8c8dfc8
feat(ai): collect cache-aware model attempts
hifizz Aug 31, 2026
45fe09a
feat(thread-chat): collect cache usage for every model step
hifizz Aug 31, 2026
8619613
fix(thread-chat): parse unknown quote part payloads
hifizz Aug 31, 2026
1f9a295
fix(ai): use JSON-compatible provider option types
hifizz Aug 31, 2026
1286189
fix(thread-chat): await AI SDK message conversion
hifizz Aug 31, 2026
32866cd
feat(ai): expose model attempt summary contract
hifizz Aug 31, 2026
f782a19
refactor(thread-chat): share deterministic quote serialization
hifizz Aug 31, 2026
324b379
feat(thread-chat): attach model attempt cache summaries to traces
hifizz Aug 31, 2026
67bd8c7
feat(ai): add cache cost and quality probe evaluator
hifizz Aug 31, 2026
5be2eab
feat(ai): add fake-safe prompt cache probe command
hifizz Aug 31, 2026
09e0b24
docs: add prompt cache runtime configuration
hifizz Aug 31, 2026
55fd877
feat(thread-chat): define tenant-isolated compiled segment cache
hifizz Aug 31, 2026
9c3096a
feat(evals): fingerprint quote and prompt cache configuration
hifizz Aug 31, 2026
276fc25
feat(evals): include prompt cache configuration in candidate identity
hifizz Aug 31, 2026
06e5212
feat(evals): add prompt cache suite and expected signals
hifizz Aug 31, 2026
301cd8b
feat(evals): include model attempts and cache summary
hifizz Aug 31, 2026
e4aacba
feat(evals): persist cache summaries in experiment results
hifizz Aug 31, 2026
41814f8
fix(evals): preserve existing dataset revisions
hifizz Aug 31, 2026
df581ce
feat(evals): expose fixture cache attempts and summaries
hifizz Aug 31, 2026
e65a7a5
chore: add prompt cache probe and evaluation commands
hifizz Aug 31, 2026
8226767
ci: run fake cache probe and eval contracts
hifizz Aug 31, 2026
2005d5e
feat(ai): select cache breakpoints and contain option failures
hifizz Aug 31, 2026
1980c7f
test(thread-chat): cover cache usage cost and multi-quote boundaries
hifizz Aug 31, 2026
167ff16
feat(evals): score prompt cache structure and evidence
hifizz Aug 31, 2026
b1526ab
feat(evals): include quote protocol diagnostics in cache summary
hifizz Aug 31, 2026
3416753
feat(evals): add quote protocol fields to cache fixtures
hifizz Aug 31, 2026
975b9cf
feat(evals): expose quote protocol diagnostics from fixtures
hifizz Aug 31, 2026
0929512
feat(evals): add isolated prompt cache evaluation suite
hifizz Aug 31, 2026
75cc35b
test(evals): verify isolated prompt cache suite
hifizz Aug 31, 2026
576a919
chore: add isolated prompt cache eval command
hifizz Aug 31, 2026
ff2df55
ci: run isolated prompt cache Agent Eval
hifizz Aug 31, 2026
07b1a62
feat(thread-chat): enforce current-thread composer quote entrypoints
hifizz Aug 31, 2026
9f419fb
test(thread-chat): verify current-thread quote draft flows
hifizz Aug 31, 2026
d7a49c3
chore: add composer quote contract test
hifizz Aug 31, 2026
645844d
ci: verify quote composer draft contracts
hifizz Aug 31, 2026
bb238ee
test(thread-chat): verify quote authorization with fake transaction
hifizz Aug 31, 2026
20d1c56
ci: verify quote resolver authorization
hifizz Aug 31, 2026
bc092df
feat(ai): retry cache-control rejection before output
hifizz Aug 31, 2026
f2aaf81
test(thread-chat): verify route rollout TTL and stream fallback
hifizz Aug 31, 2026
fd0e146
feat(ai): infer cache eligibility warmth and provider evidence
hifizz Aug 31, 2026
54c355d
test(thread-chat): verify cache state explanations
hifizz Aug 31, 2026
bfbea42
ci: add full prompt cache apply verification
hifizz Aug 31, 2026
f703f21
docs: document prompt cache implementation and operations
hifizz Aug 31, 2026
d1c49e3
docs: define frontend quote composer handoff
hifizz Aug 31, 2026
fdacee0
docs: record prompt cache route probe registry
hifizz Aug 31, 2026
43304a5
docs: add isolated prompt cache environment example
hifizz Aug 31, 2026
e491bf5
feat(ai): build deterministic provider cache marker plans
hifizz Aug 31, 2026
0246dcd
test(thread-chat): verify fake provider cache marker plans
hifizz Aug 31, 2026
c2919d6
test(thread-chat): verify quote edit intent preservation
hifizz Aug 31, 2026
8215b12
feat(thread-chat): define conservative prompt preflight reserve
hifizz Aug 31, 2026
69fa2c2
ci: record prompt cache base branch baseline
hifizz Aug 31, 2026
9cb4384
fix: export prompt cache ttl class
hifizz Aug 31, 2026
dd7e443
fix: complete prompt cache rollout policy helpers
hifizz Aug 31, 2026
531cde2
fix: expose prompt cache fallback ttft
hifizz Aug 31, 2026
11b1de4
test: model visible output before cache stream failure
hifizz Aug 31, 2026
07fa2be
test(thread-chat): guard prompt cache architecture boundaries
hifizz Aug 31, 2026
cee3349
fix: contain rejected primary cache usage
hifizz Aug 31, 2026
35254d1
feat: compose route-scoped prompt cache controls
hifizz Aug 31, 2026
5b04bdd
feat: apply cache markers at stable prompt boundaries
hifizz Aug 31, 2026
0692d8d
feat: attach prompt cache ttft to model attempts
hifizz Aug 31, 2026
3267330
feat: integrate route-scoped prompt caching into generation
hifizz Aug 31, 2026
bff8b64
feat: record prompt cache fallback and ttft
hifizz Aug 31, 2026
a2844c2
test: verify compiled cache boundary markers
hifizz Aug 31, 2026
a55d9d3
ci: cover prompt cache adapters and compiled boundaries
hifizz Aug 31, 2026
7da4391
ci: run complete prompt cache boundary coverage
hifizz Aug 31, 2026
27a0292
feat: reserve runtime budget before paid routing
hifizz Aug 31, 2026
1466db4
feat: preflight prompt budget before routing calls
hifizz Aug 31, 2026
8da12a7
test: include prompt cache strategy diagnostics
hifizz Aug 31, 2026
28de1cc
fix: preserve prompt cache probe compatibility
hifizz Aug 31, 2026
9b7c52a
fix: preserve compiled segment cache call compatibility
hifizz Aug 31, 2026
a492a31
test: assert explicit short cache ttl markers
hifizz Aug 31, 2026
cd4f170
test: consume cache stream usage rejection
hifizz Aug 31, 2026
c9abf5d
docs(openspec): align cache rollout with quote-safe prompt
hifizz Aug 31, 2026
4be8592
ci: prepare normalized thread chat test database
hifizz Aug 31, 2026
6cebed6
ci: prepare normalized database for base baseline
hifizz Aug 31, 2026
ce194e5
ci: enforce prompt cache architecture invariants
hifizz Aug 31, 2026
24710b4
ci: enforce prompt cache architecture in full verification
hifizz Aug 31, 2026
452de6e
docs: clarify quote-safe cache rollout modes
hifizz Aug 31, 2026
89662f4
ci: initialize guarded evaluation database
hifizz Aug 31, 2026
b321446
refactor: remove invalid fork additional quotes
hifizz Aug 31, 2026
a612ba3
refactor: make fork first turn origin-only
hifizz Aug 31, 2026
c307b13
test: enforce origin-only fork first turn
hifizz Aug 31, 2026
34e3740
ci: verify origin-only fork first turn
hifizz Aug 31, 2026
a801d42
ci: include origin-only fork contract in full verification
hifizz Aug 31, 2026
26b8119
feat(cache): enforce quote and model input budgets
hifizz Aug 31, 2026
7f9b1c2
feat(quotes): validate and freeze current-thread quote selections
hifizz Aug 31, 2026
1beda55
docs(cache): start OpenSpec apply progress log
hifizz Aug 31, 2026
52677ee
feat(cache): expose model route and cache capabilities
hifizz Aug 31, 2026
498ed62
feat(cache): add route-scoped rollout and short TTL policy
hifizz Aug 31, 2026
eef96f1
feat(cache): select deterministic provider cache boundaries
hifizz Aug 31, 2026
340b6b8
feat(evals): add deterministic prompt cache fixtures and scorers
hifizz Aug 31, 2026
7e1dc2a
test(evals): gate prompt cache savings behind quality and isolation
hifizz Aug 31, 2026
519766b
feat(quotes): centralize completed current-thread source policy
hifizz Aug 31, 2026
7606fd8
feat(cache): retry rejected cache controls before visible output
hifizz Aug 31, 2026
9311d2f
test(quotes): reject cross-thread sources at the database boundary
hifizz Aug 31, 2026
aca005a
ci(cache): schedule deterministic cache cost regression probes
hifizz Aug 31, 2026
9bad158
docs(cache): document implemented quote and prompt cache architecture
hifizz Aug 31, 2026
e71dc27
docs(cache): record route probes, TTL and cost gates
hifizz Aug 31, 2026
e4b6c65
docs(composer): hand off stable quote draft contracts
hifizz Aug 31, 2026
ab1ecf5
test(composer): cover batch annotations and canonical one-message sub…
hifizz Aug 31, 2026
345929f
test(cache): retry cache compatibility failures only before output
hifizz Aug 31, 2026
9969b70
feat(observability): allowlist metadata-only prompt cache telemetry
hifizz Aug 31, 2026
b7d8ad8
test(observability): exclude prompt and quote content from cache tele…
hifizz Aug 31, 2026
7bc8698
test(cache): keep observe shadow-only and enabled compiled
hifizz Aug 31, 2026
9cecf7c
feat(cache): track cold, partial, expired and route-drift prefixes
hifizz Aug 31, 2026
ed64fa1
test(cache): classify cold, warm, expired and route-drift prefixes
hifizz Sep 1, 2026
e638d3a
test(cache): cover cohorts, budgets, cost and edit preservation
hifizz Sep 1, 2026
8995085
test(cache): measure first output across cache fallback
hifizz Sep 1, 2026
88bea41
test(quotes): verify direct and delayed fork first turns are equivalent
hifizz Sep 1, 2026
1cfcfed
docs(cache): add server-only rollout configuration example
hifizz Sep 1, 2026
d33c5e8
docs(cache): record base baseline and implementation evidence
hifizz Sep 1, 2026
7f80063
feat(thread-chat): add quote protocol constants
hifizz Sep 1, 2026
aaff2fd
feat(thread-chat): add current-thread quote selection contract
hifizz Sep 1, 2026
151102a
feat(thread-chat): add current-thread quote draft model
hifizz Sep 1, 2026
58fb4aa
test(thread-chat): cover quote protocol and composer contracts
hifizz Sep 1, 2026
6848916
ci(thread-chat): validate prompt cache implementation
hifizz Sep 1, 2026
dab7efd
test(thread-chat): cover quote authorization boundaries
hifizz Sep 1, 2026
e01c8d0
feat(thread-chat): add prompt cache policy versions
hifizz Sep 1, 2026
34a63cf
feat(thread-chat): define prompt cache compiler contracts
hifizz Sep 1, 2026
b77d0ef
feat(thread-chat): add stable prompt hashing
hifizz Sep 1, 2026
8fca036
feat(thread-chat): compile stable prompt base segments
hifizz Sep 1, 2026
f983f4a
feat(thread-chat): define stable generation tool profiles
hifizz Sep 1, 2026
b7d311a
feat(thread-chat): add route-scoped prompt cache controls
hifizz Sep 1, 2026
6799ffd
feat(thread-chat): enforce preflight input budgets
hifizz Sep 1, 2026
271bf7f
feat(thread-chat): finalize cache-aware generation prompts
hifizz Sep 1, 2026
e935abe
test(thread-chat): cover prompt cache compiler invariants
hifizz Sep 1, 2026
e9d5ef9
feat(thread-chat): normalize prompt cache usage per model step
hifizz Sep 1, 2026
729abb0
test(thread-chat): cover cache usage normalization
hifizz Sep 1, 2026
72c98a4
feat(thread-chat): define prompt cache route probe policy
hifizz Sep 1, 2026
562f1ce
test(thread-chat): cover fake route cache probes
hifizz Sep 1, 2026
6645a8b
feat(prompt-cache): add deterministic fake cache probe
hifizz Sep 1, 2026
3953d69
ci(prompt-cache): schedule deterministic cache probe
hifizz Sep 1, 2026
246046e
test(thread-chat): cover branch draft and annotation aggregation
hifizz Sep 1, 2026
b83a9c7
test(thread-chat): cover breakpoint and cache outcome states
hifizz Sep 1, 2026
1be532b
feat(thread-chat): contain cache usage parsing failures
hifizz Sep 1, 2026
7e3025a
feat(thread-chat): add cache-control stream fallback
hifizz Sep 1, 2026
21b401d
test(thread-chat): cover cache control fallback safety
hifizz Sep 1, 2026
d39a1fd
test(thread-chat): prove both fork first-turn paths are model equivalent
hifizz Sep 1, 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
13 changes: 13 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ EVAL_MODEL_ID=
EVAL_CANDIDATE=
EVAL_RUN_ID=

# === Thread Chat Prompt Cache(服务端专用) ===
# off:旧/无缓存控制;observe:只记录候选前缀;enabled:仅已验证 Route 发送缓存参数。
# 首次部署保持 off,经 fake + staging provider probe 后再按 Route 开启。
THREAD_PROMPT_CACHE_MODE=off
# OpenRouter 等支持粘性路由时,用此高熵 secret 生成用户+Project+模型隔离的 HMAC;
# 原始 user/project/thread id 不会发送给上游。
THREAD_PROMPT_CACHE_AFFINITY_SALT=
# 第一阶段只采用 Provider 默认短时缓存(支持时约 5 分钟)。
# 1 小时 Extended TTL 保持关闭,直到真实间隔/费用与 retention/ZDR 审查证明净节省。
THREAD_PROMPT_CACHE_EXTENDED_TTL_ENABLED=false
# L2 只缓存应用侧编译结果,不减少模型 Token;默认 noop,当前不需要 Redis。
THREAD_PROMPT_COMPILED_SEGMENT_CACHE=off

# === OpenRouter(固定路由的 Thread Chat 模型) ===
OPENROUTER_API_KEY=
# 可选:OpenRouter 排行榜/控制台中的应用归因;留空时不会发送对应 header。
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/prompt-cache-apply.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Prompt Cache Apply

on:
pull_request:
paths:
- "constants/thread-chat-quote.ts"
- "lib/thread-chat/**"
- "lib/chat/thread-chat-prompt.ts"
- "app/thread-chat/chat/composer/quote-draft.ts"
- "e2e/thread-chat/prompt-cache-*.test.mjs"
- ".github/workflows/prompt-cache-apply.yml"
- "openspec/changes/optimize-thread-chat-prompt-cache/**"
workflow_dispatch:

permissions:
contents: read

jobs:
validate:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Typecheck
run: pnpm typecheck
- name: Quote and cache contracts
run: node --import tsx e2e/thread-chat/prompt-cache-quote-contract.test.mjs
- name: OpenSpec strict validation
run: pnpm exec openspec validate --all --strict
106 changes: 106 additions & 0 deletions .github/workflows/prompt-cache-baseline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Prompt Cache Base Baseline

on:
pull_request:
paths:
- ".github/workflows/prompt-cache-baseline.yml"
- "openspec/changes/optimize-thread-chat-prompt-cache/**"
workflow_dispatch:

permissions:
contents: read

jobs:
record-baseline:
runs-on: ubuntu-24.04
timeout-minutes: 45
services:
postgres:
image: pgvector/pgvector:pg17
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: thread_chat_base_test
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres -d thread_chat_base_test"
--health-interval 5s
--health-timeout 5s
--health-retries 20
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/thread_chat_base_test
DIRECT_URL: postgres://postgres:postgres@localhost:5432/thread_chat_base_test
TEST_DATABASE_URL: postgres://postgres:postgres@localhost:5432/thread_chat_base_test
EVAL_DATABASE_URL: postgres://postgres:postgres@localhost:5432/thread_chat_base_eval_test
EVAL_ALLOW_DATABASE_WRITES: "true"
EVAL_DATABASE_GUARD_TOKEN: prompt-cache-base-guard-token-2026
BETTER_AUTH_SECRET: prompt-cache-base-better-auth-secret-2026
BETTER_AUTH_URL: http://localhost:4040
MINIMAX_API_KEY: fake-ci-key
AI_TELEMETRY_ENABLED: "false"
AI_DEVTOOLS_ENABLED: "false"
AI_LANGFUSE_ENABLED: "false"
steps:
- name: Checkout Base branch
uses: actions/checkout@v4
with:
ref: codex/feat-agent-observability-evaluation
- uses: pnpm/action-setup@v4
with:
version: 10.32.1
- uses: actions/setup-node@v4
with:
node-version: 24
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Prepare databases
env:
PGPASSWORD: postgres
run: |
createdb -h localhost -U postgres thread_chat_base_eval_test || true
psql -h localhost -U postgres -d postgres -v ON_ERROR_STOP=1 \
-c "ALTER DATABASE thread_chat_base_eval_test SET thread_chat.evaluation_guard TO 'prompt-cache-base-guard-token-2026'"
pnpm db:migrate
pnpm db:test:setup
pnpm db:test:migrate
DATABASE_URL="$EVAL_DATABASE_URL" DIRECT_URL="$EVAL_DATABASE_URL" pnpm db:migrate
- name: Record baseline checks
id: baseline
shell: bash
run: |
set +e
: > baseline-results.tsv
run_check() {
name="$1"
shift
echo "::group::$name"
"$@"
code=$?
echo "::endgroup::"
printf '%s\t%s\n' "$name" "$code" >> baseline-results.tsv
}
run_check typecheck pnpm typecheck
run_check build env NODE_ENV=production pnpm build
run_check thread-chat-gate1-db pnpm test:thread-chat:gate1-db
run_check thread-chat-gate2-api pnpm test:thread-chat:gate2-api
run_check observability pnpm test:observability
run_check agent-evals pnpm test:agent-evals
run_check openspec pnpm openspec:validate
{
echo '## Prompt Cache Base Baseline'
echo
echo '| Check | Exit code |'
echo '|---|---:|'
while IFS=$'\t' read -r name code; do
echo "| $name | $code |"
done < baseline-results.tsv
} >> "$GITHUB_STEP_SUMMARY"
exit 0
- name: Upload baseline record
uses: actions/upload-artifact@v4
with:
name: prompt-cache-base-baseline
path: baseline-results.tsv
retention-days: 30
116 changes: 116 additions & 0 deletions .github/workflows/prompt-cache-final.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Prompt Cache Final Verification

on:
pull_request:
paths:
- "constants/**"
- "lib/ai/**"
- "lib/chat/**"
- "lib/thread-chat/**"
- "app/thread-chat/**"
- "app/api/thread-chat/**"
- "e2e/**"
- "evals/**"
- "scripts/**"
- "package.json"
- "pnpm-lock.yaml"
- ".github/workflows/prompt-cache-final.yml"
- "openspec/changes/optimize-thread-chat-prompt-cache/**"
workflow_dispatch:

permissions:
contents: read

jobs:
full-verification:
runs-on: ubuntu-24.04
timeout-minutes: 45
services:
postgres:
image: pgvector/pgvector:pg17
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: thread_chat_test
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres -d thread_chat_test"
--health-interval 5s
--health-timeout 5s
--health-retries 20
env:
NODE_ENV: test
DATABASE_URL: postgres://postgres:postgres@localhost:5432/thread_chat_test
DIRECT_URL: postgres://postgres:postgres@localhost:5432/thread_chat_test
TEST_DATABASE_URL: postgres://postgres:postgres@localhost:5432/thread_chat_test
EVAL_DATABASE_URL: postgres://postgres:postgres@localhost:5432/thread_chat_eval_test
EVAL_ALLOW_DATABASE_WRITES: "true"
EVAL_DATABASE_GUARD_TOKEN: prompt-cache-ci-guard-token-2026
BETTER_AUTH_SECRET: prompt-cache-ci-better-auth-secret-2026
BETTER_AUTH_URL: http://localhost:4040
MINIMAX_API_KEY: fake-ci-key
AI_TELEMETRY_ENABLED: "false"
AI_DEVTOOLS_ENABLED: "false"
AI_LANGFUSE_ENABLED: "false"
THREAD_PROMPT_CACHE_MODE: observe
THREAD_PROMPT_CACHE_EXTENDED_TTL_ENABLED: "false"
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 10.32.1
- uses: actions/setup-node@v4
with:
node-version: 24
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Prepare evaluation database
env:
PGPASSWORD: postgres
run: |
createdb -h localhost -U postgres thread_chat_eval_test || true
psql -h localhost -U postgres -d postgres -v ON_ERROR_STOP=1 \
-c "ALTER DATABASE thread_chat_eval_test SET thread_chat.evaluation_guard TO 'prompt-cache-ci-guard-token-2026'"
DATABASE_URL="$EVAL_DATABASE_URL" DIRECT_URL="$EVAL_DATABASE_URL" pnpm db:migrate
- name: Apply application migrations
run: pnpm db:migrate
- name: Prepare normalized Thread Chat test database
run: pnpm db:test:setup && pnpm db:test:migrate
- name: Typecheck
run: pnpm typecheck
- name: Lint
run: pnpm lint
- name: Production build
run: pnpm build
- name: Prompt cache architecture guard
run: node scripts/check-prompt-cache-architecture.mjs
- name: Prompt cache and Quote contracts
run: >-
pnpm test:thread-chat:prompt-cache &&
pnpm test:thread-chat:prompt-cache-eval &&
pnpm test:thread-chat:composer-quotes &&
node --import tsx e2e/thread-chat/fork-origin-contract.test.mjs &&
node --import tsx e2e/thread-chat/quote-resolver-contract.test.mjs &&
node --import tsx e2e/thread-chat/prompt-cache-adapter.test.mjs &&
node --import tsx e2e/thread-chat/prompt-cache-compiler-boundaries.test.mjs &&
node --import tsx e2e/thread-chat/prompt-cache-rollout.test.mjs &&
node --import tsx e2e/thread-chat/prompt-cache-state.test.mjs &&
pnpm prompt-cache:probe
- name: Thread Chat database and protocol gates
run: >-
pnpm test:thread-chat:gate1-db &&
pnpm test:thread-chat:gate2-session &&
pnpm test:thread-chat:gate2-pipeline &&
pnpm test:thread-chat:gate2-db &&
pnpm test:thread-chat:gate2-api &&
pnpm test:thread-chat:gate2-api-db &&
pnpm test:thread-chat:gate3-client &&
pnpm test:thread-chat:gate4-cutover
- name: Observability suite
run: pnpm test:observability
- name: Agent evaluation suite
run: pnpm test:agent-evals
- name: OpenSpec strict validation
run: pnpm openspec:validate
32 changes: 32 additions & 0 deletions .github/workflows/prompt-cache-probe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Prompt Cache Probe

on:
workflow_dispatch:
schedule:
- cron: "17 4 * * 3"

permissions:
contents: read

jobs:
fake-contract-probe:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: 24
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Warm and reuse the fake provider prefix
run: >-
node --import tsx scripts/probe-thread-chat-prompt-cache.ts
--mode=fake
--output=evals/agent/results/local/prompt-cache-probe.json
- uses: actions/upload-artifact@v4
with:
name: prompt-cache-fake-probe
path: evals/agent/results/local/prompt-cache-probe.json
if-no-files-found: error
retention-days: 14
32 changes: 32 additions & 0 deletions .github/workflows/prompt-cache-scheduled.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Prompt Cache Scheduled Probe

on:
schedule:
- cron: "37 5 * * 1"
workflow_dispatch:

jobs:
fake-cache-probe:
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 10.32.1
- uses: actions/setup-node@v4
with:
node-version: 24
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Warm-up and reuse probe
run: node --import tsx scripts/probe-prompt-cache.ts > prompt-cache-probe.json
- name: Quality and cache eval gate
run: node --import tsx e2e/observability/prompt-cache-eval.test.mjs
- name: Upload reproducible probe evidence
uses: actions/upload-artifact@v4
with:
name: prompt-cache-fake-probe-${{ github.sha }}
path: prompt-cache-probe.json
if-no-files-found: error
retention-days: 30
Loading
Loading