Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
eea048e
feat: a project can have a lead chat
badcuban Nov 16, 2026
c5a9917
fix(web): drop the lead chat's keybinding command
badcuban Nov 16, 2026
fd22ec8
feat: the lead chat passes work to threads, and the card starts some …
badcuban Nov 16, 2026
2dd3060
feat(web): a Threads panel groups a project's threads by what needs you
badcuban Nov 16, 2026
cb3fe3a
fix(web): the Threads tab opens on a phone too, and its badge keeps i…
badcuban Nov 16, 2026
447606b
feat(web): a thread's family shows as tabs under the chat header
badcuban Nov 16, 2026
0e896a4
fix(web): family tabs fit their titles and pack to the left
badcuban Nov 17, 2026
a011b7e
feat: a usage limit pauses a thread an agent started instead of faili…
badcuban Nov 17, 2026
1337ea0
fix: passed work keeps the lead's access when handed on, and known pu…
badcuban Nov 17, 2026
fd1a2df
Merge remote-tracking branch 'origin/main' into feat/lead-chat-2-pass
badcuban Nov 17, 2026
009a921
Merge branch 'feat/lead-chat-2-pass' into feat/lead-chat-3-panel-stacked
badcuban Nov 17, 2026
ef9f7f1
Merge branch 'feat/lead-chat-3-panel-stacked' into feat/lead-chat-5-tabs
badcuban Nov 17, 2026
a42f100
Merge branch 'feat/lead-chat-5-tabs' into feat/lead-chat-4-pause
badcuban Nov 17, 2026
c30e6b8
fix: a lead chat's pass is checked against its ceiling again right be…
badcuban Nov 17, 2026
5fc5d1f
Merge branch 'feat/lead-chat-2-pass' into feat/lead-chat-3-panel-stacked
badcuban Nov 17, 2026
fa6af50
Merge branch 'feat/lead-chat-3-panel-stacked' into feat/lead-chat-5-tabs
badcuban Nov 17, 2026
931c7fa
Merge branch 'feat/lead-chat-5-tabs' into feat/lead-chat-4-pause
badcuban Nov 17, 2026
fdb3039
fix: a lead chat's pass that never ran is marked not sent and stays o…
badcuban Nov 17, 2026
8502866
fix: a pass stopped while prepared, or moved to another computer, sta…
badcuban Nov 17, 2026
4ff5e65
Merge branch 'feat/lead-chat-2-pass' into feat/lead-chat-3-panel-stacked
badcuban Nov 17, 2026
ecd3b3e
Merge branch 'feat/lead-chat-3-panel-stacked' into feat/lead-chat-5-tabs
badcuban Nov 17, 2026
51623cb
Merge branch 'feat/lead-chat-5-tabs' into feat/lead-chat-4-pause
badcuban Nov 17, 2026
facda57
Merge remote-tracking branch 'origin/main' into feat/lead-chat-2-pass
badcuban Nov 17, 2026
0f5007d
fix: an agent's message still queued when its thread moves arrives as…
badcuban Nov 17, 2026
48194cf
Merge branch 'feat/lead-chat-2-pass' into feat/lead-chat-3-panel-stacked
badcuban Nov 17, 2026
d33e3d5
Merge branch 'feat/lead-chat-3-panel-stacked' into feat/lead-chat-5-tabs
badcuban Nov 17, 2026
fcaa33e
Merge branch 'feat/lead-chat-5-tabs' into feat/lead-chat-4-pause
badcuban Nov 17, 2026
f64279e
fix: history handed to an agent never calls another agent's message t…
badcuban Nov 17, 2026
a8da9ad
test(web): the family tabs test waits as long as a slow CI runner needs
badcuban Nov 17, 2026
5dee061
Merge branch 'feat/lead-chat-5-tabs' into feat/lead-chat-4-pause
badcuban Nov 17, 2026
f526932
Merge remote-tracking branch 'origin/main' into feat/lead-chat-2-pass
badcuban Nov 17, 2026
e12c1a4
Merge branch 'feat/lead-chat-2-pass' into feat/lead-chat-3-panel-stacked
badcuban Nov 17, 2026
1435486
Merge branch 'feat/lead-chat-3-panel-stacked' into feat/lead-chat-5-tabs
badcuban Nov 17, 2026
ffb6103
Merge branch 'feat/lead-chat-5-tabs' into feat/lead-chat-4-pause
badcuban Nov 17, 2026
5fb5471
Merge main into feat/lead-chat-3-panel-stacked
badcuban Nov 17, 2026
0b8f4d9
Merge branch 'feat/lead-chat-3-panel-stacked' into feat/lead-chat-5-tabs
badcuban Nov 17, 2026
1e99230
Merge main into feat/lead-chat-5-tabs
badcuban Nov 17, 2026
df930af
Merge remote-tracking branch 'origin/main' into feat/lead-chat-5-tabs
badcuban Nov 17, 2026
618b100
Merge remote-tracking branch 'origin/feat/lead-chat-5-tabs' into feat…
badcuban Nov 17, 2026
5a9b064
Merge remote-tracking branch 'origin/main' into feat/lead-chat-4-pause
badcuban Nov 17, 2026
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
2 changes: 1 addition & 1 deletion apps/server/src/guide/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ When Claude Code refuses to start (a settings file that is not valid JSON, a bad

If Codex's sign-in goes stale in a chat before it has started on your message, Threadlines restarts Codex and sends the message again, once, with a note in the chat. If that fails too, the chat asks you to sign in.

When a Claude or Codex usage limit stops a thread, the notice above the composer says which limit and when it resets. Its Continue at reset switch sends "Continue where you left off." a minute after the reset, from the computer the thread runs on (a Mac that wakes only briefly for upkeep waits until it's fully awake), or within a few minutes of the limit resetting early because the user spent a limit reset, and {place:threads.continueAfterUsageLimits} turns it on for every limit. If you added another account of the same agent that still has room, the notice offers it by name. Threadlines never switches accounts on its own.`,
When a Claude or Codex usage limit stops a thread, the notice above the composer says which limit and when it resets. Its Continue at reset switch sends "Continue where you left off." a minute after the reset, from the computer the thread runs on (a Mac that wakes only briefly for upkeep waits until it's fully awake), or within a few minutes of the limit resetting early because the user spent a limit reset, and {place:threads.continueAfterUsageLimits} turns it on for every limit. With it on, a thread another thread's agent started on this computer also waits for the reset instead of failing, and its answer goes back once it continues; so does a thread hearing back from one it started. Stop ends the wait, and a turn you stopped never comes back by itself. If you added another account of the same agent that still has room, the notice offers it by name. Threadlines never switches accounts on its own.`,
},
{
id: "plugins-skills-instructions",
Expand Down
134 changes: 134 additions & 0 deletions apps/server/src/orchestration/Layers/ChildThreadReactor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,140 @@ describe("ChildThreadReactor", () => {
),
);

describe("a child errored on a usage limit (docs/design/lead-chat.md, ruling 3)", () => {
const erroredTurn = TurnId.make("child-turn-1");
const asked = {
id: CHILD_MESSAGE,
role: "user" as const,
text: "Write it.",
fromThread: { threadId: PARENT, requestId: REQUEST, kind: "request" as const },
turnId: null,
streaming: false,
createdAt: now,
updatedAt: now,
};
const errored = (overrides: Partial<OrchestrationThread> = {}) =>
thread(CHILD, {
messages: [asked],
latestTurn: {
turnId: erroredTurn,
state: "running",
requestedAt: now,
startedAt: now,
completedAt: null,
assistantMessageId: null,
},
session: {
threadId: CHILD,
status: "error",
providerName: "codex",
runtimeMode: "auto-accept-edits",
activeTurnId: null,
lastError: "You've hit your usage limit",
updatedAt: now,
},
...overrides,
});
const sessionChanged = (harness: Harness) =>
PubSub.publish(harness.events, {
type: "thread.session-set",
payload: { threadId: CHILD },
} as unknown as OrchestrationEvent);

it.effect("waits for a late turn end that arms the wait, and then holds the request", () =>
withReactor([parentWith([]), errored()], {}, (harness) =>
Effect.gen(function* () {
// The request opens after startup, so no restart pass settles it.
harness.threads.set(PARENT, parentWith([request()]));
yield* sessionChanged(harness);
yield* settle;
// Past today's 5 s: its turn hasn't ended, so nothing settles yet.
yield* TestClock.adjust(Duration.seconds(6));
yield* settle;
expect(settles(harness)).toEqual([]);
// The turn's end arrives with the reset: the wait is armed.
harness.threads.set(
CHILD,
errored({
latestTurn: {
turnId: erroredTurn,
state: "error",
requestedAt: now,
startedAt: now,
completedAt: now,
assistantMessageId: null,
},
session: {
threadId: CHILD,
status: "error",
providerName: "codex",
runtimeMode: "auto-accept-edits",
activeTurnId: null,
lastError: "You've hit your usage limit",
continueAtReset: { resetsAt: now, at: now },
updatedAt: now,
},
}),
);
yield* TestClock.adjust(Duration.seconds(15));
yield* settle;
expect(settles(harness)).toEqual([]);
}),
),
);

it.effect("settles the request failed at the bound when the turn's end never comes", () =>
withReactor([parentWith([]), errored()], {}, (harness) =>
Effect.gen(function* () {
// The request opens after startup, so no restart pass settles it.
harness.threads.set(PARENT, parentWith([request()]));
yield* sessionChanged(harness);
yield* settle;
yield* TestClock.adjust(Duration.seconds(19));
yield* settle;
expect(settles(harness)).toEqual([]);
yield* TestClock.adjust(Duration.seconds(2));
yield* settle;
expect(settles(harness)).toMatchObject([{ outcome: "failed" }]);
}),
),
);

it.effect("keeps a held request across a restart", () =>
withReactor(
[
parentWith([request()]),
errored({
latestTurn: {
turnId: erroredTurn,
state: "error",
requestedAt: now,
startedAt: now,
completedAt: now,
assistantMessageId: null,
},
session: {
threadId: CHILD,
status: "error",
providerName: "codex",
runtimeMode: "auto-accept-edits",
activeTurnId: null,
lastError: "You've hit your usage limit",
continueAtReset: { resetsAt: now, at: now },
updatedAt: now,
},
}),
],
{},
(harness) =>
Effect.gen(function* () {
yield* settle;
expect(settles(harness)).toEqual([]);
}),
),
);
});

it.effect("starts a child with no more access than its parent has now", () =>
withReactor(
[
Expand Down
33 changes: 32 additions & 1 deletion apps/server/src/orchestration/Layers/ChildThreadReactor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
childDeliveryAfterRestart,
childDeliveryForQuietCandidate,
finishedTurnAfterRestart,
isHeldByContinueAtReset,
isQuietCandidate,
} from "../childThreadDelivery.ts";
import {
Expand All @@ -58,6 +59,16 @@ const QUIET_GRACE = Duration.seconds(15);
*/
const STOP_GRACE = Duration.seconds(5);

/**
* How long an errored child whose answering turn hasn't ended yet gets for
* that end before its request is settled from the error. A provider can
* report the session's error first and the turn's end, with a usage limit's
* reset time, later: Codex refreshes usage first and gives up on that after
* 15 s (freshProviderSnapshot). The turn's end decides whether the request
* waits to continue at the reset (docs/design/lead-chat.md, ruling 3).
*/
const LATE_TURN_END_GRACE = Duration.seconds(20);

type ReactorEvent = Extract<
OrchestrationEvent,
{ type: "thread.child-request-submitted" | "thread.child-request-updated" | "thread.session-set" }
Expand Down Expand Up @@ -282,6 +293,19 @@ export const makeChildThreadReactor = Effect.gen(function* () {
if ((status === "stopped" || status === "error") && !stopChecks.has(childId)) {
stopChecks.add(childId);
yield* Effect.sleep(STOP_GRACE).pipe(
// An error whose turn hasn't ended yet: its end may still come,
// with the reset time, up to the bound; then the error settles it.
Effect.andThen(
status === "error"
? readThread(childId).pipe(
Effect.flatMap((latest) =>
latest?.latestTurn?.state === "running"
? Effect.sleep(Duration.subtract(LATE_TURN_END_GRACE, STOP_GRACE))
: Effect.void,
),
)
: Effect.void,
),
Effect.andThen(settleStoppedAnswers(parent.id, childId, status)),
Effect.ensuring(Effect.sync(() => stopChecks.delete(childId))),
Effect.forkDetach,
Expand Down Expand Up @@ -325,7 +349,9 @@ export const makeChildThreadReactor = Effect.gen(function* () {
for (const request of parent.childRequests.open) {
if (
request.childThreadId !== childId ||
(request.status !== "running" && request.status !== "awaiting_background")
(request.status !== "running" && request.status !== "awaiting_background") ||
// Waiting to continue at a usage limit's reset: the continue answers it.
isHeldByContinueAtReset(child, request)
) {
continue;
}
Expand Down Expand Up @@ -406,6 +432,11 @@ export const makeChildThreadReactor = Effect.gen(function* () {
});
continue;
}
// Still waiting to continue at a usage limit's reset (the wait is
// kept across a restart): the continue answers it.
if (isHeldByContinueAtReset(child, request)) {
continue;
}
const childTurns = yield* turns
.listByThreadId({ threadId: child.id })
.pipe(Effect.orElseSucceed(() => [] as const));
Expand Down
13 changes: 13 additions & 0 deletions apps/server/src/orchestration/Layers/ProjectionPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,18 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
yield* projectionThreadSessionRepository.setContinueAtReset(event.payload);
return;
}
// Stop names the turn it is for: no usage limit brings that turn back.
if (
(event.type === "thread.turn-interrupt-requested" ||
event.type === "thread.session-stop-requested") &&
event.payload.stopsTurnId !== undefined
) {
yield* projectionThreadSessionRepository.setStopRequested({
threadId: event.payload.threadId,
turnId: event.payload.stopsTurnId,
});
return;
}
if (event.type !== "thread.session-set") {
return;
}
Expand Down Expand Up @@ -2183,6 +2195,7 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
lastErrorDismissedAt: event.payload.session.lastErrorDismissedAt ?? null,
lastErrorUsageLimit: event.payload.session.lastErrorUsageLimit ?? null,
continueAtReset: event.payload.session.continueAtReset ?? null,
stopRequestedTurnId: event.payload.session.stopRequestedTurnId ?? null,
updatedAt: event.payload.session.updatedAt,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ function mapSessionRow(
...(row.lastErrorDismissedAt ? { lastErrorDismissedAt: row.lastErrorDismissedAt } : {}),
...(row.lastErrorUsageLimit ? { lastErrorUsageLimit: row.lastErrorUsageLimit } : {}),
...(row.continueAtReset ? { continueAtReset: row.continueAtReset } : {}),
...(row.stopRequestedTurnId ? { stopRequestedTurnId: row.stopRequestedTurnId } : {}),
updatedAt: row.updatedAt,
};
}
Expand Down Expand Up @@ -1399,6 +1400,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
last_error_dismissed_at AS "lastErrorDismissedAt",
last_error_usage_limit AS "lastErrorUsageLimit",
continue_at_reset AS "continueAtReset",
stop_requested_turn_id AS "stopRequestedTurnId",
updated_at AS "updatedAt"
FROM projection_thread_sessions
ORDER BY thread_id ASC
Expand Down Expand Up @@ -1454,6 +1456,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
sessions.last_error_dismissed_at AS "lastErrorDismissedAt",
sessions.last_error_usage_limit AS "lastErrorUsageLimit",
sessions.continue_at_reset AS "continueAtReset",
sessions.stop_requested_turn_id AS "stopRequestedTurnId",
sessions.updated_at AS "updatedAt"
FROM projection_thread_sessions sessions
INNER JOIN projection_threads threads
Expand Down Expand Up @@ -1489,6 +1492,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
sessions.last_error_dismissed_at AS "lastErrorDismissedAt",
sessions.last_error_usage_limit AS "lastErrorUsageLimit",
sessions.continue_at_reset AS "continueAtReset",
sessions.stop_requested_turn_id AS "stopRequestedTurnId",
sessions.updated_at AS "updatedAt"
FROM projection_thread_sessions sessions
INNER JOIN projection_threads threads
Expand Down Expand Up @@ -2403,6 +2407,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
last_error_dismissed_at AS "lastErrorDismissedAt",
last_error_usage_limit AS "lastErrorUsageLimit",
continue_at_reset AS "continueAtReset",
stop_requested_turn_id AS "stopRequestedTurnId",
updated_at AS "updatedAt"
FROM projection_thread_sessions
WHERE thread_id = ${threadId}
Expand Down Expand Up @@ -3876,6 +3881,8 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
last_error_dismissed_at AS "lastErrorDismissedAt",
last_error_usage_limit AS "lastErrorUsageLimit",
continue_at_reset AS "continueAtReset",
stop_requested_turn_id AS "stopRequestedTurnId",
stop_requested_turn_id AS "stopRequestedTurnId",
updated_at AS "updatedAt"
FROM projection_thread_sessions
WHERE ${sql.in("thread_id", threadIds)}
Expand Down
63 changes: 63 additions & 0 deletions apps/server/src/orchestration/childThreadDelivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from "@threadlines/contracts";

import { childReportMessageId, childReportText } from "./childThreadDecisions.ts";
import { turnStartingMessage } from "./continueTurns.ts";

/** What the delivery rules read of a request, wherever it is kept. */
export type ChildDeliveryRequest = Pick<
Expand Down Expand Up @@ -157,6 +158,11 @@ export function childDeliveryForTurnEnd(input: {
);
}
if (end.outcome === "failed") {
// A usage limit paused it: the request waits for the continue at the
// reset, which answers it (docs/design/lead-chat.md, "Usage limits").
if (isHeldByContinueAtReset(child, request)) {
return null;
}
const error = end.error ?? "Its turn did not finish.";
return settle(
request,
Expand All @@ -174,6 +180,63 @@ export function childDeliveryForTurnEnd(input: {
);
}

/**
* Whether a parent's request is held open by the child's wait to continue
* after a usage limit (docs/design/lead-chat.md, "Usage limits"): the child
* waits to continue at the reset, and the request is `running` and answered
* by the turn that stopped on the limit. Only such a request is held: one
* waiting on background work (`awaiting_background`) follows its own path.
*/
export function isHeldByContinueAtReset(
child: OrchestrationThread,
request: ChildDeliveryRequest,
): boolean {
const session = child.session;
return (
session !== null &&
(session.continueAtReset ?? null) !== null &&
request.status === "running" &&
request.childMessageId === failedTurnMessage(child)?.id
);
}

/**
* The message that started the child's last turn, not counting messages still
* waiting in its queue: an agent's message is written into the chat when it
* is queued, so the newest user message may not have run yet.
*/
export function failedTurnMessage(child: OrchestrationThread) {
const session = child.session;
if (session === null) return undefined;
const queued = new Set((child.queuedFollowUps ?? []).map((entry) => entry.messageId));
if (queued.size === 0) return turnStartingMessage(child, session);
return turnStartingMessage(
{ ...child, messages: child.messages.filter((message) => !queued.has(message.id)) },
session,
);
}

/**
* A held request whose wait ended without its continue: it settles as it
* would have when its turn stopped, with why it did not go on.
*/
export function heldRequestEnded(
child: OrchestrationThread,
request: ChildDeliveryRequest,
outcome: "failed" | "stopped",
why: string,
): Extract<ChildDelivery, { readonly type: "thread.child-request.settle" }> {
const text =
outcome === "stopped"
? `The user stopped '${child.title}' while it waited for a usage limit to reset.`
: `'${child.title}' stopped on a usage limit and won't continue: ${why}`;
const delivery = settle(request, outcome, `${text}${partialAnswer(child, request)}`, null);
return {
...(delivery as Extract<ChildDelivery, { readonly type: "thread.child-request.settle" }>),
...(outcome === "failed" ? { error: why } : {}),
};
}

/**
* A child whose turn ended while it waited on background work has gone quiet
* with nothing left running and no follow-up turn: its answer so far stands.
Expand Down
Loading
Loading