{"record":{"id":"369e568b12814c93","repo":"paperclipai/paperclip","slug":"latest-campaign-is-absent-from-history","errorCode":null,"errorMessage":"Latest campaign is absent from history","messagePattern":"Latest campaign is absent from history","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scripts/evals-hub/build.py","lineNumber":29,"sourceCode":"\nORIGIN = \"https://d1p6rlowie26tp.cloudfront.net\"\nSYSTEMS = {\n    \"runner\": (\"runner-protocol-evals\", \"paperclip.runner-protocol-eval.history/v1\"),\n    \"product\": (\"runner-e2e\", \"paperclip.runner-e2e.history/v1\"),\n}\n\n\ndef latest(history, schema):\n    if history.get(\"schema\") != schema:\n        raise ValueError(\"Unsupported history schema\")\n    campaign_id = history.get(\"latestCampaignId\")\n    if not campaign_id:\n        raise ValueError(\"History has no latest campaign\")\n    candidates = [c for c in history[\"campaigns\"] if\n                  c[\"campaignId\"] == campaign_id or\n                  c.get(\"reportRevision\", {}).get(\"sourceCampaignId\") == campaign_id]\n    if not candidates:\n        raise ValueError(\"Latest campaign is absent from history\")\n    # Report refreshes replace presentation, never the measurement date.\n    return max(candidates, key=lambda c: c.get(\"reportRevision\", {}).get(\"renderedAt\", c[\"generatedAt\"]))\n\n\ndef public_report(url, prefix):\n    parsed = urlsplit(url)\n    if (parsed.scheme != \"https\" or parsed.netloc != urlsplit(ORIGIN).netloc\n            or not parsed.path.startswith(f\"/{prefix}/campaigns/\")\n            or parsed.query or parsed.fragment):\n        raise ValueError(\"Unexpected public report URL\")\n    return html.escape(url, quote=True)\n\n\ndef display_date(value):\n    date = datetime.fromisoformat(value.replace(\"Z\", \"+00:00\"))\n    if date.tzinfo is None:\n        raise ValueError(\"History date must include a timezone\")\n    return date.astimezone(timezone.utc).strftime(\"%d %b %Y · %H:%M UTC\")","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/paperclipai/paperclip/blob/3f1d897a7c018d76563a21c6e39c3c9b03933622/scripts/evals-hub/build.py#L11-L47","documentation":"latest() filters history['campaigns'] for entries matching latestCampaignId either directly (campaignId) or via a reportRevision whose sourceCampaignId points at it. If no entry matches, the pointer references a campaign the list does not contain — an inconsistent feed — and the script raises rather than falling back to an arbitrary run.","triggerScenarios":"latestCampaignId names a campaign that was pruned from the campaigns list (retention/truncation), a reportRevision references a sourceCampaignId that was dropped, or the id was typo'd in a hand-edited fixture.","commonSituations":"Retention job trimming old campaigns without updating latestCampaignId; partial history upload; fixtures edited by hand where campaignId strings don't match.","solutions":["Re-publish history.json so the campaigns list contains the campaign named by latestCampaignId (or its reportRevision sourceCampaignId).","Fix the publisher/retention logic to update or clear latestCampaignId whenever campaigns are pruned.","If a stale pointer is expected, regenerate the pointer to the newest retained campaignId.","Correct the campaignId in your fixture so it matches an entry in campaigns."],"exampleFix":"# before\n{\"latestCampaignId\": \"c-42\", \"campaigns\": [{\"campaignId\": \"c-41\", ...}]}\n# after\n{\"latestCampaignId\": \"c-41\", \"campaigns\": [{\"campaignId\": \"c-41\", ...}]}","handlingStrategy":"validation","validationCode":"def latest_is_present(history):\n    cid = history.get(\"latestCampaignId\")\n    return any(c.get(\"campaignId\") == cid or\n               c.get(\"reportRevision\", {}).get(\"sourceCampaignId\") == cid\n               for c in history.get(\"campaigns\", []))","typeGuard":"def pointer_resolves(history):\n    cid = history.get(\"latestCampaignId\")\n    return isinstance(cid, str) and any(\n        c.get(\"campaignId\") == cid or c.get(\"reportRevision\", {}).get(\"sourceCampaignId\") == cid\n        for c in history.get(\"campaigns\", []))","tryCatchPattern":"try:\n    values = summarize(history, kind)\nexcept ValueError as e:\n    if str(e) == \"Latest campaign is absent from history\":\n        history = refetch_history()  # pointer/list mismatch; re-download consistent feed\n        values = summarize(history, kind)\n    else:\n        raise","preventionTips":["Update or clear latestCampaignId whenever a retention job prunes campaigns.","Never hand-edit campaignId strings in fixtures; generate ids programmatically.","Re-fetch the feed when a pointer/list mismatch is detected instead of proceeding.","Add an integrity check post-publish: pointer must resolve within the campaigns list."],"tags":["validation","data-integrity","python","feed"],"backgroundTag":"record-not-found","analyzedSha":"3f1d897a7c018d76563a21c6e39c3c9b03933622","analyzedAt":"2026-09-18T08:03:59.046Z","contentChangedAt":"2026-09-18T08:03:59.046Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}