Commit 3e57623
authored
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_result48 files changed
Lines changed: 1945 additions & 206 deletions
File tree
- .github/workflows
- backend
- charts
- backend-listen
- llm-gateway/templates
- deploy
- runtime_env
- docs/llm
- llm_gateway
- config
- gateway
- scripts/runtime_env_validation
- tests
- unit
- utils
- llm
- memory
- other
- config
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
83 | 99 | | |
84 | 100 | | |
85 | 101 | | |
86 | 102 | | |
87 | 103 | | |
88 | 104 | | |
89 | 105 | | |
| 106 | + | |
90 | 107 | | |
91 | 108 | | |
92 | 109 | | |
| |||
119 | 136 | | |
120 | 137 | | |
121 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
122 | 152 | | |
123 | 153 | | |
124 | 154 | | |
| |||
132 | 162 | | |
133 | 163 | | |
134 | 164 | | |
| 165 | + | |
| 166 | + | |
135 | 167 | | |
136 | 168 | | |
137 | 169 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
| 153 | + | |
152 | 154 | | |
153 | 155 | | |
154 | 156 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
132 | 134 | | |
133 | 135 | | |
134 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
7 | 11 | | |
8 | 12 | | |
9 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
| |||
857 | 860 | | |
858 | 861 | | |
859 | 862 | | |
| 863 | + | |
| 864 | + | |
860 | 865 | | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
861 | 869 | | |
862 | 870 | | |
863 | 871 | | |
| |||
871 | 879 | | |
872 | 880 | | |
873 | 881 | | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
874 | 889 | | |
875 | 890 | | |
876 | 891 | | |
| |||
947 | 962 | | |
948 | 963 | | |
949 | 964 | | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
950 | 968 | | |
951 | 969 | | |
952 | 970 | | |
| |||
1003 | 1021 | | |
1004 | 1022 | | |
1005 | 1023 | | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
1006 | 1027 | | |
1007 | 1028 | | |
1008 | 1029 | | |
| |||
1753 | 1774 | | |
1754 | 1775 | | |
1755 | 1776 | | |
| 1777 | + | |
| 1778 | + | |
1756 | 1779 | | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
1757 | 1783 | | |
1758 | 1784 | | |
1759 | 1785 | | |
| |||
1767 | 1793 | | |
1768 | 1794 | | |
1769 | 1795 | | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
1770 | 1803 | | |
1771 | 1804 | | |
1772 | 1805 | | |
| |||
1798 | 1831 | | |
1799 | 1832 | | |
1800 | 1833 | | |
| 1834 | + | |
1801 | 1835 | | |
1802 | 1836 | | |
1803 | 1837 | | |
| |||
1836 | 1870 | | |
1837 | 1871 | | |
1838 | 1872 | | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
1839 | 1876 | | |
1840 | 1877 | | |
1841 | 1878 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
| |||
488 | 491 | | |
489 | 492 | | |
490 | 493 | | |
| 494 | + | |
| 495 | + | |
491 | 496 | | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
492 | 500 | | |
493 | 501 | | |
494 | 502 | | |
| |||
502 | 510 | | |
503 | 511 | | |
504 | 512 | | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
505 | 520 | | |
506 | 521 | | |
507 | 522 | | |
| |||
567 | 582 | | |
568 | 583 | | |
569 | 584 | | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
| 421 | + | |
| 422 | + | |
421 | 423 | | |
| 424 | + | |
| 425 | + | |
422 | 426 | | |
423 | 427 | | |
424 | 428 | | |
| |||
439 | 443 | | |
440 | 444 | | |
441 | 445 | | |
| 446 | + | |
| 447 | + | |
442 | 448 | | |
443 | 449 | | |
444 | 450 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
| 367 | + | |
| 368 | + | |
367 | 369 | | |
| 370 | + | |
| 371 | + | |
368 | 372 | | |
369 | 373 | | |
370 | 374 | | |
| 375 | + | |
| 376 | + | |
371 | 377 | | |
372 | 378 | | |
373 | 379 | | |
| |||
381 | 387 | | |
382 | 388 | | |
383 | 389 | | |
| 390 | + | |
| 391 | + | |
384 | 392 | | |
385 | 393 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| |||
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| 52 | + | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
| |||
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
78 | 90 | | |
79 | 91 | | |
80 | 92 | | |
| |||
0 commit comments