paseo-follow-up 2.0.1-beta.7 → 2.0.1-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "paseo-follow-up",
3
3
  "private": false,
4
- "version": "2.0.1-beta.7",
4
+ "version": "2.0.1-beta.8",
5
5
  "description": "A Paseo plugin that follows every workspace until the work is done: one Home for what needs you, questions you answer anywhere, and repairs that send themselves.",
6
6
  "type": "module",
7
7
  "files": [
package/server/daemon.ts CHANGED
@@ -339,9 +339,12 @@ export class PaseoGateway implements Gateway {
339
339
  /**
340
340
  * Which workspaces Follow-up follows, from the shared directory: no daemon request unless the directory is due, a
341
341
  * parent agent is missing from it, or a loaded agent's history needs reading. `workspaceId` (Track, session start)
342
- * places one workspace and never reads history.
342
+ * places one workspace and never reads history. `scope` (a nudge, a-nudge-costs-its-workspace) places only those
343
+ * workspaces and rescans only their dirty agents: from the turn read still kept (TurnTimeline.since, no daemon read),
344
+ * or, when there is none (the next turn already started, or no turn cursor yet), with its own read of that agent, so
345
+ * nothing a nudge saw is left for the timer's tick to read later.
343
346
  */
344
- async discover(state: State, workspaceId?: string): Promise<DiscoveredWorkspace[]> {
347
+ async discover(state: State, workspaceId?: string, scope?: { workspaces: ReadonlySet<string> }): Promise<DiscoveredWorkspace[]> {
345
348
  await this.histories.load();
346
349
  const now = this.now();
347
350
  const windowMs = this.windowMs = activeWindowMs(state);
@@ -367,9 +370,9 @@ export class PaseoGateway implements Gateway {
367
370
  return this.unknownParents.get(id);
368
371
  };
369
372
  const discovered: DiscoveredWorkspace[] = [];
370
- const scans: { row: DiscoveredWorkspace; agent: Agent; repo: string | null }[] = [];
373
+ const scans: { row: DiscoveredWorkspace; agent: Agent; repo: string | null; kept?: Read }[] = [];
371
374
  const defaults = new Set(projects.filter(p => defaultTracking(p, state.projectDefaults, followsEvery(state))).map(p => p.projectId));
372
- for (const workspace of workspaces.filter(w => !w.archivingAt && (workspaceId ? w.id === workspaceId : (defaults.has(w.projectId ?? "") && !optedOut(state, w.id)) || state.workspaces.some(saved => saved.id === w.id && saved.enable_tracking && !saved.archived)))) {
375
+ for (const workspace of workspaces.filter(w => !w.archivingAt && (!scope || scope.workspaces.has(w.id)) && (workspaceId ? w.id === workspaceId : (defaults.has(w.projectId ?? "") && !optedOut(state, w.id)) || state.workspaces.some(saved => saved.id === w.id && saved.enable_tracking && !saved.archived)))) {
373
376
  const existing = state.workspaces.find(w => w.id === workspace.id);
374
377
  if (existing?.archived) continue;
375
378
  // The Overseer's own workspace is Follow-up's, never tracked or repaired (1.4.0-beta.0).
@@ -397,6 +400,12 @@ export class PaseoGateway implements Gateway {
397
400
  if (row.active) for (const agent of roots) {
398
401
  if (!isLoaded(agent)) continue;
399
402
  const cached = this.histories.get(agent.id);
403
+ if (scope) {
404
+ if (!this.dirty.has(agent.id)) continue;
405
+ const kept = cached?.cursor && cached.history.complete && !cached.history.error ? this.turnTimeline?.since(agent.id, cached.cursor, OVERLAP) : null;
406
+ scans.push({ row, agent, repo, ...(kept ? { kept } : {}) });
407
+ continue;
408
+ }
400
409
  if (!cached || cached.messageAt !== agent.lastUserMessageAt || this.dirty.has(agent.id) || (cached.history.error && now >= cached.retryAt) || (["running", "initializing"].includes(agent.status) && now - cached.at >= 15_000)) scans.push({ row, agent, repo });
401
410
  }
402
411
  discovered.push(row);
@@ -404,19 +413,19 @@ export class PaseoGateway implements Gateway {
404
413
  // Oldest scan first prevents busy workspaces from starving later sessions.
405
414
  scans.sort((a, b) => (this.histories.get(a.agent.id)?.at ?? 0) - (this.histories.get(b.agent.id)?.at ?? 0) || (b.agent.lastUserMessageAt ?? "").localeCompare(a.agent.lastUserMessageAt ?? ""));
406
415
  // Session opening and Track need only ownership metadata. Read transcripts in the poll.
407
- const due = scans.slice(0, workspaceId ? 0 : 4);
416
+ // A scoped pass takes all its scans: they are its workspaces' dirty agents only, most of them kept reads.
417
+ const due = scope ? scans : scans.slice(0, workspaceId ? 0 : 4);
408
418
  const refs = new Map<string, LinkRef[]>();
409
- if (due.length) await this.connect(async client => {
410
- for (const { row: dueRow, agent: listed, repo } of due) {
419
+ const rescan = async (client: Daemon | null, { row: dueRow, agent: listed, repo, kept }: typeof scans[number]) => {
411
420
  // The directory may predate the daemon unloading this agent: confirm it is still loaded before reading,
412
- // since a timeline read would wake it.
413
- const agent = await this.directory.confirmLoaded(client, listed).catch(() => null);
414
- if (!agent) continue;
421
+ // since a timeline read would wake it. A kept read is already in hand and wakes nothing.
422
+ const agent = kept ? listed : await this.directory.confirmLoaded(client!, listed).catch(() => null);
423
+ if (!agent) return;
415
424
  let history: History; let submissions: Submission[] = []; let artifacts: Artifact[] = []; let end: { epoch: string; seq: number } | null = null;
416
425
  this.timelineReads++;
417
426
  const cached = this.histories.get(agent.id);
418
427
  try {
419
- const read = (cached?.cursor && cached.history.complete && !cached.history.error ? this.turnTimeline?.since(agent.id, cached.cursor, OVERLAP) ?? await readSince(client, agent.id, cached.cursor) : null) ?? await readAll(client, agent.id);
428
+ const read = kept ?? (cached?.cursor && cached.history.complete && !cached.history.error ? this.turnTimeline?.since(agent.id, cached.cursor, OVERLAP) ?? await readSince(client!, agent.id, cached.cursor) : null) ?? await readAll(client!, agent.id);
420
429
  end = read.end;
421
430
  const items = read.entries.map(e => e.item);
422
431
  // Linked items ride this read. Best-effort: a throw here must never mark the history unreadable.
@@ -441,8 +450,10 @@ export class PaseoGateway implements Gateway {
441
450
  const at = this.now();
442
451
  this.histories.set(agent.id, { messageAt: agent.lastUserMessageAt, at, failures, retryAt: at + historyRetryDelay(failures), history, submissions, artifacts, cursor: history.error ? null : end });
443
452
  this.dirty.delete(agent.id);
444
- }
445
- });
453
+ };
454
+ for (const s of due.filter(s => s.kept)) await rescan(null, s);
455
+ const reads = due.filter(s => !s.kept);
456
+ if (reads.length) await this.connect(async client => { for (const s of reads) await rescan(client, s); });
446
457
  if (refs.size) try { this.linkRefs?.(refs); } catch { /* linked items are best-effort */ }
447
458
  for (const row of discovered) {
448
459
  const ids = [row.mainAgentId, ...(row.contributorAgentIds ?? [])];
package/server/engine.ts CHANGED
@@ -9,7 +9,7 @@ import { answerRecipients, developerAnswer, syncTaskQuestions, type AnswerAction
9
9
  import { answerMessage, isOpen as isOpenQuestion, type Question } from "../shared/questions";
10
10
  import { reconcileSubmittedStacks } from "./submissions";
11
11
  import { applyDiscovery, interruptionHold, startsWithAutoSend, type DiscoveredWorkspace } from "./discovery";
12
- import { followsByDefault, migrateActiveScope } from "../shared/settings";
12
+ import { ACTIVE_SCOPE_MIGRATION, followsByDefault, migrateActiveScope } from "../shared/settings";
13
13
  import { replyRecorded } from "../shared/communication";
14
14
  import { DeliveryDeferred, ConversationGone, realTimers, withDeadline, type Timers } from "./delivery";
15
15
  import { recordSnapshot } from "./deployment-anchor";
@@ -39,7 +39,8 @@ const GONE_REASON = "The main agent's conversation no longer exists, so Follow-u
39
39
  /** A batch that asks the agent to verify it's finished and declare Done. These never go out on their own. */
40
40
  export { interruptionHold };
41
41
  export interface Gateway {
42
- discover?(state: State, workspaceId?: string): Promise<DiscoveredWorkspace[]>;
42
+ /** `scope`: a nudge's pass, only those workspaces and only reads already in hand (a-nudge-costs-its-workspace). */
43
+ discover?(state: State, workspaceId?: string, scope?: { workspaces: ReadonlySet<string> }): Promise<DiscoveredWorkspace[]>;
43
44
  observe(w: Workspace, fresh?: boolean): Promise<Runtime>;
44
45
  send(w: Workspace, batch: Batch, text: string): Promise<void>;
45
46
  prepareRecovery(w: Workspace, batch: Batch): Promise<{ agentId: string; contextPath: string }>;
@@ -210,7 +211,7 @@ export class Engine {
210
211
  this.gateway.tickStarted?.();
211
212
  const saved = await this.store.snapshot();
212
213
  if (this.stopped) return;
213
- if (this.gateway.discover) {
214
+ if (this.gateway.discover && !(o.affected && await this.discoverScoped(saved, o.affected))) {
214
215
  const discovered = await this.gateway.discover(saved);
215
216
  // Discovery's write copies the whole state; skip it when the rows and the state are what the last one left
216
217
  // (a-tick-copies-the-state-at-most-once), at most OBSERVE_FULL_MS (its time-based rules run then). The rows are
@@ -237,7 +238,8 @@ export class Engine {
237
238
  const hot = keys(active.filter(isHot));
238
239
  const read = o.affected ? active.filter(w => o.affected!.has(w.id)) : active;
239
240
  const observations = await this.github.observe(read.flatMap(w => w.prs), o.background || o.workspaceId ? { background: true, hot, fresh: keys(active.filter(w => w.id === o.workspaceId)) } : {});
240
- for (const original of active) {
241
+ // A nudge observes only its workspaces (a-nudge-costs-its-workspace); the timer's tick observes every active one.
242
+ for (const original of o.affected ? read : active) {
241
243
  if (this.stopped) return;
242
244
  const runtime = await this.gateway.observe(original).catch((): Runtime => ({ busy: false, reason: "Agent state unavailable; refresh will retry", archived: false }));
243
245
  const pruned: Batch[] = [];
@@ -343,6 +345,24 @@ export class Engine {
343
345
  }
344
346
  this.error = null;
345
347
  }
348
+ /**
349
+ * A nudge's discovery (a-nudge-costs-its-workspace): only the nudged workspaces and their dirty agents (the kept turn
350
+ * read, else a read of that agent), each applied with a one-workspace mutation. 2026-11-13 (run Y, the CI live shape): every turn end's nudge ran
351
+ * discovery over all 140 workspaces and a whole-state copy, and the burst grew V8's committed pages from 87 to 165 MB.
352
+ * False when a nudged workspace needs the whole state (not yet saved, parked by the active-scope migration, or the
353
+ * migration not yet run): the full discovery runs instead.
354
+ */
355
+ private async discoverScoped(saved: State, affected: ReadonlySet<string>): Promise<boolean> {
356
+ if (!saved.migrations?.includes(ACTIVE_SCOPE_MIGRATION)) return false;
357
+ if ([...affected].some(id => !saved.workspaces.some(w => w.id === id) || saved.autoSendsParked?.includes(id))) return false;
358
+ const rows = await this.gateway.discover!(saved, undefined, { workspaces: affected });
359
+ for (const row of rows) {
360
+ const current = await this.store.snapshot();
361
+ if (!followsByDefault(current, row) && !current.workspaces.some(w => w.id === row.id && w.enable_tracking && !w.archived)) continue;
362
+ await this.store.mutateWorkspace(row.id, w => applyDiscovery({ ...current, workspaces: current.workspaces.map(x => x.id === w.id ? w : x) }, [row], this.now()));
363
+ }
364
+ return true;
365
+ }
346
366
  async activate(workspaceId: string): Promise<Workspace> {
347
367
  if (this.stopped || !this.gateway.discover) throw new Error("Workspace tracking is unavailable");
348
368
  const rows = await this.gateway.discover(await this.store.snapshot(), workspaceId);