Skip to content
Closed
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
8 changes: 5 additions & 3 deletions packages/eve/src/harness/tool-loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,11 @@ export function createToolLoopHarness(config: ToolLoopHarnessConfig): StepFn {
outcome: authorized.kind === "authorization-required" ? "pending" : authorized.kind,
requestId: authorized.requestId,
responderPrincipalId:
getApprovalAuditState(session.state).activeCandidates.find(
(candidate) => candidate.candidateId === authorized.candidateId,
)?.responder.principalId ?? "unknown",
[
...getApprovalAuditState(session.state).activeCandidates,
...getApprovalAuditState(session.state).candidateHistory,
].find((candidate) => candidate.candidateId === authorized.candidateId)?.responder
.principalId ?? "unknown",
safeReason: "safeReason" in authorized ? authorized.safeReason : undefined,
sequence: emissionState.sequence,
stepIndex: emissionState.stepIndex,
Expand Down
27 changes: 27 additions & 0 deletions packages/eve/src/public/channels/slack/defaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,33 @@ describe("defaultEvents approval lifecycle", () => {
);
});

it("delivers an immediate rejection to the current responder without prior mapping", async () => {
const { channel, postEphemeral } = buildChannelStub();
const ctx = sessionContext({
attributes: { user_id: "U777" },
authenticator: "slack-webhook",
principalId: "slack:T1:U777",
principalType: "user",
});

await defaultEvents["approval.candidate"]!(
{
candidateId: "candidate-1",
outcome: "rejected",
requestId: "approval-1",
responderPrincipalId: "slack:T1:U777",
safeReason: "GitHub write access is required.",
sequence: 1,
stepIndex: 0,
turnId: "turn-1",
},
channel,
ctx,
);

expect(postEphemeral).toHaveBeenCalledWith("U777", "GitHub write access is required.");
});

it("updates the shared card only after settlement", async () => {
const { channel, request } = buildChannelStub({
pendingApprovalCards: {
Expand Down
7 changes: 6 additions & 1 deletion packages/eve/src/public/channels/slack/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,12 @@ export const defaultEvents: SlackChannelInternalEvents = {
);
return;
}
const userId = channel.state.pendingApprovalCandidateUsers?.[event.candidateId];
const mappedUserId = channel.state.pendingApprovalCandidateUsers?.[event.candidateId];
const userId =
mappedUserId ??
(ctx.session.auth.current?.principalId === event.responderPrincipalId
? currentUserId
: undefined);
if (userId === undefined) return;
if (event.outcome === "rejected" || event.outcome === "failed") {
await channel.thread.postEphemeral(
Expand Down