Skip to content

feat: add ProjectID to Bedrock and Bedrock Mantle key configs for Mantle project scoping - #5131

Merged
Pratham-Mishra04 merged 1 commit into
devfrom
07-13-feat_project_id_support_for_bedrock_provider
Jul 13, 2026
Merged

feat: add ProjectID to Bedrock and Bedrock Mantle key configs for Mantle project scoping#5131
Pratham-Mishra04 merged 1 commit into
devfrom
07-13-feat_project_id_support_for_bedrock_provider

Conversation

@impoiler

@impoiler impoiler commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds ProjectID support to both BedrockKeyConfig and BedrockMantleKeyConfig, allowing inference requests and model listing to be scoped to a specific Bedrock project. Without a project ID, AWS continues to route to the account's default project.

Changes

  • Added ProjectID *SecretVar to BedrockKeyConfig and BedrockMantleKeyConfig schemas. On the OpenAI-compatible surface (chat/completions, responses, /models) it is sent as the OpenAI-Project header; on the native-Anthropic (Claude) surface it is sent as anthropic-workspace-id.
  • Introduced WithMantleProject in core/providers/bedrock/mantle.go — a pure function that clones the shared networkConfig.ExtraHeaders map and injects the project header only when a project ID is present, ensuring the base map is never mutated.
  • Added resolveMantleProjectID (bedrock provider) and resolveProjectID (bedrockmantle provider) helpers that read the project ID from the respective key config, returning "" when unset.
  • Applied WithMantleProject across all Mantle request paths in both the bedrock and bedrockmantle providers: mantleChatCompletions, mantleChatCompletionsStream, mantleResponses, mantleResponsesStream, listMantleModels, ChatCompletion, ChatCompletionStream, Responses, ResponsesStream, and listModelsByKey.
  • Added bedrock_project_id and bedrock_mantle_project_id columns to the config_keys table via a new migration (add_bedrock_project_id_columns), with full encrypt/decrypt lifecycle in BeforeSave/AfterFind hooks and reconstruction into the key config structs.
  • Project IDs are treated as non-credential identifiers in the redacted config view and are surfaced in plaintext rather than masked.

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

go test ./core/providers/bedrock/... ./core/providers/bedrockmantle/... ./framework/configstore/...

To validate end-to-end:

  1. Configure a BedrockKeyConfig or BedrockMantleKeyConfig with a project_id value pointing to a valid Bedrock project.
  2. Issue a chat completion or model listing request and confirm the OpenAI-Project (or anthropic-workspace-id for Claude) header is present in the outbound request and that responses are scoped to the specified project.
  3. Omit project_id and confirm requests continue to route to the account's default project without any header being injected.

New config fields:

Provider Config struct JSON field Header sent
bedrock BedrockKeyConfig project_id OpenAI-Project (Mantle paths only)
bedrock_mantle BedrockMantleKeyConfig project_id OpenAI-Project or anthropic-workspace-id

Breaking changes

  • Yes
  • No

Security considerations

  • ProjectID values are encrypted at rest in the database alongside other key config fields, consistent with how credentials are stored.
  • They are intentionally exposed in plaintext in the redacted config view because they are routing identifiers, not secrets.
  • WithMantleProject always clones the base headers map before writing, preventing accidental mutation of the shared networkConfig.ExtraHeaders reference across concurrent requests.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7c76bca5-8f9e-4f6f-9591-3b7765b80318

📥 Commits

Reviewing files that changed from the base of the PR and between e4118c0 and 168168e.

📒 Files selected for processing (13)
  • core/providers/bedrock/bedrock.go
  • core/providers/bedrock/mantle.go
  • core/providers/bedrock/mantle_project_test.go
  • core/providers/bedrock/utils.go
  • core/providers/bedrockmantle/bedrockmantle.go
  • core/providers/bedrockmantle/project_test.go
  • core/providers/bedrockmantle/utils.go
  • core/schemas/account.go
  • framework/configstore/clientconfig.go
  • framework/configstore/migrations.go
  • framework/configstore/tables/encryption_test.go
  • framework/configstore/tables/key.go
  • transports/config.schema.json

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added optional Bedrock project selection for model listings and inference requests.
    • Supports project scoping across OpenAI-compatible and native Anthropic request paths.
    • Added configuration support for securely storing and managing Bedrock project IDs.
    • Requests without a configured project continue using the account’s default project.
  • Bug Fixes

    • Ensured project settings are consistently applied across streaming and non-streaming requests.
  • Tests

    • Added coverage for project selection, persistence, encryption, and default behavior.

Walkthrough

Adds optional Bedrock and Bedrock Mantle project IDs, persists them through encrypted configstore fields, and injects project-specific headers into Mantle model listing, Chat Completions, Responses, OpenAI-compatible, and native Anthropic request paths.

Changes

Bedrock project configuration and persistence

Layer / File(s) Summary
Persist Bedrock project configuration
core/schemas/account.go, framework/configstore/..., transports/config.schema.json
Adds optional project ID fields, database migration columns, redaction support, encrypted save/load handling, runtime reconstruction, schema definitions, and persistence tests.

Bedrock header helpers and model listing

Layer / File(s) Summary
Add Mantle header helpers
core/providers/bedrock/mantle.go, core/providers/bedrock/utils.go, core/providers/bedrockmantle/utils.go, core/providers/bedrock/..._test.go
Adds project header constants, non-mutating header augmentation, and project ID resolution for Bedrock and Bedrock Mantle configurations.

Wire project headers into Mantle requests

Layer / File(s) Summary
Wire project headers into Mantle requests
core/providers/bedrock/bedrock.go, core/providers/bedrock/mantle.go, core/providers/bedrockmantle/bedrockmantle.go
Applies OpenAI-compatible and native Anthropic project headers across model listing, Chat Completions, and Responses, including streaming and SigV4 paths.

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

Possibly related PRs

Suggested reviewers: akshaydeo, danpiths, roroghost17, pratham-mishra04

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding ProjectID support for Bedrock and Bedrock Mantle project scoping.
Description check ✅ Passed The description covers the required template sections with summary, changes, testing, breaking changes, security, and checklist.
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.
✨ 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 07-13-feat_project_id_support_for_bedrock_provider

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.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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

@impoiler
impoiler force-pushed the 07-13-feat_project_id_support_for_bedrock_provider branch from dbbae1e to 2592af4 Compare July 13, 2026 07:32
@Pratham-Mishra04

Copy link
Copy Markdown
Collaborator

@impoiler will need to add this support in BedrockAliasCfg{} as well

@impoiler
impoiler force-pushed the 07-13-feat_project_id_support_for_bedrock_provider branch from 2592af4 to e4118c0 Compare July 13, 2026 09:19
@impoiler impoiler self-assigned this Jul 13, 2026
@impoiler impoiler changed the title feat: project id support for bedrock provider feat: add ProjectID to Bedrock and Bedrock Mantle key configs for Mantle project scoping Jul 13, 2026
Comment thread core/providers/bedrock/mantle.go

@Pratham-Mishra04 Pratham-Mishra04 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small refactor comment

@impoiler
impoiler marked this pull request as ready for review July 13, 2026 11:16
@greptile-apps

greptile-apps Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 2/5

These issues need to be fixed before merging.

  • The Bedrock provider package can fail to compile because the same resolver name is declared twice.
  • Saved Bedrock project scopes can be cleared during unrelated key updates.
  • The schema path now accepts the new field, but the update path still needs matching preservation.

core/providers/bedrock/mantle.go, core/providers/bedrock/utils.go, framework/configstore/tables/key.go

Important Files Changed

Filename Overview
core/providers/bedrock/mantle.go Adds Mantle project header helpers and request-path plumbing, but the new resolver collides with another resolver in the same package.
core/providers/bedrock/utils.go Adds a context-aware project resolver that needs to be reconciled with the resolver in mantle.go.
framework/configstore/tables/key.go Adds storage and encryption lifecycle for Bedrock project IDs, but update merge handling can still clear the new fields.
transports/config.schema.json Adds project_id to both Bedrock key schema definitions so config validation accepts the new field.

Reviews (4): Last reviewed commit: "feat: project id support for bedrock pro..." | Re-trigger Greptile

Comment thread core/schemas/account.go
Comment thread core/providers/bedrock/mantle.go
@impoiler
impoiler force-pushed the 07-13-feat_project_id_support_for_bedrock_provider branch from e4118c0 to 774393b Compare July 13, 2026 11:20
Comment thread core/schemas/account.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
core/providers/bedrockmantle/project_test.go (1)

11-32: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover header injection, not only project resolution.

This test verifies resolveProjectID, but not that OpenAI-Project and anthropic-workspace-id are added or omitted correctly across model listing, Chat Completions, Responses, and native Anthropic requests. Add request-level tests so wiring regressions cannot pass while this helper test remains green.

Based on learnings from the PR objective, project IDs must affect multiple Mantle request surfaces and header variants.

🤖 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 `@core/providers/bedrockmantle/project_test.go` around lines 11 - 32, Expand
TestResolveProjectID coverage with request-level tests for the Bedrock Mantle
provider, verifying project-derived OpenAI-Project and anthropic-workspace-id
headers are correctly added or omitted across model listing, Chat Completions,
Responses, and native Anthropic requests. Exercise both configured and absent
project IDs, and assert the outgoing requests rather than only the
resolveProjectID helper.
framework/configstore/migrations.go (1)

1168-1204: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Add a migration-level upgrade test.

The current framework/configstore/tables/encryption_test.go setup calls AutoMigrate(&TableKey{}), which creates the new columns directly and therefore does not verify that this migration upgrades an existing database or that its registration is correct.

Based on learnings from the existing test setup, the current round-trip tests do not exercise migrationAddBedrockProjectIDColumns.

🤖 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 `@framework/configstore/migrations.go` around lines 1168 - 1204, The
migrationAddBedrockProjectIDColumns change lacks an upgrade test that validates
registration and alteration of an existing schema. Add a migration-level test
that creates the pre-migration TableKey schema without the Bedrock project
columns, runs the registered migration through the normal migrator path, and
asserts both columns are added; avoid AutoMigrate on the current TableKey
definition before migration.
🤖 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 `@core/schemas/account.go`:
- Around line 701-705: Add project_id?: SecretVar to both BedrockKeyConfig and
BedrockMantleKeyConfig in the frontend types, and add matching optional
SecretVar validation fields to their schemas in providerForm.ts and the relevant
definitions in ui/lib/types/schemas.ts so the provider key form can round-trip
ProjectID.
- Around line 674-678: Update BedrockAliasCfg and its related config handling to
define and propagate the ProjectID SecretVar, including redaction and Bedrock
Mantle request header selection. Ensure Bedrock alias validation accepts this
Bedrock-specific override and uses the alias ProjectID when setting the
OpenAI-Project header, while preserving account-level fallback when it is unset.

In `@framework/configstore/migrations.go`:
- Around line 1190-1197: Update the migration containing the Rollback function
to explicitly mark it as destructive/non-rollbackable, using the migration
framework’s established non-rollbackable flag or metadata. Preserve the existing
column-dropping behavior unless the framework requires exporting values first,
and ensure the migration is clearly documented as non-reversible.

---

Nitpick comments:
In `@core/providers/bedrockmantle/project_test.go`:
- Around line 11-32: Expand TestResolveProjectID coverage with request-level
tests for the Bedrock Mantle provider, verifying project-derived OpenAI-Project
and anthropic-workspace-id headers are correctly added or omitted across model
listing, Chat Completions, Responses, and native Anthropic requests. Exercise
both configured and absent project IDs, and assert the outgoing requests rather
than only the resolveProjectID helper.

In `@framework/configstore/migrations.go`:
- Around line 1168-1204: The migrationAddBedrockProjectIDColumns change lacks an
upgrade test that validates registration and alteration of an existing schema.
Add a migration-level test that creates the pre-migration TableKey schema
without the Bedrock project columns, runs the registered migration through the
normal migrator path, and asserts both columns are added; avoid AutoMigrate on
the current TableKey definition before migration.
🪄 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 Plus

Run ID: 7ff498da-afce-407f-a762-7077caca0dd0

📥 Commits

Reviewing files that changed from the base of the PR and between 344d2ea and e4118c0.

📒 Files selected for processing (11)
  • core/providers/bedrock/bedrock.go
  • core/providers/bedrock/mantle.go
  • core/providers/bedrock/mantle_project_test.go
  • core/providers/bedrockmantle/bedrockmantle.go
  • core/providers/bedrockmantle/project_test.go
  • core/providers/bedrockmantle/utils.go
  • core/schemas/account.go
  • framework/configstore/clientconfig.go
  • framework/configstore/migrations.go
  • framework/configstore/tables/encryption_test.go
  • framework/configstore/tables/key.go

Comment thread core/schemas/account.go
Comment thread core/schemas/account.go
Comment thread framework/configstore/migrations.go
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 13, 2026
@impoiler
impoiler force-pushed the 07-13-feat_project_id_support_for_bedrock_provider branch from 774393b to 41b7be7 Compare July 13, 2026 11:44
Comment thread core/providers/bedrock/utils.go

Pratham-Mishra04 commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Merge activity

  • Jul 13, 2:14 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jul 13, 2:15 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jul 13, 2:16 PM UTC: @Pratham-Mishra04 merged this pull request with Graphite.

@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 07-13-feat_project_id_support_for_bedrock_provider branch from 41b7be7 to 168168e Compare July 13, 2026 14:14
@Pratham-Mishra04
Pratham-Mishra04 merged commit eebd9c3 into dev Jul 13, 2026
14 of 15 checks passed
@Pratham-Mishra04
Pratham-Mishra04 deleted the 07-13-feat_project_id_support_for_bedrock_provider branch July 13, 2026 14:16
Comment on lines +44 to +49
func resolveMantleProjectID(key schemas.Key) string {
if key.BedrockKeyConfig != nil && key.BedrockKeyConfig.ProjectID != nil {
return key.BedrockKeyConfig.ProjectID.GetValue()
}
return ""
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0 Duplicate resolver declaration This declares resolveMantleProjectID in package bedrock, but core/providers/bedrock/utils.go also declares a package-level resolveMantleProjectID with a different signature. Go does not support function overloading, so any build or test target that includes this package fails before the new project-scoping code can run. Keep one resolver and update the call sites to that signature.

Comment on lines 269 to +277
} else {
k.BedrockRoleSessionName = nil
}
if k.BedrockKeyConfig.ProjectID != nil {
pid := *k.BedrockKeyConfig.ProjectID
k.BedrockProjectID = &pid
} else {
k.BedrockProjectID = nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Project ID can clear This saves BedrockKeyConfig.ProjectID, but the provider-key update merge path still preserves the older Bedrock fields without including project_id. When a Bedrock key already has a project scope and a later API update submits a redacted or partial key config, the merge can leave ProjectID nil; this branch then clears bedrock_project_id, so future requests silently fall back to the default project. Add project_id to the Bedrock key preserve logic as part of this new persisted field.

Comment on lines 342 to +350
} else {
k.BedrockMantleRoleSessionName = nil
}
if k.BedrockMantleKeyConfig.ProjectID != nil {
pid := *k.BedrockMantleKeyConfig.ProjectID
k.BedrockMantleProjectID = &pid
} else {
k.BedrockMantleProjectID = nil
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Mantle project can clear The new Bedrock Mantle project field has the same update-path gap. Existing update merge handling preserves the Bedrock Mantle credential fields, but not project_id, so an unrelated key edit can save a nil BedrockMantleKeyConfig.ProjectID here and clear bedrock_mantle_project_id. That makes the key lose its project scope and route later inference to the default project.

akshaydeo pushed a commit that referenced this pull request Jul 14, 2026
…antle project scoping (#5131)

## Summary

Adds `ProjectID` support to both `BedrockKeyConfig` and `BedrockMantleKeyConfig`, allowing inference requests and model listing to be scoped to a specific Bedrock project. Without a project ID, AWS continues to route to the account's default project.

## Changes

- Added `ProjectID *SecretVar` to `BedrockKeyConfig` and `BedrockMantleKeyConfig` schemas. On the OpenAI-compatible surface (`chat/completions`, `responses`, `/models`) it is sent as the `OpenAI-Project` header; on the native-Anthropic (Claude) surface it is sent as `anthropic-workspace-id`.
- Introduced `WithMantleProject` in `core/providers/bedrock/mantle.go` — a pure function that clones the shared `networkConfig.ExtraHeaders` map and injects the project header only when a project ID is present, ensuring the base map is never mutated.
- Added `resolveMantleProjectID` (bedrock provider) and `resolveProjectID` (bedrockmantle provider) helpers that read the project ID from the respective key config, returning `""` when unset.
- Applied `WithMantleProject` across all Mantle request paths in both the `bedrock` and `bedrockmantle` providers: `mantleChatCompletions`, `mantleChatCompletionsStream`, `mantleResponses`, `mantleResponsesStream`, `listMantleModels`, `ChatCompletion`, `ChatCompletionStream`, `Responses`, `ResponsesStream`, and `listModelsByKey`.
- Added `bedrock_project_id` and `bedrock_mantle_project_id` columns to the `config_keys` table via a new migration (`add_bedrock_project_id_columns`), with full encrypt/decrypt lifecycle in `BeforeSave`/`AfterFind` hooks and reconstruction into the key config structs.
- Project IDs are treated as non-credential identifiers in the redacted config view and are surfaced in plaintext rather than masked.

## Type of change

- [ ] Bug fix
- [x] Feature
- [ ] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [x] Core (Go)
- [ ] Transports (HTTP)
- [x] Providers/Integrations
- [ ] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

```sh
go test ./core/providers/bedrock/... ./core/providers/bedrockmantle/... ./framework/configstore/...
```

To validate end-to-end:
1. Configure a `BedrockKeyConfig` or `BedrockMantleKeyConfig` with a `project_id` value pointing to a valid Bedrock project.
2. Issue a chat completion or model listing request and confirm the `OpenAI-Project` (or `anthropic-workspace-id` for Claude) header is present in the outbound request and that responses are scoped to the specified project.
3. Omit `project_id` and confirm requests continue to route to the account's default project without any header being injected.

**New config fields:**

| Provider | Config struct | JSON field | Header sent |
|---|---|---|---|
| `bedrock` | `BedrockKeyConfig` | `project_id` | `OpenAI-Project` (Mantle paths only) |
| `bedrock_mantle` | `BedrockMantleKeyConfig` | `project_id` | `OpenAI-Project` or `anthropic-workspace-id` |

## Breaking changes

- [ ] Yes
- [x] No

## Security considerations

- `ProjectID` values are encrypted at rest in the database alongside other key config fields, consistent with how credentials are stored.
- They are intentionally exposed in plaintext in the redacted config view because they are routing identifiers, not secrets.
- `WithMantleProject` always clones the base headers map before writing, preventing accidental mutation of the shared `networkConfig.ExtraHeaders` reference across concurrent requests.

## Checklist

- [x] I read `docs/contributing/README.md` and followed the guidelines
- [x] I added/updated tests where appropriate
- [ ] I updated documentation where needed
- [x] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable
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