Skip to content

Today I learned / DevOps and tooling

DevOps and tooling notes

CI, hosting, Firebase, Git and the command line: the one-line fixes and settings that save an afternoon the next time.

How do I repost a video to a Telegram channel without uploading the file again?

My video job renders an MP4, sends it to me in a private chat, and exits. Hours later a different service (the website) has to post the same video to a channel, and by then the file is gone.

Keep the file_id from the first send and pass it instead of the file. Telegram reuses the upload, and the size limit for multipart uploads doesn't apply:

js
// 1. The job: upload once, keep the id
const res = await bot('sendVideo', form) // multipart with the MP4
const fileId = res.result.video.file_id   // save it next to the record

// 2. Later, anywhere: no file, just the id
await bot('sendVideo', { chat_id: '@my_channel', video: fileId, caption })

Three rules I hit:

  1. A file_id belongs to the bot that got it. The service that reposts must use the same bot token.
  2. Resend with the same method: a video id goes back through sendVideo, not sendDocument.
  3. Read file_id from the API response. If you shell out to a send script, make it print the id (I print one JSON line), or you lose it.

I hit this while wiring my TIL Shorts pipeline: the Cloud Run job sends me the Short to review, and when it goes public on YouTube the site posts that same upload to the channel by file_id.

Docs: Telegram Bot API, sending files

How do I stop a bot from posting the same message twice across server instances?

My site announces new posts in a Telegram channel. It runs on two instances, a post can be republished, and a worker may retry the call. A plain "if not sent yet, send" check races, and the channel gets the post twice.

Fix: one ledger document per message, claimed in a transaction before the send.

ts
async function claim(ref: DocumentReference): Promise<boolean> {
  return db.runTransaction(async (tx) => {
    const cur = (await tx.get(ref)).data()
    if (cur?.status === 'sent') return false
    if (cur?.status === 'sending' && Date.now() - Date.parse(cur.claimedAt) < 5 * 60_000) return false
    tx.set(ref, { status: 'sending', claimedAt: new Date().toISOString() })
    return true
  })
}

const ref = db.collection('channel_ledger').doc(`blog-${slug}`)
if (await claim(ref)) {
  try {
    const msg = await sendToChannel(post)
    await ref.set({ status: 'sent', messageId: msg.message_id })
  } catch (err) {
    await ref.delete() // release, so a retry can send
    throw err
  }
}
  • Key by the message, not the request (blog-<slug>, til-<slug>-video), so a republish does nothing.
  • The 5-minute TTL frees a claim whose process died. A crash between Telegram's OK and the sent write can still repost once: that is the limit without an idempotency key on the API.
  • Keep messageId to reply to the original post later.

Built for the channel announcements on ravy.pro. Firestore transactions.

How do I version builds by git commit count in GitHub Actions?

I wanted versions nobody has to bump: <major.minor>.<commits>, the line from package.json, the patch from git rev-list --count HEAD. On CI every build came out as 0.1.1: actions/checkout clones with fetch-depth: 1, so there is one commit to count.

Fetch the whole history without file contents, which stays fast:

yaml
- uses: actions/checkout@v5
  with: { fetch-depth: 0, filter: "blob:none" }
- id: version
  run: |
    line=$(jq -r '.version | split(".")[:2] | join(".")' package.json)
    echo "game=$line.$(git rev-list --count HEAD)" >> "$GITHUB_OUTPUT"
  1. Docker has no .git. Count in the workflow, pass build-args: GAME_VERSION=${{ steps.version.outputs.game }}, read it with ARG GAME_VERSION.
  2. Guard against shallow clones. If git rev-parse --is-shallow-repository says true, fail or show <line>-dev, never a wrong number.
  3. A desktop client gets its own counter: <line>.${{ github.run_number }}, written into the app's package.json before packaging. A re-run keeps the same number.

Set this up for my Electron game on Steam: settings now show game: 0.1.191, steam: 0.1.30, patch: 5d4112a, and every bug report carries all three.

Docs: actions/checkout

How do I cap a Postgres table by size and delete the oldest rows first?

Preview images for share links sat in a bytea column and were never deleted. Refusing new links at a ceiling is worse: the newest links are the ones in fresh posts.

One DELETE with a running sum, newest first, removes every row past the ceiling:

sql
DELETE FROM shares WHERE id IN (
  SELECT id FROM (
    SELECT id,
      sum(octet_length(image)) OVER (ORDER BY created_at DESC, id DESC) AS acc,
      row_number()             OVER (ORDER BY created_at DESC, id DESC) AS nth
    FROM shares
  ) t
  WHERE acc > $1 AND nth > 1   -- $1 = ceiling in bytes; keep the newest row
) RETURNING octet_length(image) AS freed;
  • Trim to 95% of the ceiling, or a full table runs this on every insert.
  • Cache the total: re-read the sum every 10 minutes, add each insert's size in between. octet_length on bytea doesn't decompress, so it's cheap.
  • Add a per-user cap (newest 200 per user_id), or one heavy user evicts everyone else.

Hit this bounding share-image storage in a game backend (1 GB guests, 4 GB players). Window functions docs

Why doesn't SetLive put my Steam build live on the default branch?

"SetLive" in a SteamPipe app_build script only works for beta branches. Steam refuses to set the default branch live automatically: that last step is always a click on the app's Builds page in Steamworks.

json
"AppBuild"
{
  "AppID" "1000"
  "Desc" "CI build"
  "SetLive" "staging"   // a beta branch, never "default"
  "Preview" "0"         // "1" = dry run: logs and manifest only, nothing uploaded
  "Depots" { "1001" "depot_build_1001.vdf" }
}
bash
steamcmd +login <account> +run_app_build ../scripts/app_build.vdf +quit

So my pipeline uploads every build straight to a private staging branch, I play it there, and promoting it to default stays a deliberate manual step. That is a feature, not a gap: CI can never ship to all players by itself. Also note that the account setting builds live on a released app needs Steam Guard via a phone or the mobile app.

Source: Steamworks: Uploading to Steam

YouTube API: containsSyntheticMedia not set after upload

I upload AI-voiced Shorts through the YouTube Data API with status.containsSyntheticMedia: true in videos.insert. The upload works, but the "Altered content" flag in Studio stays off.

The fix is to set the flag in a second call, videos.update on the status part. That call replaces the whole status object, so send every field again. Any field you leave out goes back to its default.

js
await fetch('https://www.googleapis.com/youtube/v3/videos?part=status', {
  method: 'PUT',
  headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' },
  body: JSON.stringify({
    id: videoId,
    status: {
      privacyStatus: 'private', // resend, or it changes
      selfDeclaredMadeForKids: false,
      embeddable: true,
      license: 'youtube',
      containsSyntheticMedia: true,
    },
  }),
})

Check status.containsSyntheticMedia in the response and warn if it is still false. Calls made right after a fresh upload can return 409 ABORTED or a 5xx for a while, so retry them with backoff.

Hit this while building the bot that turns my TIL notes into Shorts with a cloned voice.

Docs: https://developers.google.com/youtube/v3/docs/videos#status.containsSyntheticMedia

How do I restart a Node.js container when its event loop hangs?

A Node server stuck in an endless loop answers nothing, and Docker won't restart it: a failing healthcheck only marks it unhealthy, and restart: acts only when the process exits. Nothing on the stuck thread can notice, so the watchdog lives on a worker thread and kills the process from there.

ts
// main thread
const w = new Worker(new URL('./watchdog.js', import.meta.url), { workerData: 30_000 })
w.unref()
setInterval(() => w.postMessage(0), 1000).unref()

// watchdog.js (worker)
let last = Date.now()
parentPort.on('message', () => { last = Date.now() })
setInterval(() => {
  if (Date.now() - last > workerData) process.kill(process.pid, 'SIGKILL')
}, 1000)

The gotcha: in a container your server is PID 1, and the kernel won't deliver that SIGKILL to PID 1. Add init: true to the service in Compose so the server runs as a normal child.

I added this to a game's WebSocket gateway, where every player socket hangs on one thread. Keep it off in development: a breakpoint looks exactly like a hang. Docs: Compose init.

Newsletter

Occasional notes on engineering, game tech, and new tools — no spam, unsubscribe anytime.

Ravy

Engineering manager, founder, and software developer building web platforms, game systems, real-time services, and automation tools. 15 years of shipped work — currently at Gaijin.net.

Get in Touch

Building an MVP, shipping a game feature, or automating a team workflow? Open source or paid — let's talk.

Contact Me
© 2020-2026 XPLOIT FZE. All trademarks, names and logos belong to their respective copyright holders.