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
5 changes: 5 additions & 0 deletions .changeset/assistant-action-authority.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sapiom/harness": patch
---

Discard Assistant inspection and Resume responses after an authorized binding changes in the same workspace.
4 changes: 4 additions & 0 deletions packages/harness/docs/assistant-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,7 @@ Resume and Continue. Attach includes verified public continuation provenance and
rechecks its lease after receipt reads. Pending children stay out of history and
cannot attach, including after restart; only prepared children publish a session
event. Runtime activation remains an explicit capability from its existing owner.

Inspection and Resume responses recheck the complete opaque history scope after
asynchronous work. A changed project, account, harness or native binding invalidates
the result even when the workspace path and lifecycle revision are unchanged.
25 changes: 25 additions & 0 deletions packages/harness/src/server/assistant-lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const savedEntry = {
history: "partial",
nativeResume: "unchecked",
recordRevision: 7,
continuationScope: "a".repeat(64),
};
const session = {
id: "studio-a",
Expand Down Expand Up @@ -235,6 +236,30 @@ it("discards Resume when a newer lifecycle or authorization wins before the resp
expect(response.status).toBe(403);
expect(await response.text()).not.toContain("private");
});
it.each([
["inspect", "b".repeat(64)],
["inspect", undefined],
["resume", "b".repeat(64)],
["resume", undefined],
] as const)(
"discards %s results when the authorized binding changes in the same workspace (%s)",
async (action, continuationScope) => {
entry.mockResolvedValueOnce(savedEntry).mockResolvedValueOnce({
...savedEntry,
continuationScope,
lifecycle: action === "resume" ? attachment.lifecycle : lifecycle,
});
const response = await post(action, {
expectedRevision: 4,
...(action === "resume" ? { operationId: op } : {}),
});
expect(response.status).toBe(409);
expect(await response.json()).toEqual({
error: openCodeTransportFailure("lifecycle_changed"),
});
},
);

it("projects Continue provenance without receipt inputs or accepted-reference authority", async () => {
const response = await post("continue", {
expectedRevision: 4,
Expand Down
6 changes: 4 additions & 2 deletions packages/harness/src/server/assistant-lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ export function createAssistantLifecycleRouter(options: {
if (
!current ||
current.lifecycle.revision !== parsed.data.expectedRevision ||
current.cwd !== entry.cwd
current.cwd !== entry.cwd ||
current.continuationScope !== entry.continuationScope
)
throw changed();
res.json({
Expand All @@ -165,12 +166,13 @@ export function createAssistantLifecycleRouter(options: {
request.expectedRevision,
request.operationId,
);
const session = options.getSession(id);
const current = await options.history.entry(id);
const session = options.getSession(id);
if (
!session ||
!current ||
current.cwd !== entry.cwd ||
current.continuationScope !== entry.continuationScope ||
current.lifecycle.revision !== attachment.lifecycle.revision ||
current.lifecycle.lifecycle !== "open"
)
Expand Down
Loading