Skip to content

feat(memory): enable full canonical maintenance for first-user whitelist in dev - #9295

Merged
Git-on-my-level merged 2 commits into
mainfrom
feat/memory-whitelist-full-promotion
Jul 9, 2026
Merged

Git-on-my-level merged 2 commits into
mainfrom
feat/memory-whitelist-full-promotion

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 9, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Turns on durable full canonical maintenance for the single whitelisted UID (vi7SA9ckQCe4ccobWNxlbdcNdC23) in dev only: MEMORY_MODE=read (already on) plus MEMORY_CANONICAL_PROMOTION_CRON_ENABLED=true and MEMORY_CANONICAL_PROMOTION_FAST_TRACK_ENABLED=true.
  • Wires hourly notifications-job into backend/deploy/runtime_env.yaml (env + consolidation secrets) and updates gcp_notifications_job.yml to render/apply that contract on deploy — so merge+deploy is enough for real ST→LT (TTL → consolidation → promotion), not a half-enabled backend-only flag flip.
  • Leaves prod off/empty and does not expand CANONICAL_MEMORY_USERS. Non-whitelisted users stay on legacy API with Desktop lifecycle UI fail-closed.

Isolation

  • Code cohort: only David’s UID in CANONICAL_MEMORY_USERS.
  • Env allowlist: only that UID in MEMORY_ENABLED_USERS (dev); prod empty + MEMORY_MODE=off.
  • Cron iterates code whitelist only; each UID still must pass resolve_memory_system().
  • Desktop lifecycle requires X-Omi-Memory-Canonical-Lifecycle-Exposed: true (exact).

Preflight (read-only, 2026-07-08)

Firestore based-hardware enrollment already at read-stage for this UID:

  • global_read_gate open (memory_reads_enabled=true, kill switch off)
  • write_convergence_gate ready
  • users/.../memory_control/state mode=read, stage gates passed, grants.omi_chat.default_memory=true
  • memory_state/head and v3_compatibility_projection/state present

Test plan

  • python3 backend/scripts/validate-backend-runtime-env.py --env dev --check-workflows
  • python3 backend/scripts/validate-backend-runtime-env.py --env prod --check-workflows
  • pytest tests/unit/test_render_backend_runtime_env.py tests/unit/test_backend_runtime_env_validator.py (19 passed)
  • CI backend unit / lint on this PR

Post-merge deploy checklist (only remaining work)

  1. Merge with a regular merge (not squash).
  2. Confirm auto-dev backend deploy picks up promotion flag parity on Cloud Run backend / GKE listen (or dispatch backend deploy if needed).
  3. workflow_dispatch .github/workflows/gcp_notifications_job.yml with environment=development, branch=main.
  4. Confirm live job env: cron+fast-track true, allowlist = David only, secrets present (SERVICE_ACCOUNT_JSON, OPENAI_API_KEY, Pinecone, Typesense).
  5. Wait for next hourly tick (or execute the job once) → logs show maintenance for David only.
  6. Desktop dogfood: Long-term layer filter shows promotions; Short-term continues; non-whitelist account unchanged.

Kill switches

  1. Set MEMORY_CANONICAL_PROMOTION_CRON_ENABLED=false on notifications-job (dev) and redeploy.
  2. Remove UID from MEMORY_ENABLED_USERS.
  3. Remove UID from CANONICAL_MEMORY_USERS + redeploy (hard kill).

Made with Cursor

Review in cubic

Git-on-my-level and others added 2 commits July 8, 2026 21:05
…ist in dev

Wire notifications-job into the runtime env contract and turn on promotion
cron + fast-track for the single allowlisted UID so merge+deploy yields
real ST→LT maintenance without affecting non-whitelist or prod.

Co-authored-by: Cursor <[email protected]>
@mintlify

mintlify Bot commented Jul 9, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
omi 🟢 Ready View Preview Jul 9, 2026, 1:09 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 9 files

Confidence score: 3/5

  • In .github/workflows/gcp_notifications_job.yml, the deploy label/tag SHA can diverge from the actual checked-out commit when branch differs from the workflow run ref, which risks deploying or recording the wrong revision and makes rollback/debugging unreliable — compute the short SHA from the checked-out HEAD (post-checkout) before merging.

You’re at about 92% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name=".github/workflows/gcp_notifications_job.yml">

<violation number="1" location=".github/workflows/gcp_notifications_job.yml:71">
P2: Deploy revisions can be labeled with a SHA that does not match the checked-out source when the `branch` input differs from the workflow run ref. Since this workflow now deploys the short-SHA tag, deriving it from `git rev-parse HEAD` after checkout would keep the image tag tied to the actual built commit.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

- name: Compute short SHA
id: image-tag
run: |
echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Deploy revisions can be labeled with a SHA that does not match the checked-out source when the branch input differs from the workflow run ref. Since this workflow now deploys the short-SHA tag, deriving it from git rev-parse HEAD after checkout would keep the image tag tied to the actual built commit.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .github/workflows/gcp_notifications_job.yml, line 71:

<comment>Deploy revisions can be labeled with a SHA that does not match the checked-out source when the `branch` input differs from the workflow run ref. Since this workflow now deploys the short-SHA tag, deriving it from `git rev-parse HEAD` after checkout would keep the image tag tied to the actual built commit.</comment>

<file context>
@@ -65,16 +65,35 @@ jobs:
+      - name: Compute short SHA
+        id: image-tag
+        run: |
+          echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
+
       - name: Google Service Account
</file context>
Suggested change
echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
echo "short_sha=$(git rev-parse --short=7 HEAD)" >> "$GITHUB_OUTPUT"

@chatgpt-codex-connector

Copy link
Copy Markdown

💡 Codex Review

run: |
python3 backend/scripts/render_backend_runtime_env.py --env ${{ vars.ENV }} >> "$GITHUB_OUTPUT"

P1 Badge Pass VPC vars when rendering prod job env

When this workflow is dispatched for prod, vars.ENV makes render_backend_runtime_env.py render the prod manifest before it emits notifications_job_* outputs. The prod manifest's Cloud Run network flags are backed by CLOUD_RUN_VPC_NETWORK/CLOUD_RUN_VPC_SUBNET, but this step does not pass those GitHub vars into the renderer (unlike the backend deploy workflow), so the render exits before the job deploy can start. Add the same env: bindings here or make the job-only render path skip network flags.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Git-on-my-level
Git-on-my-level merged commit a8d3780 into main Jul 9, 2026
20 checks passed
@Git-on-my-level
Git-on-my-level deleted the feat/memory-whitelist-full-promotion branch July 9, 2026 02:31
Git-on-my-level added a commit that referenced this pull request Jul 9, 2026
)

## Summary
Follow-up to #9295 review feedback before any prod `notifications-job`
deploy:

- Pass `CLOUD_RUN_VPC_NETWORK` / `CLOUD_RUN_VPC_SUBNET` into the render
step (same as `gcp_backend.yml`). Prod network flags are
`env_var`-backed; without them `render_backend_runtime_env.py` exits
before `notifications_job_*` outputs are emitted.
- Derive the immutable image short SHA from `git rev-parse --short=7
HEAD` after checkout so the tag matches the `branch` input, not a
divergent `GITHUB_SHA` workflow-file ref.

## Why
- Codex P1 on #9295: prod workflow_dispatch could fail at render.
- Cubic P2 on #9295: SHA/tag mismatch when `branch` ≠ run ref.

## Test plan
- [x] `pytest backend/tests/unit/test_render_backend_runtime_env.py` (8
passed), including regression that prod render requires VPC vars and
workflow source assertions
- [x] `validate-backend-runtime-env.py --env dev|prod --check-workflows`
- [ ] CI on this PR

## Notes
- No memory flag / cohort / prod enablement changes.
- Safe to land independently of whitelist dogfood; required before
relying on prod notifications-job deploys.

Made with [Cursor](https://cursor.com)

<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/BasedHardware/omi/pull/9296?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. -->
mdmohsin7 added a commit that referenced this pull request Jul 10, 2026
…anager binds (#9385)

## Summary

Daily summaries silently stopped generating for every user on
2026-07-01. Root cause: the `notifications-job` Cloud Run Job's
`OPENAI_API_KEY` was a **plain-literal env var** with a stale key value
that OpenAI is now rejecting (`sk-proj-…wMAA` → `401 Unauthorized`).
Every daily-summary run since caught the 401 in a broad `except
Exception`, logged it, and returned without writing a summary or firing
a push.

The underlying architectural issue: **Cloud Run rejects updates when the
same name is bound as both a plain-literal env-var and a Secret Manager
secret**. If any earlier deploy hard-coded `OPENAI_API_KEY` (or any
other secret name) into env, the literal silently wins forever —
subsequent workflow runs that render `OPENAI_API_KEY` as a secret ref
via `notifications_job_secrets` can't take effect because the deploy
step never removes the conflicting literal.

The `backend/deploy/runtime_env.yaml` manifest already correctly
declares `OPENAI_API_KEY`, `PINECONE_API_KEY`, `SERVICE_ACCOUNT_JSON`,
and `ENCRYPTION_SECRET` as Secret Manager binds on `notifications-job`.
The workflow was just missing the cleanup step.

## How the intent was declared but never took effect

PR #9295 (2026-07-08) first added `notifications-job` to the runtime env
contract — the manifest section with `OPENAI_API_KEY` as a Secret
Manager binding, plus the render + `secrets:` output wiring in
`.github/workflows/gcp_notifications_job.yml`. The same PR also
introduced the workflow's `--remove-env-vars=…` flag, but only listed
the retired canonical-maintenance and Typesense keys — not the
newly-declared secret names. Subsequent tightening in #9296, #9308, and
#9358 kept the same `--remove-env-vars=` list without adding the secret
names to it.

Because `google-github-actions/deploy-cloudrun@v2` merges `secrets:`
additively rather than removing overlapping env-vars, and Cloud Run
silently keeps the pre-existing literal when a name is bound both ways,
the secret ref for `OPENAI_API_KEY` was declared correctly but never
actually replaced the (broken) literal. The literal was already broken
as of 2026-07-01 01:06 UTC — Loki logs show a clean cutover from working
summaries to `401 Unauthorized: invalid_api_key` at that timestamp, ~7
days before the Secret Manager binding was declared — so the July 8
change would have unblocked summaries immediately if it had also
stripped the literal.

Not a blame-y point: this class of gap is easy to miss because the
intent looks correct in code review — the manifest says "secret", the
workflow reads `notifications_job_secrets`, and `deploy-cloudrun@v2`
accepts it. The failure mode only surfaces on a target that already had
a plain literal by the same name, which isn't visible from the PR diff
alone. The mitigation is small and general (this PR).

## Change

- `render_backend_runtime_env.py` emits a new `<prefix>_secret_names`
output per service/job — a comma-separated list of exactly the names in
`secrets:`.
- `gcp_notifications_job.yml` appends that output to its existing
`--remove-env-vars=…` flag. `--remove-env-vars` is a no-op on a clean
target, so this is safe on healthy deployments and cleanup on polluted
ones.
- Manifest stays the single source of truth — adding/removing a secret
in `runtime_env.yaml` automatically flows both `--update-secrets` and
the matching `--remove-env-vars` on the next deploy.

## Immediate live fix (already applied)

To unblock tonight's summaries without waiting for the workflow to run,
the live job was updated manually:

```bash
gcloud run jobs update notifications-job \
  --project=based-hardware --region=us-central1 \
  --remove-env-vars=OPENAI_API_KEY \
  --update-secrets=OPENAI_API_KEY=OPENAI_API_KEY:latest
gcloud run jobs execute notifications-job --project=based-hardware --region=us-central1
```

Post-execution logs are clean — zero `invalid_api_key`, `Sending daily
summary` firing normally across all timezones. This PR makes the fix
durable so future deploys can't regress.

## Test plan

- [x] `pytest backend/tests/unit/test_render_backend_runtime_env.py` — 9
passed, includes new assertion that `notifications_job_secret_names`
emits `{SERVICE_ACCOUNT_JSON, ENCRYPTION_SECRET, OPENAI_API_KEY,
PINECONE_API_KEY}`.
- [x] Manual `python3 backend/scripts/render_backend_runtime_env.py
--env prod` output verified.
- [x] Existing workflow-structure assertion
(`test_notifications_job_workflow_passes_vpc_vars_and_checkout_sha`)
still passes — the change is additive to the flag string.
- [ ] Trigger `gcp_notifications_job.yml` prod deploy and verify the
live job's spec shows `OPENAI_API_KEY` as `secretKeyRef` (not `value`).

## Notes / follow-ups

- The live job carries several other historical literal env vars
(`FAL_KEY`, `GROQ_API_KEY`, `SONIOX_API_KEY`, `DEEPGRAM_API_KEY`,
`ADMIN_KEY`, `REDIS_DB_PASSWORD`, `GITHUB_TOKEN`, and more) that aren't
declared in the manifest at all — the current manifest deliberately
narrows `notifications-job` to just the 4 secrets it needs. Whether the
extras should be added, removed, or ignored is a separate call.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

This branch was successfully deployed

1 active deployment
staging - docs — 8361d309 Deployed Jul 9, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant