Repository navigation
fix: properly track time since code update from CI deployment - #39
Conversation
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>
📝 WalkthroughWalkthroughThe ChangesDeploy Timestamp Stamping
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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
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. Comment |
There was a problem hiding this comment.
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
|
|
||
| // 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') | ||
| } | ||
| } |
There was a problem hiding this comment.
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:
- Lines 463-466: Startup detects SHA changed, writes both
DEPLOY_SHA_FILEandDEPLOY_AT_FILE - Line 902:
postDeployChangelogruns in ClientReady handler - Line 294: Reads
DEPLOY_SHA_FILE→ gets the SHA that was just written - Line 298:
lastSha === currentSha→ returns early - 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:
runLivestartup managesDEPLOY_SHA_FILEandDEPLOY_AT_FILEfor "time since update" tracking (as intended by this PR)postDeployChangelogmanagesDEPLOY_CHANGELOG_SHA_FILEindependently 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.
Summary
Fixes issue where 'time since update' in bot status always equals 'time up' (bot uptime).
Changes
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