Repository navigation
fix(backend): count explicit app selections, reject invalid ones, and make field exemptions appliable - #11872
Conversation
… make field exemptions appliable Three follow-ups from the beta rollout, each validated before it was fixed. Two of my three original claims held; the third was partly wrong and the report says so. **Explicit app selections were never counted.** `record_app_usage` was skipped whenever `is_reprocess` was true, and client app selection goes through the reprocess route on both Flutter and macOS — so the one interaction opt-in mode exists to measure produced no usage history. Attribution is now typed rather than inferred from a boolean: automatic processing and a successfully executed explicit selection are recorded; plain regenerate, sync reprocessing, and lazy enrichment of deferred desktop conversations are not. My brief claimed lazy enrichment reached this through `is_reprocess=True`; it does not — it passes `is_reprocess=False` — so it is now marked non-user explicitly instead of relying on a flag that never distinguished it. **An invalid app_id silently produced a successful no-app response.** Under opt-in that is worse than before, because there is no default app to fall back on: the caller asked for something specific, got a 200, and received the first-party note. Selection is now validated before processing mutates anything — 404 unknown, 403 not available to this user, 400 cannot summarize, 409 disabled or not enabled — and `_trigger_apps` raises if it is ever handed an unvalidated id, so the two cannot drift. Both clients already enable an app before selecting it (macOS does so with a comment naming this exact footgun), so the enablement check matches what they do rather than restricting them. **Firestore field exemptions were declared but nothing applied them.** The reconciler reads only `indexes` and shells out only to `gcloud firestore indexes composite`, so the `fieldOverrides` #11865 added saved nothing. Exempting a field deletes existing single-field indexes, which is precisely the destructive class the create-only reconciler refuses by design, and it targets the production data plane. So automatic reconciliation stays create-only and a separate manual operation owns the deletion: prod-only, exact-confirmed, dispatched-SHA-verified, restricted to generated `indexes: []` overrides. The automatic run now also fails visibly when exemptions are declared but unapplied, so the gap cannot be implied-but-absent again. Note the consequence: this workflow will fail on main until that manual operation is run. That is the intended signal, not a regression. Contracts regenerated for the new response codes; only the OpenAPI and TypeScript projections changed. Verified: 142 tests across six suites, run per-file. Not verified: no live Firestore state was read and the exemptions are not applied; Swift was not compiled (the delegated sandbox denied SwiftPM's nested sandbox-exec), though no Swift source changed. Failure-Class: none Co-Authored-By: Claude Opus 5 <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
…mport graph CI caught a real regression, not a flake. Adding `database.apps` and `utils.apps` as module-level imports broke test_conversation_search_date_validation (collection error) and test_conversations_date_range_validation (9 errors), both deterministically. Those suites load routers.conversations through the sanctioned isolation seam (backend/docs/test_isolation.md) to test pure request validation, stubbing the heavy chains the router otherwise pulls at import time. `utils.apps` reaches the memory and social graph, so a module-level import forces every such suite to stub a graph it never calls — and the next module added to that chain breaks them again. The router already solved this once: it imports from `utils.apps` inside a function around line 1510 for exactly this reason. The selection validator now follows that precedent, with a comment saying why so it is not "tidied" back to the top later. Its tests patch at the source modules rather than on the router, which is where the functions actually live now. Verified: the two suites CI failed now pass (23 and 9), the selection suite still passes (8), and usage attribution, enrichment wiring, and the beta rollout contract are unaffected (37, 10, 4). No other test patched these names on the router. Failure-Class: none Co-Authored-By: Claude Opus 5 <[email protected]>
Two jobs on this PR failed by hanging, not by failing: `Linux package · helper smoke` rode out the full 6h GitHub Actions job ceiling, and `Replay Harness Phase 0A Feasibility (advisory)` burned its entire 20m budget. Both stopped producing output mid-`apt-get update` while fetching package indices, and both surfaced only as an opaque cancellation. Neither is caused by this branch. The Linux job has hung for exactly 6h on several unrelated PRs and on main; the replay-harness job shares its `Install Redis server` step verbatim with two sibling gauntlets that passed in the same run. The common defect is that `apt-get update` has no built-in fetch timeout and these steps set no `timeout-minutes`, so a half-open connection to a mirror has nothing to stop it. Bound both: `Acquire::Retries` plus explicit http/https timeouts so a stalled mirror fails over in seconds, and `timeout-minutes` on the steps (and on the previously uncapped `build-linux` job) as a backstop. This does not make a mirror outage succeed -- it makes one fail in minutes with a legible error instead of silently consuming the job. Co-Authored-By: Claude Opus 5 <[email protected]>
|
@cursor fix CI failures in a non-flaky way |
|
The reported Backend unit suite failure was deterministic, not a flake. I fixed two real contract misses and the suite is green on CI (16m32s).
Hygiene is still red: the PR body’s |
The previous commit bound apt network calls so a stalled mirror fails fast, but the static wiring tests still required the unbounded `sudo apt-get install --yes redis-server` form. That is a deterministic contract miss, not a flake: both gauntlet jobs failed in the unit suite for the same substring. The contract now requires Acquire retries/timeouts, a 5-minute step timeout, and that the unbounded install form is absent from the workflow. Job slices are scoped to the named job so a later gauntlet cannot satisfy the assertion. Co-authored-by: David Zhang <[email protected]>
…rtial CI failed test_lazy_enrichment_uses_non_user_usage_attribution with AttributeError on the real file-backed proactive_engine module: a circular import can leave that module in sys.modules without persist_desktop_meeting_arrival_best_effort. monkeypatch.setattr then raises before the route is exercised. Patch the in-function import with create=True, and parametrize a partial module so that missing-attribute case is the regression, not a flake. Co-authored-by: David Zhang <[email protected]>
|
Hygiene: The two Verified before updating: reproduced the exact CI failure locally by running |
undivisible
left a comment
There was a problem hiding this comment.
Review
The six named backend suites pass on the live head (114 tests under the pinned Python 3.11 environment).
The destructive field-exemption path is correctly constrained in this tip: manual workflow_dispatch on main, operation=field-exemptions, environment=prod, protected prod Environment, exact APPLY_FIRESTORE_FIELD_EXEMPTIONS confirmation, dispatched-SHA verification, and a reconciler limited to generated ttl: false, indexes: [] overrides using gcloud firestore indexes fields update --disable-indexes. Composite indexes stay on the separate create-only reconciler.
Keep this as a human-ops hold: the automatic path is intentionally red until the one-time prod apply is run and verified, so I am not approving or merging this PR.
* ci: guard apt-get network bounds instead of trusting a comment apt has no built-in timeout. Against the hosted runners' default Azure Ubuntu mirror it can connect and then never complete the transfer, so the step emits no further output and the job runs to its ceiling - six hours, where no explicit timeout-minutes exists - and reports `cancelled`, which reads as an infrastructure mystery rather than a stalled mirror. #11872 fixed this by hand in two workflows. It left one line unbounded: desktop-windows-ci.yml bounds its `apt-get update` and not the `apt-get install` directly beneath it, under a comment that says "Bound apt's network calls explicitly". The comment was already true of one line and false of the next, and nothing could tell. Bound that line, and add a check that derives the requirement from the source signal - an apt-get subcommand that touches the network - so a newly added call cannot be unbounded and nobody has to remember. Each such line must carry Acquire::Retries plus http and https Acquire timeouts, and its step must declare timeout-minutes as a backstop for what the acquire options do not cover (dpkg, a debconf prompt, a wedged post-install). `clean` and `autoremove` touch no mirror and are deliberately left alone. The self-test asserts the exact regression shape - update bounded, install forgotten - rather than only asserting today's tree is clean, so the guard cannot pass by accident once the tree is fixed. Failure-Class: none Co-Authored-By: Claude Opus 5 <[email protected]> * fix(ci): run the apt-bounds guard on an interpreter that has PyYAML The check failed in CI with `No module named pytest`. Two mistakes, both mine: it was written against pytest when nothing in checks-manifest.yaml uses pytest, and it was verified locally with the backend venv rather than the bare `python3` the preflight runner actually invokes. Convert the self-test to stdlib unittest, matching every sibling in .github/scripts, and route it through a wrapper that resolves the canonical backend interpreter and provisions it when PyYAML is absent - the same shape as scripts/run-release-process-guards.sh, which is the existing precedent for a guard that needs the repository's locked PyYAML. The self-test carries the tree-wide case, so the wrapper is both the proof and the enforcement. Verified by reintroducing the unbounded install line: the wrapper fails, and passes again once bounded. --------- Co-authored-by: Claude Opus 5 <[email protected]>


Three follow-ups from the beta rollout. Each claim was validated before it was fixed — two held, one was partly wrong, and this says which.
Explicit app selections were never counted
record_app_usagewas skipped wheneveris_reprocesswas true, and client app selection goes throughPOST /v1/conversations/{id}/reprocesson both Flutter (summarized_apps_sheet.dart→conversations.dart) and macOS (ConversationDetailView.swift→APIClient+Apps.swift). So the one interaction opt-in mode exists to measure produced no usage history at all.Attribution is now typed rather than inferred from a boolean. Recorded: automatic processing, and an explicit selection that actually executed. Not recorded: plain regenerate, sync reprocessing, and lazy enrichment of deferred desktop conversations.
Correction to the original premise. I claimed lazy enrichment reached this through
is_reprocess=True. It does not — it passesis_reprocess=False. It is now marked non-user explicitly rather than relying on a flag that never distinguished it.An invalid
app_idsilently produced a successful no-app responseConfirmed for unknown, inaccessible, and non-summarization ids: the lookup returned no candidate,
apps_resultswas cleared, and the route still returned 200. Under opt-in that is worse than it used to be — there is no default app to fall back on, so the caller asked for something specific, got a success, and silently received the first-party note.Selection is validated before processing mutates anything:
works_with_memories())No
app_id— plain regenerate — is unchanged._trigger_appsnow raises if it is ever handed an unvalidated id, so route validation and execution cannot drift apart.Partly refuted. I claimed an available-but-unenabled app degraded to "no app". It did not —
get_available_app_model_by_idnever enforced enablement, so such an app ran successfully. The 409 is therefore a new restriction rather than a fix. It is safe: both clients already enable an app before selecting it, and the macOS client does so with a comment naming this exact footgun.Client handling was checked before choosing the codes: Flutter converts any non-200 into its existing
REPROCESS_FAILEDflow, macOS throwsAPIError.httpErrorand does not adopt the response, and none of these codes trip either client's 401 session-invalidation path.Firestore field exemptions were declared but nothing applied them
Confirmed.
reconcile_firestore_indexes.pyreads onlyindexesand shells out only togcloud firestore indexes composite; the workflow invokes only that reconciler; there is nofirebase deployfor indexes anywhere in the repo. ThefieldOverridesthat #11865 added saved nothing, and the storage reduction claimed there has not been happening.Exempting a field deletes existing single-field indexes — precisely the destructive class the create-only reconciler refuses by design — and it targets the production data plane, which dev and prod share. So the create-only guarantee is untouched and a separate operation owns the deletion: manual dispatch only, prod-only (non-prod dispatch is rejected), gated on an exact
APPLY_FIRESTORE_FIELD_EXEMPTIONSconfirmation, dispatched-SHA-verified, serialized under the existing schema lock, and restricted to generatedttl: false, indexes: []overrides so it can never touch a composite index.The automatic run now also fails when exemptions are declared but unapplied.
Consequence worth knowing before merge: this workflow will fail on main until that manual operation is run once. That is the intended signal — the alternative is the silent gap this PR exists to close — but it is a red workflow until someone acts on it, and the saving is not live until then.
CI follow-up (second commit)
The first push failed the backend unit suite on two files — a real regression, not a flake. Adding
database.appsandutils.appsas module-level imports broketest_conversation_search_date_validation(collection error) andtest_conversations_date_range_validation(9 errors), deterministically.Those suites load this router through the sanctioned isolation seam to test pure request validation, stubbing the heavy chains it otherwise pulls at import time.
utils.appsreaches the memory and social graph, so a module-level import forces every such suite to stub a graph it never calls — and the next module added to that chain would break them again.The router already solved this once: it imports from
utils.appsinside a function around line 1510 for exactly this reason. The validator now follows that precedent, with a comment saying why so it does not get "tidied" back to the top. Its tests patch at the source modules instead of on the router.Both CI-failing suites now pass (23 and 9), the selection suite still passes (8), and usage attribution, enrichment wiring, and the beta rollout contract are unaffected (37, 10, 4).
Verification
142 tests across six suites, run per-file: app-selection route (8), usage attribution (37), field reconciler (6), firestore index config (9), composite reconciler (33), release vector (49). Contracts regenerated for the new response codes; only the OpenAPI and TypeScript projections changed.
Not verified: no live Firestore state was read and the exemptions are not applied by this PR. Swift was not compiled in the delegated sandbox, though no Swift source changed here.
Failure-Class: none
Line-Count-Exception: backend/routers/conversations.py | 1604 -> 1659 | the selection validator must run in the route, before
process_conversationmutates the conversation; moving it elsewhere would reintroduce the validate-after-mutate ordering this PR fixesLine-Count-Exception: backend/utils/conversations/process_conversation.py | 2221 -> 2251 | the attribution enum and its guard belong with
_trigger_apps, the only place that decides whether an app execution is user-attributable; splitting them would let route validation and execution drift apart again