Skip to content

[fix] Resolve data corruption related to retrieval#4476

Merged
junaway merged 17 commits into
release/v0.100.7from
fix/resolve-data-corruption-related-to-retrieval
May 29, 2026
Merged

[fix] Resolve data corruption related to retrieval#4476
junaway merged 17 commits into
release/v0.100.7from
fix/resolve-data-corruption-related-to-retrieval

Conversation

@junaway
Copy link
Copy Markdown
Contributor

@junaway junaway commented May 28, 2026

No description provided.

Copilot AI review requested due to automatic review settings May 28, 2026 12:03
@vercel
Copy link
Copy Markdown

vercel Bot commented May 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Ready Ready Preview, Comment May 29, 2026 12:14pm

Request Review

@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. Backend Bug Report Something isn't working labels May 28, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e9fbb6b6-968a-4beb-8935-c0be40f2a1d4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR repairs corrupted workflow variant slugs and backfills stale slug references embedded in environment data. Migrations perform the rewrites, backend services re-enable reference-consistency validation, and frontend changes standardize slug-based resolution for deployment/code-snippet paths.

Changes

Slug Corruption Repair and Reference Normalization

Layer / File(s) Summary
Database migration metadata (Alembic definitions)
api/ee/databases/postgres/migrations/core/versions/d5e6f7a8b9c0_*.py, api/oss/databases/postgres/migrations/core/versions/d5e6f7a8b9c0_*.py, api/oss/databases/postgres/migrations/core/versions/e6f7a8b9c0d2_*.py
Alembic migration wrapper files define revision metadata and entry points for retrieval slug corruption repair and environment reference slug backfill across EE and OSS codebases.
Data migration SQL and repair logic
api/oss/databases/postgres/migrations/core/data_migrations/retrieval_slug_corruption.py, api/oss/databases/postgres/migrations/core/data_migrations/environment_reference_slugs.py
SQL/Python migrations normalize corrupted workflow_variants.slug values and rewrite stale embedded variant/artifact/revision slugs inside environment_revisions.data.references by resolving authoritative lineage and applying JSONB updates.
Environment service slug normalization
api/oss/src/core/environments/service.py
Adds _normalize_references_from_lineage and integrates normalization into fetch, commit, and delta commit paths; fetch path re-enables consistency validation against resolved revision lineage.
Backend service validation re-enablement
api/oss/src/core/{applications,evaluators,queries,testsets,workflows}/service.py, api/oss/src/apis/fastapi/legacy_variants/router.py
Restore imports and active calls to validate_retrieve_refs_consistent so retrieval flows validate requested refs against resolved refs from fetched revisions or environment-derived references.
Frontend slug resolution standardization
web/oss/src/code_snippets/endpoints/fetch_variant/python.ts, web/oss/src/components/DeploymentsDashboard/*, web/oss/src/components/Playground/..., web/oss/src/pages/.../endpoints/index.tsx, web/packages/agenta-entities/src/runnable/deploy.ts, web/packages/agenta-entities/src/environment/core/types.ts
Prefer slug fields over name, adjust variantSlug fallbacks to use workflow_variant_slug/variant_slug, pass apiKey into Python snippet generation, and derive variant slugs from local atoms when publishing deployments.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.03% which is insufficient. The required threshold is 60.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No description was provided by the author; this is a lenient check, but the absence makes it inconclusive whether the author intended to document specifics. Consider adding a brief description explaining what data corruption was addressed and why the migrations/validation changes resolve it.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main intent of the changeset—fixing data corruption related to retrieval through migrations and validation re-enablement.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/resolve-data-corruption-related-to-retrieval

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@junaway junaway changed the title Fix/resolve data corruption related to retrieval [fix] Resolve data corruption related to retrieval May 28, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes data corruption affecting retrieval by ensuring that the variant/application slugs embedded in environment references are always the canonical row slugs (never names or revision slugs), repairing the historical corruption in the DB, and re-enabling the previously-hot-fixed validate_retrieve_refs_consistent check across all retrieve paths.

Changes:

  • Web: stop falling back to name when building deploy payloads / API snippets / app keys, and re-derive variantSlug from the revision lineage (resolveVariantSlug) so wrong client-side slugs can't be persisted.
  • Backend: re-enable validate_retrieve_refs_consistent in workflows/testsets/queries/evaluators/applications/environments, and normalize embedded ref slugs at commit time via _normalize_references_from_lineage.
  • Migrations: two new Alembic data migrations (OSS + EE) — one to repair illegally-charactered workflow_variants.slug plus the matching embedded references, and one to backfill embedded artifact/variant/revision slugs in environment_revisions.data from the revision lineage.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
web/packages/agenta-entities/src/runnable/deploy.ts Adds resolveVariantSlug re-derivation from revision/variants atoms before publishing.
web/oss/src/pages/.../endpoints/index.tsx Drops name fallback; uses appSlug consistently.
web/oss/src/components/Playground/.../DeployVariantModal/store/deployVariantModalStore.ts Resolves variant/application slug strictly from slug (no name fallback).
web/oss/src/components/Playground/.../CommitVariantChangesModal/index.tsx Sources variantSlug from workflow_variant_slug/variant_slug fields.
web/oss/src/components/pages/overview/deployments/DeploymentModal.tsx Same variantSlug sourcing fix on publish.
web/oss/src/components/pages/overview/deployments/DeploymentDrawer/index.tsx Removes name fallbacks in code-snippet and appSlug props.
web/oss/src/components/DeploymentsDashboard/modals/SelectDeployVariantModalContent.tsx Sends variantSlug (not name) and drops application name fallback.
web/oss/src/components/DeploymentsDashboard/index.tsx Uses correct slug fields for variantSlug.
web/oss/src/components/DeploymentsDashboard/assets/VariantUseApiContent.tsx Removes name fallbacks; threads apiKey into snippets.
web/oss/src/components/DeploymentsDashboard/assets/UseApiContent.tsx Removes name fallback for currentApp.slug in snippet generation.
web/oss/src/code_snippets/endpoints/fetch_variant/python.ts Adds API key/URL env wiring to the generated Python snippet.
api/oss/src/core/{workflows,testsets,queries,evaluators,applications,environments}/service.py Re-enables validate_retrieve_refs_consistent.
api/oss/src/core/environments/service.py Adds _normalize_references_from_lineage and invokes it during commit.
api/oss/src/apis/fastapi/legacy_variants/router.py Uses revision.variant_slug when variant is missing.
api/oss/databases/.../d5e6f7a8b9c0_repair_retrieval_slug_corruption.py + data_migrations/retrieval_slug_corruption.py Repairs corrupted variant slugs and matching embedded references slugs.
api/oss/databases/.../e6f7a8b9c0d2_backfill_environment_reference_slugs.py + data_migrations/environment_reference_slugs.py Backfills embedded artifact/variant/revision slugs from revision lineage.
api/ee/databases/.../d5e6f7a8b9c0_.py, e6f7a8b9c0d2_.py EE Alembic shims that reuse the OSS data migration functions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread api/oss/src/core/environments/service.py
Comment thread web/oss/src/code_snippets/endpoints/fetch_variant/python.ts Outdated
@junaway
Copy link
Copy Markdown
Contributor Author

junaway commented May 28, 2026

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 24 out of 24 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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 (1)
api/oss/src/core/environments/service.py (1)

205-225: ⚡ Quick win

Cache repeated revision lookups during lineage normalization.

If multiple reference groups point to the same revision ID, this currently repeats identical fetches. A tiny in-method cache removes duplicate calls and reduces commit latency on larger payloads.

♻️ Proposed patch
         workflows_service = self.embeds_service.workflows_service

         normalized: Dict[str, Dict[str, Reference]] = {}
+        revision_cache: Dict[UUID, Optional[Any]] = {}

         for key, group in references.items():
@@
-            revision = await workflows_service.fetch_workflow_revision(
-                project_id=project_id,
-                workflow_revision_ref=Reference(id=revision_ref.id),
-            )
+            if revision_ref.id not in revision_cache:
+                revision_cache[revision_ref.id] = (
+                    await workflows_service.fetch_workflow_revision(
+                        project_id=project_id,
+                        workflow_revision_ref=Reference(id=revision_ref.id),
+                    )
+                )
+            revision = revision_cache[revision_ref.id]

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 174a8ebe-393f-4ed4-a364-31e691dc6dda

📥 Commits

Reviewing files that changed from the base of the PR and between 2117842 and 303e3a2.

📒 Files selected for processing (24)
  • api/ee/databases/postgres/migrations/core/versions/d5e6f7a8b9c0_repair_retrieval_slug_corruption.py
  • api/ee/databases/postgres/migrations/core/versions/e6f7a8b9c0d2_backfill_environment_reference_slugs.py
  • api/oss/databases/postgres/migrations/core/data_migrations/environment_reference_slugs.py
  • api/oss/databases/postgres/migrations/core/data_migrations/retrieval_slug_corruption.py
  • api/oss/databases/postgres/migrations/core/versions/d5e6f7a8b9c0_repair_retrieval_slug_corruption.py
  • api/oss/databases/postgres/migrations/core/versions/e6f7a8b9c0d2_backfill_environment_reference_slugs.py
  • api/oss/src/apis/fastapi/legacy_variants/router.py
  • api/oss/src/core/applications/service.py
  • api/oss/src/core/environments/service.py
  • api/oss/src/core/evaluators/service.py
  • api/oss/src/core/queries/service.py
  • api/oss/src/core/testsets/service.py
  • api/oss/src/core/workflows/service.py
  • web/oss/src/code_snippets/endpoints/fetch_variant/python.ts
  • web/oss/src/components/DeploymentsDashboard/assets/UseApiContent.tsx
  • web/oss/src/components/DeploymentsDashboard/assets/VariantUseApiContent.tsx
  • web/oss/src/components/DeploymentsDashboard/index.tsx
  • web/oss/src/components/DeploymentsDashboard/modals/SelectDeployVariantModalContent.tsx
  • web/oss/src/components/Playground/Components/Modals/CommitVariantChangesModal/index.tsx
  • web/oss/src/components/Playground/Components/Modals/DeployVariantModal/store/deployVariantModalStore.ts
  • web/oss/src/components/pages/overview/deployments/DeploymentDrawer/index.tsx
  • web/oss/src/components/pages/overview/deployments/DeploymentModal.tsx
  • web/oss/src/pages/w/[workspace_id]/p/[project_id]/apps/[app_id]/endpoints/index.tsx
  • web/packages/agenta-entities/src/runnable/deploy.ts

Comment thread web/oss/src/code_snippets/endpoints/fetch_variant/python.ts Outdated
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Actionable comments posted: 0

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 28, 2026

Railway Preview Environment

Status Destroyed (PR closed)

Updated at 2026-05-29T12:16:53.285Z

@junaway junaway requested a review from Copilot May 28, 2026 12:33
@junaway
Copy link
Copy Markdown
Contributor Author

junaway commented May 28, 2026

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 26 out of 26 changed files in this pull request and generated 1 comment.

Comment thread web/packages/agenta-entities/src/runnable/deploy.ts Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
web/packages/agenta-entities/src/environment/core/types.ts (1)

126-126: ⚡ Quick win

Use an interface for the application_variant reference shape.

This contract change is good, but this inline object type should be extracted to an interface to stay consistent and reusable across deploy/reference types.

♻️ Proposed refactor
+export interface ApplicationVariantReference {
+    id?: string
+    slug?: string
+}
+
 export interface DeployToEnvironmentParams {
@@
     references: {
         application: {id: string; slug?: string}
-        application_variant: {id?: string; slug?: string}
+        application_variant: ApplicationVariantReference
         application_revision: {id: string; slug?: string; version?: string}
     }

As per coding guidelines, "Prefer interface for defining object shapes in TypeScript".


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 99347fdd-9fe7-4ca4-b496-2281f6230aad

📥 Commits

Reviewing files that changed from the base of the PR and between 46a35a0 and 2389196.

📒 Files selected for processing (6)
  • api/oss/databases/postgres/migrations/core/data_migrations/environment_reference_slugs.py
  • api/oss/src/core/environments/service.py
  • web/oss/src/code_snippets/endpoints/fetch_config/python.ts
  • web/oss/src/code_snippets/endpoints/fetch_variant/python.ts
  • web/packages/agenta-entities/src/environment/core/types.ts
  • web/packages/agenta-entities/src/runnable/deploy.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • api/oss/src/core/environments/service.py
  • web/oss/src/code_snippets/endpoints/fetch_variant/python.ts
  • api/oss/databases/postgres/migrations/core/data_migrations/environment_reference_slugs.py

Comment thread web/packages/agenta-entities/src/runnable/deploy.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 31 out of 31 changed files in this pull request and generated no new comments.

@junaway junaway changed the base branch from release/v0.100.5 to release/v0.100.6 May 29, 2026 06:47
@junaway junaway changed the base branch from release/v0.100.6 to release/v0.100.7 May 29, 2026 10:56
Copilot AI review requested due to automatic review settings May 29, 2026 11:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings May 29, 2026 12:13
…thub.com:Agenta-AI/agenta into fix/resolve-data-corruption-related-to-retrieval
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated no new comments.

@junaway junaway merged commit 354bf52 into release/v0.100.7 May 29, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backend Bug Report Something isn't working size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants