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(server): a usage-limited thread no longer auto-settles by EhsanulHaqueSiam · Pull Request #28359 · pingdotgg/t3code

fix(server): a usage-limited thread no longer auto-settles #28359

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

Open
EhsanulHaqueSiam wants to merge 13 commits into pingdotgg:main
base: main
Loading
Loading
from EhsanulHaqueSiam:fix/auto-settle-usage-limit
+198 −2
Open

fix(server): a usage-limited thread no longer auto-settles #28359

Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit Hold shift + click to select a range
3e69b68
fix(server): a usage-limited thread no longer auto-settles
EhsanulHaqueSiam Oct 31, 2026
54eada7
fix(server): match the shell's blocked run when skipping usage-limite…
EhsanulHaqueSiam Oct 31, 2026
b2c9981
test(server): cover a usage limit that ended after a newer run
EhsanulHaqueSiam Oct 31, 2026
1b7badf
fix(server): a differing session error lets a usage-limited thread se…
EhsanulHaqueSiam Oct 31, 2026
26144a2
test(server): cover a session error that matches the usage limit
EhsanulHaqueSiam Oct 31, 2026
60d864c
Merge remote-tracking branch 'github/main' into fix/auto-settle-usage…
maria-rcks Nov 5, 2026
6fd0106
Merge remote-tracking branch 'origin/main' into fix/auto-settle-usage…
juliusmarminge Nov 12, 2026
e62eae8
fix(server): abandoned usage-limited subagents still settle for cleanup
juliusmarminge Nov 12, 2026
2e962b2
fix(server): abandoned subagents settle even with limit recovery armed
juliusmarminge Nov 12, 2026
a849e8e
Merge remote-tracking branch 'origin/main' into fix/auto-settle-usage…
juliusmarminge Nov 12, 2026
2d062a6
test(server): trim usage-limit settlement cases to the SQL branches
juliusmarminge Nov 12, 2026
c7eb902
Merge remote-tracking branch 'origin/main' into fix/auto-settle-usage…
EhsanulHaqueSiam Nov 13, 2026
9cda0f5
Merge remote-tracking branch 'upstream/main' into mod/28359
EhsanulHaqueSiam Nov 21, 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

65 changes: 64 additions & 1 deletion 65 apps/server/src/orchestration-v2/ProjectionSettlement.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,44 @@ const createItem = Effect.fn(function* (
});
});

const createFailure = Effect.fn(function* (
threadId: ThreadId,
runId: RunId,
failureClass: "usage_limit" | "provider_error",
) {
const store = yield* ProjectionStore.ProjectionStoreV2;
yield* store.apply({
id: EventId.make(`event:failure:${runId}`),
type: "turn-item.updated",
threadId,
occurredAt: old,
payload: {
id: TurnItemId.make(`failure:${runId}`),
threadId,
runId,
nodeId: null,
providerThreadId: null,
providerTurnId: null,
nativeItemRef: null,
parentItemId: null,
ordinal: 1,
type: "error",
status: "failed",
title: failureClass,
startedAt: old,
completedAt: old,
updatedAt: old,
failure: {
class: failureClass,
message: failureClass,
code: null,
retryable: true,
resetAt: DateTime.formatIso(DateTime.add(now, { hours: 1 })),
},
},
});
});

it.effect(
"sql: discovers settlement work with the same activity and background semantics as the shell",
() =>
Expand Down Expand Up @@ -210,6 +248,22 @@ it.effect(
snoozedAt: DateTime.subtract(old, { days: 1 }),
});
yield* createRun(woke, "failed");
const limited = yield* createThread("usage-limited");
yield* createFailure(limited, yield* createRun(limited, "failed"), "usage_limit");
// A message queued behind the limit is the newest run, but the limit still blocks.
const queuedBehindLimit = yield* createThread("queued-behind-limit");
yield* createFailure(
queuedBehindLimit,
yield* createRun(queuedBehindLimit, "failed"),
"usage_limit",
);
yield* createRun(queuedBehindLimit, "queued", 2);
const providerFailed = yield* createThread("provider-failed");
yield* createFailure(
providerFailed,
yield* createRun(providerFailed, "failed"),
"provider_error",
);
const background = yield* createThread("idle-background");
yield* createItem(background, yield* createRun(background), "idle");
const persistent = yield* createThread("persistent-monitor");
Expand Down Expand Up @@ -250,7 +304,16 @@ it.effect(
);
assert.deepEqual(
new Set(eligible.map((thread) => thread.id)),
new Set([idle, completed, queued, woke, background, persistent, rolledBack]),
new Set([
idle,
completed,
queued,
woke,
providerFailed,
background,
persistent,
rolledBack,
]),
);
assert.deepEqual(
new Set(eligible.map((thread) => thread.id)),
Expand Down
40 changes: 40 additions & 0 deletions 40 apps/server/src/orchestration-v2/ProjectionStore.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export type ProjectionSettlementCandidate = Pick<
| "latestRunCompletedAt"
| "latestUserMessageAt"
| "status"
| "lastErrorClass"
| "activityRunStartedAt"
| "activityRunStatus"
| "pendingRuntimeRequest"
Expand Down Expand Up @@ -6292,6 +6293,43 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
WHERE link.thread_id = t.thread_id
AND link.type = 'link_request' AND link.status = 'waiting'
)
-- A usage limit interrupts work; settling would hide its recovery controls.
-- Matches the shell's blocked run, so a message queued behind the limit
-- does not hide it. The cheap EXISTS keeps the run sort off other threads.
AND NOT (
EXISTS (
SELECT 1 FROM orchestration_v2_projection_turn_items failure
WHERE failure.thread_id = t.thread_id
AND failure.type = 'error' AND failure.status = 'failed'
AND json_extract(failure.payload_json, '$.failure.class') = 'usage_limit'
)
AND EXISTS (
SELECT 1 FROM orchestration_v2_projection_runs blocked
WHERE blocked.run_id = (
SELECT latest.run_id FROM orchestration_v2_projection_runs latest
WHERE latest.thread_id = t.thread_id
AND latest.status <> 'queued'
AND NOT (
latest.status = 'cancelled'
AND json_extract(latest.payload_json, '$.startedAt') IS NULL
)
-- latestExecutedRun: the run that ended last (runRanAfter).
ORDER BY latest.completed_at IS NULL DESC, latest.completed_at DESC,
latest.ordinal DESC, latest.run_id DESC
LIMIT 1
)
AND blocked.status = 'failed'
AND (
SELECT json_extract(error.payload_json, '$.failure.class')
FROM orchestration_v2_projection_turn_items error
WHERE error.thread_id = t.thread_id AND error.run_id = blocked.run_id
AND error.type = 'error' AND error.status = 'failed'
AND error.node_id IS json_extract(blocked.payload_json, '$.rootNodeId')
ORDER BY error.updated_at DESC, error.ordinal DESC, error.turn_item_id DESC
LIMIT 1
) = 'usage_limit'
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Uh oh!

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

)
)
ORDER BY t.updated_at ASC, t.thread_id ASC
`;
if (rows.length === 0) return [];
Expand Down Expand Up @@ -6339,6 +6377,8 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
activityRunStatus: null,
activityRunStartedAt: null,
pendingRuntimeRequest: null,
// The query above drops usage-limited threads.
lastErrorClass: null,
pendingGuestMessageCount: pendingGuestMessageCount(thread.guestShare),
pendingBackgroundTasks: derivePendingBackgroundWork({
latestRun:
Expand Down
11 changes: 11 additions & 0 deletions 11 apps/server/src/orchestration-v2/ThreadSettlementService.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ describe("isAutoSettlementCandidate", () => {
expect(ThreadSettlementService.isSnoozed(snoozed, NOW_MS)).toBe(false);
});

it("never settles a thread stopped by a usage limit", () => {
const limited = shell({ status: "failed", lastErrorClass: "usage_limit" });
expect(ThreadSettlementService.isAutoSettlementCandidate(limited, NOW_MS)).toBe(false);
expect(
ThreadSettlementService.isAutoSettlementCandidate(
{ ...limited, lastErrorClass: "provider_error" },
NOW_MS,
),
).toBe(true);
});

it("keeps snoozed threads parked until a fresh failure or timer wake", () => {
const snoozed = shell({
snoozedUntil: at(60 * 60 * 1_000),
Expand Down
2 changes: 2 additions & 0 deletions 2 apps/server/src/orchestration-v2/ThreadSettlementService.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ export function isAutoSettlementCandidate(
// A guest is waiting on the owner; settling would hide the Request.
if ((thread.pendingGuestMessageCount ?? 0) > 0) return false;
if (thread.activityRunStatus != null) return false;
// A usage limit interrupts the work; settling would hide Resume at reset.
if (thread.status === "failed" && thread.lastErrorClass === "usage_limit") return false;
if (backgroundWorkHoldsCompletion(thread.pendingBackgroundTasks ?? [])) return false;
if (threadHasQueuedTurnStart(thread, nowMs)) return false;
// Interrupted runs must keep the same snooze protection the sidebar shows.
Expand Down
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.