Skip to content

fix: restore reactions and S3 uploads in production - #30

Merged
pulkitxm merged 3 commits into
mainfrom
fix/reactions-and-uploads
Jul 23, 2026
Merged

pulkitxm merged 3 commits into
mainfrom
fix/reactions-and-uploads

Conversation

@pulkitxm

@pulkitxm pulkitxm commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

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_parent check 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.ts is a new module that resolves AWS credentials either from static config or from the EKS web-identity token file (STS AssumeRoleWithWebIdentity), with a 20-minute proactive refresh margin and a fallback to still-valid cached credentials on transient STS errors.
  • s3.ts is refactored to consume the credential resolver: instead of a single static S3Client, it lazily creates and caches a client keyed on accessKeyId:sessionToken, recreating it only when credentials rotate.
  • content.ts removes the reaction_one_parent check constraint and the reaction_issue_unique index from the reaction table 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

Filename Overview
packages/db/src/schema/content.ts Removes the reaction_one_parent check constraint and the reaction_issue_unique index; only the comment-side unique index remains, leaving issue reactions without a deduplication guard at the database level.
packages/services/src/storage/credentials.ts New credential-resolver module: correctly handles static keys, EKS web-identity STS exchange, proactive 20-minute refresh, concurrent-request deduplication via the inflight promise, and fallback to still-valid cached credentials on STS errors.
packages/services/src/storage/credentials.test.ts New test suite covering static keys, missing config, successful web-identity caching (dedup verified), stale refresh, and the STS-failure fallback path — good coverage of the happy and failure paths.
packages/services/src/storage/s3.ts Cleanly refactored to lazy-initialize and cache the S3Client keyed on credential identity, delegating credential lifecycle to the new resolver; assertConfiguredCredentialsAreUsed is correctly skipped for session-token-bearing (web-identity) credentials.
packages/db/src/schema/index.test.ts Test updated to reflect the removed check constraint and to validate the remaining reaction_comment_unique index; no test covers issue-reaction uniqueness, which is now absent from both schema and tests.

Reviews (2): Last reviewed commit: "fix(storage): survive transient STS fail..." | Re-trigger Greptile

pulkitxm added 2 commits July 24, 2026 02:50
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.
@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Reaction invariants

Layer / File(s) Summary
Reaction schema and invariant test
packages/db/src/schema/content.ts, packages/db/src/schema/index.test.ts
The reaction parent check and issue uniqueness constraint are removed, while the invariant test checks the reaction_comment_unique index.

Dynamic S3 credentials

Layer / File(s) Summary
Credential resolution and refresh
packages/services/src/storage/credentials.ts, packages/services/src/storage/credentials.test.ts
Adds static and web-identity credential resolution, STS XML parsing, caching, expiration-based refresh, concurrent refresh deduplication, and coverage for configuration and failure paths.
Credential-aware S3 client operations
packages/services/src/storage/s3.ts
S3 clients are resolved and cached by credential values, and storage operations use the asynchronously resolved client.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • Noveum/orbit#22: Both changes modify S3StorageDriver behavior.
  • Noveum/orbit#23: Both changes modify S3 credential and client handling.
  • Noveum/orbit#25: Both changes modify the reaction schema constraints and invariant expectations.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly matches the main changes: restoring reactions and S3 uploads in production.
Description check ✅ Passed The description is directly related to the schema and S3 credential changes in the pull request.
✨ 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/reactions-and-uploads

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

Comment thread packages/db/src/schema/content.ts Resolved
Comment thread packages/db/src/schema/content.ts Resolved

@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: 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 win

Credential-resolution failures get mislabeled as storage-read failures in stat.

await this.client() now sits inside the same try that only expects errors from client.stat(key). If credential resolution throws (e.g., STS AssumeRoleWithWebIdentity failure from credentials.ts), it's caught here, fails the isNotFound check, 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 win

Add 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/invalid Expiration (relevant to the fix suggested in credentials.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

📥 Commits

Reviewing files that changed from the base of the PR and between da427a4 and be7e972.

📒 Files selected for processing (5)
  • packages/db/src/schema/content.ts
  • packages/db/src/schema/index.test.ts
  • packages/services/src/storage/credentials.test.ts
  • packages/services/src/storage/credentials.ts
  • packages/services/src/storage/s3.ts
💤 Files with no reviewable changes (1)
  • packages/db/src/schema/content.ts

Comment thread packages/db/src/schema/index.test.ts Resolved
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.
@pulkitxm
pulkitxm merged commit 7ae17cb into main Jul 23, 2026
6 checks passed
@pulkitxm
pulkitxm deleted the fix/reactions-and-uploads branch July 23, 2026 21:37
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