Skip to content

fix(browser-handoff): raise handoff TTL/max-wait and retry the recheck-clear step - #214

Merged
convyusboy merged 3 commits into
boonfrom
ridho/eng-17466-recheck-reliability-clean
Sep 9, 2026
Merged

convyusboy merged 3 commits into
boonfrom
ridho/eng-17466-recheck-reliability-clean

Conversation

@convyusboy

@convyusboy convyusboy commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Live-testing the browser login handoff flow (Gmail, BuildingConnected) surfaced two related reliability gaps in the agent-side recheck loop:

  1. BROWSER_HANDOFF_STATE_DEFAULT_TTL_MS (60 min) and MAX_TOTAL_WAIT_MS (30 min) were both shorter than boon-core's async Anchor profile-snapshot step alone has been observed taking (~20 minutes), on top of however long the human takes to sign in. Once either expired, action=status would silently dead-end into "no pending handoff found" or a false "may have expired" message — even when boon-core's actual backend state was already ready. Live-observed: the agent told a customer "Gmail's still marked not connected... the sign-in link expired" while the backend profile had a fully working, ready session.

  2. scheduleRecheck gave up scheduling the next durable recheck forever the moment clearScheduledRecheck reported any failure, even a transient one (e.g. the cron service being briefly unavailable for one call). Since handleStatus is the only place that reschedules, one hiccup silently killed the entire recheck chain for that handoff, with nothing ever trying again.

Why This Change Was Made

Both timeouts are raised to match Anchor's own default session max_duration (180 minutes, confirmed against docs.anchorbrowser.io/advanced/session-timeout) rather than an arbitrary guess — waiting longer than Anchor's own hard session cap has no upside anyway. The recheck-clear step now retries a few times with a short delay before giving up, so a single transient failure no longer permanently ends the recheck chain.

User Impact

Handoffs that take longer than ~30-60 minutes end-to-end (a real, observed scenario given Anchor's own snapshot latency) no longer get falsely reported as expired/not-connected once the fix in boon-core (companion PR) makes the snapshot step itself much faster in the common case. The recheck loop is also more resilient to one-off scheduling hiccups.

Evidence

  • All 43 extension tests pass (added 1 new test covering the recheck retry).
  • node scripts/run-oxlint.mjs and oxfmt --check clean on touched files.
  • Live-reproduced both original bugs this session via direct boon-core Rails console inspection during real handoff attempts (Gmail thread stuck reporting "not connected" for 85+/98+ minutes past the old 60-min TTL, while the backend profile was already ready).

Summary by cubic

Fixes two reliability gaps in the browser handoff recheck loop that caused false "expired"/"not connected" reports and silently dead handoffs.

Bug Fixes

  • Raises the handoff record TTL from 60 minutes to 4 hours and the total recheck wait from 30 to 180 minutes, matching Anchor's default session duration so legitimate long handoffs no longer dead-end into false expiration messages.
  • Retries the scheduled-recheck clear step up to 3 times before giving up, so one transient cron failure no longer permanently stops all future rechecks for that handoff.
  • Adds a test covering the recheck retry behavior.

Links to ENG-17466 for the browser login handoff reliability work.

Written for commit 90ad1d6. Summary will update on new commits.

Review in cubic

…k-clear step

Two related fixes for the recheck reliability gap found during live retesting:

- BROWSER_HANDOFF_STATE_DEFAULT_TTL_MS and MAX_TOTAL_WAIT_MS were both
  shorter than boon-core's async profile-snapshot step alone has been
  observed taking (~20 minutes), so a handoff that legitimately took a
  while would silently dead-end action=status into a false 'no pending
  handoff'/'may have expired' report instead of ever reflecting boon-core's
  real (ready) state. Both raised, matching Anchor's own default session
  max_duration (180 minutes).
- scheduleRecheck gave up scheduling the next recheck forever the moment
  clearScheduledRecheck reported any failure, even a transient one. Since
  handleStatus is the only place that reschedules, one hiccup silently
  killed the entire recheck chain. Now retries a few times first.
@convyusboy
convyusboy requested a review from a team September 9, 2026 13:28
@claude

claude Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

4 issues found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="extensions/browser-handoff/src/tool.ts">

<violation number="1" location="extensions/browser-handoff/src/tool.ts:63">
P3: The new root comment embeds a lengthy live-incident narrative instead of documenting the retry invariant. Replace it with a concise explanation that transient cleanup failures are retried before abandoning the replacement schedule.</violation>
</file>

<file name="extensions/browser-handoff/src/tool.test.ts">

<violation number="1" location="extensions/browser-handoff/src/tool.test.ts:439">
P3: This test title embeds incident history instead of the invariant under test, making the suite harder to scan and maintain. Shorten it to state only that clearing the previous schedule is retried after a transient failure.

(Based on your team's feedback about concise changed source comments and test titles.)</violation>

<violation number="2" location="extensions/browser-handoff/src/tool.test.ts:455">
P3: This retry test waits on the real 200 ms backoff, which makes it slower and less deterministic under timer contention. Use fake timers, advance through the retry delay, and restore real timers in a `finally` block.

(Based on your team's feedback about deterministic retry tests.)</violation>
</file>

<file name="extensions/browser-handoff/src/state.ts">

<violation number="1" location="extensions/browser-handoff/src/state.ts:4">
P3: The new state comment is overly long and preserves incident lore in production source. Reduce it to the TTL invariant and its user-visible consequence.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread extensions/browser-handoff/src/tool.ts Resolved
Comment thread extensions/browser-handoff/src/state.ts Resolved
@claude

claude Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

@gandalfboon gandalfboon Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approved. Focused reliability fix — both changes address real observed failures (60m TTL sweeping records with ready state upstream, and single transient clearScheduledRecheck failure permanently killing the recheck chain).

Good:

  • TTL bump to 4h keeps BROWSER_HANDOFF_STATE_DEFAULT_TTL_MS comfortably above MAX_TOTAL_WAIT_MS (180m) so the sweeper cannot beat the recheck cap — the invariant is stated in the comment.
  • 180m cap matches Anchor's own session max_duration — no upside to waiting past that hard cap.
  • Retry loop for clearScheduledRecheck is bounded (3 attempts, 200ms delay) and preserves the safety property (still refuses to schedule a replacement if it can't confirm the old job is cleared) — no risk of stacking overlapping rechecks.
  • New test uses fake timers + finally cleanup, mock chain simulates a genuine transient failure then recovery.
  • Cubic's three P3 comments already addressed in later commits.

Minor observation (not blocking):

  • The retry loop only backs off between attempts, not on the final failed attempt — matches your intent (|| attempt === CLEAR_RECHECK_RETRY_ATTEMPTS short-circuit). Total added latency worst-case is 400ms, which is fine on the request path.

Ship it.

@convyusboy
convyusboy merged commit 32b7282 into boon Sep 9, 2026
140 of 143 checks passed
@convyusboy
convyusboy deleted the ridho/eng-17466-recheck-reliability-clean branch September 9, 2026 15:19
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