Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions backend/app/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -2499,7 +2499,7 @@ def proposal_lifecycles(
}
]
seen_agent_improvements: set[str] = set()
for record in records:
for record_index, record in enumerate(records):
if not isinstance(record, dict):
continue
iteration = record.get("iteration")
Expand Down Expand Up @@ -2557,12 +2557,15 @@ def proposal_lifecycles(
if record.get("stage") != "agent_proposal_assessment":
issue_proposals = (
[
(f"{run.id}:{record.get('iteration', 0)}:{index}", proposal)
(f"{run.id}:{record.get('iteration', 0)}:{record_index}:{index}", proposal)
for index, proposal in enumerate(improvements)
]
if improvements
else [
(f"{run.id}:{record.get('iteration', 0)}:issue:{index}", proposal)
(
f"{run.id}:{record.get('iteration', 0)}:{record_index}:issue:{index}",
proposal,
)
for index, proposal in enumerate(reported_issues)
]
)
Expand Down Expand Up @@ -2733,9 +2736,35 @@ def _save_issue_management_records(self, values: dict[str, dict[str, Any]]) -> N

def issue_management_items(self) -> list[dict[str, Any]]:
records = self._issue_management_records()
proposals = self.proposal_lifecycles()

# Before supervisor-record position became part of the ID, records from
# separate assessments in one iteration could collide. Preserve a
# legacy management record only where it maps to exactly one proposal.
# A collided legacy record has no safe owner, so each new row starts
# independently instead of sharing comments, status, or deletion state.
legacy_ids: dict[str, str] = {}
legacy_counts: dict[str, int] = {}
for proposal in proposals:
proposal_id = str(proposal["proposal_id"])
prefix = f"{proposal.get('run_id')}:{proposal.get('iteration')}:"
suffix = proposal_id.removeprefix(prefix).split(":")
if len(suffix) == 2 and all(part.isdigit() for part in suffix):
legacy_id = f"{prefix}{suffix[1]}"
elif len(suffix) == 3 and suffix[0].isdigit() and suffix[1] == "issue" and suffix[2].isdigit():
legacy_id = f"{prefix}issue:{suffix[2]}"
else:
continue
legacy_ids[proposal_id] = legacy_id
legacy_counts[legacy_id] = legacy_counts.get(legacy_id, 0) + 1
values = []
for proposal in self.proposal_lifecycles():
record = records.get(proposal["proposal_id"], {})
for proposal in proposals:
proposal_id = str(proposal["proposal_id"])
record = records.get(proposal_id)
legacy_id = legacy_ids.get(proposal_id)
if record is None and legacy_id and legacy_counts[legacy_id] == 1:
record = records.get(legacy_id)
record = record or {}
# Issues are derived from immutable run evidence. A deletion is a
# management-level tombstone, not deletion of the underlying run.
if record.get("status") == "deleted":
Expand Down
58 changes: 58 additions & 0 deletions backend/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2612,6 +2612,64 @@ def test_issue_management_excludes_agent_assessment_feedback_from_issue_rational
assert managed_issue["comments"][0]["assigner"] == "AI supervisor"


def test_issue_management_separates_multiple_supervisor_records_in_one_iteration(tmp_path, monkeypatch):
monkeypatch.setattr(store_module, "RUNS", tmp_path / "runs")
monkeypatch.setattr(store_module, "ISSUE_MANAGEMENT", tmp_path / "issue-management.yaml")
store = store_module.ConsoleStore()
timestamp = store_module.now()
store._save(
Run(
id="run-duplicate-assessments",
workflow_id="workflow",
workflow_name="Workflow",
status="succeeded",
created_at=timestamp,
updated_at=timestamp,
supervisor_results=[
{
"iteration": 1,
"stage": "issue_assessment",
"response": {"improvements": [{"title": "First issue"}], "reported_issues": []},
},
{
"iteration": 1,
"stage": "issue_assessment",
"response": {"improvements": [{"title": "Second issue"}], "reported_issues": []},
},
{
"iteration": 2,
"stage": "issue_assessment",
"response": {
"improvements": [],
"reported_issues": [{"title": "First reported issue"}],
},
},
{
"iteration": 2,
"stage": "issue_assessment",
"response": {
"improvements": [],
"reported_issues": [{"title": "Second reported issue"}],
},
},
],
)
)

items = store.issue_management_items()
assert {item["proposal_id"] for item in items} == {
"run-duplicate-assessments:1:0:0",
"run-duplicate-assessments:1:1:0",
"run-duplicate-assessments:2:2:issue:0",
"run-duplicate-assessments:2:3:issue:0",
}
first = next(item for item in items if item["title"] == "First issue")
store.update_issue_management_item(first["proposal_id"], comment="Only the first issue")
by_title = {item["title"]: item for item in store.issue_management_items()}
assert by_title["First issue"]["comments"][0]["body"] == "Only the first issue"
assert by_title["Second issue"]["comments"] == []


def test_hello_accepts_unsaved_profile_settings():
response = TestClient(app).post(
"/api/settings/hello",
Expand Down
18 changes: 17 additions & 1 deletion frontend/src/components/ui/evidence-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

export type EvidenceArtifact = { id?: string; name?: string; screenshot?: string; html?: string };

export function visualEvidenceArtifacts(files: SavedDataFile[]): EvidenceArtifact[] {

Check warning on line 13 in frontend/src/components/ui/evidence-viewer.tsx

View workflow job for this annotation

GitHub Actions / frontend

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components
return files.reduce<EvidenceArtifact[]>((artifacts, file, index) => {
const path = file.relative_path ?? file.path;
if (!path) return artifacts;
if (artifacts.some((artifact) => artifact.id === path)) return artifacts;
const name = file.label || file.filename || `#${index + 1}`;
const contentType = file.content_type?.toLowerCase();
const extension = path.toLowerCase().split(".").at(-1);
Expand Down Expand Up @@ -53,11 +54,26 @@
return <CodeMirror aria-label="HTML evidence source" value={result.source ?? ""} editable={false} height="min(60vh, 640px)" theme={oneDark} extensions={[html(), EditorView.lineWrapping]} basicSetup={{ lineNumbers: true, highlightActiveLine: true, bracketMatching: true, foldGutter: true }} />;
}

export function VisualEvidenceModal({ open, onClose, title, runId, iteration, artifacts }: { open: boolean; onClose: () => void; title: string; runId: string; iteration: number; artifacts: EvidenceArtifact[] }) {
const imageArtifacts = artifacts.filter((artifact) => artifact.screenshot);
const htmlArtifacts = artifacts.filter((artifact) => artifact.html);
const tabs = [
...imageArtifacts.map((artifact, index) => ({ id: `image-${index}`, label: artifact.screenshot!.split("/").at(-1) ?? `#${index + 1}`, artifact })),
...(htmlArtifacts.length ? [{ id: "html", label: "HTML" }] : []),
];
const [activeTab, setActiveTab] = useState(tabs[0]?.id ?? "");
const selectedImage = imageArtifacts[Number(activeTab.replace("image-", ""))];
return <Modal open={open} title={title} onClose={onClose} className="modal--evidence">
{tabs.length > 1 && <div className="run-tabs" role="tablist">{tabs.map((tab) => <button key={tab.id} type="button" role="tab" aria-selected={activeTab === tab.id} className={activeTab === tab.id ? "active" : ""} onClick={() => setActiveTab(tab.id)}>{tab.label}</button>)}</div>}
{activeTab === "html" ? htmlArtifacts.map((artifact, index) => <figure className="persona-evidence" key={`${artifact.id ?? index}-html`}><figcaption>{artifact.html!.split("/").at(-1) ?? artifact.name ?? `#${index + 1}`}</figcaption><HtmlEvidenceViewer url={artifactUrl(runId, iteration, artifact.html!)} /></figure>) : selectedImage?.screenshot && <figure className="persona-evidence"><figcaption>{selectedImage.screenshot.split("/").at(-1) ?? selectedImage.name}</figcaption><img src={artifactUrl(runId, iteration, selectedImage.screenshot)} alt={selectedImage.name ?? selectedImage.id ?? ""} /></figure>}
</Modal>;
}

export function EvidenceViewer({ runId, iteration, artifacts, className, imageLabel, htmlLabel, imageTitle, htmlTitle }: { runId: string; iteration: number; artifacts: EvidenceArtifact[]; className?: string; imageLabel: string; htmlLabel: string; imageTitle: string; htmlTitle: string }) {
const [evidenceModal, setEvidenceModal] = useState<{ kind: "image" | "html"; artifacts: EvidenceArtifact[] } | null>(null);
const imageArtifacts = artifacts.filter((artifact) => artifact.screenshot);
const htmlArtifacts = artifacts.filter((artifact) => artifact.html);
const modalArtifacts = evidenceModal?.artifacts.filter((artifact) => evidenceModal.kind === "image" ? Boolean(artifact.screenshot) : Boolean(artifact.html)) ?? [];
if (!imageArtifacts.length && !htmlArtifacts.length) return null;
return <><span className={className}>{imageArtifacts.length > 0 && <button className="ghost icon-button" type="button" aria-label={imageLabel} title={imageLabel} onClick={() => setEvidenceModal({ kind: "image", artifacts: imageArtifacts })}><Image size={16} /></button>}{htmlArtifacts.length > 0 && <button className="ghost icon-button" type="button" aria-label={htmlLabel} title={htmlLabel} onClick={() => setEvidenceModal({ kind: "html", artifacts: htmlArtifacts })}><CodeXml size={16} /></button>}</span>{evidenceModal && createPortal(<Modal open title={evidenceModal.kind === "image" ? imageTitle : htmlTitle} onClose={() => setEvidenceModal(null)} className="modal--evidence">{modalArtifacts.map((artifact, index) => <figure className="persona-evidence" key={`${artifact.id ?? index}-${evidenceModal.kind}`}><figcaption>{artifact.name ?? artifact.id ?? `#${index + 1}`}</figcaption>{evidenceModal.kind === "image" ? <img src={artifactUrl(runId, iteration, artifact.screenshot!)} alt={artifact.name ?? artifact.id ?? ""} /> : <HtmlEvidenceViewer url={artifactUrl(runId, iteration, artifact.html!)} />}</figure>)}</Modal>, document.body)}</>;
return <><span className={className}>{imageArtifacts.length > 0 && <button className="ghost icon-button" type="button" aria-label={imageLabel} title={imageLabel} onClick={() => setEvidenceModal({ kind: "image", artifacts: imageArtifacts })}><Image size={16} /></button>}{htmlArtifacts.length > 0 && <button className="ghost icon-button" type="button" aria-label={htmlLabel} title={htmlLabel} onClick={() => setEvidenceModal({ kind: "html", artifacts: htmlArtifacts })}><CodeXml size={16} /></button>}</span>{evidenceModal && createPortal(<VisualEvidenceModal open onClose={() => setEvidenceModal(null)} title={evidenceModal.kind === "image" ? imageTitle : htmlTitle} runId={runId} iteration={iteration} artifacts={modalArtifacts} />, document.body)}</>;
}
28 changes: 20 additions & 8 deletions frontend/src/features/improvements/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { DataTable, type Column } from "../../components/ui/data-table";
import { CircleStop, RotateCcw } from "lucide-react";
import { EvaluationsPage } from "../evaluations/page";
import { IssueManagementSection } from "../issues/page";
import { VisualEvidenceModal, visualEvidenceArtifacts } from "../../components/ui/evidence-viewer";

type ImprovementCopy = {
improvement: string;
Expand Down Expand Up @@ -223,17 +224,18 @@ type PersonaJourneyEvent = {
};

function PersonaJourneyTimeline({
buildId, runs, locale, t, hours, onSelect,
buildId, runs, locale, t, hours,
}: {
buildId: string;
runs: Run[];
locale: Locale;
t: (typeof copy)["en"];
hours: number;
onSelect: (run: Run) => void;
}) {
const [rangeStart] = useState(() => hours ? Date.now() - hours * 60 * 60 * 1000 : 0);
const drag = useRef<{ pointerId: number; startX: number; startScroll: number; moved: boolean } | null>(null);
const [isDragging, setIsDragging] = useState(false);
const [selectedEvent, setSelectedEvent] = useState<PersonaJourneyEvent | null>(null);
const lanes = useMemo(() => {
const groups = new Map<string, PersonaJourneyEvent[]>();
for (const run of runs) {
Expand Down Expand Up @@ -297,32 +299,41 @@ function PersonaJourneyTimeline({
}, [buildId, rangeStart, runs]);
const startDrag = (event: ReactPointerEvent<HTMLDivElement>) => {
if (event.button !== 0) return;
event.currentTarget.setPointerCapture(event.pointerId);
drag.current = { pointerId: event.pointerId, startX: event.clientX, startScroll: event.currentTarget.scrollLeft, moved: false };
};
const moveDrag = (event: ReactPointerEvent<HTMLDivElement>) => {
const active = drag.current;
if (!active || active.pointerId !== event.pointerId) return;
const distance = event.clientX - active.startX;
if (Math.abs(distance) > 4) active.moved = true;
if (!active.moved && Math.abs(distance) <= 6) return;
if (!active.moved) {
active.moved = true;
event.currentTarget.setPointerCapture(event.pointerId);
setIsDragging(true);
}
event.currentTarget.scrollLeft = active.startScroll - distance;
};
const endDrag = (event: ReactPointerEvent<HTMLDivElement>) => {
if (drag.current?.pointerId === event.pointerId) event.currentTarget.releasePointerCapture(event.pointerId);
if (drag.current?.pointerId !== event.pointerId) return;
if (event.currentTarget.hasPointerCapture(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId);
if (!drag.current.moved) drag.current = null;
setIsDragging(false);
};
const selectedArtifacts = selectedEvent ? visualEvidenceArtifacts((selectedEvent.run.step_results ?? []).filter((step) => step.loop_index === selectedEvent.iteration).flatMap((step) => step.data_files ?? [])) : [];
return <section className="panel persona-journeys">
<h3><SectionInfo title={t.personaJourneys} description={t.personaJourneysHint} /></h3>
<p className="hint">{t.personaJourneysHint}</p>
{lanes.length ? <div className="persona-journeys__lanes">
{lanes.map((lane) => <section className="persona-journeys__lane" key={lane.persona}>
<header><strong>{lane.persona}</strong><small>{lane.events.length}</small></header>
<div className="persona-journeys__events" onPointerDown={startDrag} onPointerMove={moveDrag} onPointerUp={endDrag} onPointerCancel={endDrag} onClickCapture={(event) => {
<div className={`persona-journeys__events${isDragging ? " is-dragging" : ""}`} onPointerDown={startDrag} onPointerMove={moveDrag} onPointerUp={endDrag} onPointerCancel={endDrag} onClickCapture={(event) => {
if (!drag.current?.moved) return;
event.preventDefault();
event.stopPropagation();
drag.current = null;
setIsDragging(false);
}}>
{lane.events.map((event) => <button className="persona-journeys__event" key={event.id} onClick={() => onSelect(event.run)}>
{lane.events.map((event) => <button className="persona-journeys__event" key={event.id} onClick={() => setSelectedEvent(event)}>
<time>{compactTimestamp(locale, event.recordedAt)}</time>
<small>{t.run} {event.run.id} · {t.iteration} #{event.iteration}</small>
<dl>
Expand All @@ -335,6 +346,7 @@ function PersonaJourneyTimeline({
</div>
</section>)}
</div> : <p className="catalog-empty">{t.noPersonaJourneys}</p>}
{selectedEvent && <VisualEvidenceModal open onClose={() => setSelectedEvent(null)} title={`${selectedEvent.persona} · ${t.iteration} #${selectedEvent.iteration}`} runId={selectedEvent.run.id} iteration={selectedEvent.iteration} artifacts={selectedArtifacts} />}
</section>;
}
function Card({
Expand Down Expand Up @@ -771,7 +783,7 @@ function ImprovementBuildContent({
onRetryRequest={setRetryingRun}
onSelect={setSelectedRun}
/>
<PersonaJourneyTimeline key={`${buildId}:${hours}`} buildId={buildId} runs={runs} locale={locale} t={t} hours={hours} onSelect={setSelectedRun} />
<PersonaJourneyTimeline key={`${buildId}:${hours}`} buildId={buildId} runs={runs} locale={locale} t={t} hours={hours} />
<IssueManagementSection key={buildId} buildId={buildId} locale={locale} onNotice={onNotice} />
<StoredState buildId={buildId} locale={locale} t={t} />
{selectedRun && <EvaluationsPage
Expand Down
1 change: 1 addition & 0 deletions frontend/src/features/issues/discussion.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
.issue-message time,.issue-message small { color:var(--muted); font:10px 'DM Mono',monospace; }
.proposal-detail .issue-message p { margin:0; font-size:11px; line-height:1.55; white-space:pre-wrap; }
.issue-discussion__composer { display:grid; gap:8px; padding:12px; border:1px solid var(--line); border-radius:9px; background:var(--bg); }
.issue-discussion__composer input,.issue-discussion__composer textarea,.issue-discussion__composer select { font:11px/1.5 Manrope,sans-serif; }
.issue-discussion__composer textarea { min-height:96px; resize:vertical; }
.issue-discussion__composer .modal-actions { justify-content:flex-end; }
12 changes: 3 additions & 9 deletions frontend/src/features/issues/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Copy = {
resolved: string;
deferred: string;
comment: string;
assigner: string;
commentAuthor: string;
assignerPlaceholder: string;
commentPlaceholder: string;
verificationRun: string;
Expand Down Expand Up @@ -334,12 +334,6 @@ export function IssueManagementSection({
render: (x) => (x.personas ?? []).join(", ") || "—",
sortValue: (x) => (x.personas ?? []).join(", "),
},
{
id: "assigner",
header: t.assigner,
render: (x) => x.assigner || "—",
sortValue: (x) => x.assigner,
},
{
id: "decision",
header: t.aiDecision,
Expand Down Expand Up @@ -470,7 +464,7 @@ export function IssueManagementSection({
setRun("");
}}
className="issue-management-table"
gridTemplateColumns="36px 42px minmax(410px,1fr) 112px 76px 96px 110px 110px 110px"
gridTemplateColumns="36px 42px minmax(410px,1fr) 112px 76px 96px 110px 110px"
/>
</div>
<Pagination
Expand Down Expand Up @@ -600,7 +594,7 @@ export function IssueManagementSection({
</strong>
<small>
{e.type === "status" ? label(e.status ?? "") : e.body}
{e.assigner ? ` · ${t.assigner} ${e.assigner}` : ""}
{e.assigner ? ` · ${t.commentAuthor} ${e.assigner}` : ""}
{e.verification_run_id
? ` · ${t.run} ${e.verification_run_id}`
: ""}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@
"resolved": "Resolved",
"deferred": "Deferred",
"comment": "Comment",
"assigner": "Comment author",
"commentAuthor": "Comment author",
"assignerPlaceholder": "Comment author name",
"commentPlaceholder": "Record what you checked or changed.",
"verificationRun": "Verification run",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/languages/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@
"resolved": "解決済み",
"deferred": "保留",
"comment": "コメント",
"assigner": "コメント作成者",
"commentAuthor": "コメント作成者",
"assignerPlaceholder": "コメント作成者の名前",
"commentPlaceholder": "確認内容または修正内容を記録してください。",
"verificationRun": "検証実行",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/locales/languages/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@
"resolved": "해결됨",
"deferred": "보류됨",
"comment": "코멘트",
"assigner": "작성자",
"commentAuthor": "작성자",
"assignerPlaceholder": "코멘트 작성자 이름",
"commentPlaceholder": "확인 내용 또는 수정 사항을 남기세요.",
"verificationRun": "검증 실행",
Expand Down
Loading
Loading