Skip to content

fix(backend): harden goal suggestions, filter locked Wrapped 2025 items, and strip BLE firmware padding (#21871) - #23434

Merged
kodjima33 merged 2 commits into
BasedHardware:mainfrom
ducanh3005:fix/goals-wrapped-firmware-hardening-21871
Oct 24, 2026
Merged

kodjima33 merged 2 commits into
BasedHardware:mainfrom
ducanh3005:fix/goals-wrapped-firmware-hardening-21871

Conversation

@ducanh3005

@ducanh3005 ducanh3005 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #21871
/claim #21871

Summary

  • �ackend/utils/llm/goals.py:
    • Return the default goal suggestion without invoking the LLM when all user memories are locked (
      ot memory_texts).
    • Coerce None values in suggest_goal JSON responses (suggested_target, suggested_min, suggested_max, suggested_title, suggested_type,
      easoning) and in extract_and_update_goal_progress (current_value, arget_value).
  • �ackend/utils/wrapped/generate_2025.py:
    • Filter out locked conversations (is_locked=True) and locked action items (is_locked=True) in generate_wrapped_2025, _build_conversations_context, and _find_signature_phrases.
    • Ignore None segment end timestamps in _compute_conversation_duration and guard None nested dicts in memorable_days and struggles_wins.
  • �ackend/routers/firmware.py:
    • Strip trailing null bytes (\x00) and whitespace in _parse_firmware_version and validate
      elease_firmware_version in _find_candidate_releases even when current_firmware_tuple is None.
  • Unit Tests: Added hermetic unit tests in �ackend/tests/unit/test_goals_wrapped_firmware_hardening.py (6/6 passing).

View guided diff

@Dimank92

Copy link
Copy Markdown
Contributor

💰 Payout Details

  • Bounty Recipient Wallet: 0xC345C07229307d4f1c7935aD2cAe48e390215808
  • Networks: Polygon / Base / Arbitrum / Stellar
  • Token: USDC

@Git-on-my-level

Copy link
Copy Markdown
Member

Solid, well-scoped set of fixes for #21871 — all four surfaces check out on this head; positive signal, with one verification gap noted below.

  • backend/utils/wrapped/generate_2025.py — the locked-item filtering is the important part: generate_wrapped_2025, _build_conversations_context, and _find_signature_phrases now keep locked conversation titles/overviews/transcript n-grams out of both the Gemini prompts and the Wrapped output, and locked action items are dropped before analysis (verified get_action_items returns dicts, so item.get("is_locked") is safe). The seg.end is not None guard in _compute_conversation_duration fixes a real max()-on-None TypeError that could fail the whole Wrapped job, and the (memorable_days.get('most_fun_day') or {}) guards handle Gemini returning null day objects.
  • backend/utils/llm/goals.py — moving memory_texts ahead of the default-return means an all-locked memory set now short-circuits to the default suggestion without a wasted LLM call, and the null coercion of suggested_target/min/max lives inside suggest_goal's existing except, so a bad LLM value degrades to the fallback dict instead of a 500. extract_and_update_goal_progress likewise no longer feeds None into the progress prompt.
  • backend/routers/firmware.py — _parse_firmware_version now strips \x00 and whitespace, matching padded BLE DIS revision strings, and hoisting the unparseable-release skip out of the current_firmware_tuple guard means /v2/firmware/stable no longer treats releases with garbage release_firmware_version metadata as candidates.
  • backend/tests/unit/test_goals_wrapped_firmware_hardening.py — good hermetic coverage via the existing testing/import_isolation helpers, including asserting the LLM is not invoked for the all-locked case.

Privacy: strictly positive — locked content is excluded from prompts and outputs. Cost: slightly positive (no LLM call when all memories are locked).

USER IMPACT: users who locked conversations/memories/action items no longer see that content surface in Wrapped 2025 or goal suggestions, and firmware checks accept BLE-padded version strings instead of erroring.

Two things I'd still want: (1) CI on this head only ran the AI reviewer — please make sure the backend unit suite actually runs/passes on this branch (the 6/6 local claim isn't yet exercised by CI); (2) nit — in suggest_goal, one non-numeric LLM string field (e.g. suggested_target: "five") currently discards the entire suggestion to the fallback via the except; per-field safe coercion would preserve the rest.

Leaving for human maintainer review before merge — first contribution touching privacy-filtering surfaces, plus the CI test gap above.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution backend Backend Task (python) labels Oct 23, 2026
@ducanh3005

Copy link
Copy Markdown
Contributor Author

Official PR Author (@ducanh3005) Payout Details

Note to maintainers: The earlier comment above from @Dimank92 is from an unrelated third-party account attempting to spoof payout details on open PRs.

  • PR Author: @ducanh3005
  • Bounty Recipient Wallet (EVM — Base / Polygon / Arbitrum): 0xdF4Ff9D2f45f99f11A90b16F277D4B7EddDB72A5
  • Bounty Recipient Wallet (Solana): 3peh7eRyemZQ3ppVC9CeUeEbHq6aADmwqvSTRnQf17b7
  • Token: USDC

@ducanh3005

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Addressed the nit in 53547cbb34:

  • Added _safe_float_field(value, default) in backend/utils/llm/goals.py so suggested_target, suggested_min, and suggested_max are coerced individually per field, preserving valid fields (suggested_title, suggested_type, reasoning, and the remaining numeric fields) when the LLM returns a non-numeric string (e.g. "suggested_target": "five").
  • Added unit test test_suggest_goal_preserves_valid_fields_when_one_numeric_field_is_non_numeric_string in backend/tests/unit/test_goals_wrapped_firmware_hardening.py.

Local test execution output:
text $ PYTHONPATH=backend pytest backend/tests/unit/test_goals_wrapped_firmware_hardening.py -v backend/tests/unit/test_goals_wrapped_firmware_hardening.py::TestGoalsSuggestionAndNullHardening::test_suggest_goal_returns_default_without_llm_when_all_memories_are_locked PASSED backend/tests/unit/test_goals_wrapped_firmware_hardening.py::TestGoalsSuggestionAndNullHardening::test_suggest_goal_coerces_null_numeric_fields_from_llm_json PASSED backend/tests/unit/test_goals_wrapped_firmware_hardening.py::TestGoalsSuggestionAndNullHardening::test_suggest_goal_preserves_valid_fields_when_one_numeric_field_is_non_numeric_string PASSED backend/tests/unit/test_goals_wrapped_firmware_hardening.py::TestWrapped2025Hardening::test_compute_conversation_duration_ignores_none_segment_end PASSED backend/tests/unit/test_goals_wrapped_firmware_hardening.py::TestWrapped2025Hardening::test_build_conversations_context_and_signature_phrases_skip_locked_conversations PASSED backend/tests/unit/test_goals_wrapped_firmware_hardening.py::TestFirmwareVersionPaddingAndValidation::test_parse_firmware_version_strips_null_bytes_and_whitespace PASSED backend/tests/unit/test_goals_wrapped_firmware_hardening.py::TestFirmwareVersionPaddingAndValidation::test_find_candidate_releases_skips_unparseable_release_version_when_current_is_none PASSED ======================== 7 passed in 0.67s =========================

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

fix(backend) 4/5: fixes #21871, clear root cause (None coercion + locked-item filtering), tests added, CI green; diff >300 lines but focused to 4 files.

@kodjima33
kodjima33 merged commit 6b0ebdd into BasedHardware:main Oct 24, 2026
Git-on-my-level added a commit that referenced this pull request Oct 24, 2026
**2026-10-24 17:13:37 UTC — NOT SHIP / blocked handoff.** Published head
`2f364978ca1b7a786e62bb8217cdb79d795e5813` has495focused test passes and
passed every normal push gate. Current-head E2E and backend guardrails
are green, but six unit shards fail on five main-side Pyright
diagnostics. The R2 source finding is fixed with red/green proof; a lead
ruling is required for further review. The T3 freeze was missed. No
merge, deployment, credential or quota change occurred.

Live-window HTTP failures currently open a listener's whole Parakeet
family circuit, so a stale load-balancer backend can send unrelated
English audio onto paid vendors. Route internal HTTP windows directly to
fresh, DNS-ready GPU pods and quarantine only the contacted pod
(120/240/300 seconds, one half-open POST per listener/pod pair). Retry
once on a distinct pod within the original POST and first-text budgets;
retry model-empty output once per empty episode without advancing
audio/replay anchors or treating silence as an outage.

`PARAKEET_WINDOW_REPLICA_RECOVERY_ENABLED` ships on. Set false/0/off to
restore service-VIP routing, no replica retries and the previous family
breaker behavior for new sockets. Account/auth/quota, rate limits,
signalled queue pressure, local semaphore waits and invalid input never
retry. Failed attempts remain in the new bounded replica-attempt metric;
successful recovery uses shared fallback telemetry. An idle selection
gauge now expires when its cooldown expires, without changing breaker
admission.

`omi_stt_provider_circuit_trip_total` retains `error_class` and adds
normalized `reason=auth|quota|5xx|latency|no_text|connect`; capacity and
unknown evidence have explicit buckets. Zero baselines include the
mapped reason, and tests pin actual trip transitions and each cause
group. Existing queries that aggregate by provider/kind/error_class work
across mixed listener revisions; wait for full rollout before requiring
the new label.

adm2 integration: separate fresh DNS membership from pressure-sample
routing eligibility, so temporary metrics failures cannot erase a
DNS-ready pod's quarantine. Both accessors honor its
unavailable-discovery flag. An active pod-scoped socket may make an
initial VIP POST only before any direct-pod attempt, when fresh
discovery is absent and the pressure owner's public admission check
still permits bounded cached grace. Later windows retain the no-VIP
fence. This path never retries the VIP or renews the grace timestamp;
`service_*` outcomes expose it.

Production investigation (ro-prod, aggregate infrastructure evidence
only; 2026-10-23 23:45–2026-10-24 05:45Z):
- Parakeet: 21 selection trips across 19 listener pods, all
`provider_5xx`. `/v1/transcribe` ILB logs have 20 HTTP503s (15
backend_connection_closed, 5 failed_to_connect_to_backend) and one
HTTP500. Failed connects line up with GPU shutdowns at02:57Z,03:12Z
and05:11Z. HTTP500 matches a NeMo single-feature-frame normalization
exception on one GPU; exact failed-request-to-pod mapping is unavailable
in ILB logs.
- Modulate: four `modulate_serve_error` frames say Unable to complete
the request; two trips are connection losses. No account/auth/budget
trips in this window. No credentials, quota, funding or production
configuration changed. The existing account cooldown remains30minutes;
existing selection starts180seconds and escalates, rather than a
flat30minute bench.
- Extended24-hour check at the same cutoff: the `backend-listen-metrics`
job has53 serving-fault and19 connection-loss transitions, no Modulate
account trips or failed connects. A targeted139-entry log read was
untruncated:55 vendor error frames all say Unable to complete the
request, with no auth/402/quota/rejected-connect signature. Actual
credit balance and auto-reload are unverified because vendor billing
access is unavailable; no account repair or change is proposed from
these samples.

Validation:

- Published head `2f364978ca1b7a786e62bb8217cdb79d795e5813`,
independently matched by remote Git advertisement and clean local
HEAD.495focused tests passed across8 files. The real-pump regression
fails at the expected quarantine assertion on4009, then passes after
classifying its first-text deadline as owned timeout evidence; external
cancellation stays non-outage evidence. Window source1496/1497frozen
lines.
- Every normal push gate passed:36shared preflight
checks(1078.76seconds), enforced
Pyright0errors(167seconds),19runtime-image closures(235seconds),
and306selected unit tests(86seconds). No suppression, size exception,
guard threshold, allowlist or skip flag changed.
- Exact-head GitHub Hermetic Backend E2E and Backend unit guardrails
succeeded. The six unit shards and aggregate failed before pytest at the
same five Pyright diagnostics in main-side retrieval/Wrapped changes
outside this PR. CI checked merge1d882247f6(2f intoe86cda5). Producer
changes are#23433/#23434; CI run40113372612 contains the exact
diagnostics. CI is NOT green; no blind rerun or skip exception was used.
- Both authorized read-only review rounds completed. Round2 identified
the first-text callback ordering above, corrected in2f with red/green
proof. The review cap requires a scoped lead ruling for further review;
no third round or independent SHIP verdict for2f is claimed. The
automated review threads have implementation/test replies and are
resolved; overall approval remains blocked.
- Earlier pressure/metrics seam testing with adm2localfe563c1 passed532;
it is not qualification of the latest combined train. The read-only
merge-tree of4009 with fetchedmain70a78b3 was clean. The lead owns
combined-train/live acceptance and next release disposition; the13:00Z
T3 freeze was missed.

The new integration regression executes the managed live leg through
VAD, window POST, alternate pod and transcript emission, proving one
transcript and no vendor dial. Other cases cover real outages,
cancellation, stale generations, single probes, bounds, cooldown ladder,
account conditions, pressure, original deadlines and kill-switch
rollback. Local hermetic checks do not establish production transcript
quality or reduced Soniox hours; the lead owns the T3 listen deployment
and live first-text/no-text/vendor-hours readback with adm2. No workflow
or production mutation is included.

## Product invariants affected

none

Failure-Class: FC-recoverable-provider-failure-terminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend Task (python) positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants