AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(platform): explain why a skill stopped after its source was removed (#15597)
Nicholas Tindleb971b758879e
diff --git a/autogpt_platform/backend/backend/api/features/skill_learning/routes_test.py b/autogpt_platform/backend/backend/api/features/skill_learning/routes_test.pyindex c034d1946f..376c8085a2 100644--- a/autogpt_platform/backend/backend/api/features/skill_learning/routes_test.py+++ b/autogpt_platform/backend/backend/api/features/skill_learning/routes_test.py@@ -618,6 +618,45 @@ def test_detail_of_a_deleted_skill_says_deleted(store, test_user_id):assert (deleted["id"], deleted["state"]) == (current.id, "archived")+def test_detail_of_a_deleted_skill_stays_deleted_under_a_later_proposal(+ store, test_user_id+):+ _, current = run(_publish(store, test_user_id))+ run(+ store.record_skill_deletion(+ test_user_id,+ expert_id=EXPERT,+ skill_name="csv-import-checks",+ expected_current_version_id=current.id,+ behaviors=[],+ actor_user_id=test_user_id,+ )+ )+ head = run(store.get_head(test_user_id, EXPERT, "csv-import-checks"))+ proposal = run(+ store.create_version(+ test_user_id,+ head=head,+ content=render_skill_markdown(+ ParsedSkill(+ name="csv-import-checks", description="Import CSV", body=BODY+ )+ ),+ description="Import CSV",+ triggers=[],+ origin="saved_overnight",+ state="needs_decision",+ )+ )+ resp = client.get(+ "/skill-learning/skills/csv-import-checks", params={"expert_id": EXPERT}+ )+ assert resp.status_code == 200+ body = resp.json()+ assert (body["state"], body["state_label"]) == ("deleted", "Deleted")+ assert body["open_decision"]["id"] == proposal.id++@pytest.mark.parametrize("payload", [{}, {"edited_body": ""}, {"edited_body": " "}])def test_apply_edited_requires_an_edited_body(store, test_user_id, payload):_, version = run(_publish(store, test_user_id))diff --git a/autogpt_platform/backend/backend/copilot/learning/publication_state.py b/autogpt_platform/backend/backend/copilot/learning/publication_state.pyindex 5a2321f750..ceed64c987 100644--- a/autogpt_platform/backend/backend/copilot/learning/publication_state.py+++ b/autogpt_platform/backend/backend/copilot/learning/publication_state.py@@ -1,8 +1,13 @@from backend.data.db_accessors import skill_versions_db-from backend.data.skill_versions import SkillHeadRecord+from backend.data.skill_versions import SkillHeadRecord, SkillVersionRecordfrom .publication_models import PublishOutcome+WITHDRAWN_REASON = (+ "a source of the current version is no longer available; edit the skill, "+ "or restore an earlier version if there is one, to resume"+)+async def require_settled_head(user_id: str, head: SkillHeadRecord | None@@ -10,9 +15,26 @@ async def require_settled_head(if head is None or head.current_version_id is None:return Nonecurrent = await skill_versions_db().get_version(user_id, head.current_version_id)+ if _withdrawn(current):+ return PublishOutcome(status="paused", reason=WITHDRAWN_REASON)if current is None or current.state != "ready":return PublishOutcome(status="write_failed",reason="the current skill publication must recover before another update",)return None+++async def current_version_withdrawn(user_id: str, head: SkillHeadRecord) -> bool:+ """Revocation found no earlier version to fall back to, so the current+ version stays invalidated. Learning waits for the owner rather than build+ on evidence that was withdrawn."""+ if head.current_version_id is None:+ return False+ return _withdrawn(+ await skill_versions_db().get_version(user_id, head.current_version_id)+ )+++def _withdrawn(current: SkillVersionRecord | None) -> bool:+ return current is not None and current.state == "invalidated"diff --git a/autogpt_platform/backend/backend/copilot/learning/publish_test.py b/autogpt_platform/backend/backend/copilot/learning/publish_test.pyindex 67e38cd6ed..9859f21fd6 100644--- a/autogpt_platform/backend/backend/copilot/learning/publish_test.py+++ b/autogpt_platform/backend/backend/copilot/learning/publish_test.py@@ -288,6 +288,61 @@ async def test_revocation_keeps_invalidated_head_retryable_if_restore_fails(assert restore.await_count == 2+async def test_learning_waits_for_the_owner_when_revocation_left_no_fallback(+ fake_store, workspace+):+ """With no earlier version to restore, revocation leaves the invalidated+ version current. Learning then waits for the owner and says why,+ instead of reporting a save that must recover."""+ source = await fake_store.upsert_source_revision(+ USER,+ expert_id=EXPERT,+ source_kind=KIND,+ source_id="withdrawn",+ revision="1",+ evidence_refs=[],+ outcome_signals=[],+ )+ head = await fake_store.ensure_head(USER, EXPERT, NAME)+ learned = await fake_store.commit_version_safe(+ USER,+ head=head,+ expected_current_version=head.current_version,+ draft=VersionDraft(+ content=_content(BODY_V1),+ description="Import a CSV",+ triggers=["csv"],+ origin="saved_overnight",+ sources=[{"source_id": source.id}],+ ),+ )+ await fake_store.complete_publication(+ USER, version_id=learned.version.id, review_id=None+ )+ excluded = await fake_store.set_source_eligibility(+ USER, source.id, "excluded", excluded_by_user_id=USER+ )+ await revocation.invalidate_versions_for_source(USER, excluded, "excluded")++ outcome = await publish.publish_learned_version(+ publish.PublishRequest(+ user_id=USER,+ expert_id=EXPERT,+ skill_name=NAME,+ description="Import a CSV",+ triggers=["csv"],+ body=BODY_V2,+ summary="Validate the row count",+ origin="saved_overnight",+ )+ )++ assert outcome.status == "paused"+ assert "restore an earlier version" in outcome.reason+ workspace.assert_not_awaited()++@pytest.mark.asyncioasync def test_completed_restore_is_acknowledged_if_suppression_recording_fails(fake_store, workspace, monkeypatch, caplogdiff --git a/autogpt_platform/backend/backend/copilot/learning/review_preconditions.py b/autogpt_platform/backend/backend/copilot/learning/review_preconditions.pyindex 690325a3c9..66aeeb46f2 100644--- a/autogpt_platform/backend/backend/copilot/learning/review_preconditions.py+++ b/autogpt_platform/backend/backend/copilot/learning/review_preconditions.py@@ -1,9 +1,10 @@-"""Reuse a known review target without billing while its owner pauses learning."""+"""Reuse a known review target without billing while it waits for its owner."""from backend.data.db_accessors import skill_versions_dbfrom backend.data.skill_reviews import LearningReviewRecordfrom .contract import LearningScope+from .publication_state import current_version_withdrawnasync def review_target_is_paused(@@ -19,4 +20,8 @@ async def review_target_is_paused(head = await skill_versions_db().get_head(scope.user_id, scope.owner_key, review.skill_name)- return head is not None and head.learning_paused_at is not None+ if head is None:+ return False+ return head.learning_paused_at is not None or await current_version_withdrawn(+ scope.user_id, head+ )diff --git a/autogpt_platform/backend/backend/copilot/learning/skill_pause_test.py b/autogpt_platform/backend/backend/copilot/learning/skill_pause_test.pyindex 572ed68de4..a495bb8547 100644--- a/autogpt_platform/backend/backend/copilot/learning/skill_pause_test.py+++ b/autogpt_platform/backend/backend/copilot/learning/skill_pause_test.py@@ -2,8 +2,12 @@ from unittest.mock import AsyncMockimport pytest-from . import nightly, nightly_test-from .nightly_test import EXPERT, USER, _completion, _proposal, _run, _source+from backend.copilot.tools.skills import ParsedSkill, render_skill_markdown+from backend.data.skill_publication import VersionDraft++from . import nightly, nightly_test, publish, revocation+from .nightly_test import EXPERT, GOOD_BODY, USER, _completion, _proposal, _run, _source+from .publication_state import WITHDRAWN_REASONadapter = nightly_test.adapterboundaries = nightly_test.boundaries@@ -106,3 +110,66 @@ async def test_pause_returning_during_a_paid_retry_keeps_its_cost_stamp(assert ledger.attempts == 2assert boundaries["review"].await_count == 2assert (await _run()).model_calls == 0+++async def test_a_withdrawn_skill_waits_for_its_owner_without_paying_again(+ fake_store, adapter, boundaries, monkeypatch+):+ """Revocation left the invalidated version current. Later passes reuse+ the ledger instead of paying for a review, even after its kept replay+ expires, until the owner edits the skill."""+ learned_from = await _source(fake_store, ref="withdrawn")+ assert (await _run()).applied == 1+ excluded = await fake_store.set_source_eligibility(+ USER, learned_from.id, "excluded", excluded_by_user_id=USER+ )+ await revocation.invalidate_versions_for_source(USER, excluded, "excluded")+ source = await _source(fake_store, ref="later")++ assert (await _run()).dispositions == {"paused": 1}+ ledger = await fake_store.get_review_for_revision(+ USER, source.id, source.revision, nightly.POLICY_VERSION+ )+ assert ledger.reason == WITHDRAWN_REASON+ await fake_store.set_review_replay(USER, ledger.id, ledger.run_id, None)+ for _ in range(3):+ result = await _run()+ assert result.dispositions == {"paused": 1}+ assert result.model_calls == 0+ assert (await fake_store.get_source(USER, source.id)).processed_revision is None+ assert boundaries["review"].await_count == 2++ head = await fake_store.get_head(USER, EXPERT, NAME)+ edited_skill = ParsedSkill(+ name=NAME,+ description="Import a CSV with an encoding check",+ body=GOOD_BODY.replace("2. Validate the row count\n", ""),+ triggers=("csv import",),+ )+ content = render_skill_markdown(edited_skill)+ edited = await fake_store.commit_version_safe(+ USER,+ head=head,+ expected_current_version=head.current_version,+ draft=VersionDraft(+ content=content,+ description=edited_skill.description,+ triggers=list(edited_skill.triggers),+ origin="edited",+ ),+ )+ await fake_store.complete_publication(+ USER, version_id=edited.version.id, review_id=None+ )+ monkeypatch.setattr(+ nightly, "_existing_skills", AsyncMock(return_value=[edited_skill])+ )+ monkeypatch.setattr(+ publish, "read_user_skill_markdown", AsyncMock(return_value=content)+ )+ boundaries["review"].return_value = _completion(_proposal(decision="update"))++ resumed = await _run()++ assert resumed.applied == 1 and resumed.model_calls == 1diff --git a/autogpt_platform/frontend/src/app/(platform)/team/[expertId]/__tests__/skill-learning.test.tsx b/autogpt_platform/frontend/src/app/(platform)/team/[expertId]/__tests__/skill-learning.test.tsxindex ea1baec4cd..7a3292daa7 100644--- a/autogpt_platform/frontend/src/app/(platform)/team/[expertId]/__tests__/skill-learning.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/team/[expertId]/__tests__/skill-learning.test.tsx@@ -462,6 +462,37 @@ describe("Expert skills — learning", () => {).toBe(true);});+ test("explains a skill Otto stopped using after a source was removed", async () => {+ const revoked = {+ ...v2,+ state: "invalidated",+ state_label: "Archived (source unavailable)",+ };+ server.use(+ getGetSkillLearningDetailMockHandler200({+ ...detail,+ state: "paused",+ state_label: "Paused (not in use)",+ current_version: revoked,+ versions: [revoked, v1],+ policy: { ...detail.policy, use_paused: true },+ }),+ );+ searchParams.set("tab", "skills");+ searchParams.set("skill", "csv-import-checks");+ render(<ExpertDetailPage />);++ const panel = await screen.findByRole("complementary", {+ name: "csv-import-checks",+ });+ const notice = await within(panel).findByTestId("source-removed-notice");+ expect(notice.textContent).toContain("Otto stopped using this skill");+ expect(notice.textContent).toContain("Resume using this skill");+ expect(+ within(panel).getByRole("button", { name: "Resume using this skill" }),+ ).toBeDefined();+ });+test("navigating to another version resets the selection to the requested record", async () => {server.use(getGetSkillLearningDetailMockHandler200({@@ -487,6 +518,7 @@ describe("Expert skills — learning", () => {expect((await within(panel).findByTestId("version-state")).textContent,).toBe("Archived (source unavailable)");+ expect(within(panel).queryByTestId("source-removed-notice")).toBeNull();expect(within(panel).getByRole("button", { name: "Restore v1" })diff --git a/autogpt_platform/frontend/src/components/organisms/SkillLearningSheet/components/SourceRemovedNotice.tsx b/autogpt_platform/frontend/src/components/organisms/SkillLearningSheet/components/SourceRemovedNotice.tsxnew file mode 100644index 0000000000..bb64cbc155--- /dev/null+++ b/autogpt_platform/frontend/src/components/organisms/SkillLearningSheet/components/SourceRemovedNotice.tsx@@ -0,0 +1,16 @@+import { Text } from "@/components/atoms/Text/Text";++interface Props {+ usePaused?: boolean;+}++export function SourceRemovedNotice({ usePaused }: Props) {+ return (+ <Text variant="small" tone="danger" data-testid="source-removed-notice">+ A source this version was learned from is no longer available, so Otto+ stopped using this skill. To use it again, edit the skill, or restore an+ earlier version from History if there is one+ {usePaused ? ", then choose Resume using this skill" : ""}.+ </Text>+ );+}diff --git a/autogpt_platform/frontend/src/components/organisms/SkillLearningSheet/components/SummaryView.tsx b/autogpt_platform/frontend/src/components/organisms/SkillLearningSheet/components/SummaryView.tsxindex d98ab8d9ab..4458f66445 100644--- a/autogpt_platform/frontend/src/components/organisms/SkillLearningSheet/components/SummaryView.tsx+++ b/autogpt_platform/frontend/src/components/organisms/SkillLearningSheet/components/SummaryView.tsx@@ -10,6 +10,7 @@ import { reuseLabel, versionLabel } from "@/services/skill-learning/helpers";import { formatDistanceToNow } from "date-fns";import { OutcomeReportRequestOutcome } from "@/app/api/__generated__/models/outcomeReportRequestOutcome";import { SkillPolicyRequest } from "@/app/api/__generated__/models/skillPolicyRequest";+import { SourceRemovedNotice } from "./SourceRemovedNotice";interface Props {detail: SkillLearningDetail;@@ -64,6 +65,9 @@ export function SummaryView({as a whole, not to this historical version.</Text>) : null}+ {isCurrent && version?.state === "invalidated" ? (+ <SourceRemovedNotice usePaused={detail.policy.use_paused} />+ ) : null}{version ? (<><Text variant="body" tone="primary">