Skip to content

fix(backend): hint hunt hints reach the station on time (BAC-206) - #378

Merged
hycursion merged 3 commits into
mainfrom
adam/bac-206-stretch-hint-hunt-hints-reach-the-station-on
Nov 16, 2026
Merged

hycursion merged 3 commits into
mainfrom
adam/bac-206-stretch-hint-hunt-hints-reach-the-station-on

Conversation

@hycursion

Copy link
Copy Markdown
Collaborator

Summary

On production the hint hunt's hints arrived late or not at all when no map was open (HAR-55, 16 Nov). Cloud Run gives the Event Service a processor only while a request is in progress, so the timer that sends hints 2 to 4 and the round's end didn't fire between requests. In one round the first message the station got was hint 3, 25 seconds late.

The fix: each station's Durable Object on the GeekyKey Service, which already holds the station's socket, now also keeps the times the hint hunt's steps are due and sets an alarm for the earliest. When the alarm fires, the object calls the Event Service, and that request has a processor while it does the step and sends the message.

a step is scheduled (end of tapping in, hints 2 to 4, the round's end)
  Event Service --POST /api/v1/station-wakes {station_id, at}--> GeekyKey Service (11.13)
    station's object stores at, alarm = earliest pending time
at the alarm
  object --POST /geekykey/v1/wake {station_id}--> Event Service (11.14)
    advance(): sends each due hint or ending once (hints_announced)
      --POST /api/v1/station-messages--> GeekyKey Service --socket--> station
  • The map poll and the in-process timer stay, so whichever comes first sends the message, once.
  • A wake's time is the step's time plus 250 ms, so a small difference between Cloudflare's and Google's clocks can't bring the call before the step.
  • A step already due when its round's transaction commits still gets a wake.
  • The tap that opens a round waits up to 2 seconds for its wake to be registered before it answers, so the request still has a processor while it registers. Station messages are still sent without waiting.
  • A failed callback is retried by Cloudflare up to six times with backoff. On the last failure the object logs station_wake_abandoned, drops the due wakes and keeps the later ones.
  • The object stores wake times only, never messages or game state. Alarms need no new binding or migration in wrangler.jsonc.
 apps/event-service/src/
 ├── event/handoff-routes.ts      # + POST /geekykey/v1/wake
 ├── event/station-messages.ts    # + wake(); send() and wake() share one bounded POST
 └── games/hint-hunt/hint-hunt.ts # every scheduled step requests a wake
 apps/geekykey-service/src/
+├── station-wake-routes.ts       # POST /api/v1/station-wakes
 ├── station-message-routes.ts    # Event Service auth and the station check, shared with wakes
 └── station-sockets.ts           # wake times in storage, alarm() calls the Event Service
 packages/handoff/                # wake schemas and their JSON Schema files

Agreement additions for the next version, after 0.14

All in this PR's apps/API-AGREEMENT.md, marked "for the next version, after 0.14 (BAC-206)":

  • 11.13: POST /api/v1/station-wakes on the GeekyKey Service, { station_id, at }, answered 202 { scheduled: true }. at may be at most 1 minute past or 10 minutes ahead.
  • 11.14: POST /geekykey/v1/wake on the Event Service, { station_id }, answered 204.
  • 6.1: wakes beside the timer and the map poll, with the 250 ms margin.
  • 11.7: the three wake schemas.
  • Section 2 and the authentication table: invalid_event_service_key and the Event Service key also cover station wakes.
  • A changelog row dated 16 Nov.

The unknown-station 400 on station messages now carries Zod's code: "custom" in its issue, as section 2 says issues follow Zod's format. It was missing before.

ADR 0009 still says the object stores nothing. BAC-207 updates it. The GeekyKey Service README is updated here.

Evidence

  • Event Service: 801 tests in 52 files pass. GeekyKey Service: 271 in 18 files, in workerd. Handoff: 41 in 7.
  • Typecheck, lint, format, the dash check and wrangler deploy --dry-run pass.
  • New tests cover both routes (auth, validation, forwarding), the object's alarm (the earliest time wins, the callback reschedules the next one, a failed callback is retried and then abandoned), a wake for every step, a wake for a step already due when a late poll starts the round, the opening tap waiting for its wake, and a failed wake leaving the tap and the timer working.
  • Not yet checked on a real station. HAR-55 re-runs its rounds on production, with no map open and no poll, once this is deployed.

Deploying

Merging deploys both services: the Event Service through the Deploy workflow and the Worker through Workers Builds. Until both are live the wake requests fail and are logged as station_wake_failed. The hint hunt then behaves as it does today.

🤖 Generated with Claude Code

hycursion and others added 2 commits November 16, 2026 23:28
…-206)

Review fixes on the station alarms:

- A step already due when its round's transaction commits still gets its
  wake, since the request may end before anything else advances the round.
- Each wake is the step's time plus 250 ms, so a small clock difference
  between Cloudflare and Cloud Run can't bring the callback before the step,
  when it would do nothing.
- send() and wake() share one bounded POST to the GeekyKey Service.
- Station messages and wakes share the unknown-station check, and its 400
  issues carry Zod's code, as section 2 says.
- The GeekyKey Service README says what the station's object stores.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keeps both 16 Nov changelog rows in the agreement, BAC-208's first, and
applies the formatter to the hint hunt files from BAC-208.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hycursion
hycursion merged commit 519b120 into main Nov 16, 2026
8 checks passed
@hycursion
hycursion deleted the adam/bac-206-stretch-hint-hunt-hints-reach-the-station-on branch November 16, 2026 23:27
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.

1 participant