Skip to content

fix(team-reports): keep the missed closed day when catch-up runs after midnight - #165780

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
yetval:fix/team-reports-catchup-day
Oct 6, 2026
Merged

vincentkoc merged 1 commit into
openclaw:mainfrom
yetval:fix/team-reports-catchup-day

Conversation

@yetval

@yetval yetval commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Team Reports can permanently skip a closed daily report after a gateway restart. If the gateway was down when day D-1 should have closed (default 00:05 UTC on day D) and it comes back late on day D, the first automatic run lands after the next UTC midnight and collects only D and D+1. Nothing ever collects D-1. Weekly and monthly rollups built from stored daily activity leave that day out.

When it triggers:

  • schedule.intradayEveryHours set to 0 or 24, and any restart on day D after the closed-day slot.
  • The default 4-hour cadence, and a restart after about 19:55 UTC.

Before #165356 (df96d22), startup queued a catch-up 60 seconds after the restart for the day before startup.

Root cause

extensions/team-reports/src/scheduler.ts now defers catch-up to the first scheduled tick, but works out "yesterday" from the tick's fire time instead of the startup time:

// before
const catchUp = this.catchUp;
this.catchUp = false;
const runKind = catchUp ? "closed-day" : kind;
const now = Date.now();
const days =
  runKind === "closed-day"
    ? [describePeriod("day", now - DAY_MS), describePeriod("day", now)]
    : [describePeriod("day", now)];

nextIntradayDue caps at the next midnight, and the closed-day slot is on the following day. So the first tick can fire on D+1, where now - DAY_MS is D. The day before startup (D-1) drops out of the catch-up window.

Fix

Capture the catch-up day when the scheduler starts. The first run includes it when it is not already one of that run's days:

// after
this.catchUpDay = describePeriod("day", now - DAY_MS); // in start()
...
if (catchUpDay && !days.some((day) => day.key === catchUpDay.key)) {
  days.unshift(catchUpDay);
}
await this.begin(runKind, days, catchUpDay !== undefined);

The first run still passes reuseCollectedDays, so a day that already has an accepted closed report is reused, not collected again. Startup still triggers no report job, and the five-minute grace window and later cadence are unchanged.

Why this is the right boundary

The scheduler owns choosing which days the catch-up run covers. The worker's accepted-day reuse already makes an extra day cheap when it was collected before. Manual generation, intraday ticks after the first run, and closed-day recurrence are untouched. The docs sentence on the first scheduled run now says it also covers the day before startup.

Verification

  • Rebased onto main 6693bb9; the rebase applied cleanly with no conflicts (the only main commit touching scheduler.ts since the PR opened, refactor(channels): deslop channels #165883, changed the TeamReportsHealth type and does not overlap these lines).
  • Regression coverage in extensions/team-reports/src/scheduler.test.ts: two new intradayEveryHours 0 and 24 cases, and the existing 23:58 restart case now expects the missed 2026-08-18 closed day. Before the rebase, the file passed with the patch and those 3 cases failed with only scheduler.ts reverted to main.
  • Local scoped gates (vitest, oxlint, oxfmt, tsgo) were not re-run after the rebase; left to CI.

Real behavior proof

Behavior addressed: after a restart late on day D with no closed report for D-1, the first automatic Team Reports run skips D-1 and collects only D and D+1, so that daily report is never produced.
Real environment tested: the real TeamReportsScheduler handing its run to the real TeamReportsRunner, which runs the production extensions/team-reports/src/run.worker.ts worker thread (generateReportPeriods, GitHub source and response parsing, activity aggregation) against the real worker-backed Team Reports SQLite store, on pristine main 6693bb9 and on this branch at 73717ad. The only replaced boundary is GitHub HTTP: inside the worker, globalThis.fetch answers api.github.com with one repo and one commit by alex in each requested day window, so no real API calls are made; the SSRF-guarded fetch path and its host policy still run. The host timer surface is stubbed so the first due task fires at its due time, and the clock is pinned to the simulated time in both threads. Summaries are disabled. The day list and report are read back from SQLite via store.listRuns() and store.getPeriod().
Exact steps or command run after this patch: from the repo root, NODE_OPTIONS="--import fake-github.mjs" node_modules/.bin/tsx proof.mts 2026-10-05T21:00:00Z 4, then the same with 2026-10-05T10:00:00Z 0. The script starts the scheduler on an empty store at the given time, advances to the first scheduled task, runs it through the production report worker until the run row finishes, and prints the persisted run days and the stored 2026-10-04 day report. scheduler.ts was swapped to the main copy for BEFORE and restored for AFTER; everything else was identical.
Evidence after fix:

# BEFORE (main 6693bb9665c)
gateway restarted at 2026-10-05T21:00:00.000Z (intradayEveryHours=4); no closed report exists for 2026-10-04
first automatic run at 2026-10-06T00:00:00.000Z kind=closed-day status=ok days=2026-10-05,2026-10-06
stored day report 2026-10-04: none
gateway restarted at 2026-10-05T10:00:00.000Z (intradayEveryHours=0); no closed report exists for 2026-10-04
first automatic run at 2026-10-06T00:09:46.329Z kind=closed-day status=ok days=2026-10-05,2026-10-06
stored day report 2026-10-04: none
# AFTER (this branch 73717ad9ac0, identical inputs)
gateway restarted at 2026-10-05T21:00:00.000Z (intradayEveryHours=4); no closed report exists for 2026-10-04
first automatic run at 2026-10-06T00:00:00.000Z kind=closed-day status=ok days=2026-10-04,2026-10-05,2026-10-06
stored day report 2026-10-04: status=closed commits=1 activeMembers=1
gateway restarted at 2026-10-05T10:00:00.000Z (intradayEveryHours=0); no closed report exists for 2026-10-04
first automatic run at 2026-10-06T00:08:15.799Z kind=closed-day status=ok days=2026-10-04,2026-10-05,2026-10-06
stored day report 2026-10-04: status=closed commits=1 activeMembers=1

Observed result after fix: the first automatic run now carries 2026-10-04 into the production report worker, and a closed 2026-10-04 day report with its activity is stored. On main the same run never requests that day and no report for it exists.
What was not tested: no live GitHub or Discord API calls (GitHub HTTP answered in-process inside the worker), no full gateway process, summaries disabled, and the scoped local gates and full build were not run after the rebase.

@clawsweeper

clawsweeper Bot commented Oct 5, 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.

@clawsweeper clawsweeper Bot added 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. labels Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 10:47 AM ET / 14:47 UTC (Revision 2).

ClawSweeper review

What this changes

Team Reports retains the day before startup for its first automatic report run when that run occurs after UTC midnight.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still misses the closed day in the reported scenario. The new production-worker trace resolves the previous proof request; no actionable patch defects were found.

Likely related people: steipete (high-confidence routing).

Priority: P2
Reviewed head: 73717ad9ac02c2be46792c904a48625792ab8e36

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and sufficient production-worker evidence.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The captured before/after terminal trace exercises the actual scheduler, runner, report worker, and SQLite store and shows the missed closed report persisted for two schedules. Controlled time and synthetic GitHub HTTP are adequate for this date-selection repair; live API compatibility is unchanged. The previous worker-coverage gap is resolved, and no stored-data contract changes require migration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The captured before/after terminal trace exercises the actual scheduler, runner, report worker, and SQLite store and shows the missed closed report persisted for two schedules. Controlled time and synthetic GitHub HTTP are adequate for this date-selection repair; live API compatibility is unchanged. The previous worker-coverage gap is resolved, and no stored-data contract changes require migration.
Evidence reviewed 8 items Verified introduced change: The pinned introduction delta only changes the scheduler, its regression tests, and scheduling documentation. It captures the prior day at startup and adds that descriptor to the first automatic run without changing cadence or manual generation.
Current main still needs the repair: Current main retains a boolean catch-up flag and derives both requested days from the tick time. A restart on October 5 followed by an October 6 tick therefore requests October 5 and 6, omitting October 4. No merged fixing PR is established by the supplied related context. The supplied latest release is v2026.9.8; inspection of its scheduler blob was unavailable, so no shipped-fix claim is made.
Existing accepted-report reuse: The unchanged report owner reuses healthy closed daily reports for the same organization scope. The scheduler preserves that option, so including the startup date does not force accepted historical reports to be recollected. No schema, serialized format, configuration, or public plugin API changes are introduced.
Findings None None.
Security None None.

How this fits together

Team Reports collects GitHub and optional Discord activity into stored daily reports and weekly or monthly rollups. Its scheduler selects report dates and sends them through the report worker to the plugin-owned SQLite store.

flowchart TD
  A[Service startup] --> B[Remember prior UTC day]
  C[Configured schedule] --> D[First automatic run]
  B --> D
  D --> E[Select missing and current days]
  E --> F[Report worker collects or reuses activity]
  F --> G[Stored reports and rollups]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +4, Tests +26, Docs +1. Total +31 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 9 5 +4
Tests 1 34 8 +26
Docs 1 2 1 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 45 14 +31

Review metrics

None.

Technical review

Best possible solution:

Keep catch-up date selection in the scheduler and reuse the existing worker pipeline to recover the missed day without changing startup timing or accepted reports.

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

Yes: current-main source deterministically omits the day before startup when the first tick crosses midnight, and the contributor supplies matching before/after production-worker traces. This reviewer did not execute the scenario.

Is this the best way to solve the issue?

Yes: retaining the startup date repairs the scheduler's date-selection invariant while preserving the existing grace period, cadence, worker, and accepted-day reuse.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured before/after terminal trace exercises the actual scheduler, runner, report worker, and SQLite store and shows the missed closed report persisted for two schedules. Controlled time and synthetic GitHub HTTP are adequate for this date-selection repair; live API compatibility is unchanged. The previous worker-coverage gap is resolved, and no stored-data contract changes require migration.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The captured before/after terminal trace exercises the actual scheduler, runner, report worker, and SQLite store and shows the missed closed report persisted for two schedules. Controlled time and synthetic GitHub HTTP are adequate for this date-selection repair; live API compatibility is unchanged. The previous worker-coverage gap is resolved, and no stored-data contract changes require migration.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This repairs a bounded report-scheduling defect that omits historical daily activity after a late restart.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The captured before/after terminal trace exercises the actual scheduler, runner, report worker, and SQLite store and shows the missed closed report persisted for two schedules. Controlled time and synthetic GitHub HTTP are adequate for this date-selection repair; live API compatibility is unchanged. The previous worker-coverage gap is resolved, and no stored-data contract changes require migration.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured before/after terminal trace exercises the actual scheduler, runner, report worker, and SQLite store and shows the missed closed report persisted for two schedules. Controlled time and synthetic GitHub HTTP are adequate for this date-selection repair; live API compatibility is unchanged. The previous worker-coverage gap is resolved, and no stored-data contract changes require migration.

Evidence

What I checked:

  • Verified introduced change: The pinned introduction delta only changes the scheduler, its regression tests, and scheduling documentation. It captures the prior day at startup and adds that descriptor to the first automatic run without changing cadence or manual generation. (extensions/team-reports/src/scheduler.ts:78, 73717ad9ac02)
  • Current main still needs the repair: Current main retains a boolean catch-up flag and derives both requested days from the tick time. A restart on October 5 followed by an October 6 tick therefore requests October 5 and 6, omitting October 4. No merged fixing PR is established by the supplied related context. The supplied latest release is v2026.9.8; inspection of its scheduler blob was unavailable, so no shipped-fix claim is made. (extensions/team-reports/src/scheduler.ts:226, bff90d69144c)
  • Existing accepted-report reuse: The unchanged report owner reuses healthy closed daily reports for the same organization scope. The scheduler preserves that option, so including the startup date does not force accepted historical reports to be recollected. No schema, serialized format, configuration, or public plugin API changes are introduced. (extensions/team-reports/src/run.ts:76, 73717ad9ac02)
  • After-fix production-worker proof: The captured PR body reports paired before/after runs at main 6693bb9 and head 73717ad. The actual scheduler, runner, report worker, parsing, aggregation, and worker-backed SQLite store produced a closed October 4 report with one commit and one active member after the fix, whereas the baseline stored no such report. Both four-hour and disabled intraday schedules were exercised. Time and GitHub HTTP responses were controlled; no live external API or full Gateway execution is claimed. (extensions/team-reports/src/run.worker.ts:63, 73717ad9ac02)
  • Previous review addressed: The previous completed review requested evidence that the missed report was produced through the actual report worker. The new body trace and contributor response at fix(team-reports): keep the missed closed day when catch-up runs after midnight #165780 (comment) directly address that requirement. The previous review had no functional findings. (73717ad9ac02)
  • Focused regression coverage: The tests extend the existing lifecycle table for midnight rollover and add disabled and 24-hour cadence cases that assert a persisted closed report. They use the existing fake-clock and storage fixture without adding production seams. The contributor reports that three affected cases failed with the original scheduler. (extensions/team-reports/src/scheduler.test.ts:523, 73717ad9ac02)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-05T20:55:54.812Z sha 8815a1f32d6dbef92c2e0ed330b8353d8960a5f5 :: needs real behavior proof before merge. :: none

…r midnight

The startup catch-up moved into the first scheduled run, but that run
computes yesterday from its own fire time. When the first run lands after
the next UTC midnight (intraday 0 or 24, or a late-day restart with the
default 4-hour cadence), the day before startup is never collected.
Capture the catch-up day at start and include it in the first run.
@yetval
yetval force-pushed the fix/team-reports-catchup-day branch from 8815a1f to 73717ad Compare October 6, 2026 14:30
@yetval

yetval commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review on 8815a1f32d6, now rebased to 73717ad on main 6693bb9:

  • Add real behavior proof / Complete next step (P2): done. The proof in the PR body now runs the first automatic run through the production report path. TeamReportsScheduler hands off to TeamReportsRunner, which runs the real run.worker.ts (generateReportPeriods, GitHub source parsing, aggregation) against the real SQLite store. Only GitHub HTTP is answered in-process inside the worker. On main the run never requests 2026-10-04 and no report for that day exists. With this branch, stored day report 2026-10-04: status=closed commits=1 activeMembers=1 appears for both the 4-hour and the disabled intraday schedules.
  • Stale base: rebased onto current main with no conflicts. The only main commit that touched scheduler.ts since this PR opened is refactor(channels): deslop channels #165883 (a TeamReportsHealth type cleanup), and it does not overlap these lines.
  • Findings and Security were None. The code diff is unchanged apart from the rebase.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation plugin: team-reports size: S labels Oct 6, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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. labels Oct 6, 2026
@vincentkoc vincentkoc self-assigned this Oct 6, 2026
@vincentkoc
vincentkoc merged commit f0984df into openclaw:main Oct 6, 2026
116 of 118 checks passed
vincentkoc added a commit that referenced this pull request Oct 6, 2026
* commit 'c39d9b0692dbaafa5b1bfe02514c9f6411ab5546': (30 commits)
  fix(ci): clear MCP audit and service-worker test blockers (#166217)
  test(gateway): wait for steering admission in FIFO fixtures
  fix(llama-cpp): managed setup crashes and loops on macOS below 13.3 (#163358)
  perf(worktrees): avoid full session parsing during GC (#166072)
  fix(update): recover stopped legacy managed services (#166232)
  perf(gateway): stream bounded link preview metadata (#166195)
  perf(diagnostics): release completed Git operation state (#166214)
  chore(deps): update fs-safe to 0.24.1 and clone plugin source captures (#166189)
  feat(clients): adopt worker-local inference placement (#163647)
  test: serialize PowerShell completion process suites (#166229)
  test: stabilize release timing boundaries (#166218)
  refactor(sessions): persist run outcomes only; liveness comes from the run registry (#165733)
  test(gateway): prove mention refresh after config retargeting
  fix(team-reports): keep the missed closed day when catch-up runs after midnight (#165780)
  test(gateway): join WebChat queue admission and drain completion
  fix(logging): reject blank diagnostic stability query fields (#145532)
  fix(agents): report unparseable serialized edit arguments (#163577)
  improve(anthropic): log Claude Code version probe failures (#157697)
  fix(agents): clarify prompt-size provider failures (#159712)
  fix(memory): re-throw non-ENOENT/ENOTDIR errors in root memory file lookup (#107921)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…r midnight (openclaw#165780)

The startup catch-up moved into the first scheduled run, but that run
computes yesterday from its own fire time. When the first run lands after
the next UTC midnight (intraday 0 or 24, or a late-day restart with the
default 4-hour cadence), the day before startup is never collected.
Capture the catch-up day at start and include it in the first run.

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

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. plugin: team-reports proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants