Skip to content

fix(msteams): expire pending uploads across clock changes - #188239

Closed
chengzhichao-xydt wants to merge 1 commit into
openclaw:mainfrom
chengzhichao-xydt:fix/msteams-pending-uploads-clock
Closed

chengzhichao-xydt wants to merge 1 commit into
openclaw:mainfrom
chengzhichao-xydt:fix/msteams-pending-uploads-clock

Conversation

@chengzhichao-xydt

@chengzhichao-xydt chengzhichao-xydt commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: an in-memory Teams pending upload (a file waiting for FileConsentCard approval) can be dropped while still fresh, or kept past its TTL, when the system clock steps (NTP correction, manual change, VM snapshot restore). Besides the 5-minute TTL timer, getPendingUpload runs an explicit age check for the case where the timer has not fired yet, and that check compares Date.now() readings — so a backward step keeps stale uploads alive and a forward step makes the user's Accept click hit an already-gone file.

User Impact

Pending uploads expire exactly at their 5-minute TTL regardless of system-clock corrections, and fresh uploads are never dropped early by a forward clock jump. No configuration, public API, schema, or migration changes.

Why This Change Was Made

The explicit expiry check is an in-process duration decision, so it now rides a monotonic deadline (performance.now()), which is immune to system-clock steps. The public createdAt field keeps its epoch value for API consumers, and the TTL timer itself is unchanged.

Evidence

node scripts/run-vitest.mjs run extensions/msteams/src/pending-uploads.test.ts extensions/msteams/src/pending-uploads.lifecycle.test.ts: 7/7 pass. The stale-entry case now advances the monotonic clock without firing timers, and a new regression keeps fresh entries across one-hour wall-clock steps in both directions (red against the base implementation). oxlint and oxfmt --check clean on changed files. Local tsgo lane unavailable on this host (glibc 2.28 vs binary requirement 2.33+); type gates run in hosted CI. Net test growth +10 lines is recorded in config/test-lines-allocations/chengzhichao-msteams-uploads-clock-20261030.txt.

Real behavior proof

Behavior addressed: The shipped Teams file-consent callback (runMSTeamsFileConsentInvokeHandler) must still find a fresh pending upload after a wall-clock step.
Real environment tested: This branch at HEAD b0d8d53915f766304669bd9791d4629cf1ca3206, Node v24.13.1, Linux x64; a real subprocess drives the shipped consent handler end to end: real in-memory store plus a real sqlite-backed plugin-state store (isolated OPENCLAW_STATE_DIR) for the FS fallback path. Date.now is stepped forward one hour after a real storePendingUpload; performance.now stays native. The synthetic upload URL is rejected by the SSRF allowlist as designed, which is what marks reaching the upload stage.
Exact steps or command run after this patch: WT=$PWD OUT=/tmp/clock-proof/msteams-invoke-head.json node --import tsx /tmp/clock-proof/msteams-invoke.mts, then the same command with extensions/msteams/src/pending-uploads.ts restored to the base revision.
Evidence after fix: HEAD terminal output: {"reachedUploadStage":true,"expiredPath":false,"activities":["File upload failed. Please try again."]} — the fresh upload is found after the step, the handler proceeds to the upload stage, and only the synthetic URL stops it. BASE under the identical step: {"reachedUploadStage":false,"expiredPath":true,"activities":["The file upload request has expired. Please try sending the file again."]} — the fresh upload is wrongly expired before the user is ever served. Receipts: /tmp/clock-proof/msteams-invoke-{head,base}.json.
Observed result after fix: A fresh consent accept reaches the upload stage after a one-hour forward wall-clock step; base reports the request as expired instead.
What was not tested: Teams live delivery, Graph upload, the fs-backed pending-upload variant (see below), and OS/NTP clock adjustment. The earlier helper-level red/green pair (driving storePendingUpload/getPendingUpload directly, freshEntrySurvivesForwardStep true-vs-false) remains as supplementary evidence.

Intentionally out of scope

  • pending-uploads-fs.ts: the fs-backed variant persists createdAt across restarts, so its expiry must stay on epoch time by design (a monotonic reading cannot cross a process restart).
  • TTL length, timer behavior, and the consent-card flow.

@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added channel: msteams Channel integration: msteams size: XS labels Oct 30, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR uses a monotonic deadline to expire in-memory Microsoft Teams pending uploads while preserving epoch creation timestamps.

Example: A user accepts proof.txt one minute after sending it, after the system clock jumps forward one hour.

  • Before: The fresh pending upload is treated as expired.
  • After: The pending upload remains available until its five-minute duration expires.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused implementation and distinct regression cases are sound, with successful exact-head CI; helper-level evidence leaves the external PR's shipped-behavior gate unmet.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A fresh Teams file-consent request can appear expired after the system clock advances.
Reason: Elapsed-time expiry should survive wall-clock corrections, and the focused patch preserves the existing five-minute policy and storage boundaries.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this PR fixes a source-verifiable clock-change bug that remains on current main, and no introduced correctness defect was found.

Priority: P2
Reviewed head: b0d8d53915f766304669bd9791d4629cf1ca3206

Before merge

  • Add real behavior proof - The reported Node 24 subprocess exercises the real in-memory owner and shows proof.txt surviving a one-hour Date.now step on head but not base; it calls helpers directly and does not exercise the shipped Teams consent callback. Provide redacted logs, live output, or a recording showing that fresh consent completes through the running Gateway after the clock step; redact IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied helper subprocess and unit tests do not show a fresh Teams consent request completing through the shipped Gateway callback after a forward clock step.
Agent review details

How this fits together

The Teams plugin temporarily holds file bytes while awaiting FileConsentCard approval; the consent callback retrieves them for upload or removes them after decline or expiry.

flowchart LR
A[Teams file reply] --> B[Consent card preparation]
B --> C[In-memory pending uploads]
B --> D[User consent card]
D --> E[Consent callback]
C --> E
F[Persisted CLI upload fallback] --> E
E --> G[Upload and file info card]
Loading

Technical review

Best possible solution:

Keep expiry duration in the existing in-memory upload owner, preserve epoch timestamps and persisted-upload semantics, and retain timer cleanup.

Do we have a high-confidence way to reproduce the issue?

Current main's wall-clock age check directly establishes the forward-step failure; the contributor also reports a head-versus-base subprocess comparison, but no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch is a small, complete repair for the stated in-memory boundary: one deadline field serves the existing expiry owner without changing public values, persistent records, or lifecycle cleanup.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against aef29790c634.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 283b8a0 adds extensions/msteams/src/pending-uploads.ts:23 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 283b8a014381; files: extensions/msteams/src/pending-uploads.ts)
  • sudie-codes: Raw commit 7843187 adds extensions/msteams/src/pending-uploads.ts:17 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 784318799bf0; files: extensions/msteams/src/pending-uploads.ts)

PR surface

Source +14, Tests +11, Other +2. Total +27 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 21 7 +14
Tests 1 13 2 +11
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 3 36 9 +27

Labels

Label changes:

  • add P2: Clock corrections can incorrectly expire Teams consent uploads, but the failure is limited to pending in-memory files during clock changes.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: Clock corrections can incorrectly expire Teams consent uploads, but the failure is limited to pending in-memory files during clock changes.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Attach evidence of the changed expiry behavior through the running Gateway's Teams consent flow.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 30, 2026, 6:24 AM ET / 10:24 UTC.

@chengzhichao-xydt

Copy link
Copy Markdown
Contributor Author

Added the requested shipped-callback proof: a real subprocess drives runMSTeamsFileConsentInvokeHandler end to end (real in-memory store + real sqlite-backed plugin-state for the FS fallback), stepping Date.now forward one hour after a real storePendingUpload. HEAD: the fresh upload is found and the handler reaches the upload stage (only the synthetic URL stops it, SSRF allowlist working as designed); BASE under the identical step: the fresh upload is reported expired (pending file not found for consent + expired-message activity). Full terminal output in the updated body. @clawsweeper re-review

obviyus added a commit that referenced this pull request Oct 30, 2026
…nges (#188293)

fix(irc,msteams): measure in-process durations with a monotonic clock

IRC and Microsoft Teams measured some in-process durations with wall-clock time, so a system clock jump changed them:
- the IRC probe latency could be wrong;
- IRC reconnect backoff reset too early or not at all;
- a fresh Teams file-consent upload could expire too early.

These durations now use `performance.now()`. Persisted dates and public `createdAt` timestamps are unchanged, and so are the budgets.

Evidence: built Gateway, main twice and candidate twice, with `Date.now` stepped inside the process only. Main reproduced the wrong probe latency, the wrong reconnect resets and the early expiry of a fresh Teams upload; the candidate corrected all three. The Teams path ran authenticated consent invokes, exact-byte uploads and the original card update. Controls passed: normal timing and expiry, invalid JWT, conversation mismatch and decline. Details: #188293 (comment).

Includes the fixes from #188237, #188238 and #188239, with their commits kept.

Co-authored-by: chengzhichao-xydt <[email protected]>
Co-authored-by: Claude Code <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus

obviyus commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Thanks @chengzhichao-xydt. Your fix landed in #188293 (9b5c4e8), which keeps your commit. I'm closing this one as included.

@obviyus obviyus closed this Oct 30, 2026
@chengzhichao-xydt
chengzhichao-xydt deleted the fix/msteams-pending-uploads-clock branch October 30, 2026 12:03
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…nges (openclaw#188293)

fix(irc,msteams): measure in-process durations with a monotonic clock

IRC and Microsoft Teams measured some in-process durations with wall-clock time, so a system clock jump changed them:
- the IRC probe latency could be wrong;
- IRC reconnect backoff reset too early or not at all;
- a fresh Teams file-consent upload could expire too early.

These durations now use `performance.now()`. Persisted dates and public `createdAt` timestamps are unchanged, and so are the budgets.

Evidence: built Gateway, main twice and candidate twice, with `Date.now` stepped inside the process only. Main reproduced the wrong probe latency, the wrong reconnect resets and the early expiry of a fresh Teams upload; the candidate corrected all three. The Teams path ran authenticated consent invokes, exact-byte uploads and the original card update. Controls passed: normal timing and expiry, invalid JWT, conversation mismatch and decline. Details: openclaw#188293 (comment).

Includes the fixes from openclaw#188237, openclaw#188238 and openclaw#188239, with their commits kept.

Co-authored-by: chengzhichao-xydt <[email protected]>
Co-authored-by: Claude Code <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: msteams Channel integration: msteams P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants