@koalaauto/agentchannel 3.94.0 → 3.95.1

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.
@@ -179,10 +179,6 @@ export function unseenReplies(messages, myId, seen) {
179
179
  }
180
180
  /** A task handed back this many times for an account's usage or rate limit then fails normally. */
181
181
  const ACCOUNT_RELEASES = 3;
182
- export function budgetBlocked(me) {
183
- const budget = Number(me.budget_usd ?? 0);
184
- return budget > 0 && Number(me.spent_usd ?? 0) >= budget;
185
- }
186
182
  /** How often the runner lists the runtime's models again (besides at start and after a rejected model). */
187
183
  export const MODELS_EVERY_MS = 24 * 60 * 60_000;
188
184
  export class Runner {
@@ -321,7 +317,6 @@ export class Runner {
321
317
  if (me.role === 'system' && (await this.systemInCheckout()))
322
318
  return;
323
319
  // New tasks.
324
- const blocked = budgetBlocked(me);
325
320
  const now = Date.now();
326
321
  const waiting = new Set(inbox.tasks_to_me.map((t) => t.id));
327
322
  for (const id of this.readAhead.keys())
@@ -333,10 +328,6 @@ export class Runner {
333
328
  const sentAt = Date.parse(String(t.created ?? '').replace(' ', 'T'));
334
329
  if (this.o.claimDelayMs && sentAt && now - sentAt < this.o.claimDelayMs)
335
330
  continue;
336
- if (blocked) {
337
- await this.notifyBudget(t, me);
338
- continue;
339
- }
340
331
  if (now < this.accountPausedUntil)
341
332
  continue; // the account cannot run: it is tried again when the pause is over
342
333
  // a code task waits for its owner to take it over (owner-pulls-tasks.md): read each new one ahead first, then work only what
@@ -655,22 +646,6 @@ export class Runner {
655
646
  this.modelsBusy = false;
656
647
  }
657
648
  }
658
- async notifyBudget(t, me) {
659
- if (this.state.runs.budgetNotified[t.id])
660
- return;
661
- try {
662
- await this.o.client.postMessage(t.id, {
663
- kind: 'decision_request',
664
- topic: 'budget',
665
- body: `Budget reached for agent ${me.name}: spent $${Number(me.spent_usd ?? 0).toFixed(2)} of $${Number(me.budget_usd).toFixed(2)}. The task was not started. An admin must raise the budget (this decision is informational).`,
666
- });
667
- }
668
- catch (e) {
669
- this.log(`budget notice for ${t.id} failed: ${e?.message ?? e}`);
670
- }
671
- this.state.runs.budgetNotified[t.id] = new Date().toISOString();
672
- this.state.saveRuns();
673
- }
674
649
  /**
675
650
  * Cancel running jobs whose task went terminal; forget parked runs of
676
651
  * terminal tasks; keep parked leases alive; and (C1) resume a parked run
@@ -881,7 +856,7 @@ export class Runner {
881
856
  return this.runAnswer(job.question, entry);
882
857
  }
883
858
  /**
884
- * The agent's own record (permission, network allowlist, budget), read again when it is older than ME_TTL_MS: an admin who
859
+ * The agent's own record (permission, network allowlist), read again when it is older than ME_TTL_MS: an admin who
885
860
  * lowers the permission or narrows net_allow (say, after a suspected injection) is obeyed by the next run, not the next restart.
886
861
  */
887
862
  /**
@@ -1014,12 +989,6 @@ export class Runner {
1014
989
  catch (e) {
1015
990
  if (is401(e))
1016
991
  return this.authFailed(`claim ${taskId}`, e);
1017
- if (e instanceof HubError && e.code === 'budget_exceeded') {
1018
- this.me = await this.o.client.me();
1019
- const t = (await this.o.client.getTask(taskId)).task;
1020
- await this.notifyBudget(t, this.me);
1021
- return;
1022
- }
1023
992
  if (is409(e)) {
1024
993
  this.log(`claim ${taskId}: taken by another run, skipping`);
1025
994
  this.state.drop(taskId);
@@ -1549,6 +1518,27 @@ export class Runner {
1549
1518
  // how it went, told to the hub when the mention is closed: a run that ends with nothing said in the thread is made visible there
1550
1519
  let outcome = { ok: false, error: 'the run did not finish' };
1551
1520
  let recorded;
1521
+ // the run says it is alive, like a task run: a runner that stops (a restart for a new release, a crash) is then missed by the
1522
+ // hub in minutes and the mention is handed out again, instead of the asker hearing "lost" when the token expires two hours later
1523
+ let beat;
1524
+ if (client.mentionHeartbeat) {
1525
+ beat = setInterval(() => {
1526
+ client.mentionHeartbeat(mid, runId).catch((e) => {
1527
+ if (is401(e))
1528
+ return this.authFailed(`mention-heartbeat ${mid}`, e);
1529
+ // a hub without the call yet (or the message was withdrawn): nothing to keep alive
1530
+ if (e instanceof HubError && e.status === 404)
1531
+ return clearInterval(beat);
1532
+ this.log(`mention-heartbeat ${mid}: ${e?.message ?? e}`);
1533
+ // 409: the hub gave this run up and queued the mention again (it heard nothing for minutes); its token is dead, stop it
1534
+ if (is409(e) && !entry.reason) {
1535
+ entry.reason = 'lost';
1536
+ this.taskLog(key, 'heartbeat 409: the run no longer holds the mention; aborting');
1537
+ entry.controller.abort();
1538
+ }
1539
+ });
1540
+ }, this.o.heartbeatMs);
1541
+ }
1552
1542
  try {
1553
1543
  const material = [run.post?.body, run.thread?.body, ...(run.replies ?? []).map((p) => p.body), run.task?.handoff, ...(run.task?.messages ?? []).map((m) => m.body)];
1554
1544
  const docs = structured ? await this.linkedDocs(material, key) : [];
@@ -1595,6 +1585,8 @@ export class Runner {
1595
1585
  throw e;
1596
1586
  }
1597
1587
  finally {
1588
+ if (beat)
1589
+ clearInterval(beat);
1598
1590
  if (!this.fatal)
1599
1591
  await client.mentionEnd?.(mid, runId, outcome).catch((e) => this.log(`mention-end ${mid}: ${e?.message ?? e}`));
1600
1592
  }
@@ -1952,8 +1944,6 @@ export class Runner {
1952
1944
  readRoots: [...this.readRoots(rec.workdir, rec.readRepos, rec.taskId), ...(env.HOME ? [join(env.HOME, '.gitconfig')] : [])],
1953
1945
  ...(env.TMPDIR ? { tmpDir: env.TMPDIR } : {}),
1954
1946
  ...(Array.isArray(me.net_allow) ? { netAllow: me.net_allow } : {}),
1955
- // the agent's budget is a cap on the run too, not only a gate on taking the next task (a run that loops stops at what is left)
1956
- ...(Number(me.budget_usd ?? 0) > 0 ? { maxBudgetUsd: Math.max(0.01, Number(me.budget_usd) - Number(me.spent_usd ?? 0)) + ((sessKey ? this.state.session(sessKey, sessKind) : undefined)?.costTotal ?? 0) } : {}),
1957
1947
  ...(outputSchema ? { outputSchema } : {}),
1958
1948
  onEvent: (e) => {
1959
1949
  lastEvent = Date.now();
@@ -35,8 +35,6 @@ export interface RunsFile {
35
35
  task: string;
36
36
  at: string;
37
37
  } | string>;
38
- /** Tasks that already got the one budget decision_request (§14.6). */
39
- budgetNotified: Record<string, string>;
40
38
  }
41
39
  export interface SessionRef {
42
40
  id: string;
@@ -73,7 +71,7 @@ export declare class RunnerState {
73
71
  get(taskId: string): RunRecord | undefined;
74
72
  put(rec: RunRecord): void;
75
73
  drop(taskId: string): void;
76
- /** Task ids referenced by bookkeeping entries (handled questions, budget notices). */
74
+ /** Task ids referenced by bookkeeping entries (handled questions). */
77
75
  bookkeepingTasks(): string[];
78
76
  /** C8: forget bookkeeping (and sessions) of tasks that are terminal or gone. */
79
77
  pruneTasks(taskIds: string[]): void;
@@ -15,7 +15,7 @@ export class RunnerState {
15
15
  this.runsPath = join(home, 'runs.json');
16
16
  this.sessionsPath = join(home, 'sessions.json');
17
17
  const r = readJson(this.runsPath, {});
18
- this.runs = { runs: r.runs ?? {}, handledQuestions: r.handledQuestions ?? {}, budgetNotified: r.budgetNotified ?? {} };
18
+ this.runs = { runs: r.runs ?? {}, handledQuestions: r.handledQuestions ?? {} };
19
19
  this.sessions = readJson(this.sessionsPath, {});
20
20
  }
21
21
  saveRuns() {
@@ -37,9 +37,9 @@ export class RunnerState {
37
37
  this.saveRuns();
38
38
  }
39
39
  }
40
- /** Task ids referenced by bookkeeping entries (handled questions, budget notices). */
40
+ /** Task ids referenced by bookkeeping entries (handled questions). */
41
41
  bookkeepingTasks() {
42
- const ids = new Set(Object.keys(this.runs.budgetNotified));
42
+ const ids = new Set();
43
43
  for (const v of Object.values(this.runs.handledQuestions))
44
44
  if (typeof v === 'object' && v?.task)
45
45
  ids.add(v.task);
@@ -50,10 +50,8 @@ export class RunnerState {
50
50
  if (!taskIds.length)
51
51
  return;
52
52
  const drop = new Set(taskIds);
53
- for (const id of taskIds) {
54
- delete this.runs.budgetNotified[id];
53
+ for (const id of taskIds)
55
54
  delete this.runs.runs[id];
56
- }
57
55
  for (const [q, v] of Object.entries(this.runs.handledQuestions)) {
58
56
  if (typeof v === 'object' && drop.has(v.task))
59
57
  delete this.runs.handledQuestions[q];
@@ -1,4 +1,4 @@
1
- export declare const VERSION = "3.94.0";
1
+ export declare const VERSION = "3.95.1";
2
2
  /** The npm package (scripts/release.mjs keeps it and VERSION in step with package.json). */
3
3
  export declare const PKG_NAME = "@koalaauto/agentchannel";
4
4
  /**
@@ -1,4 +1,4 @@
1
- export const VERSION = '3.94.0';
1
+ export const VERSION = '3.95.1';
2
2
  /** The npm package (scripts/release.mjs keeps it and VERSION in step with package.json). */
3
3
  export const PKG_NAME = '@koalaauto/agentchannel';
4
4
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalaauto/agentchannel",
3
- "version": "3.94.0",
3
+ "version": "3.95.1",
4
4
  "description": "Hand work between your team's agents (Claude Code, Codex) and follow it in one panel: the ach CLI, MCP server and runner for AgentChannel v2",
5
5
  "keywords": [
6
6
  "agentchannel",