Skip to content

Commit 3e57623

Browse files
Optimize GPT-5.6 caching and route scheduled memory work through Flex (#11648)
## Summary - restore explicit GPT-5.6 prompt caching through the LangChain/OpenAI wire payload, with stable versioned cache keys and a default-off rollout flag - put all eligible scheduled Flex work behind one live switch: Short-term to Long-term promotion, required L2 memory processing, and scheduled X memory extraction - preserve the prior Standard path exactly when the shared switch is off; manual and OAuth-triggered X syncs remain Standard regardless of the switch - isolate the three workloads on dedicated gateway lanes with 900-second request timeouts, zero SDK retries, generation/apply fencing, and durable deferral rather than silent Standard fallback ## One Flex switch The deployment capability and live Firestore control are fail-closed gates: - capability: `OMI_BACKGROUND_FLEX_CAPABLE=true` only on the scheduled memory-maintenance and notifications jobs - live control: `llm_runtime_controls/background_flex` - accepted document shape: exactly `enabled` (boolean) and `generation` (positive integer) - missing, malformed, or disabled control: all three workloads use their existing Standard logic - enabled control: all three eligible scheduled workloads use Flex; capacity/deadline deferrals remain pending for a later scheduled run and never silently fall back to Standard Initial disabled control: ```json { "enabled": false, "generation": 1 } ``` Enable all scheduled Flex processing without redeploying: ```json { "enabled": true, "generation": 2 } ``` Increment `generation` on every change. A generation change fences in-flight results before durable apply. Turning `enabled` off restores the old Standard routes for new work without a redeployment. No live Firestore control or deployment is changed by this PR. ## Safety and latency - dedicated gateway routes: `memory_conflict_flex`, `memory_l2_flex`, and `x_memory_extraction_flex` - 15-minute provider timeout, 20-minute leases, one-hour Cloud Run job budgets, and a five-minute completion margin - zero SDK retries on Flex calls, preventing a request from consuming two full Flex windows - memory maintenance limits the Flex-enabled run to one user and one required L2 item so worst-case work fits the job budget - deferred L2 work releases its claim without consuming the existing quality-failure retry budget - scheduled X acknowledges raw posts only after extraction, writes, and generation fencing succeed; deferred posts stay pending - the notifications deployment verifies and probes the private LLM gateway route and carries the required VPC configuration OpenAI documents Flex as lower-cost processing with slower responses and occasional resource-unavailable errors, intended for non-production or lower-priority asynchronous work: https://developers.openai.com/api/docs/guides/flex-processing ## Product invariants affected - INV-MEM-1 ## Failure class (fixes) Failure-Class: none ## Prompt-cache rollout 1. Deploy the LLM gateway revision first so generated GPT-5.6 routes no longer contain the legacy `prompt_cache_retention: 24h` field. 2. Deploy backend-listen with `OMI_LLM_GPT56_EXPLICIT_CACHE_ENABLED=false`. 3. Enable the prompt-cache flag in a reviewed rollout change and watch cache writes/hits, provider 4xx errors, finalizer retries, and structure latency. 4. Roll back by setting the flag to `false`. ## Review Cursor Grok 4.6 reviewed the implementation four times through agentctl: - initial promotion review: `exec-curious-involve-shoulder-tower-panda-attend` - promotion post-fix review: `exec-viable-tool-profit-polar-small-chef` - shared-switch review: `exec-chunk-banana-abstract-potato-grab-else` - final shared-switch post-fix review: `exec-seven-dragon-enough-recycle-ginger-orphan` The shared-switch reviews drove zero-retry Flex invocation, whole-job budgeting, private-gateway routing and deployment verification, cursor-safe memory limits, pending-until-applied X acknowledgement, and preservation of Flex deferrals across extraction boundaries. ## Verification - 304 focused post-rebase tests passed: 209 routing, X, L2, cron, gateway, runtime, and prompt-cache tests plus 95 QoS tests - local pre-push gate passed after typecheck completed with 0 errors; runtime-image closure, workflow/runtime validation, generated manifests, and selected backend tests passed - runtime environment validation passed for development and production - Python compile validation and `git diff --check` passed - GitHub CI is authoritative for the full suite Line-Count-Exception: backend/utils/memory/canonical_consolidation.py | 1927 -> 2079 | adds transactional Flex deferral release and apply fencing beside the consolidation retry state it protects <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/BasedHardware/omi/pull/11648?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. --> Line-Count-Exception: backend/utils/llm/conversation_processing.py | 1498 -> 1510 | gateway-mode cache_key split review fix: explicit formatted-flag docstrings plus the gateway-mode/explicit-cache split in get_reprocess_transcript_structure and get_app_result
2 parents d6918b0 + 329300a commit 3e57623

48 files changed

Lines changed: 1945 additions & 206 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/gcp_notifications_job.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,30 @@ jobs:
8080
- name: Install Python deps for deploy scripts
8181
run: python3 -m pip install -q pyyaml
8282

83+
- name: Get GKE credentials for gateway serving gate
84+
uses: google-github-actions/get-gke-credentials@v3
85+
with:
86+
cluster_name: ${{ vars.GKE_CLUSTER }}
87+
location: ${{ env.REGION }}
88+
project_id: ${{ vars.GCP_PROJECT_ID }}
89+
90+
- name: Verify LLM Gateway serving data plane
91+
id: gateway-serving
92+
run: |
93+
python3 backend/scripts/verify-llm-gateway-serving.py \
94+
--environment="${{ vars.ENV }}" \
95+
--project="${{ vars.GCP_PROJECT_ID }}" \
96+
--region="${{ env.REGION }}" \
97+
--github-output "$GITHUB_OUTPUT"
98+
8399
- name: Render backend runtime env
84100
id: runtime-env
85101
env:
86102
# Prod network flags are env_var-backed; without these the renderer
87103
# exits before notifications_job_* outputs are emitted (same as gcp_backend.yml).
88104
CLOUD_RUN_VPC_NETWORK: ${{ vars.CLOUD_RUN_VPC_NETWORK }}
89105
CLOUD_RUN_VPC_SUBNET: ${{ vars.CLOUD_RUN_VPC_SUBNET }}
106+
OMI_LLM_GATEWAY_URL: ${{ steps.gateway-serving.outputs.gateway_url }}
90107
run: |
91108
python3 backend/scripts/render_backend_runtime_env.py --env ${{ vars.ENV }} --job notifications-job >> "$GITHUB_OUTPUT"
92109
@@ -119,6 +136,19 @@ jobs:
119136
docker push gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }}:latest
120137
docker push gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }}:${{ steps.image-tag.outputs.short_sha }}
121138
139+
- name: Probe X Flex gateway lane from the Cloud Run VPC
140+
run: |
141+
bash backend/scripts/probe-llm-gateway-from-cloud-run.sh \
142+
--project "${{ vars.GCP_PROJECT_ID }}" \
143+
--region "${{ env.REGION }}" \
144+
--image "gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }}:${{ steps.image-tag.outputs.short_sha }}" \
145+
--gateway-url "${{ steps.gateway-serving.outputs.gateway_url }}" \
146+
--network "${{ vars.CLOUD_RUN_VPC_NETWORK }}" \
147+
--subnet "${{ vars.CLOUD_RUN_VPC_SUBNET }}" \
148+
--vpc-egress private-ranges-only \
149+
--lane omi:auto:x-memory-extraction-flex \
150+
--name-suffix "${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
151+
122152
- name: Deploy to Cloud Run
123153
id: deploy
124154
uses: google-github-actions/deploy-cloudrun@v3
@@ -132,6 +162,8 @@ jobs:
132162
# Strip retired maintenance/Pusher keys, plus any literal shadowing a
133163
# Secret Manager binding (no-op on a clean target).
134164
flags: >-
165+
${{ steps.runtime-env.outputs.cloud_run_flags }}
166+
--task-timeout=3600s
135167
--remove-env-vars=MEMORY_MODE,MEMORY_ENABLED_USERS,MEMORY_V3_GET_ENABLED,MEMORY_CANONICAL_MAINTENANCE_ENABLED,MEMORY_CANONICAL_CONSOLIDATION_ENABLED,MEMORY_CANONICAL_PROMOTION_CRON_ENABLED,MEMORY_CANONICAL_PROMOTION_CRON_INTERVAL_HOURS,MEMORY_CANONICAL_PROMOTION_FAST_TRACK_ENABLED,MEMORY_TYPESENSE_COLLECTION,TYPESENSE_HOST,TYPESENSE_HOST_PORT,TYPESENSE_API_KEY,HOSTED_PUSHER_API_URL,${{ steps.runtime-env.outputs.notifications_job_secret_names }}
136168
137169
# If required, use the Cloud Run url output in later steps

backend/charts/backend-listen/dev_omi_backend_listen_values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ env:
149149
value: "3600"
150150
- name: OMI_LLM_GATEWAY_FEATURE_MODE
151151
value: "gateway"
152+
- name: OMI_LLM_GPT56_EXPLICIT_CACHE_ENABLED
153+
value: "false"
152154
- name: OMI_LLM_CHAT_AGENT_ROUTE
153155
value: "gateway"
154156
- name: PUBLIC_SHARED_CONVERSATION_CHAT_MODE

backend/charts/backend-listen/prod_omi_backend_listen_values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ env:
129129
value: "prod"
130130
- name: OMI_LLM_GATEWAY_FEATURE_MODE
131131
value: "gateway"
132+
- name: OMI_LLM_GPT56_EXPLICIT_CACHE_ENABLED
133+
value: "false"
132134
- name: OMI_LLM_CHAT_AGENT_ROUTE
133135
value: "gateway"
134136
- name: PUBLIC_SHARED_CONVERSATION_CHAT_MODE

backend/charts/llm-gateway/templates/backendconfig.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ kind: BackendConfig
44
metadata:
55
name: {{ .Values.service.backendConfig }}
66
spec:
7+
# Flex requests have a route-level 15-minute deadline. Keep the ingress
8+
# connection alive slightly longer; ordinary lanes retain shorter gateway
9+
# deadlines from their route artifacts.
10+
timeoutSec: 960
711
healthCheck:
812
checkIntervalSec: 10
913
timeoutSec: 5

backend/deploy/runtime_env.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ environments:
4444
OMI_LLM_GATEWAY_FEATURE_MODE:
4545
value: gateway
4646
category: rollout
47+
OMI_LLM_GPT56_EXPLICIT_CACHE_ENABLED:
48+
value: 'false'
49+
category: rollout
4750
OMI_LLM_CHAT_AGENT_ROUTE:
4851
value: gateway
4952
category: rollout
@@ -857,7 +860,12 @@ environments:
857860
- HOSTED_PUSHER_API_URL
858861
jobs:
859862
notifications-job:
863+
flags:
864+
--task-timeout: 3600s
860865
secrets:
866+
OMI_LLM_GATEWAY_SERVICE_TOKEN:
867+
secret: OMI_LLM_GATEWAY_SERVICE_TOKEN
868+
version: latest
861869
OPENAI_API_KEY:
862870
secret: OPENAI_API_KEY
863871
version: latest
@@ -871,6 +879,13 @@ environments:
871879
secret: PINECONE_API_KEY
872880
version: latest
873881
env:
882+
OMI_LLM_GATEWAY_URL:
883+
env_var: OMI_LLM_GATEWAY_URL
884+
default: http://127.0.0.1:9
885+
category: service_discovery
886+
OMI_BACKGROUND_FLEX_CAPABLE:
887+
value: 'true'
888+
category: memory_rollout
874889
PINECONE_INDEX_NAME:
875890
category: integrations
876891
value: memories-backend-dev
@@ -947,6 +962,9 @@ environments:
947962
MEMORY_CANONICAL_CONSOLIDATION_ENABLED:
948963
value: 'true'
949964
category: memory_rollout
965+
OMI_BACKGROUND_FLEX_CAPABLE:
966+
value: 'true'
967+
category: memory_rollout
950968
GOOGLE_CLOUD_PROJECT:
951969
value: based-hardware
952970
MEMORY_CANONICAL_GRAPH_BACKFILL_PAGE_SIZE:
@@ -1003,6 +1021,9 @@ environments:
10031021
OMI_LLM_GATEWAY_FEATURE_MODE:
10041022
value: gateway
10051023
category: rollout
1024+
OMI_LLM_GPT56_EXPLICIT_CACHE_ENABLED:
1025+
value: 'false'
1026+
category: rollout
10061027
OMI_LLM_CHAT_AGENT_ROUTE:
10071028
value: gateway
10081029
category: rollout
@@ -1753,7 +1774,12 @@ environments:
17531774
category: rollout
17541775
jobs:
17551776
notifications-job:
1777+
flags:
1778+
--task-timeout: 3600s
17561779
secrets:
1780+
OMI_LLM_GATEWAY_SERVICE_TOKEN:
1781+
secret: OMI_LLM_GATEWAY_SERVICE_TOKEN
1782+
version: latest
17571783
OPENAI_API_KEY:
17581784
secret: OPENAI_API_KEY
17591785
version: latest
@@ -1767,6 +1793,13 @@ environments:
17671793
secret: PINECONE_API_KEY
17681794
version: latest
17691795
env:
1796+
OMI_LLM_GATEWAY_URL:
1797+
env_var: OMI_LLM_GATEWAY_URL
1798+
default: http://127.0.0.1:9
1799+
category: service_discovery
1800+
OMI_BACKGROUND_FLEX_CAPABLE:
1801+
value: 'true'
1802+
category: memory_rollout
17701803
PINECONE_INDEX_NAME:
17711804
category: integrations
17721805
value: memories-backend
@@ -1798,6 +1831,7 @@ environments:
17981831
version: latest
17991832
flags:
18001833
--remove-env-vars: MEMORY_ENABLED_USERS,MEMORY_CANONICAL_PROMOTION_CRON_ENABLED,MEMORY_CANONICAL_PROMOTION_CRON_INTERVAL_HOURS,MEMORY_CANONICAL_PROMOTION_FAST_TRACK_ENABLED
1834+
--task-timeout: 3600s
18011835
env:
18021836
OMI_LLM_GATEWAY_URL:
18031837
env_var: OMI_LLM_GATEWAY_URL
@@ -1836,6 +1870,9 @@ environments:
18361870
MEMORY_CANONICAL_CONSOLIDATION_ENABLED:
18371871
value: 'true'
18381872
category: memory_rollout
1873+
OMI_BACKGROUND_FLEX_CAPABLE:
1874+
value: 'true'
1875+
category: memory_rollout
18391876
OMI_LLM_GATEWAY_ALLOW_PROD_FEATURE_MODE:
18401877
value: 'true'
18411878
category: rollout

backend/deploy/runtime_env/_base.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ environment_shared:
5151
OMI_LLM_GATEWAY_FEATURE_MODE:
5252
value: gateway
5353
category: rollout
54+
OMI_LLM_GPT56_EXPLICIT_CACHE_ENABLED:
55+
value: 'false'
56+
category: rollout
5457
OMI_LLM_CHAT_AGENT_ROUTE:
5558
value: gateway
5659
category: rollout
@@ -488,7 +491,12 @@ environment_shared:
488491
category: memory_rollout
489492
jobs:
490493
notifications-job:
494+
flags:
495+
--task-timeout: 3600s
491496
secrets:
497+
OMI_LLM_GATEWAY_SERVICE_TOKEN:
498+
secret: OMI_LLM_GATEWAY_SERVICE_TOKEN
499+
version: latest
492500
OPENAI_API_KEY:
493501
secret: OPENAI_API_KEY
494502
version: latest
@@ -502,6 +510,13 @@ environment_shared:
502510
secret: PINECONE_API_KEY
503511
version: latest
504512
env:
513+
OMI_LLM_GATEWAY_URL:
514+
env_var: OMI_LLM_GATEWAY_URL
515+
default: http://127.0.0.1:9
516+
category: service_discovery
517+
OMI_BACKGROUND_FLEX_CAPABLE:
518+
value: 'false'
519+
category: memory_rollout
505520
PINECONE_INDEX_NAME:
506521
category: integrations
507522
OMI_ENV_STAGE:
@@ -567,3 +582,6 @@ environment_shared:
567582
MEMORY_CANONICAL_CONSOLIDATION_ENABLED:
568583
value: 'true'
569584
category: memory_rollout
585+
OMI_BACKGROUND_FLEX_CAPABLE:
586+
value: 'false'
587+
category: memory_rollout

backend/deploy/runtime_env/dev.overlay.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,11 @@ overlay:
418418
version: latest
419419
jobs:
420420
notifications-job:
421+
flags:
422+
--task-timeout: 3600s
421423
env:
424+
OMI_BACKGROUND_FLEX_CAPABLE:
425+
value: 'true'
422426
GOOGLE_CLOUD_PROJECT:
423427
value: based-hardware
424428
PINECONE_INDEX_NAME:
@@ -439,6 +443,8 @@ overlay:
439443
value: 'false'
440444
MEMORY_CANONICAL_GRAPH_BACKFILL_ENABLED:
441445
value: 'false'
446+
OMI_BACKGROUND_FLEX_CAPABLE:
447+
value: 'true'
442448
MEMORY_CANONICAL_GRAPH_BACKFILL_PAGE_SIZE:
443449
value: '25'
444450
PINECONE_INDEX_NAME:

backend/deploy/runtime_env/prod.overlay.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,16 @@ overlay:
364364
value: 'off'
365365
jobs:
366366
notifications-job:
367+
flags:
368+
--task-timeout: 3600s
367369
env:
370+
OMI_BACKGROUND_FLEX_CAPABLE:
371+
value: 'true'
368372
PINECONE_INDEX_NAME:
369373
value: memories-backend
370374
memory-maintenance-job:
375+
flags:
376+
--task-timeout: 3600s
371377
env:
372378
OMI_LLM_GATEWAY_ALLOW_PROD_FEATURE_MODE:
373379
value: 'true'
@@ -381,5 +387,7 @@ overlay:
381387
value: 'false'
382388
MEMORY_CANONICAL_GRAPH_BACKFILL_ENABLED:
383389
value: 'false'
390+
OMI_BACKGROUND_FLEX_CAPABLE:
391+
value: 'true'
384392
PINECONE_INDEX_NAME:
385393
value: memories-backend

backend/docs/llm/model_endpoint_inventory.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ model_config_features:
3737
- memories
3838
- memory_category
3939
- memory_conflict
40+
- memory_conflict_flex
4041
- memory_l1
42+
- memory_l2_flex
4143
- notifications
4244
- onboarding
4345
- openglass
@@ -47,6 +49,7 @@ model_config_features:
4749
- session_titles
4850
- smart_glasses
4951
- wrapped_analysis
52+
- x_memory_extraction_flex
5053
- app_generator
5154
- app_integration
5255
structured_output:

backend/llm_gateway/config/generated_route_overrides.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ generated_route_overrides:
7575
- feature: memory_conflict
7676
primary: {provider: openai, model: gpt-5.6-luna}
7777
provider_options: {reasoning_effort: low}
78+
- feature: memory_conflict_flex
79+
primary: {provider: openai, model: gpt-5.6-luna}
80+
provider_options: {reasoning_effort: low}
81+
request_timeout_ms: 900000
82+
- feature: memory_l2_flex
83+
primary: {provider: openai, model: gpt-5.6-luna}
84+
provider_options: {reasoning_effort: medium}
85+
request_timeout_ms: 900000
86+
- feature: x_memory_extraction_flex
87+
primary: {provider: openai, model: gpt-5.6-luna}
88+
provider_options: {reasoning_effort: low}
89+
request_timeout_ms: 900000
7890
- feature: memory_l1
7991
primary: {provider: openai, model: gpt-5.6-luna}
8092
provider_options: {reasoning_effort: low}

0 commit comments

Comments
 (0)