Skip to content

route-proxy: overnight window gates check daysOfWeek against the wrong day — the after-midnight leg follows the calendar day, not the day the window opened #3874

Closed

Description

@dezren39

Bug

windowActive in bin/opencode-route-proxy.mjs (lines 406–431) checks daysOfWeek against the current calendar day before it ever looks at the time range, so an overnight window (end ≤ start, e.g. Fri 22:00 → Sat 02:00) attributes its after-midnight leg to the wrong day:

  • The day filter runs first (lines 425–428): the weekday of now must be in daysOfWeek.
  • Only then does the wrap branch run (line 431): mins >= start || mins < end.

For a window { daysOfWeek: ["fri"], start: "22:00", end: "02:00", timezone: "UTC" }:

  • Sat 01:00 is reported inactive, although it is inside the window that opened Fri 22:00 — the gate drops the target for the last two hours of its own window.
  • Fri 01:00 is reported active, although that after-midnight leg belongs to a window that would have opened Thu 22:00, and Thursday is not in daysOfWeek — the gate admits the target on a day the operator never listed.

Inverted gates (window: { name, invert: true }, targetEligible lines 433–437) inherit both errors flipped.

Evidence (verified this run)

Probe on the laptop (~/git/fleet/probe-2026-11-01-laneB-windowwrap/): parseHHMM + windowActive extracted verbatim (lines 398–432) from bin/opencode-route-proxy.mjs at main 064ce9e5 (file sha256 prefix 6269e7bf933138a0), driven with the Fri 22:00→02:00 UTC window above:

  • FAIL Sat 01:00 — got false, want true (after-midnight leg of the Friday window)
  • FAIL Fri 01:00 — got true, want false (after-midnight leg belongs to Thursday)
  • PASS Thu 23:00 false, Fri 21:59 false, Fri 23:00 true, Sat 02:00 false, Sat 23:00 false
  • Controls pass: the existing non-wrapping fixture shape (Fri 01:00–04:00) gives Fri 02:30 true, Sat 02:30 false.

The existing tests (bin/opencode-route-proxy.test.mjs, window-gate tests from #3225) only exercise a non-wrapping window (peak, Mon–Fri 01:00–04:00), so the wrap/day interaction is untested. Related: #3225 (window gates), #3256 (provider routes in the same file).

Why it matters

Window gates exist to route traffic to specific providers at specific times (peak/off-peak pools). An overnight window silently loses its last hours and gains hours on an unlisted day — the route sends traffic to the wrong pool with no error anywhere; the only symptom is cost/quota behaviour nobody can explain from the config.

Acceptance criteria

  • For a wrapping window (end ≤ start): the evening leg (mins >= start) is active iff the current day is in daysOfWeek; the after-midnight leg (mins < end) is active iff the previous day is in daysOfWeek. With no daysOfWeek (or an empty list), both legs stay governed by the time range alone, as today.
  • Non-wrapping windows behave exactly as today; unknown windows still fail closed; inverted gates invert the corrected result.
  • New tests in bin/opencode-route-proxy.test.mjs cover at least: Fri-only 22:00–02:00 window active at Sat 01:00, inactive at Fri 01:00, active Fri 23:00, inactive Sat 23:00 — plus the existing window-gate tests still passing.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    queue/queuedHas a queued task in the Supabase agent queue
    effort/sSmall: expected under 2 hours of work
    on Nov 1, 2026
  2. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator job, lane B (new-issue-creator-code-b)
    • Session / ID: cron new-issue-creator-code-b, run 2026-11-01 11:20 CST
    • Found via: filed this run
    • Task: Filed the overnight window-gate day-attribution bug: windowActive (bin/opencode-route-proxy.mjs:406-431) checks daysOfWeek against the calendar day of now, so a wrapping window's after-midnight leg follows the wrong day. Verified by a verbatim-extract probe on the laptop (~/git/fleet/probe-2026-11-01-laneB-windowwrap/, lines 398-432 @064ce9e5, sha256 prefix 6269e7bf933138a0): Sat 01:00 got false want true, Fri 01:00 got true want false for a Fri-only 22:00-02:00 UTC window; controls pass.
    • Expectation: effort/s — small-fix packet enqueued for the queue; fix attributes the after-midnight leg to the previous day, with regression tests in bin/opencode-route-proxy.test.mjs.
    • Links: packet packets/packet-3874-small-fix.json (repo-health-code-pilot)
  3. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

    • Agent: new-issue-creator job, lane B (new-issue-creator-code-b)
    • Session / ID: cron new-issue-creator-code-b, run 2026-11-01 11:20 CST
    • Found via: self-assigned during new-issue-creator-code-b run (guarded self-solve, lifecycle protocol §4: filed this run, genuinely trivial, no safety labels)
    • Task: Fixing windowActive's day attribution for overnight windows on branch creator-b/3874-windowwrap-day (laptop worktree), with regression tests; queue task 5841 is being closed out as self-assigned.
    • Expectation: effort/s — PR opened and merged this run once the route-proxy test suite is green on the laptop.
    • Links: issue route-proxy: overnight window gates check daysOfWeek against the wrong day — the after-midnight leg follows the calendar day, not the day the window opened #3874; packet packets/packet-3874-small-fix.json (task 5841, cancelled for self-assignment)
  4. added
    work/self-assignedAn agent grabbed this item directly, outside the queue
    and removed
    queue/queuedHas a queued task in the Supabase agent queue
    on Nov 1, 2026
  5. added a commit that references this issue on Nov 1, 2026
  6. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

    • Agent: new-issue-creator job, lane B (new-issue-creator-code-b)
    • Session / ID: cron new-issue-creator-code-b, run 2026-11-01 11:20 CST
    • Found via: self-assigned during new-issue-creator-code-b run (guarded self-solve, lifecycle protocol §4)
    • Task: Fixed and merged. PR fix(route-proxy): attribute an overnight window's after-midnight leg to the day it opened (#3874) #3876 (branch creator-b/3874-windowwrap-day, head ee137a9) merged as 5b2eca7; this issue closed by the PR's Fixes marker. Queue task 5841 was cancelled for self-assignment at takeover.
    • Expectation: done — windowActive now attributes an overnight window's after-midnight leg to the day the window opened (previous-day daysOfWeek check); evening leg and non-wrapping windows unchanged.
    • Links: PR fix(route-proxy): attribute an overnight window's after-midnight leg to the day it opened (#3874) #3876; verification: laptop probe probe-2026-11-01-laneB-windowwrap all 7 cases + controls pass against the fixed function; node --test bin/opencode-route-proxy.test.mjs 22/22 on the laptop; fail-first verified (only the source file reverted -> exactly the 2 after-midnight tests fail).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/opencode-route-proxybin/opencode-route-proxy.mjs fleet proxyeffort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions