Skip to content

CORE-410: cherry-pick auth + repetition fixes from Zambia fork#691

Merged
rav3n11 merged 9 commits into
mainfrom
feat/core-410-cherry-pick
May 27, 2026
Merged

CORE-410: cherry-pick auth + repetition fixes from Zambia fork#691
rav3n11 merged 9 commits into
mainfrom
feat/core-410-cherry-pick

Conversation

@nraffa

@nraffa nraffa commented May 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

Brings the authentication and skills-explorer repetition fixes developed on the Zambia fork over the past months into core Compass. Each change is an atomic cherry-pick -x (provenance trailer preserved); fork-only features were deliberately excluded.

Resolves CORE-410.

Changes

Authentication

  • Remove client-side token expiry/iat checks — rely on server 401 to handle device clock skew (01b41a60)
  • Retry token refresh on network errors (30f36852)

Skills-explorer repetition / disengagement (the core of the ticket)

  • Runtime repetition detection + force-summarization (_flush_if_repeating, REPETITION_SHORT_CIRCUIT_THRESHOLD) (a486465b)
  • Prompt-level NEVER re-ask + DISENGAGEMENT SIGNALS rules, wrapped around core's existing (a)/(b)/(c) question structure (3679765d)
  • Don't persist the outgoing agent's response on phase transition — the incoming agent produces the message the user sees (23341141)
  • Sentence-decomposition grammatical-person consistency (15b0b771)
  • Scripted loop-detection eval tests replaying real production transcripts (daf74094)

Config

  • Split VERTEX_API_REGIONVERTEX_API_EMBEDDINGS_REGION + VERTEX_API_GEN_AI_REGION (embeddings models need their own regional endpoint) (6c00932a)

⚠️ Deploy prerequisite — VERTEX_API_* migration

embeddings_model.py hard-raises if VERTEX_API_EMBEDDINGS_REGION is unset (gen-AI only warns + defaults to us-central1). In-repo templates are updated, but before deploying to any environment both new vars must be added to: GitHub Actions secrets, Pulumi config/ESC, and each Cloud Run env (plus every dev's local backend/.env). Backend will not boot otherwise. Do not merge with [pulumi up] until external envs are updated.

Adaptations from upstream (intentional divergences, noted in commit bodies)

  • API Gateway rate limit set to 1200 req/min (upstream raised to 3600) to match core's traffic profile
  • Prompt restructure keeps core's existing questions — no achievement/challenge question added (upstream 3fb9fb60 skipped for that reason)
  • Transition fix trimmed of fork-only counseling sub-phase / sticky-routing / observability infra

Follow-ups (non-blocking)

  • Tighten expect_errors_in_logs=True to assert on the specific expected error
  • Enable the xtest Firebase retry tests (parked upstream due to fake-timer issue)
  • Add a deterministic unit test for _flush_if_repeating boundary cases

rav3n11 and others added 9 commits May 20, 2026 10:31
…rk errors

API gateway STANDARD rate kept at 1200 req/min (upstream raised it to 3600) to match core's traffic profile.

(cherry picked from commit 30f3685)
…REGION` and `VERTEX_API_GEN_AI_REGION`

- Update environment variable names for better specificity.
- Refactor related configurations, initialization code, and documentation to align with changes.

Upstream career-explorer / jobs MongoDB env-var additions and the non_priority_sector_explorer.py / ingest_sector_document.py scripts dropped — those features do not exist in core compass.

(cherry picked from commit 6c00932)
…n sentence corrections [pulumi up]

(cherry picked from commit 15b0b77)
…verage

- Update `_detect_stickiness` to handle both consecutive and non-consecutive duplicate questions.
- Introduce new test to validate forced finish behavior upon non-consecutive duplicate questions.
- Refine `_conversation_llm` templates to strictly forbid re-asking or repeating questions.

TURN FLOW + Transition adapted to reference core's existing (a)/(b)/(c) question categories; achievement-question gating and {turn_target} placeholder dropped (not present in core).

(cherry picked from commit 3679765)
…on for EXPLORE_SKILLS_AGENT questions

(cherry picked from commit a486465)
…g phase transition [pulumi up]

Upstream's counseling sub-phase / sticky-routing / skip-phase / observability ctx-var infrastructure trimmed — those features don't exist in core compass. Core retains the essential transition-aware history-save gate.

(cherry picked from commit 2334114)
…rAgent loop detection

(cherry picked from commit daf7409)
Country.ZAMBIA is fork-only and not in core's Country enum; the reference broke pytest collection (AttributeError: ZAMBIA) and failed backend CI even though these are deselected evaluation_tests.
@nraffa nraffa changed the title Feat/core 410 cherry pick CORE-410: cherry-pick auth + repetition fixes from Zambia fork May 21, 2026
@nraffa
nraffa marked this pull request as ready for review May 21, 2026 02:04
Comment on lines +474 to +479
# Deduplicate: keep one copy of the repeated question so the NEVER re-ask rule still fires
state.question_asked_until_now = questions[:-consecutive] + [last]
# Trim answers_provided to stay in sync with the new question list length
new_len = len(state.question_asked_until_now)
if len(state.answers_provided) > new_len:
state.answers_provided = state.answers_provided[:new_len]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: In _flush_if_repeating, trimming answers_provided to [:new_len] creates an off-by-one error, breaking the invariant that len(answers) should be len(questions) - 1.
Severity: MEDIUM

Suggested Fix

In _flush_if_repeating, when trimming the answers_provided list, adjust the slice to [:new_len - 1]. This will correctly maintain the invariant where the number of answers is one less than the number of questions.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: backend/app/agent/explore_experiences_agent_director.py#L474-L479

Potential issue: The `_flush_if_repeating` method incorrectly trims the
`answers_provided` list, causing an off-by-one error. The code is intended to maintain
an invariant where `len(answers) == len(questions) - 1`. However, when the `questions`
list is deduplicated to a `new_len`, the `answers_provided` list is also trimmed to
`new_len`. This makes both lists the same length, breaking the invariant. Consequently,
when the final user answer is appended later, it is dropped by `zip(questions,
answers)`, leading to data loss for downstream tasks.

Did we get this right? 👍 / 👎 to inform future reviews.

@rav3n11
rav3n11 merged commit b7da405 into main May 27, 2026
8 checks passed
@rav3n11
rav3n11 deleted the feat/core-410-cherry-pick branch May 27, 2026 16:36
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.

3 participants