Skip to content

fix: properly track time since code update from CI deployment - #39

Merged
frostebite merged 1 commit into
mainfrom
fix/deploy-time-tracking
Jun 10, 2026
Merged

frostebite merged 1 commit into
mainfrom
fix/deploy-time-tracking

Conversation

@frostebite

@frostebite frostebite commented Jun 9, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes issue where 'time since update' in bot status always equals 'time up' (bot uptime).

Changes

  • Track actual git SHA changes instead of resetting deploy timestamp on every bot startup
  • Only update 'time since update' timestamp when code genuinely changes from CI deployment
  • Preserve original deploy time across bot restarts if code hasn't changed
  • First run: initialize both SHA and timestamp with current time

Why

Previously, the deploy timestamp was overwritten to the current time on every bot restart, making 'time since update' always equal 'time up'. Now the bot intelligently detects real code changes and only updates the timestamp when the git SHA actually differs.

Summary by CodeRabbit

  • Bug Fixes
    • Improved deploy timestamp handling to only update when actual code changes are deployed, rather than on every startup when code remains unchanged.

Instead of resetting deploy timestamp on every bot startup, track actual git SHA
changes. Only update the 'time since update' timestamp when code has genuinely
changed from a CI deployment, not when the bot restarts with the same code.

- Check git SHA on startup instead of blindly overwriting deploy timestamp
- Preserve original deploy time across bot restarts if code hasn't changed
- First run: initialize both SHA and timestamp with current time
- New deployment: update timestamp only when SHA differs

Fixes issue where 'time since update' always equaled 'time up' in status output.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 9, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The runLive startup function now conditionally updates the deploy timestamp. Instead of always overwriting it, the function checks if code has changed by comparing the stored and current git SHAs. It updates the timestamp only when code differs, preserving the timestamp when code is unchanged.

Changes

Deploy Timestamp Stamping

Layer / File(s) Summary
Conditional deploy timestamp stamping
src/core/live.ts
runLive now conditionally updates last-deploy-at.txt based on SHA comparison. It reads the previously recorded deployed SHA from last-deploy-sha.txt, compares to current git HEAD, and only updates both files when code has changed, preserving the timestamp when SHA is unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • game-ci/help-bot#34: Both PRs modify deploy metadata handling in runLive—this PR changes when deploy timestamp is updated, while the related PR adjusts how deploy info is retrieved and output.

Poem

🐰 With whiskers twitching and nose in the air,
A rabbit reads the SHA with utmost care,
"The code's unchanged!" she crows with glee,
"Keep that timestamp, let it be!"
Only when fresh commits roll through,
Does she stamp the time anew! ⏰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: tracking deploy time properly by comparing git SHAs instead of always overwriting the timestamp, which fixes the reported issue.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/deploy-time-tracking

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/core/live.ts`:
- Around line 444-474: Startup writes DEPLOY_SHA_FILE and DEPLOY_AT_FILE before
postDeployChangelog runs, so postDeployChangelog sees the new SHA and exits
early; fix by introducing a separate changelog marker (e.g.,
DEPLOY_CHANGELOG_SHA_FILE) that postDeployChangelog reads/writes instead of
DEPLOY_SHA_FILE/DEPLOY_AT_FILE. Change postDeployChangelog to: read current git
SHA as before, compare it to DEPLOY_CHANGELOG_SHA_FILE (not DEPLOY_SHA_FILE),
return early only if they match, and write the new SHA into
DEPLOY_CHANGELOG_SHA_FILE after posting (remove writing/updating
DEPLOY_AT_FILE/timestamp there). Leave runLive’s logic that writes
DEPLOY_SHA_FILE and DEPLOY_AT_FILE unchanged so time tracking remains decoupled
from changelog idempotency.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8425e3e5-2124-4dd3-831e-cc8e68810e92

📥 Commits

Reviewing files that changed from the base of the PR and between 019060c and edc25a8.

📒 Files selected for processing (1)
  • src/core/live.ts

Comment thread src/core/live.ts
Comment on lines +444 to +474

// Only update deploy timestamp if code has actually changed
let deployTimestampExists = false
try {
await readFile(DEPLOY_AT_FILE, 'utf-8')
deployTimestampExists = true
} catch {
// Deploy timestamp file doesn't exist yet
}

try {
const currentSha = execSync('git rev-parse HEAD', { cwd: REPO_ROOT, encoding: 'utf-8' }).trim()
let lastDeployedSha = ''
try {
lastDeployedSha = (await readFile(DEPLOY_SHA_FILE, 'utf-8')).trim()
} catch {
// First run — no previous SHA recorded
}

if (lastDeployedSha !== currentSha) {
// Code has changed — update both SHA and timestamp
await writeFile(DEPLOY_SHA_FILE, currentSha, 'utf-8')
await writeFile(DEPLOY_AT_FILE, new Date().toISOString(), 'utf-8')
}
// If SHA hasn't changed, preserve the existing deploy timestamp
} catch {
// If git operations fail, ensure deploy timestamp exists for first run
if (!deployTimestampExists) {
await writeFile(DEPLOY_AT_FILE, new Date().toISOString(), 'utf-8')
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Critical: Deploy changelog will never be posted due to conflicting file writes.

The new startup logic writes DEPLOY_SHA_FILE (line 465) before postDeployChangelog executes (line 902). When postDeployChangelog runs, it reads the SHA file (line 294), sees it matches the current SHA, and returns early (line 298) without posting the changelog to triage channels.

Execution flow on new deployment:

  1. Lines 463-466: Startup detects SHA changed, writes both DEPLOY_SHA_FILE and DEPLOY_AT_FILE
  2. Line 902: postDeployChangelog runs in ClientReady handler
  3. Line 294: Reads DEPLOY_SHA_FILE → gets the SHA that was just written
  4. Line 298: lastSha === currentSha → returns early
  5. Result: No changelog message is posted to Discord ❌

This also occurs on first run, breaking the "First deploy" flow mentioned in the comment at line 296.

Additionally, note that postDeployChangelog writes a fresh timestamp at line 303, which would slightly differ from the one written at line 466, though this is now moot since line 303 is never reached.

🔧 Suggested fix: Use separate marker file for changelog idempotency

Decouple the "deploy time tracking" concern from the "changelog posting" concern by having postDeployChangelog use its own marker file:

@@ -82,6 +82,7 @@ let activeInvestigations = 0
 const onlineSince = Date.now()
 let deployedSha = ''
 const STATUS_ROTATION_INTERVAL_MS = 5 * 60_000
+const DEPLOY_CHANGELOG_SHA_FILE = join(DATA_DIR, 'last-deploy-changelog-sha.txt')
 const DEPLOY_AT_FILE = join(DATA_DIR, 'last-deploy-at.txt')
 const ANSWERED_WINDOWS = [
   { label: 'daily', days: 1 },
@@ -290,7 +291,7 @@ async function postDeployChangelog(
     const currentAt = new Date().toISOString()
     let lastSha = ''
     try {
-      lastSha = (await readFile(DEPLOY_SHA_FILE, 'utf-8')).trim()
+      lastSha = (await readFile(DEPLOY_CHANGELOG_SHA_FILE, 'utf-8')).trim()
     } catch {
       // First deploy — no previous SHA
     }
@@ -299,8 +300,7 @@ async function postDeployChangelog(
     // Save SHA immediately so restarts don't re-post
     await ensureDir(DATA_DIR)
-    await writeFile(DEPLOY_SHA_FILE, currentSha, 'utf-8')
-    await writeFile(DEPLOY_AT_FILE, currentAt, 'utf-8')
+    await writeFile(DEPLOY_CHANGELOG_SHA_FILE, currentSha, 'utf-8')

     const version = getGitVersion()

This allows:

  • runLive startup manages DEPLOY_SHA_FILE and DEPLOY_AT_FILE for "time since update" tracking (as intended by this PR)
  • postDeployChangelog manages DEPLOY_CHANGELOG_SHA_FILE independently to track whether changelog was posted
  • No timestamp conflicts (line 303 removal ensures startup-written timestamp is preserved)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core/live.ts` around lines 444 - 474, Startup writes DEPLOY_SHA_FILE and
DEPLOY_AT_FILE before postDeployChangelog runs, so postDeployChangelog sees the
new SHA and exits early; fix by introducing a separate changelog marker (e.g.,
DEPLOY_CHANGELOG_SHA_FILE) that postDeployChangelog reads/writes instead of
DEPLOY_SHA_FILE/DEPLOY_AT_FILE. Change postDeployChangelog to: read current git
SHA as before, compare it to DEPLOY_CHANGELOG_SHA_FILE (not DEPLOY_SHA_FILE),
return early only if they match, and write the new SHA into
DEPLOY_CHANGELOG_SHA_FILE after posting (remove writing/updating
DEPLOY_AT_FILE/timestamp there). Leave runLive’s logic that writes
DEPLOY_SHA_FILE and DEPLOY_AT_FILE unchanged so time tracking remains decoupled
from changelog idempotency.

@frostebite
frostebite merged commit 78b95a3 into main Jun 10, 2026
2 checks passed
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