Skip to content

fix(backend): expose with_rate_limit on the task-sharing endpoints stub - #12057

Merged
Git-on-my-level merged 1 commit into
BasedHardware:mainfrom
aryanorastar:fix/task-sharing-stub-rate-limit
Aug 22, 2026
Merged

Git-on-my-level merged 1 commit into
BasedHardware:mainfrom
aryanorastar:fix/task-sharing-stub-rate-limit

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Aug 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

tests/unit/test_task_sharing.py fails at collection on main, which errors the whole Backend unit suite job:

ERROR tests/unit/test_task_sharing.py - AttributeError: module 'utils.other.endpoints' has no attribute 'with_rate_limit'
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!

Because it is a collection error rather than a test failure, the job exits 1 before running, so every backend PR inherits a red Backend unit suite through its merge ref.

Cause

The file stubs utils.other.endpoints with a single attribute:

_stub_module("utils.other.endpoints")
sys.modules["utils.other.endpoints"].get_current_user_uid = MagicMock()

routers/action_items.py:362 now resolves the rate-limit wrapper at module level, so it is evaluated at import:

uid: str = Depends(auth.with_rate_limit(auth.get_current_user_uid, "action_items:list")),

Importing the router under that stub raises before any test runs. The stub predates the wrapper; nothing about the sharing behavior under test changed.

The fix

One stub entry that passes the auth dependency straight through. The real with_rate_limit only wraps it with a Redis per-UID check — which these tests neither exercise nor have a Redis for, since database.redis_db.r is itself a MagicMock a few lines above in the same file.

Verification

Both directions, on a pristine checkout of main (not on a feature branch):

before:  no tests collected, 1 error in 0.35s
after:   30 passed

black --line-length 120 --skip-string-normalization --check reports the file unchanged.

Notes

I hit this because it reddens Backend unit suite on my own PR #11452, but the failure is not from that diff — main's own run at 08-22T14:42 (fix(backend): cap GET /v1/action-items at 12) shows the identical error. This is the same shape as #12035 earlier today: a small test-side fix unblocking a lane for everyone, and I am equally happy for someone to land an equivalent fix directly instead of merging this.

Product invariants affected

none

Failure-Class: none

Review in cubic

tests/unit/test_task_sharing.py fails at collection on main, which errors
the whole Backend unit suite:

  ERROR tests/unit/test_task_sharing.py - AttributeError: module
  'utils.other.endpoints' has no attribute 'with_rate_limit'

The file stubs utils.other.endpoints with only get_current_user_uid, but
routers/action_items.py:362 now resolves the wrapper at module level:

  Depends(auth.with_rate_limit(auth.get_current_user_uid, "action_items:list"))

so importing the router under the stub raises before any test runs. The
stub predates that wrapper; nothing about the sharing behavior under test
changed.

The stub passes the auth dependency straight through. The real
with_rate_limit only wraps it with a Redis per-UID check, which these
tests neither exercise nor have a Redis for -- database.redis_db.r is
itself a MagicMock a few lines above.

Verified both directions on a pristine checkout of main:
  before: no tests collected, 1 error in 0.35s
  after:  30 passed
black --line-length 120 --skip-string-normalization clean.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@Git-on-my-level
Git-on-my-level merged commit 79de236 into BasedHardware:main Aug 22, 2026
34 checks passed
abunet added a commit to abunet/omi that referenced this pull request Aug 22, 2026
…dy fixed one of our PRs

Four conflicts, all real this time (no generated-file counters).

  backend/database/action_items.py     both sides had independently replaced the streaming counts with
                                       count() aggregations. Upstream's version wins: it also handles
                                       legacy rows where `deleted` is ABSENT, which ours did not — it
                                       reads that small subset once and subtracts, where ours filtered
                                       `deleted == True` and so would have missed them.
  backend/tests/unit/test_task_sharing.py   upstream fixed this themselves (BasedHardware#12057, one day after we
                                       proposed the same fix) with the same diagnosis in the same terms.
                                       Theirs is canonical now; ours was a proposal. Taken as-is.
  backend/tests/unit/test_desktop_migration.py   their test for their rewritten counting.
  app/pubspec.yaml                     union: their `sign_in_with_apple` bump plus our two additive OIDC
                                       dependencies (ADR-0038).

**A mistake worth recording, because it nearly shipped.** I first resolved action_items.py with
`git checkout --theirs`, which replaces the WHOLE FILE, not the conflicting hunks — silently discarding
our `AlreadyExists` import and its handler from the Mongo unique-index dedup (ADR-0085), which had
auto-merged cleanly nowhere near the conflict. Caught by grepping the file for our own deltas after
resolving rather than by any test: the dedup path has contract cover, but that suite would only have
gone red later, on a branch where the loss looked like part of the merge. Both files were re-resolved
hunk by hunk.

Post-merge audit (ADR-0029/0030): one finding, from the guards.

  PROMETHEUS_SIDECAR_PORT   a new upstream runtime variable. Written off rather than declared, with the
                            reason: unset, `utils/metrics.py:445` returns immediately and nothing starts;
                            set, it opens a SECOND http server on 127.0.0.1 for a Cloud Run sidecar to
                            scrape. On-prem there is no sidecar and /metrics is already reachable on the
                            backend's own surface (ADR-0068), so a loopback duplicate would serve nobody.
                            The note points at the metrics-consumer work (L43), where it becomes relevant
                            if the collector ever runs beside the backend instead of scraping it.

One observation not acted on, to keep the merge a merge: upstream's `daily_completed` and `daily_total`
come from two separate aggregations, so a concurrent write between them can leave completed above total.
Ours capped the pair; theirs does not. Product logic, theirs to decide — worth a PR, not a local
divergence.

Verification
  guards 9/9 exit 0 — the env-parity guard is what surfaced the finding above
  contract lane 55 files, 1083 passed, 78 skipped (live-tier only), 0 failed
  full sweep 1027 files in 3m19s, FAIL set identical to the pre-merge baseline
  black 24.4.2 clean on all three resolved backend files
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.

2 participants