Repository navigation
fix(auth): keep OAuth refresh fence timeout monotonic across clock skew - #167619
fuller-stack-dev merged 2 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
✅ Maintainer security changes approvedA maintainer approved this revision with an explicit security approval comment.
A later push requires a fresh approval comment for an external contributor's PR. |
|
Codex review: needs maintainer review before merge. What this changesThis PR measures OAuth refresh observation deadlines with a monotonic clock so system-clock changes cannot distort timeout budgets. Example: A healthy OAuth refresh completes in 8 seconds while the wall clock jumps forward 119 seconds during a 120-second observation budget.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a current OAuth timeout defect with a focused change and no actionable findings; exact-head security approval remains outstanding. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe auth-profile lifecycle owns refresh claims and durable credential settlement; its observers consume pending-store snapshots or settlement promises and return credentials, cancellation, or timeout without canceling the refresh owner. flowchart TD
A[Credential request] --> B[OAuth refresh manager]
B --> C[Durable refresh owner]
C --> D[Credential store]
B --> E[Monotonic deadline observer]
D --> E
C --> E
E --> F[Credential result or timeout]
Technical reviewBest possible solution: Land the focused monotonic-clock repair through the existing security-review gate while preserving independent durable settlement. Do we have a high-confidence way to reproduce the issue? Current-main source exposes both clock-domain failures directly, and the contributor supplies matching before/after output; this read-only review executed no target code. Is this the best way to solve the issue? Changing the clock at the shared observation owner fixes both paths without adding policy, configuration, or a competing timeout owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8ab860a75c9e. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource 0, Tests +32. Total +32 across 3 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (11 earlier review cycles; latest 8 shown)
Reviewed October 15, 2026, 10:15 PM ET / October 16, 2026, 02:15 UTC (Revision 12). |
d212c67 to
05fd23f
Compare
1a981e5 to
3b0be2b
Compare
|
🦞👀 Re-review progress:
|
3b0be2b to
3710b59
Compare
|
🦞👀 Re-review progress:
|
|
@obviyus @altaywtf — you both have merged the sibling monotonic-clock fixes (#155323, #155603, #156979) with the same
Could one of you post |
|
🦞👀 Re-review progress:
|
441aa69 to
f5fe745
Compare
f5fe745 to
832c8a2
Compare
observeOAuthRefreshSettlementBeforeDeadline seeded its deadline with Date.now() and fed deadline - Date.now() to setTimeout. Wall-clock adjustments (NTP, container drift, sleep resume) warped the remaining budget: a rewind let the fence hang past the configured timeout and a forward jump tripped the timeout on a healthy refresh. Seed the deadline from performance.now() and read remaining budget from the same monotonic clock, flooring the value before handing it to setTimeout/sleepWithAbort. Mirrors the canonical wall-clock fix in openclaw#155323. Ref: BUG-153-oauth-refresh-fence-deadline-wall-clock (local finding)
832c8a2 to
588022c
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
/allow-security-sensitive-change |
|
@fuller-stack-dev Thanks! I also have a couple of other small wall-clock fix PRs under my name — all fairly minor changes. Feel free to check them out if you have some bandwidth. Thanks a lot~ |
…ew (openclaw#167619) * fix(auth): keep OAuth refresh fence timeout monotonic across clock skew observeOAuthRefreshSettlementBeforeDeadline seeded its deadline with Date.now() and fed deadline - Date.now() to setTimeout. Wall-clock adjustments (NTP, container drift, sleep resume) warped the remaining budget: a rewind let the fence hang past the configured timeout and a forward jump tripped the timeout on a healthy refresh. Seed the deadline from performance.now() and read remaining budget from the same monotonic clock, flooring the value before handing it to setTimeout/sleepWithAbort. Mirrors the canonical wall-clock fix in openclaw#155323. Ref: BUG-153-oauth-refresh-fence-deadline-wall-clock (local finding) * fix(auth): yield across fractional refresh polling remainders --------- Co-authored-by: Jason (Json) <[email protected]>
…ew (openclaw#167619) * fix(auth): keep OAuth refresh fence timeout monotonic across clock skew observeOAuthRefreshSettlementBeforeDeadline seeded its deadline with Date.now() and fed deadline - Date.now() to setTimeout. Wall-clock adjustments (NTP, container drift, sleep resume) warped the remaining budget: a rewind let the fence hang past the configured timeout and a forward jump tripped the timeout on a healthy refresh. Seed the deadline from performance.now() and read remaining budget from the same monotonic clock, flooring the value before handing it to setTimeout/sleepWithAbort. Mirrors the canonical wall-clock fix in openclaw#155323. Ref: BUG-153-oauth-refresh-fence-deadline-wall-clock (local finding) * fix(auth): yield across fractional refresh polling remainders --------- Co-authored-by: Jason (Json) <[email protected]> (cherry picked from commit 27b0180) Co-authored-by: RomneyDa <[email protected]>
…ew (#167619) * fix(auth): keep OAuth refresh fence timeout monotonic across clock skew observeOAuthRefreshSettlementBeforeDeadline seeded its deadline with Date.now() and fed deadline - Date.now() to setTimeout. Wall-clock adjustments (NTP, container drift, sleep resume) warped the remaining budget: a rewind let the fence hang past the configured timeout and a forward jump tripped the timeout on a healthy refresh. Seed the deadline from performance.now() and read remaining budget from the same monotonic clock, flooring the value before handing it to setTimeout/sleepWithAbort. Mirrors the canonical wall-clock fix in #155323. Ref: BUG-153-oauth-refresh-fence-deadline-wall-clock (local finding) * fix(auth): yield across fractional refresh polling remainders --------- Co-authored-by: Jason (Json) <[email protected]> (cherry picked from commit 27b0180)
What Problem This Solves
A wall-clock rollback can make callers observing an OAuth refresh wait beyond their timeout. The refresh observer calculated its deadline with
Date.now(), although its timers measure elapsed time. Forward clock changes can also reject a healthy settlement too early.Change
Measure the existing observation deadlines with
performance.now(). Keep token expiration timestamps and credential validity checks on wall time. Refresh ownership, persistence, cancellation, timeout messages, and configured budgets remain unchanged.Thanks @SunnyShu0925 for the report and fix; the contributor's commit is retained unchanged. The fix stays in the existing shared observer, with no new state or compatibility path. The original monotonic conversion is retained. Follow-up fixes round fractional observer timeouts and positive polling remainders upward so neither expires early nor busy-polls without yielding. Tests cover both wall-clock directions, exact boundaries, blocked reads, late settlement and cancellation.
Evidence
Validation for current head
fe34335fe5c31fdabb5b0753244dcffa64cf0b5a(same source tree as locally tested139811d3e675c87abf48156c9d47dbd2a201406f):5462f7f146436a50a56354dd39f8405eaeb5b60f, merged treea0a623d39589a51a16b873a9ba7962f1542640ab: 65 passed across OAuth fence sync/async, abort-signal and backoff tests. Command:pnpm test src/agents/auth-profiles/oauth-refresh-fence.test.ts src/agents/auth-profiles/oauth-refresh-fence.async.test.ts src/infra/abort-signal.test.ts src/infra/backoff.test.ts --maxWorkers=1.Original contributor validation (historical head)
Built current main
56c315156f4542f197a2b7f727681ba3f41c21b5and this head588022c34c35772d025eb7c73c4c0a8b26e9dd5cin an isolated Node 24.16.0 Linux container. Synthetic pending refresh credentials were persisted in the real SQLite auth store. Only the process'sDate.now()was stepped backward by 5,000 ms; the system clock was not changed. Elapsed durations were measured withperformance.now().The compiled observer reading the real persisted store, with a 200 ms budget:
The shipped
openclaw/plugin-sdk/provider-authresolver,resolveProviderAuthProfileApiKey, also observed a pending refresh through the normal auth manager. This path keeps its production 120,000 ms budget. Total call durations include initialization:All calls ended with the existing OAuth refresh timeout error; the pending owner was intentionally never settled. Current main requires its published asynchronous runtime-config initialization before the resolver call.
A separate public-SDK control checked the same unchanged token-expiry timestamp before expiry, after expiry, and after a wall-clock rollback. Both builds returned
[true, false, true], confirming that token validity still follows wall time.Focused tests:
pnpm test src/agents/auth-profiles/oauth-refresh-fence.test.ts src/agents/auth-profiles/oauth-refresh-fence.async.test.ts --maxWorkers=1— 33 passed, 2 files; command elapsed 200.31 seconds. These also cover cancellation and durable success/failure settlement.No real-provider gate is needed for this observation-deadline-only change. No live provider credentials were used. The runtime reproduction covers pending-generation observation; the existing focused tests cover the other settlement boundaries.
Merge risk
Two-way door: reverting fully restores the previous behavior; there is no schema, stored-token, configuration, or public API migration. The affected surface is OAuth callers waiting for a refresh or refresh settlement. An incorrect deadline could return a timeout too early or let those callers wait too long; it does not change token expiry or cancel the durable refresh owner.