feat(environments): expose boot-relevant drift attribution in the custom-image overview (#11751)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Paperclip lets operators prepare and use custom images for sandbox
environments
> - The custom-image overview detected drift but did not show which boot
source changed
> - Operators need the changed field and values to understand why a
template no longer matches
> - This pull request adds safe drift attribution to the overview API
and the out-of-sync banner
> - The benefit is faster diagnosis without exposing secrets or internal
snapshot data

## Linked Issues or Issue Description

**Subsystem affected**

Cross-cutting (server and UI).

**Problem or motivation**

The custom-image overview reported drift without identifying the changed
boot source. Operators had to inspect other data to find the cause.

**Proposed solution**

Return a classified drift summary with changed paths and their prior and
current values. Show the boot-source field in the UI banner. Keep legacy
templates and unclassified drift on the generic message.

**Alternatives considered**

The change does not expose the full snapshot or fingerprint. This keeps
the overview contract small and avoids secret disclosure.

**Roadmap alignment**

The change supports the existing custom-image environment workflow and
does not duplicate a roadmap item.

## What Changed

- Add `activeTemplateDrift` to the custom-image overview response.
- Classify drift as `boot_source_drift`, `knob_only`, or `unclassified`.
- Return drifted paths with safe `from` and `to` values.
- Show the changed boot-source field and values in the out-of-sync
banner.
- Keep legacy templates fail-closed and exclude secrets, fingerprints,
and raw snapshots.
- Add server and UI tests for the new behavior.

## Verification

- `npx vitest run
server/src/__tests__/environment-custom-images-service.test.ts` passes
with 27 tests.
- `npx vitest run ui/src/pages/CompanyEnvironments.test.tsx` passes with
27 tests.
- `pnpm --filter @paperclipai/ui exec tsc --noEmit` passes.
- Review the overview response and banner cases for boot-source,
knob-only, and legacy drift.

## Risks

The overview response gains one optional field. Legacy templates remain
compatible because they return `unclassified` and keep the generic
banner. The service excludes secret values, fingerprints, and raw
snapshots.

## Model Used

OpenAI Codex, GPT-5, tool use and code execution enabled. The model
reviewed the handoff and managed the pull request.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` /
`Closes: #` / `Refs: #` OR (b) described the issue in-PR following the
relevant issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [ ] I will address all Greptile and reviewer comments before
requesting merge

Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Nicky LeachandPaperclip authored and GitHub committed 2026-08-19 16:36:18 -07:00
1 parent 2eb9a09c0c
commit b8a76081ec
5 files changed
+258 -5

No files matched your search

+12
View File
@@ -20,10 +20,22 @@ export interface EnvironmentCustomImageOverview {
* back to the base image until a new image is captured. `null` when unknown.
*/
activeTemplateMatchesConfig?: boolean | null;
/**
* Boot-relevant drift attribution for the active template. It names the
* classification and the drifted paths with their `from`/`to` values, so the
* banner can name the changed field. `null` or absent when there is no active
* template or the driver is not `sandbox`.
*/
activeTemplateDrift?: EnvironmentCustomImageActiveTemplateDrift | null;
activeSession: EnvironmentCustomImageSetupSession | null;
latestSession: EnvironmentCustomImageSetupSession | null;
}
export interface EnvironmentCustomImageActiveTemplateDrift {
classification: EnvironmentCustomImageRelinkClassification;
driftedPaths: EnvironmentCustomImageDriftedPath[];
}
export type EnvironmentCustomImageReconciliation =
| { action: "relinked"; template: EnvironmentCustomImageTemplate }
| { action: "detached"; template: EnvironmentCustomImageTemplate };
+59
View File
@@ -1316,6 +1316,65 @@ describe("CompanyEnvironments — test provider button", () => {
});
});
it("names the changed boot-source field in the out-of-sync banner for a boot-source drift", async () => {
root = createRoot(container);
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
mockEnvironmentsApi.list.mockResolvedValue([
{ id: "env-1", name: "Daytona", driver: "sandbox", description: null, config: { provider: "daytona" } },
]);
mockEnvironmentsApi.capabilities.mockResolvedValue(supportedDaytonaCapabilities());
mockEnvironmentsApi.customImageTemplate.mockResolvedValue({
activeTemplate: createTemplate({ id: "template-active" }),
activeTemplateMatchesConfig: false,
activeTemplateDrift: {
classification: "boot_source_drift",
driftedPaths: [{ path: "snapshot", from: "a", to: "b" }],
},
activeSession: null,
latestSession: null,
});
await act(async () => {
root!.render(renderCompanyEnvironments(queryClient));
});
await flushReact();
await act(async () => click(editButtons(container)[0]));
await waitForAssertion(() => {
const dialog = getEnvironmentFormPage()!;
expect(dialog.textContent).toContain("Not in use — Base image changed: snapshot `a` -> `b`");
expect(dialog.textContent).not.toContain("the environment configuration changed");
});
});
it("keeps the generic out-of-sync banner for an unclassified drift", async () => {
root = createRoot(container);
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
mockEnvironmentsApi.list.mockResolvedValue([
{ id: "env-1", name: "Daytona", driver: "sandbox", description: null, config: { provider: "daytona" } },
]);
mockEnvironmentsApi.capabilities.mockResolvedValue(supportedDaytonaCapabilities());
mockEnvironmentsApi.customImageTemplate.mockResolvedValue({
activeTemplate: createTemplate({ id: "template-active" }),
activeTemplateMatchesConfig: false,
activeTemplateDrift: { classification: "unclassified", driftedPaths: [{ path: "apiUrl" }] },
activeSession: null,
latestSession: null,
});
await act(async () => {
root!.render(renderCompanyEnvironments(queryClient));
});
await flushReact();
await act(async () => click(editButtons(container)[0]));
await waitForAssertion(() => {
const dialog = getEnvironmentFormPage()!;
expect(dialog.textContent).toContain("Not in use — the environment configuration changed");
expect(dialog.textContent).not.toContain("Base image changed");
});
});
it("does not show the out-of-sync warning when the active template matches the saved config", async () => {
root = createRoot(container);
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
+32 -3
View File
@@ -20,6 +20,7 @@ import {
} from "@paperclipai/shared";
import {
environmentsApi,
type EnvironmentCustomImageActiveTemplateDrift,
type EnvironmentCustomImageConnectionPayload,
type EnvironmentCustomImageRelinkConflict,
type EnvironmentCustomImageSetupSessionResult,
@@ -290,6 +291,33 @@ function formatShortId(value: string): string {
return `${normalized.slice(0, 12)}…`;
}
function formatBootSourceDriftValue(value: unknown): string {
if (typeof value === "string") return value;
if (value === null || value === undefined) return "none";
return JSON.stringify(value);
}
/**
* Builds the drift summary for a `boot_source_drift` overview. It names each
* changed boot-source field with its `from` and `to` values (example: "snapshot
* `a` -> `b`"). It uses only value-bearing paths; an excluded path carries the
* name only, so the summary omits it. Returns `null` when no value-bearing path
* is present, so the banner keeps the generic text.
*/
function formatBootSourceDriftSummary(
drift: EnvironmentCustomImageActiveTemplateDrift | null | undefined,
): string | null {
if (!drift || drift.classification !== "boot_source_drift") return null;
const parts = drift.driftedPaths
.filter((entry) => "from" in entry || "to" in entry)
.map(
(entry) =>
`${entry.path} \`${formatBootSourceDriftValue(entry.from)}\` -> \`${formatBootSourceDriftValue(entry.to)}\``,
);
if (parts.length === 0) return null;
return `Base image changed: ${parts.join("; ")}`;
}
function readConnectionCommand(payload: EnvironmentCustomImageConnectionPayload | null | undefined): string | null {
return typeof payload?.command === "string" && payload.command.trim().length > 0
? payload.command
@@ -1129,6 +1157,7 @@ function EnvironmentImageTemplatePanel({
if (activeTemplate) {
const templateRef = activeTemplate.templateRef?.trim() || null;
const templateOutOfSync = overview?.activeTemplateMatchesConfig === false;
const bootSourceDriftSummary = formatBootSourceDriftSummary(overview?.activeTemplateDrift);
return (
<div className="mt-3 border-t border-border/60 pt-3" data-testid={`custom-image-template-state-${environment.id}`}>
<div className="flex flex-wrap items-start justify-between gap-3">
@@ -1153,9 +1182,9 @@ function EnvironmentImageTemplatePanel({
className="text-xs text-destructive"
data-testid={`custom-image-template-out-of-sync-${environment.id}`}
>
Not in use — the environment configuration changed since this image was
captured. Runs fall back to the base configuration until you relink this
image or capture a new one.
{bootSourceDriftSummary
? `Not in use — ${bootSourceDriftSummary}. Runs fall back to the base configuration until you relink this image or capture a new one.`
: "Not in use — the environment configuration changed since this image was captured. Runs fall back to the base configuration until you relink this image or capture a new one."}
</div>
) : null}
</div>