Skip to content

Commit 49601a7

Browse files
committed
chore(webapp): trim comments to the essential why across the agent PR
1 parent 62c1940 commit 49601a7

18 files changed

Lines changed: 75 additions & 154 deletions

apps/webapp/app/components/code/StreamdownRenderer.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ describe("retryImport", () => {
120120

121121
describe("loadStreamdownRenderer", () => {
122122
it("resolves to a plain-text fallback when the chunk load keeps failing", async () => {
123-
// The fallback path deliberately re-raises the original error as a process-level
124-
// unhandled rejection (for StaleAssetRecovery). Swap in our own listener so that
125-
// expected rejection is asserted on, not reported as a test-runner failure.
123+
// The fallback path re-raises as an unhandled rejection (for StaleAssetRecovery); swap
124+
// in our own listener so it's asserted on, not reported as a test-runner failure.
126125
const priorListeners = process.listeners("unhandledRejection");
127126
process.removeAllListeners("unhandledRejection");
128127
const caught = new Promise<Error>((resolve) => {

apps/webapp/app/components/dashboard-agent/DashboardAgentChat.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,11 @@ export function DashboardAgentChat({
229229

230230
const messages = orderTranscript(rawMessages, orderRef.current);
231231

232-
// Bounded waits so a stalled turn says so instead of leaving the panel on a progress
233-
// line forever. Independent of the SDK's own `error`: both drive the same live-error
234-
// callout, but a deadline firing never touches the server turn or `status`.
232+
// Independent of the SDK's own `error`: both drive the live-error callout, but a
233+
// deadline firing never touches the server turn or `status`.
235234
const [deadlineError, setDeadlineError] = useState<TurnDeadlineError | null>(null);
236-
// A retry can resend under `status: "submitted"` again — the same status the previous
237-
// turn was already in when it fired, so the first-event effect wouldn't otherwise re-run.
238-
// Bumped in `retry` to force it to. `dismissError` never bumps it: dismiss means "stop
239-
// telling me", not "start a new wait".
235+
// Bumped in `retry` to force the first-event effect to re-run when a resend reuses the
236+
// same `status: "submitted"`. `dismissError` never bumps it.
240237
const [attempt, setAttempt] = useState(0);
241238
const firstEventDeadline = useRef(
242239
createKeyedDeadline<"submitted">({

apps/webapp/app/components/dashboard-agent/turn-deadlines.test.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,8 @@ describe("turnDeadlineErrorMessage", () => {
121121
});
122122

123123
/**
124-
* These do NOT exercise `DashboardAgentChat` itself — this repo has no DOM/render test setup
125-
* (see `wake-poll.test.ts` for the same pattern: the extracted logic is what's tested). They
126-
* prove the extracted predicate (`activeToolPendingKey`) gates correctly, and that an explicit
127-
* `sync(null)` reset — which the component makes in `retry`/`dismissError` — is what lets a
128-
* deadline re-arm on a retry that reproduces the same condition; without that reset, `sync`
129-
* with an unchanged key is a no-op and the deadline never fires again.
124+
* Tests the extracted predicate, not `DashboardAgentChat` (no DOM/render setup here). The
125+
* component's explicit `sync(null)` reset is required to re-arm on retry: an unchanged key is a no-op.
130126
*/
131127
describe("the tool-pending gate and retry re-arm, standing in for DashboardAgentChat", () => {
132128
beforeEach(() => {
@@ -158,9 +154,8 @@ describe("the tool-pending gate and retry re-arm, standing in for DashboardAgent
158154
await vi.advanceTimersByTimeAsync(120_000);
159155
expect(timeouts).toEqual(["get_run"]);
160156

161-
// Retry's explicit reset (DashboardAgentChat.tsx) before the retried turn's effect
162-
// re-syncs the same key — without it, `sync("get_run")` while still `currentKey`
163-
// would be a no-op and the deadline would never fire again.
157+
// Retry's explicit reset (DashboardAgentChat.tsx): without it, re-syncing the same
158+
// key while still `currentKey` would be a no-op and the deadline would never re-fire.
164159
deadline.sync(null);
165160
deadline.sync(activeToolPendingKey("streaming", inFlightToolName(dangling)));
166161

apps/webapp/app/components/dashboard-agent/turn-deadlines.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
/**
2-
* Bounded waits during a live turn, so a stalled agent says so instead of leaving the
3-
* panel on a progress line forever. Two independent deadlines:
4-
* - "first event": nothing has streamed back since the message was sent.
5-
* - "tool pending": a single tool call has stayed pending too long.
6-
* Both drive the same live-error affordance the SDK's own errors use (`turn-error.ts`),
7-
* and both clear the moment the condition they're watching changes — including late
8-
* recovery after they've already fired.
2+
* Bounded waits during a live turn: "first event" (nothing streamed yet) and "tool
3+
* pending" (one tool call stuck). Both clear the moment the watched condition changes.
94
*/
105

116
export const FIRST_EVENT_DEADLINE_MS = 45_000;
@@ -14,9 +9,8 @@ export const TOOL_PENDING_DEADLINE_MS = 120_000;
149
export type TurnDeadlineError = { kind: "first-event" } | { kind: "tool-pending"; tool: string };
1510

1611
/**
17-
* The tool-pending deadline's key: null unless a turn is actually live. A dangling
18-
* `input-available` part on an idle chat — a stopped turn, a reload of old history — is
19-
* not a pending call, and arming a timer for it would fire with nothing able to clear it.
12+
* Null unless a turn is live. A dangling `input-available` part on an idle chat isn't a
13+
* pending call, and arming a timer for it would fire with nothing able to clear it.
2014
*/
2115
export function activeToolPendingKey(status: string, inFlightTool: string | null): string | null {
2216
const inFlight = status === "streaming" || status === "submitted";
@@ -51,9 +45,8 @@ export type KeyedDeadline<K extends string> = {
5145
};
5246

5347
/**
54-
* Watches one condition across successive `sync` calls: the timer starts the moment `sync`
55-
* sees a key it wasn't already watching, fires `onTimeout` if that same key is still active
56-
* after `deadlineMs`, and clears (`onClear`) whenever the key changes away, fired or not.
48+
* Timer starts when `sync` sees a new key, fires `onTimeout` if it's still active after
49+
* `deadlineMs`, and clears (`onClear`) whenever the key changes away, fired or not.
5750
*/
5851
export function createKeyedDeadline<K extends string>(
5952
options: KeyedDeadlineOptions<K>

apps/webapp/app/presenters/v3/QueueRetrievePresenter.server.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ export type SlotHolderFacts = {
4949
consistency: SlotHolderConsistency;
5050
};
5151

52-
// A run can only hold a slot before it reaches a final status. PENDING counts: Redis
53-
// membership is written at admission, before the Postgres status moves on. DELAYED runs
54-
// are not queued at all, so holding a slot is drift.
52+
// A run can only hold a slot before its final status. PENDING counts because Redis
53+
// membership is written at admission, ahead of the Postgres status; DELAYED never queues.
5554
const NON_HOLDING_STATUSES = new Set<TaskRunStatus>([
5655
"DELAYED",
5756
"CANCELED",

apps/webapp/app/routes/api.v1.dashboard-agent.alerts.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ import { logger } from "~/services/logger.server";
2121
import { authenticateUatOrApiRequest } from "~/services/uatRoutePreamble.server";
2222

2323
/**
24-
* `GET` lists this chat's project's watch alerts; `POST` subscribes the user's email. Only the
25-
* agent's delegated user-actor token is accepted. An environment-pinned token fixes the
26-
* environment; an org-wide one lets the request name any environment in its org.
24+
* `GET` lists this chat's watch alerts, `POST` subscribes the user's email. User-actor
25+
* token only; org-wide tokens let the request name any environment in the org.
2726
*/
2827

2928
const ListQuerySchema = z.object({

apps/webapp/app/routes/api.v1.dashboard-agent.watches.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ import {
1313
import { authenticateUatOrApiRequest } from "~/services/uatRoutePreamble.server";
1414

1515
/**
16-
* Programmatic watch creation (MCP). Only the agent's delegated user-actor token is accepted.
17-
* An environment-pinned token fixes the environment; an org-wide one lets the body name any
18-
* environment in its org, re-authorized against the user's membership, and falls back to the
19-
* token's own environment when the body names none. Never the chat's stored context.
16+
* Programmatic watch creation (MCP). User-actor token only; org-wide tokens let the body
17+
* name any environment in the org, re-authorized against membership. Never the chat's stored context.
2018
*/
2119

2220
const BodySchema = z.object({

apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.dashboard-agent.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,8 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
406406
);
407407
}
408408
} catch (error) {
409-
// Both starts are one create-session-and-trigger round trip, so a rejection usually
410-
// means no handover was dispatched and no message was sent: a session the call did
411-
// create in spite of the error idles out having done nothing. The `withTimeout` above
412-
// is the exception — its trigger can still land after we've given up and soft-deleted
413-
// the chat below, orphaning a live session on a chat the user never sees again; the
414-
// run is otherwise harmless and the `in` proxy's chat lookup treats it as missing.
415-
// Swallowed so the start's own error is what surfaces and gets logged.
409+
// A rejection usually means nothing was dispatched, except `withTimeout`'s trigger
410+
// can still land after the soft-delete below; the `in` proxy just treats it as missing.
416411
await softDeleteChat(dashboardAgentDb, {
417412
chatId,
418413
userId,

apps/webapp/app/services/dashboardAgentTokenScope.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
/**
2-
* Which environment a dashboard-agent turn may act in, from the token's claims alone.
3-
*
4-
* An org-wide token draws the boundary at its organization: the request may name any
5-
* environment inside it, and the token's own environment is only the default when it names
6-
* none. `organizationId` comes back with the target, for the caller to check the resolved
7-
* environment against — a request id is never authorization on its own.
8-
*
9-
* A token with no organization is the legacy environment-pinned form: its one environment,
10-
* which the request can echo but never replace.
2+
* Org-wide tokens allow any environment in their org (default: the token's own); legacy
3+
* tokens are pinned to one. `organizationId` comes back so the caller still checks it.
114
*/
125

136
export type AgentTokenScope =

apps/webapp/app/services/dashboardAgentWatchRunChecks.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ const FINAL_STATUSES = new Set([
3030
]);
3131

3232
/**
33-
* Statuses whose `queuedAt` is a leftover from the first enqueue, since resume/retry
34-
* re-enqueues don't restamp it, so a wait computed from it isn't this attempt's. Exported
35-
* so other run-facing readers can derive the same reliability signal from the raw status
36-
* instead of re-deriving it.
33+
* Statuses whose `queuedAt` is a leftover from the first enqueue (re-enqueues don't restamp
34+
* it). Exported so other run-facing readers can derive the same reliability signal.
3735
*/
3836
export const STALE_QUEUED_AT_STATUSES = new Set([
3937
"WAITING_TO_RESUME",

0 commit comments

Comments
 (0)