GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(muse): retry compaction after busy runs by shivamhwp · Pull Request #28455 · pingdotgg/t3code

fix(muse): retry compaction after busy runs #28455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shivamhwp wants to merge 16 commits into main from issue-watch/28436

Uh oh!

There was an error while loading. Please reload this page.

Closed

fix(muse): retry compaction after busy runs #28455

Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
4742fe8
fix(muse): wait out an active run before /compact and keep failed com…
Nov 1, 2026
5898ff1
fix(muse): retain background wakes while compaction waits
Nov 1, 2026
0738d97
Merge remote-tracking branch 'origin/main' into issue-watch/28436
shivamhwp Nov 7, 2026
4e46f4a
fix(muse): show a held wake's requests while compaction waits for it
shivamhwp Nov 7, 2026
00da4c5
style: format
shivamhwp Nov 7, 2026
bcf6056
fix(muse): show every run's requests while compaction waits
shivamhwp Nov 7, 2026
dd66022
fix(muse): settle runless requests after their turn ends
shivamhwp Nov 7, 2026
fefb2c5
Merge remote-tracking branch 'origin/main' into issue-watch/28436
shivamhwp Nov 7, 2026
2c764e3
fix(muse): keep the wake buffer reference when a request fails
shivamhwp Nov 7, 2026
d87e7be
fix(muse): keep runless requests current and ignore wake compactions …
shivamhwp Nov 7, 2026
4239e37
fix(muse): hold pre-ack compaction items and keep unowned runs' reque…
shivamhwp Nov 7, 2026
2522c99
Merge remote-tracking branch 'origin/main' into prbatch/28455
shivamhwp Nov 9, 2026
5bc9ddc
test(muse): drop a duplicate compaction rejection case
shivamhwp Nov 9, 2026
99edbb6
Merge remote-tracking branch 'origin/main' into pr-28455-clean
shivamhwp Nov 10, 2026
15a6097
fix(muse): keep compaction retry changes focused
shivamhwp Nov 10, 2026
8c7bd24
Merge remote-tracking branch 'github/main' into issue-watch/28436
maria-rcks Nov 10, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

267 changes: 260 additions & 7 deletions 267 packages/provider-muse/src/server/adapter.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,25 @@ const startConversation = Effect.fnUntraced(function* (
return { nativeId: call.commandId!, providerTurn: event.providerTurn };
});

// Returns once the adapter holds a live background Muse run, "wake-1".
const makeHeldWakeHarness = Effect.fnUntraced(function* (
fake: Effect.Success<ReturnType<typeof makeFakeMuse>>,
) {
const offered = yield* Deferred.make<ProviderContinuationRequests.ProviderContinuationRequest>();
const harness = yield* makeHarness(
fake,
INSTANCE_ID,
undefined,
undefined,
undefined,
runtimePolicy,
{ continuationRequests: { offer: (request) => Deferred.succeed(offered, request) } },
);
yield* fake.emit("turn/started", { turnId: "wake-1" });
yield* Deferred.await(offered);
return harness;
});

const SUBSCRIPTION_USAGE = {
window: { usedPercent: 0, windowDurationMins: 300, resetsAtMs: 1791465557000 },
weekly: { usedPercent: 5, resetsAtMs: 1791763200000 },
Expand Down Expand Up @@ -1622,19 +1641,253 @@ describe("MuseAdapterV2", () => {
}).pipe(Effect.scoped, Effect.provide(testLayer)),
);

it.effect("reports a no-op compaction as a visible failure and permits another turn", () =>
it.effect("reports unsuccessful compaction as a visible failure and permits another turn", () =>
Effect.gen(function* () {
const rejected = (reason: string) =>
new MspError({
code: -32030,
message: `session/compact command rejected: ${reason}`,
data: { kind: "commandRejected", reason, retryable: false },
});
for (const [response, detail] of [
[{ status: "noop", reason: "no_compactable_history" }, "no_compactable_history"],
[rejected("invalid_target"), "invalid_target"],
// No live run was observed, so there is nothing to wait for.
[rejected("run_active"), "run_active"],
] as const) {
const fake = yield* makeFakeMuse();
const harness = yield* makeHarness(fake);
fake.queueResponse("session/compact", response);
yield* harness.runtime.compactThread!(yield* turnInput(harness.providerThread));
const terminal = yield* harness.takeEvent("turn.terminal");
assert.strictEqual(terminal.status, "failed");
assert.include(terminal.failure?.message, detail);
assert.strictEqual(terminal.threadDisposition, "reusable");
assert.lengthOf(
fake.calls.filter((call) => call.method === "session/compact"),
1,
);
yield* startConversation(harness, fake, 2);
assert.lengthOf(
harness.allEvents.filter((event) => event.type === "turn.terminal"),
1,
);
}
}).pipe(Effect.scoped, Effect.provide(testLayer)),
);

const runActive = () =>
new MspError({
code: -32030,
message: "session/compact command rejected: run_active",
data: { kind: "commandRejected", reason: "run_active", retryable: false },
});
const compactionItem = (itemId: string) => ({
item: {
itemId,
turnId: "wake-1",
kind: "compaction",
status: "completed",
outcome: "compacted",
revision: 1,
},
});

it.effect("compacts when a held Muse run ends before its run_active rejection arrives", () =>
Effect.gen(function* () {
const fake = yield* makeFakeMuse();
const harness = yield* makeHarness(fake);
fake.queueResponse("session/compact", { status: "noop", reason: "no_compactable_history" });
const harness = yield* makeHeldWakeHarness(fake);
const rejection = pendingPromise<Record<string, unknown>>();
fake.queueResponse("session/compact", rejection.promise);
const compacting = yield* harness.runtime.compactThread!(
yield* turnInput(harness.providerThread),
).pipe(Effect.forkScoped);
yield* fake.takeCall("session/compact");
yield* fake.emit("turn/completed", { turnId: "wake-1", terminal: "completed" });
rejection.reject(runActive());
yield* Fiber.join(compacting);
yield* fake.takeCall("session/compact");
yield* fake.emit("item/completed", compactionItem("compaction-1"));
assert.strictEqual((yield* harness.takeEvent("turn.terminal")).status, "completed");
}).pipe(Effect.scoped, Effect.provide(testLayer)),
);

it.effect.each([
{ asked: "before compaction", run: "wake-1" },
{ asked: "while compaction waits", run: "wake-1" },
{ asked: "while compaction waits", run: "wake-2" },
] as const)(
"shows $run's approval raised $asked so compaction retries once runs end",
({ asked, run }) =>
Effect.gen(function* () {
const fake = yield* makeFakeMuse();
const harness = yield* makeHeldWakeHarness(fake);
if (asked === "before compaction") {
// An earlier automatic compaction must stay with the wake, not end this turn.
yield* fake.emit("item/completed", compactionItem("auto-compaction"));
yield* fake.emit("approval/requested", approval(run));
// Native events are processed in order; this one marks the two above as buffered.
yield* fake.emit("session/contextUsage", { usedTokens: 1 });
yield* harness.takeEvent(
"provider_thread.updated",
(event) => event.providerThread.contextUsage?.usedTokens === 1,
);
}
fake.queueResponse("session/compact", runActive());
yield* harness.runtime.compactThread!(yield* turnInput(harness.providerThread));
const first = yield* fake.takeCall("session/compact");
// A wake's own automatic compaction must not end the waiting manual one.
yield* fake.emit("item/completed", compactionItem("auto-compaction-2"));
if (run === "wake-2") {
yield* fake.emit("turn/started", { turnId: "wake-2" });
yield* fake.emit("turn/completed", { turnId: "wake-1", terminal: "completed" });
}
if (asked === "while compaction waits")
yield* fake.emit("approval/requested", approval(run));
const shown = yield* harness.takeEvent(
"runtime_request.updated",
(event) => event.runtimeRequest.status === "pending",
);
yield* harness.runtime.respondToRuntimeRequest({
requestId: shown.runtimeRequest.id,
decision: "accept",
});
yield* fake.takeCall("approval/decide");
yield* fake.emit("approval/resolved", { approvalId: "approval-1", turnId: run });
yield* fake.emit("turn/completed", { turnId: run, terminal: "completed" });
const retry = yield* fake.takeCall("session/compact");
// Command IDs are idempotency keys, so a reused one would replay the rejection.
assert.notStrictEqual(retry.commandId, first.commandId);
// The compaction runs under its own target run, not the command ID.
yield* fake.emit("item/completed", compactionItem("compaction-1"));
const terminal = yield* harness.takeEvent("turn.terminal");
assert.strictEqual(terminal.status, "completed");
assert.strictEqual(terminal.threadDisposition, "reusable");
yield* startConversation(harness, fake, 2);
}).pipe(Effect.scoped, Effect.provide(testLayer)),
);

it.effect("keeps a request shown during compaction live after the compaction is stopped", () =>
Effect.gen(function* () {
const fake = yield* makeFakeMuse();
const harness = yield* makeHeldWakeHarness(fake);
fake.queueResponse("session/compact", runActive());
yield* harness.runtime.compactThread!(yield* turnInput(harness.providerThread));
const terminal = yield* harness.takeEvent("turn.terminal");
assert.strictEqual(terminal.status, "failed");
assert.strictEqual(terminal.threadDisposition, "reusable");
yield* startConversation(harness, fake, 2);
yield* fake.takeCall("session/compact");
const running = yield* harness.takeEvent(
"provider_turn.updated",
(event) => event.providerTurn.status === "running",
);
yield* fake.emit("turn/started", { turnId: "wake-2" });
yield* fake.emit("approval/requested", approval("wake-2"));
const shown = yield* harness.takeEvent(
"runtime_request.updated",
(event) => event.runtimeRequest.status === "pending",
);
yield* harness.runtime.interruptTurn({
providerThread: harness.providerThread,
providerTurnId: running.providerTurn.id,
});
assert.strictEqual((yield* harness.takeEvent("turn.terminal")).status, "interrupted");
yield* fake.emit("approval/updated", {
...approval("wake-2"),
currentRequirementId: { approvalId: "approval-1", sourceIndex: 1 },
});
yield* harness.takeEvent(
"runtime_request.updated",
(event) =>
event.runtimeRequest.id === shown.runtimeRequest.id &&
event.runtimeRequest.status === "pending",
);
yield* harness.runtime.respondToRuntimeRequest({
requestId: shown.runtimeRequest.id,
decision: "accept",
});
const decision = yield* fake.takeCall("approval/decide");
assert.deepStrictEqual(decision.params.requirementId, {
approvalId: "approval-1",
sourceIndex: 1,
});
yield* fake.emit("approval/resolved", { approvalId: "approval-1", turnId: "wake-2" });
const resolved = yield* harness.takeEvent(
"runtime_request.updated",
(event) => event.runtimeRequest.status === "resolved",
);
assert.strictEqual(resolved.runtimeRequest.id, shown.runtimeRequest.id);
}).pipe(Effect.scoped, Effect.provide(testLayer)),
);

it.effect.each(["before compaction", "during admission"] as const)(
"keeps a Muse wake that started $0 when stopping a waiting compaction",
(wakeStarted) =>
Effect.gen(function* () {
const fake = yield* makeFakeMuse();
const offered = yield* Deferred.make<void>();
const harness = yield* makeHarness(
fake,
INSTANCE_ID,
undefined,
undefined,
undefined,
runtimePolicy,
{ continuationRequests: { offer: () => Deferred.succeed(offered, undefined) } },
);
if (wakeStarted === "before compaction") {
yield* fake.emit("turn/started", { turnId: "wake-1" });
yield* Deferred.await(offered);
}
const admission = pendingPromise<Record<string, unknown>>();
fake.queueResponse("session/compact", admission.promise);
const compacting = yield* harness.runtime.compactThread!(
yield* turnInput(harness.providerThread),
).pipe(Effect.forkScoped);
yield* fake.takeCall("session/compact");
if (wakeStarted === "during admission") {
yield* fake.emit("turn/started", { turnId: "wake-1" });
yield* Deferred.await(offered);
}
admission.reject(runActive());
yield* Fiber.join(compacting);
const running = yield* harness.takeEvent(
"provider_turn.updated",
(event) => event.providerTurn.status === "running",
);
yield* harness.runtime.interruptTurn({
providerThread: harness.providerThread,
providerTurnId: running.providerTurn.id,
});
const terminal = yield* harness.takeEvent("turn.terminal");
assert.strictEqual(terminal.status, "interrupted");
assert.strictEqual(terminal.threadDisposition, "reusable");
assert.strictEqual(fake.closeCount(), 0);
assert.isTrue(yield* harness.runtime.hasPendingBackgroundWork!);
yield* fake.emit("item/completed", {
item: {
itemId: "wake-output",
turnId: "wake-1",
kind: "agentMessage",
revision: 1,
status: "completed",
text: "Background wake finished.",
},
});
yield* fake.emit("turn/completed", { turnId: "wake-1", terminal: "completed" });
const continuation = yield* turnInput(harness.providerThread, 2);
yield* harness.runtime.startTurn({
...continuation,
message: { ...continuation.message, createdBy: "agent", creationSource: "provider" },
});
const output = yield* harness.takeEvent("message.updated");
assert.strictEqual(output.message.text, "Background wake finished.");
assert.strictEqual((yield* harness.takeEvent("turn.terminal")).status, "completed");
yield* startConversation(harness, fake, 3);
assert.lengthOf(
fake.calls.filter((call) => call.method === "session/compact"),
1,
);
}).pipe(Effect.scoped, Effect.provide(testLayer)),
);

it.effect("projects native todos with stable identity and removes cancelled steps", () =>
Effect.gen(function* () {
const fake = yield* makeFakeMuse();
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.