Repository navigation
fix: restore reactions and S3 uploads in production - #30
Conversation
Reactions always store both the comment id and the parent issue id, so the reaction_one_parent check and reaction_issue_unique index added recently made every reaction insert fail with a check violation in production. Restore the comment-scoped uniqueness and keep both parent columns indexed.
Bun.S3Client only reads static keys and the ambient AWS credential variables, so on EKS where the pod authenticates through a web identity token there were no keys to sign with and every upload failed with missing S3 credentials. Add a credential resolver that assumes the role through AssumeRoleWithWebIdentity, caches the result, and refreshes before expiry, and rebuild the client whenever the temporary credentials rotate. Static keys still take precedence for local MinIO.
📝 WalkthroughWalkthroughThe PR removes reaction parent and issue uniqueness constraints, updates the related invariant test, and adds static or web-identity AWS credential resolution. Resolved credentials are cached, refreshed, and used by dynamically created S3 clients. ChangesReaction invariants
Dynamic S3 credentials
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/services/src/storage/s3.ts (1)
124-139: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winCredential-resolution failures get mislabeled as storage-read failures in
stat.
await this.client()now sits inside the sametrythat only expects errors fromclient.stat(key). If credential resolution throws (e.g., STSAssumeRoleWithWebIdentityfailure fromcredentials.ts), it's caught here, fails theisNotFoundcheck, and gets rewrapped as'Could not read that file from storage.'— masking what is actually a credential/IAM problem and complicating incident triage.🐛 Proposed fix: resolve the client outside the not-found-scoped try
async stat(key: string): Promise<StoredObject | null> { assertSafeKey(key); + const client = await this.client(); try { - const client = await this.client(); const stats = await client.stat(key); return { key,🤖 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 `@packages/services/src/storage/s3.ts` around lines 124 - 139, Move the await this.client() call in stat outside the try block so credential-resolution failures propagate without being wrapped as storage-read errors. Keep client.stat(key), the isNotFound handling, and the existing internal error wrapping scoped to the storage stat operation.
🧹 Nitpick comments (1)
packages/services/src/storage/credentials.test.ts (1)
1-92: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for STS failure/malformed-response paths.
Current tests cover static creds, missing config, caching, and refresh-on-expiry, but not
assumeWebIdentityRole's error branches: non-2xx STS response, and missing/invalidExpiration(relevant to the fix suggested incredentials.ts).🤖 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 `@packages/services/src/storage/credentials.test.ts` around lines 1 - 92, Add tests in the createCredentialResolver suite covering assumeWebIdentityRole failures: assert that a non-2xx STS response rejects appropriately, and that responses with missing or invalid Expiration are rejected or handled according to the credentials implementation. Reuse the existing Bun.file and fetch mocks and stsResponse helper, keeping the assertions focused on each error branch.
🤖 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 `@packages/db/src/schema/index.test.ts`:
- Around line 85-86: Strengthen the test around schema.reaction and
reaction_comment_unique to verify the unique constraint covers commentId,
userId, and emoji and rejects duplicate combinations. Use index metadata when
available, or add an integration assertion that inserting the same reaction
tuple twice fails, while preserving acceptance of distinct tuples.
In `@packages/services/src/storage/credentials.ts`:
- Around line 77-81: Update the guard in the AWS web identity credential setup
to also treat an empty trimmed tokenFile as missing, matching the existing
roleArn validation. Ensure empty AWS_WEB_IDENTITY_TOKEN_FILE values return the
existing undefined-producing callback before reaching Bun.file.
- Around line 47-60: Update the credential validation in the response parsing
flow to require a present and parseable expiration alongside accessKeyId,
secretAccessKey, and sessionToken. Ensure invalid or missing Expiration causes
the existing internal error path, so the returned credentials always include a
valid expiresAt for stale() tracking.
---
Outside diff comments:
In `@packages/services/src/storage/s3.ts`:
- Around line 124-139: Move the await this.client() call in stat outside the try
block so credential-resolution failures propagate without being wrapped as
storage-read errors. Keep client.stat(key), the isNotFound handling, and the
existing internal error wrapping scoped to the storage stat operation.
---
Nitpick comments:
In `@packages/services/src/storage/credentials.test.ts`:
- Around line 1-92: Add tests in the createCredentialResolver suite covering
assumeWebIdentityRole failures: assert that a non-2xx STS response rejects
appropriately, and that responses with missing or invalid Expiration are
rejected or handled according to the credentials implementation. Reuse the
existing Bun.file and fetch mocks and stsResponse helper, keeping the assertions
focused on each error branch.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b95ab054-9f4f-40e9-9dbe-5660b343b7ea
📒 Files selected for processing (5)
packages/db/src/schema/content.tspackages/db/src/schema/index.test.tspackages/services/src/storage/credentials.test.tspackages/services/src/storage/credentials.tspackages/services/src/storage/s3.ts
💤 Files with no reviewable changes (1)
- packages/db/src/schema/content.ts
Fall back to still-valid cached credentials when a web identity refresh fails, default a missing expiration to a bounded lifetime instead of caching forever, treat an empty token-file path as unset, and assert the reaction uniqueness index is unique over the intended columns.
Fix the reaction check constraint that rejected valid reactions and resolve S3 credentials from the EKS web identity so uploads work again.
Greptile Summary
This PR fixes two independent production breakages: the
reaction_one_parentcheck constraint (and the issue-side unique index) that were rejecting valid reactions, and S3 uploads that were failing because EKS IRSA credentials weren't being picked up.credentials.tsis a new module that resolves AWS credentials either from static config or from the EKS web-identity token file (STSAssumeRoleWithWebIdentity), with a 20-minute proactive refresh margin and a fallback to still-valid cached credentials on transient STS errors.s3.tsis refactored to consume the credential resolver: instead of a single staticS3Client, it lazily creates and caches a client keyed onaccessKeyId:sessionToken, recreating it only when credentials rotate.content.tsremoves thereaction_one_parentcheck constraint and thereaction_issue_uniqueindex from thereactiontable schema.Confidence Score: 3/5
The credential-resolver and S3 refactor are solid, but the reaction schema changes leave meaningful data-integrity gaps that were flagged in previous review rounds and remain unaddressed.
The two storage files are well-structured, cover the key failure paths with tests, and correctly handle credential rotation, fallback, and client caching. The schema change in content.ts is where the risk lives: removing the check constraint was necessary to unblock production, but the simultaneous removal of the issue-reaction unique index means the database no longer prevents a user from adding the same emoji to the same issue multiple times. There is also no database-level guard preventing a reaction row from having both commentId and issueId set, or neither set — orphaned and double-parented rows can now be inserted without any constraint to catch insertion bugs in the API layer. Both gaps were raised in prior review comments and are not yet resolved.
packages/db/src/schema/content.ts — the reaction table schema lacks a unique constraint for issue reactions and no longer enforces that exactly one of commentId/issueId is non-null.
Important Files Changed
Reviews (2): Last reviewed commit: "fix(storage): survive transient STS fail..." | Re-trigger Greptile