Skip to content

feat: Jev population shadows and cohort ramp controls (EXP-004) - #19968

Merged
Git-on-my-level merged 8 commits into
mainfrom
feat/jev-population-shadow
Oct 1, 2026
Merged

Git-on-my-level merged 8 commits into
mainfrom
feat/jev-population-shadow

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Measure Jev relevance and owner probabilities asynchronously on production candidates without changing decisions. Add deterministic user arms for a later config-only ramp and keep-all control, with atomic Redis budgets and dedupe, bounded workers, text-free Firestore evidence, and EXP-004 acceptance bars.

Product invariants affected

  • INV-MEM-4: Production live flags remain off; shadow cannot change memory or relevance output. All processing hosts receive matching declared shadow settings.

  • INV-TASK-2: Cohort and shadow submission leave task candidate capture authority and user approval unchanged.

Validation

Synthetic cohort, relevance, shadow and canonical-capture tests; deployment fixtures, registry and runtime image closure; full local preflight. No cloud data reads or deployments.

Failure-Class: none

Line-Count-Exception: backend/utils/conversations/process_conversation.py | 3438 -> 3520 | Wire per-user arms and string-only owner/relevance shadow submission at the existing decision seams

🤖 Generated with Claude Code

Review in cubic

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T01:46:41.138000Z 9f03a5d New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2af2449acb

ℹ️ 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".

Comment thread backend/database/jev_shadow.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a99e0d9253

ℹ️ 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".

Comment thread backend/config/jev_decisions.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d111076166

ℹ️ 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".

Comment thread backend/config/jev_decisions.py Resolved
Comment thread backend/database/jev_shadow.py Resolved
Git-on-my-level added a commit that referenced this pull request Sep 30, 2026
Review fixes (Codex threads on #19968):
- Fence jev_shadow writes against account deletion via a transaction
  reading account_deletions/{uid}, mirroring transcription_shadow; fenced
  writes record 'dropped' (PRRT_kwDOLkKqys6ndzXn)
- Keep shadow DB work off the LLM pool: dedicated jev_shadow_executor
  and lane semaphores bound admission/store IO out of llm_executor (P2)
- Handle source=None conversations as 'unknown' instead of crashing (P2)
- Add 'entity' to the persisted subject-kind allowlist (P2)
- Prod shadow percentages start at 0 pending the jev_shadow TTL policy
  provisioning; EXP-004 doc records the gate (P1)
- Include question_version in shadow record IDs to preserve
  recalibration evidence (P2)
- Record the owner 'cohort' outcome for cohort-gated candidates (P2)
- Classify google.api_core DeadlineExceeded as 'timeout' (P2)
- Fail closed on invalid percentages before consulting allowlists via
  _percentage_or_none (P2)
- Make MEMORY_OWNER_JEV_FLIP_ENABLED universal per INV-MEM-5: remove
  owner_flip_enabled_for and the FLIP percent/allowlist flags (P1)
- ask_jev gains record_decision_metrics=False for shadow calls so live
  decision lanes stay uncontaminated (P2)
- Module-scope get_data_plane_firestore_client import per the backend
  import contract; test stubs updated (P1)
- Enforce wall-clock deadline in execute_systemone via asyncio.wait_for
  (P2)

Also: base runtime_env prod blocks aligned with overlays/charts (shadow
percentages 0); feature-flag registry regenerated.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 89d283a0eb

ℹ️ 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".

Comment thread backend/database/jev_shadow.py Resolved
Git-on-my-level added a commit that referenced this pull request Sep 30, 2026
Review fixes (Codex threads on #19968, round 2):
- Bound the deletion-fence transaction: marker.get passes retry=None and
  timeout=remaining, and client.transaction(max_attempts=1) disables the
  SDK restart loop so one write cannot exceed the 2.5s task budget (P2)
- Observe JEV_SHADOW_LATENCY in the worker's finally block (model calls
  only) so the p95 bar includes score processing and persistence (P2)
- Set a dedicated jev_shadow_{lane} usage context around ask_jev so the
  parent track_usage(Features.MEMORIES) context cannot claim the shadow
  budget in gateway accounting (P2)
- Reject owner answers whose three probabilities do not form a complete
  distribution (exact option set, sum within 0.01 of 1.0) instead of
  persisting them as ok (P2)
- Shadow transcript_only now mirrors the live Jev gate: blank-description
  photos no longer exclude a conversation from calibration (P2)
- Dev backend-sync and backend-sync-backfill shadow percentages drop to
  0: those Cloud Run hosts have no GMP sidecar/exporter entry, so their
  shadow metrics would be invisible; EXP-004 doc records the host
  scoping and the feature-flag registry is regenerated (P2)

Test stubs updated accordingly.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b818c5710

ℹ️ 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".

Comment thread backend/database/jev_shadow.py Resolved
Git-on-my-level and others added 8 commits October 1, 2026 07:52
Many suites stub database._client without get_data_plane_firestore_client;
the module-top import made process_conversation fail to load under them
(CI backend unit shards 1, 2 and 4).

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Review fixes (Codex threads on #19968):
- Fence jev_shadow writes against account deletion via a transaction
  reading account_deletions/{uid}, mirroring transcription_shadow; fenced
  writes record 'dropped' (PRRT_kwDOLkKqys6ndzXn)
- Keep shadow DB work off the LLM pool: dedicated jev_shadow_executor
  and lane semaphores bound admission/store IO out of llm_executor (P2)
- Handle source=None conversations as 'unknown' instead of crashing (P2)
- Add 'entity' to the persisted subject-kind allowlist (P2)
- Prod shadow percentages start at 0 pending the jev_shadow TTL policy
  provisioning; EXP-004 doc records the gate (P1)
- Include question_version in shadow record IDs to preserve
  recalibration evidence (P2)
- Record the owner 'cohort' outcome for cohort-gated candidates (P2)
- Classify google.api_core DeadlineExceeded as 'timeout' (P2)
- Fail closed on invalid percentages before consulting allowlists via
  _percentage_or_none (P2)
- Make MEMORY_OWNER_JEV_FLIP_ENABLED universal per INV-MEM-5: remove
  owner_flip_enabled_for and the FLIP percent/allowlist flags (P1)
- ask_jev gains record_decision_metrics=False for shadow calls so live
  decision lanes stay uncontaminated (P2)
- Module-scope get_data_plane_firestore_client import per the backend
  import contract; test stubs updated (P1)
- Enforce wall-clock deadline in execute_systemone via asyncio.wait_for
  (P2)

Also: base runtime_env prod blocks aligned with overlays/charts (shadow
percentages 0); feature-flag registry regenerated.
Review fixes (Codex threads on #19968, round 2):
- Bound the deletion-fence transaction: marker.get passes retry=None and
  timeout=remaining, and client.transaction(max_attempts=1) disables the
  SDK restart loop so one write cannot exceed the 2.5s task budget (P2)
- Observe JEV_SHADOW_LATENCY in the worker's finally block (model calls
  only) so the p95 bar includes score processing and persistence (P2)
- Set a dedicated jev_shadow_{lane} usage context around ask_jev so the
  parent track_usage(Features.MEMORIES) context cannot claim the shadow
  budget in gateway accounting (P2)
- Reject owner answers whose three probabilities do not form a complete
  distribution (exact option set, sum within 0.01 of 1.0) instead of
  persisting them as ok (P2)
- Shadow transcript_only now mirrors the live Jev gate: blank-description
  photos no longer exclude a conversation from calibration (P2)
- Dev backend-sync and backend-sync-backfill shadow percentages drop to
  0: those Cloud Run hosts have no GMP sidecar/exporter entry, so their
  shadow metrics would be invisible; EXP-004 doc records the host
  scoping and the feature-flag registry is regenerated (P2)

Test stubs updated accordingly.
The SDK's @firestore.transactional wrapper invokes transaction._commit()
with the client default timeout (google-cloud-firestore 2.20.0), so a
stalled Firestore commit could hold a shadow worker far past the
documented 2.5-second budget even with max_attempts=1 and the deadline
already applied to the marker read.

Race the transactional call on a dedicated two-worker pool and re-raise
an overrun as builtin TimeoutError, so the worker records 'timeout' and
releases its lane slot inside the budget (same pattern as
speaker_tag_prompts list verification and MCP CIMD DNS resolution).

Verified: BACKEND_UNIT_TEST_FILE_LIST focused run,
test_store_commit_race_bounds_a_stalled_sdk_commit plus the full
test_jev_population_shadow.py module pass.
…population

Dev processing hosts enable CONVERSATION_RELEVANCE_JEV_ENABLED with the
live percentage unset, and relevance_arm() defaults an unset percent to
100 when the flag is on, routing every UID to the live Jev arm — which
submit_relevance_shadow() explicitly skips. The dev relevance shadow at
100 would have recorded nothing.

Pin CONVERSATION_RELEVANCE_JEV_PERCENT to 0 on the four dev
process_conversation hosts (overlay + composed manifest + both dev
charts), keeping decisions identical across hosts and matching prod
posture while the shadow measures the full nano arm. Add a manifest
guard (test_dev_jev_shadow_hosts_keep_a_nonempty_measurement_arm) so a
shadow-enabled live-flag host can no longer ship with an unset or
all-consuming live percentage, and correct the two EXP-004 doc
sentences that described the old state.

Verified: BACKEND_UNIT_TEST_FILE_LIST focused run —
test_dev_jev_shadow_hosts_keep_a_nonempty_measurement_arm,
test_rendered_dev_pusher_direct_bindings_match_source_contract,
test_jev_rollout_flags_cover_only_process_conversation_hosts and the
full validator/pusher-config modules pass; compose_runtime_env.py
regenerated the manifest with the four pins.
@Git-on-my-level
Git-on-my-level force-pushed the feat/jev-population-shadow branch from 1b818c5 to 9f03a5d Compare October 1, 2026 01:38
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Addressed both review threads in 9f03a5d (rebased onto current main):

Bound the shadow commit by the remaining deadline (backend/database/jev_shadow.py)
The SDK's @firestore.transactional wrapper invokes transaction._commit() with the client-default timeout (google-cloud-firestore 2.20.0), so a stalled commit could hold a worker past the 2.5s budget even with max_attempts=1. The transactional call is now raced on a dedicated two-worker pool with the remaining budget and re-raises an overrun as TimeoutError (worker records timeout, releases its lane). Regression: test_store_commit_race_bounds_a_stalled_sdk_commit.

Dev relevance shadow population fix (dev.overlay.yaml, composed manifest, both dev charts)
Pinned CONVERSATION_RELEVANCE_JEV_PERCENT: '0' on the four dev process_conversation hosts: unset defaults to 100 with the live flag on, which routes every UID to the live Jev arm that submit_relevance_shadow() skips — the dev shadow would have recorded nothing. Dev decisions stay identical across hosts (nano, matching prod posture while measurement runs). New manifest guard test_dev_jev_shadow_hosts_keep_a_nonempty_measurement_arm rejects a shadow-enabled live-flag host with an unset or all-consuming live percentage; rendered flag registry and EXP-004 doc updated to match.

Verification: focused BACKEND_UNIT_TEST_FILE_LIST run through backend/test.sh — 127 passed across the jev shadow/ramp, runtime-env validator, and pusher-config modules; compose_runtime_env.py and render_feature_flag_registry.py regenerated; full bounded pre-push gate passed locally. PR-body line-count exception refreshed to the post-rebase counts (3438 → 3520).

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9f03a5d079

ℹ️ 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".

Comment on lines +33 to +37
return future.result(timeout=timeout)
except concurrent.futures.TimeoutError:
# Raised as builtin TimeoutError so the worker classifies an overran
# commit as 'timeout' rather than 'jev_failed'.
future.cancel()

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 Badge Stop timed-out transactions instead of abandoning the wait

When a Firestore commit exceeds the remaining budget, future.cancel() cannot stop the transaction once its worker has begun executing, so the SDK call can continue for its default timeout and may persist the record after _run has reported timeout and released the lane. Fresh evidence after the earlier commit-deadline report is that the new race bounds only Future.result(), not the in-flight commit; two stalled calls also occupy this ad-hoc pool and make later persistence attempts time out behind them. Propagate the deadline to the actual commit or otherwise terminate the operation rather than abandoning the wait.

AGENTS.md reference: backend/AGENTS.md:L253-L253

Useful? React with 👍 / 👎.

Comment on lines +119 to +122
jev = _percentage_or_none('CONVERSATION_RELEVANCE_JEV_PERCENT', default=100.0)
if jev is not None and (
bucket < min(100.0, (keep_all if keep_all is not None else 0.0) + jev)
or _allowlisted(uid, 'CONVERSATION_RELEVANCE_JEV_UID_ALLOWLIST')

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 Badge Fail closed when the keep-all percentage is invalid

When CONVERSATION_RELEVANCE_KEEP_ALL_PERCENT is malformed but the live flag and CONVERSATION_RELEVANCE_JEV_PERCENT are valid, keep_all becomes None and this expression silently substitutes zero, assigning users to the live Jev arm despite the documented fail-closed behavior. For example, KEEP_ALL_PERCENT=broken, JEV_PERCENT=100, and the enable flag set makes every UID return jev; return nano when either cohort boundary is invalid instead of treating an invalid keep-all boundary as zero.

Useful? React with 👍 / 👎.

Comment on lines +116 to +117
MEMORY_OWNER_JEV_SHADOW_PERCENT:
value: '100'

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 Badge Disable live owner scoring on owner-shadow hosts

On each inspected shadow-enabled dev processing host—Cloud Run backend, backend-listen, and pusher—this is set to 100% while MEMORY_OWNER_JEV_FLIP_ENABLED remains true. In _extract_memories_canonical, the first eight third-party candidates are consequently marked owner_live_scored and explicitly excluded from shadow submission even when the live call fails, so ordinary conversations produce no owner-shadow probability records and only rare candidates beyond the live budget enter the experiment. Disable the live owner flip on hosts intended to collect the owner-shadow distribution, or otherwise preserve measurements for those live-scored candidates.

Useful? React with 👍 / 👎.

Comment on lines +130 to +132
slot = _slots[lane]
if not slot.acquire(blocking=False):
record_jev_shadow_outcome(lane, 'dropped')

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 Badge Sample owner candidates before applying the two-slot bound

When live owner scoring is off and one conversation yields more than two eligible third-party candidates, the extraction loop submits them back-to-back before either Redis/LLM task can finish, so this two-slot semaphore admits the first two and deterministically records the rest as dropped. Candidate inclusion is therefore driven by extractor order rather than sampling, giving later candidates effectively zero inclusion even though the eventual live path scores up to eight; the measured owner-probability distribution cannot safely support a universal rollout. Choose the bounded candidates randomly or with a per-conversation reservoir before dispatching them.

Useful? React with 👍 / 👎.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Coordination note from the Claude session that opened this PR and is driving the EXP-004 rollout for David (authorized to admin-merge and deploy).

I see another driver has been pushing review fixes and rebasing this branch (latest 9f03a5d079). I am NOT pushing to this branch and have dropped my own local follow-ups, which this branch supersedes. State I verified against current main (34dd164): the only failing checks are the 8 test_realtime_quota_counter.py tests, which also fail on main; everything else passes. Four Codex threads remain open (Firestore commit abandonment, invalid keep-all percent, owner live scoring on dev shadow hosts, two-slot bound sampling bias on owner candidates).

Plan: if you are still working on these, push or reply here. Otherwise I will admin-merge this PR once those threads are resolved, then deploy serially (backend, listen, pusher) and monitor. Prod live Jev flags stay off; only the shadow settings ship. Please do not dispatch a prod deploy for this change yourself, so we do not overlap deploys.

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