Include issue identifier in all activity log details for notifications

Activity log events for issue.created and issue.updated were missing
the identifier field in their details, causing toast notifications to
fall back to showing a truncated UUID hash instead of the shortname
(e.g. PAP-47). Also includes checkout lock adoption and activity
query improvements.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Forgotten
2026-02-21 08:23:44 -06:00
parent 57f88f6f6a
commit fe63c10d69
4 changed files with 177 additions and 19 deletions

View File

@@ -89,7 +89,7 @@ export function issueRoutes(db: Db, storage: StorageService) {
async function assertAgentRunCheckoutOwnership(
req: Request,
res: Response,
issue: { id: string; status: string; assigneeAgentId: string | null },
issue: { id: string; companyId: string; status: string; assigneeAgentId: string | null },
) {
if (req.actor.type !== "agent") return true;
const actorAgentId = req.actor.agentId;
@@ -102,7 +102,25 @@ export function issueRoutes(db: Db, storage: StorageService) {
}
const runId = requireAgentRunId(req, res);
if (!runId) return false;
await svc.assertCheckoutOwner(issue.id, actorAgentId, runId);
const ownership = await svc.assertCheckoutOwner(issue.id, actorAgentId, runId);
if (ownership.adoptedFromRunId) {
const actor = getActorInfo(req);
await logActivity(db, {
companyId: issue.companyId,
actorType: actor.actorType,
actorId: actor.actorId,
agentId: actor.agentId,
runId: actor.runId,
action: "issue.checkout_lock_adopted",
entityType: "issue",
entityId: issue.id,
details: {
previousCheckoutRunId: ownership.adoptedFromRunId,
checkoutRunId: runId,
reason: "stale_checkout_run",
},
});
}
return true;
}
@@ -239,7 +257,7 @@ export function issueRoutes(db: Db, storage: StorageService) {
action: "issue.created",
entityType: "issue",
entityId: issue.id,
details: { title: issue.title },
details: { title: issue.title, identifier: issue.identifier },
});
if (issue.assigneeAgentId) {
@@ -297,7 +315,7 @@ export function issueRoutes(db: Db, storage: StorageService) {
action: "issue.updated",
entityType: "issue",
entityId: issue.id,
details: { ...updateFields, _previous: Object.keys(previous).length > 0 ? previous : undefined },
details: { ...updateFields, identifier: issue.identifier, _previous: Object.keys(previous).length > 0 ? previous : undefined },
});
let comment = null;
@@ -477,6 +495,7 @@ export function issueRoutes(db: Db, storage: StorageService) {
return;
}
assertCompanyAccess(req, existing.companyId);
if (!(await assertAgentRunCheckoutOwnership(req, res, existing))) return;
const actorRunId = requireAgentRunId(req, res);
if (req.actor.type === "agent" && !actorRunId) return;
@@ -558,6 +577,7 @@ export function issueRoutes(db: Db, storage: StorageService) {
reopened: true,
reopenedFrom: reopenFromStatus,
source: "comment",
identifier: currentIssue.identifier,
},
});
}