Skip to content

fix(pam): cap recording chunk size and batch live uploads#257

Merged
bernie-g merged 1 commit into
mainfrom
bernie/pam-240-upload-logs-when-they-exceed-1-mb
Jun 11, 2026
Merged

fix(pam): cap recording chunk size and batch live uploads#257
bernie-g merged 1 commit into
mainfrom
bernie/pam-240-upload-logs-when-they-exceed-1-mb

Conversation

@bernie-g

@bernie-g bernie-g commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Description 📣

Postgres session recordings could get too big to upload once a session ran a while, and long sessions also piled up thousands of tiny chunks. This caps the chunk size and batches uploads so neither happens.

Type ✨

  • Bug fix
  • New feature
  • Improvement
  • Breaking change
  • Documentation

Tests 🛠️

Ran a gateway recording to Postgres locally: a big backlog now splits into capped chunks that upload fine, and a continuous session that used to make ~50 chunks/sec batches down to a couple.


Postgres-backed session recordings could exceed the API body limit on
big sessions, and live sessions created one chunk per event. Cap chunks
at 512KB for the Postgres backend and stop the upload loop from spinning
at the live write edge.
@linear

linear Bot commented Jun 9, 2026

Copy link
Copy Markdown

PAM-240

@infisical-review-police

Copy link
Copy Markdown

💬 Discussion in Slack: #pr-review-cli-257-fix-pam-cap-recording-chunk-size-and-batch-live-uploads

Posted by Review Police — reviews, comments, new commits, and CI failures will stream into this channel.

@bernie-g bernie-g marked this pull request as ready for review June 9, 2026 18:25
@greptile-apps

greptile-apps Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes two related problems with Postgres session recordings: chunks could grow unboundedly large (causing upload failures), and a continuous session would emit one tiny chunk per event rather than batching. It adds a 512 KB plaintext cap for Postgres (where ciphertext is base64'd inline into the request body) and introduces a hasMore signal in readFromOffset so the flush loop drains only genuine backlog and stops at the live write edge.

  • chunk_uploader.go: introduces pamPostgresMaxPlaintextBytes = 512 * 1024; S3 sessions keep the existing 64 MB cap.
  • uploader.go: extends readFromOffset to return a hasMore flag (true only when the cap was hit with at least one record still pending), and updates flushSession to pick the right cap per backend and break the drain loop once caught up to the live edge.

Confidence Score: 4/5

Safe to merge; the chunk-size cap and batching logic are correct and the change is well-scoped to Postgres sessions.

The hasMore semantics are correct: newOffset is only advanced when a record is accepted into entries, so the rejected record is always re-read on the next iteration. The only gap is that the oversized-chunk warning in EncryptAndQueueChunk still fires at the S3 64 MB threshold for all backends — a monitoring blind spot but no correctness impact.

The warning threshold in EncryptAndQueueChunk (chunk_uploader.go line 223) is the only item worth a second look.

Important Files Changed

Filename Overview
packages/pam/session/chunk_uploader.go Adds pamPostgresMaxPlaintextBytes (512 KB) cap constant for Postgres chunks; oversized-chunk warning in EncryptAndQueueChunk still compares against the S3 64 MB limit.
packages/pam/session/uploader.go Adds hasMore return value to readFromOffset to distinguish backlog from live-edge; flushSession selects per-backend chunk cap and stops draining once at the live write edge. Logic is correct.

Comments Outside Diff (1)

  1. packages/pam/session/chunk_uploader.go, line 223-225 (link)

    P2 Oversized-chunk warning doesn't reflect the Postgres-specific cap

    The guard here compares against pamRecordingMaxPlaintextBytes (64 MB) for all backends. For Postgres sessions, flushSession now caps at pamPostgresMaxPlaintextBytes (512 KB), so if that cap were ever bypassed this warning would be silent until the payload reached 128× the intended limit. Since secrets.StorageBackend is already fetched a few lines below, the check could use pamPostgresMaxPlaintextBytes when secrets.StorageBackend == storageBackendPostgres, which would make on-call alerting actionable for the right threshold.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "fix(pam): cap recording chunk size and b..." | Re-trigger Greptile

Comment thread packages/pam/session/uploader.go
@veria-ai

veria-ai Bot commented Jun 9, 2026

Copy link
Copy Markdown

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

@bernie-g bernie-g merged commit 2f57156 into main Jun 11, 2026
30 of 33 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.

2 participants