agl 43.9.0 → 43.10.0

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.
Files changed (114) hide show
  1. package/changelog.md +12 -0
  2. package/dist_serve/bundle.js +997 -975
  3. package/dist_serve/bundle.js.map +2 -2
  4. package/dist_ts/00_commitinfo_data.js +2 -2
  5. package/dist_ts/aglapi/aglapisurface.document.js +3 -3
  6. package/dist_ts/classes.accountsactions.d.ts +3 -1
  7. package/dist_ts/classes.accountsactions.js +17 -1
  8. package/dist_ts/classes.controller.d.ts +1 -1
  9. package/dist_ts/classes.controller.js +21 -7
  10. package/dist_ts/classes.inferencegateway.js +7 -5
  11. package/dist_ts/classes.inferenceplacement.d.ts +1 -1
  12. package/dist_ts/classes.inferencerouter.d.ts +20 -3
  13. package/dist_ts/classes.inferencerouter.js +37 -10
  14. package/dist_ts/classes.inferenceservice.js +2 -2
  15. package/dist_ts/classes.ticketnotifier.d.ts +2 -2
  16. package/dist_ts/classes.ticketnotifier.js +6 -4
  17. package/dist_ts/classes.ticketstore.d.ts +33 -5
  18. package/dist_ts/classes.ticketstore.js +109 -26
  19. package/dist_ts/classes.workercallers.d.ts +35 -1
  20. package/dist_ts/classes.workercallers.js +139 -28
  21. package/dist_ts/fleet/classes.boardpump.d.ts +1 -1
  22. package/dist_ts/fleet/classes.boardpump.js +4 -2
  23. package/dist_ts/fleet/classes.ticketeffects.d.ts +11 -0
  24. package/dist_ts/fleet/classes.ticketeffects.js +28 -1
  25. package/dist_ts/fleet/classes.workers.d.ts +18 -1
  26. package/dist_ts/fleet/classes.workers.js +49 -8
  27. package/dist_ts/fleet/functions.workervalidation.js +7 -4
  28. package/dist_ts/functions.fleetworkercli.d.ts +3 -1
  29. package/dist_ts/functions.fleetworkercli.js +6 -2
  30. package/dist_ts/functions.inferencecli.js +4 -1
  31. package/dist_ts/functions.mcpfleetworkertools.js +3 -3
  32. package/dist_ts/functions.proxycapacity.d.ts +2 -1
  33. package/dist_ts/functions.proxycapacity.js +6 -3
  34. package/dist_ts/functions.proxycapacitycli.js +2 -2
  35. package/dist_ts/functions.workerprocessproof.d.ts +6 -0
  36. package/dist_ts/functions.workerprocessproof.js +8 -3
  37. package/dist_ts/interfaces.auth.d.ts +1 -1
  38. package/dist_ts/interfaces.auth.js +2 -1
  39. package/dist_ts/interfaces.flexipc.d.ts +3 -1
  40. package/dist_ts/interfaces.flexipc.js +1 -1
  41. package/dist_ts_authswitch/authority-contract.d.ts +25 -0
  42. package/dist_ts_authswitch/authority-contract.js +1 -1
  43. package/dist_ts_authswitch/authority-overview.d.ts +7 -0
  44. package/dist_ts_authswitch/authority-overview.js +10 -6
  45. package/dist_ts_authswitch/authority-placement.d.ts +5 -2
  46. package/dist_ts_authswitch/authority-placement.js +6 -3
  47. package/dist_ts_authswitch/classes.authoritybroker.d.ts +6 -0
  48. package/dist_ts_authswitch/classes.authoritybroker.js +26 -1
  49. package/dist_ts_authswitch/classes.authoritycli.d.ts +1 -0
  50. package/dist_ts_authswitch/classes.authoritycli.js +50 -4
  51. package/dist_ts_authswitch/classes.authorityclient.d.ts +3 -1
  52. package/dist_ts_authswitch/classes.authorityclient.js +9 -4
  53. package/dist_ts_authswitch/classes.authoritydaemon.js +7 -1
  54. package/dist_ts_authswitch/classes.authoritydatabase.js +5 -1
  55. package/dist_ts_authswitch/classes.authoritymodels.d.ts +7 -0
  56. package/dist_ts_authswitch/classes.authoritymodels.js +13 -6
  57. package/dist_ts_interfaces/fleetworkers.d.ts +26 -1
  58. package/dist_ts_interfaces/fleetworkers.js +1 -1
  59. package/dist_ts_interfaces/interfaces.d.ts +4 -2
  60. package/dist_ts_interfaces/interfaces.js +1 -1
  61. package/dist_ts_interfaces/proxycapacity.d.ts +1 -1
  62. package/dist_ts_interfaces/requests.accounts.d.ts +19 -0
  63. package/dist_ts_interfaces/requests.accounts.js +1 -1
  64. package/dist_ts_interfaces/requests.d.ts +2 -2
  65. package/dist_ts_interfaces/requests.fleetworkers.d.ts +3 -1
  66. package/dist_ts_interfaces/requests.js +1 -1
  67. package/dist_ts_migration/v41_ticketclosedcolumn.js +7 -3
  68. package/docs/authswitch.md +22 -0
  69. package/package.json +1 -1
  70. package/readme.md +54 -3
  71. package/ts/00_commitinfo_data.ts +1 -1
  72. package/ts/aglapi/aglapisurface.document.ts +2 -2
  73. package/ts/classes.accountsactions.ts +25 -0
  74. package/ts/classes.controller.ts +18 -3
  75. package/ts/classes.inferencegateway.ts +6 -4
  76. package/ts/classes.inferenceplacement.ts +1 -1
  77. package/ts/classes.inferencerouter.ts +49 -10
  78. package/ts/classes.inferenceservice.ts +1 -1
  79. package/ts/classes.ticketnotifier.ts +5 -3
  80. package/ts/classes.ticketstore.ts +103 -24
  81. package/ts/classes.workercallers.ts +165 -28
  82. package/ts/fleet/classes.boardpump.ts +3 -2
  83. package/ts/fleet/classes.ticketeffects.ts +25 -0
  84. package/ts/fleet/classes.workers.ts +47 -7
  85. package/ts/fleet/functions.workervalidation.ts +6 -3
  86. package/ts/functions.fleetworkercli.ts +5 -1
  87. package/ts/functions.inferencecli.ts +2 -0
  88. package/ts/functions.mcpfleetworkertools.ts +2 -2
  89. package/ts/functions.proxycapacity.ts +5 -2
  90. package/ts/functions.proxycapacitycli.ts +1 -1
  91. package/ts/functions.workerprocessproof.ts +10 -2
  92. package/ts/interfaces.auth.ts +1 -0
  93. package/ts/interfaces.flexipc.ts +3 -1
  94. package/ts_authswitch/authority-contract.ts +20 -0
  95. package/ts_authswitch/authority-overview.ts +17 -6
  96. package/ts_authswitch/authority-placement.ts +7 -3
  97. package/ts_authswitch/classes.authoritybroker.ts +24 -0
  98. package/ts_authswitch/classes.authoritycli.ts +58 -4
  99. package/ts_authswitch/classes.authorityclient.ts +11 -4
  100. package/ts_authswitch/classes.authoritydaemon.ts +8 -1
  101. package/ts_authswitch/classes.authoritydatabase.ts +3 -0
  102. package/ts_authswitch/classes.authoritymodels.ts +12 -4
  103. package/ts_interfaces/fleetworkers.ts +26 -1
  104. package/ts_interfaces/interfaces.ts +4 -2
  105. package/ts_interfaces/proxycapacity.ts +1 -1
  106. package/ts_interfaces/requests.accounts.ts +17 -0
  107. package/ts_interfaces/requests.fleetworkers.ts +3 -1
  108. package/ts_interfaces/requests.ts +2 -0
  109. package/ts_migration/v41_ticketclosedcolumn.ts +6 -2
  110. package/ts_web/00_commitinfo_data.ts +1 -1
  111. package/ts_web/accounts.templates.ts +12 -2
  112. package/ts_web/classes.accountsreadmodel.ts +42 -6
  113. package/ts_web/elements.accounts.ts +45 -3
  114. package/ts_web/elements.harnesscontrollerapp.ts +6 -1
@@ -3427,6 +3427,8 @@ export class OpenCodeController {
3427
3427
  claudeReleases: (releaseArg) => this.observeClaudeRelease(releaseArg, 'fleet'),
3428
3428
  // No controller event names a native thread; the Inbox reads the fleet connection's requests again.
3429
3429
  onNativeCodexAttention: () => this.inbox?.nativeAttentionChanged('codex'),
3430
+ // The views show a worker whose MCP calls run without its identity, as this controller's worker callers derive it (AGL-1888).
3431
+ callerIdentity: (workerIdArg) => this.workerCallers?.workerCallerIdentity(workerIdArg),
3430
3432
  ...(this.fleetWorkerLaunches ? { callers: this.fleetWorkerLaunches } : {}) });
3431
3433
  // The Driver view's direct reports, an open fleet worker and the session feed follow worker changes and newly observed statuses.
3432
3434
  this.fleetWorkers.watchViews(() => {
@@ -11578,7 +11580,9 @@ export class OpenCodeController {
11578
11580
  // its parent runs, from the same fleet's inventory and registry (AGL-1888).
11579
11581
  identifyClaudeProcess: async (request) => this.fleetWorkers
11580
11582
  ? await this.fleetWorkers.identifyCallerProcess(request)
11581
- : { state: 'refused', check: 'inventory', reason: 'the fleet is not running yet', forGood: false } });
11583
+ : { state: 'refused', check: 'inventory', reason: 'the fleet is not running yet', forGood: false },
11584
+ // A worker shown calling without its identity, or verified again: the fleet's views follow, and its ticket is noticed once per reason.
11585
+ workerIdentityChanged: (workerIdArg, identityArg) => { void this.fleetWorkers?.callerIdentityChanged(workerIdArg, identityArg); } });
11582
11586
  this.workerCallers = workerCallers;
11583
11587
  const mcpControllerHost = new ControllerMcpHost({
11584
11588
  controllerPort: runtimeConfig.controllerPort,
@@ -16846,6 +16850,7 @@ export class OpenCodeController {
16846
16850
  connection.status === 'active'
16847
16851
  || connection.status === 'reauthRequired'
16848
16852
  || connection.status === 'inHostCodex'
16853
+ || connection.status === 'paused'
16849
16854
  ))
16850
16855
  .map((connection) => this.toPublicProviderConnection(connection)),
16851
16856
  runtimeAvailable: response.runtimeAvailable,
@@ -21696,7 +21701,7 @@ export class OpenCodeController {
21696
21701
  /**
21697
21702
  * The usable Flex accounts in the order AGL's account placement takes a new conversation now
21698
21703
  * (`authSwitchPlacementOrder`, a priority account first), judged on each account's usage reading as
21699
- * the inference proxy judges it: an account at its limit or reserve, lapsed, or without a reading it
21704
+ * the inference proxy judges it: an account at its limit or reserve, lapsed, paused by its owner, or without a reading it
21700
21705
  * can be judged on takes none. A conversation keeps its account for its life, so accounts rank by their score and
21701
21706
  * headroom alone, with none counted as in flight. The Claude pool, which the proxy places inside,
21702
21707
  * comes last.
@@ -21738,7 +21743,9 @@ export class OpenCodeController {
21738
21743
  account.renewsAt,
21739
21744
  now,
21740
21745
  account.reserveLiftUntil,
21746
+ account.pausedAt,
21741
21747
  );
21748
+ // Lapsed, or paused by its owner (AGL-1933): no new conversation goes to it.
21742
21749
  if (placement.eligibility === 'never') return undefined;
21743
21750
  return {
21744
21751
  id: providerConnectionId,
@@ -22009,6 +22016,12 @@ export class OpenCodeController {
22009
22016
  remedy: 'accountSettings',
22010
22017
  };
22011
22018
  }
22019
+ if (connection?.status === 'paused') {
22020
+ return {
22021
+ reason: `Session Intelligence uses ${label}, but its account is paused. Resume it in Settings → Accounts.`,
22022
+ remedy: 'accountSettings',
22023
+ };
22024
+ }
22012
22025
  if (connection?.status === 'inHostCodex') {
22013
22026
  return {
22014
22027
  reason: `Session Intelligence uses ${label}, but its account runs this host's Codex. `
@@ -22257,7 +22270,8 @@ export class OpenCodeController {
22257
22270
  : !login
22258
22271
  ? undefined
22259
22272
  : login.health === 'ready' || login.health === 'refreshing' || login.health === 'retry_wait'
22260
- ? 'active'
22273
+ // Paused by its owner (AGL-1933): listed, and not to be chosen until it is resumed.
22274
+ ? accountArg.pausedAt !== null ? 'paused' : 'active'
22261
22275
  : 'reauthRequired';
22262
22276
  if (status === undefined) return [];
22263
22277
  return [{
@@ -26444,6 +26458,7 @@ export class OpenCodeController {
26444
26458
  connectionArg.status !== 'active'
26445
26459
  && connectionArg.status !== 'reauthRequired'
26446
26460
  && connectionArg.status !== 'inHostCodex'
26461
+ && connectionArg.status !== 'paused'
26447
26462
  ) {
26448
26463
  throw new Error('The Flex provider connection is not publicly listable.');
26449
26464
  }
@@ -381,12 +381,12 @@ const codexPlanType = (plansArg: readonly string[]): string | undefined => {
381
381
  };
382
382
 
383
383
  /**
384
- * The session's account cannot serve this client's pool: it left the pool, or the client's account restriction
385
- * leaves it out. The session moves to an account of the pool, as it does from an account at its limit.
384
+ * The session's account cannot serve this client's pool: it left the pool, its owner paused it (AGL-1933), or the
385
+ * client's account restriction leaves it out. The session moves to an account of the pool, as it does from an account at its limit.
386
386
  */
387
387
  const sessionAccountOutsidePool = (errorArg: unknown): boolean => errorArg instanceof InferenceRoutingError
388
388
  && (errorArg.code === 'account_left_pool' || errorArg.code === 'account_outside_restriction'
389
- || errorArg.code === 'account_lapsed');
389
+ || errorArg.code === 'account_lapsed' || errorArg.code === 'account_paused');
390
390
 
391
391
  /**
392
392
  * A Claude session's account takes no request for a reason of its own (`InferenceRoutingError.reason`): no usage reading,
@@ -398,7 +398,9 @@ const sessionAccountUnavailable = (errorArg: unknown, accountIdArg: string): boo
398
398
  /** Why a session's own account refused its request, as the placement journal names it; see `TInferencePlacementReason`. */
399
399
  const placementReason = (errorArg: InferenceRoutingError): TInferencePlacementReason =>
400
400
  errorArg.reason !== undefined ? 'unavailable'
401
- : errorArg.code === 'account_left_pool' ? 'left_pool'
401
+ // A paused account left the pool for as long as it is paused; the journal has no reason of its own for it, so an
402
+ // AGL that reads the journal after a rollback knows every reason in it.
403
+ : errorArg.code === 'account_left_pool' || errorArg.code === 'account_paused' ? 'left_pool'
402
404
  : errorArg.code === 'account_outside_restriction' ? 'outside_restriction'
403
405
  : errorArg.code === 'account_lapsed' ? 'lapsed' : errorArg.accountLimit ?? 'exhausted';
404
406
 
@@ -5,7 +5,7 @@ import { inferenceProviders, type TInferenceProvider } from './functions.proxyco
5
5
  * Why a session was placed on its account. `new`: the session had no account. Every other reason moved a session off
6
6
  * the account it had: `exhausted` (a window used up, or the provider refusing until a time it named), `reserved` (its
7
7
  * usage threshold reached), `cooling` (resting after a provider 429 another request met), `provider_429` (the provider
8
- * refused this request with a 429), `left_pool` (removed, signed out, or taken by a native tool), `outside_restriction`
8
+ * refused this request with a 429), `left_pool` (removed, signed out, taken by a native tool, or paused by its owner), `outside_restriction`
9
9
  * (the client's account restriction leaves it out), `lapsed` (its subscription ended), `unavailable` (an account that
10
10
  * takes no request for a reason of its own: no usage reading, no model list, no access, no such model, or a payment
11
11
  * problem) or `returned` (the session was on an API key, and a subscription of the pool could take its request again).
@@ -89,6 +89,12 @@ export interface IInferenceAccount {
89
89
  * account of the pool without one, as long as it takes the request (`inferencePlacementOrder`).
90
90
  */
91
91
  priorityUntil: string | null;
92
+ /**
93
+ * Since when the owner holds the account paused (`IAuthSwitchAccount.pausedAt`, AGL-1933); `null` while it is not. A
94
+ * paused account is in no pool: no new session goes to it, a session on it moves (`account_paused`), and a request
95
+ * that could reach only paused accounts is refused as `accounts_paused`.
96
+ */
97
+ pausedAt: string | null;
92
98
  /**
93
99
  * An API key's monthly spend limit in micro-dollars (`IAuthSwitchAccount.spendLimitMicroUsd`); `null` without one,
94
100
  * and for a sign-in. It decides only whether a key whose spend the proxy holds no reading of may take work: one with
@@ -756,6 +762,12 @@ export interface IInferenceAccountStatus {
756
762
  * account ranks before every account without one. A proxy of an earlier AGL reports none.
757
763
  */
758
764
  priorityUntil?: string | null;
765
+ /**
766
+ * Since when the owner holds the account paused (`IInferenceAccount.pausedAt`), or `null`: it takes no new session
767
+ * and has no placement rank, whatever `state` says of its usage; `stateText` says it is paused. A proxy of an earlier
768
+ * AGL reports none.
769
+ */
770
+ pausedAt?: string | null;
759
771
  /** The account's placement score in percent per hour (`IAuthSwitchPlacement.score`); `null` without a counted window. */
760
772
  placementScore: number | null;
761
773
  /**
@@ -988,7 +1000,7 @@ const emptySelection = (accountsArg: number, pinnedArg: boolean): ISelectionStat
988
1000
  const accountPlacement = (readingArg: plugins.authswitchAuthority.IAuthSwitchUsageSnapshot['reading'],
989
1001
  accountArg: IInferenceAccount, nowArg: number): plugins.authswitchPlacement.IAuthSwitchPlacement =>
990
1002
  plugins.authswitchPlacement.authSwitchPlacement(readingArg, accountArg.maxUsagePercent, accountArg.lapsesAt,
991
- accountArg.renewsAt, nowArg, accountArg.reserveLiftUntil);
1003
+ accountArg.renewsAt, nowArg, accountArg.reserveLiftUntil, accountArg.pausedAt);
992
1004
 
993
1005
  /** An account of a pool as a new session is placed on it: its credential tier and its rank (`IAuthSwitchPlacementRank`). */
994
1006
  interface IInferencePlacementEntry {
@@ -1056,12 +1068,13 @@ export class InferenceRouter {
1056
1068
  /**
1057
1069
  * The policy's accounts of its provider and credential tiers (`tiers`), and every eligible account's id of that pool:
1058
1070
  * an account absent from both left the pool. An account whose lapse date passed is in neither -- it is never routed to
1059
- * again -- and is named in `lapsed`. A pool that names its credential serves that kind alone: Flex's API-key pool
1071
+ * again -- and is named in `lapsed`. An account its owner holds paused (AGL-1933) is in neither as well, for as long
1072
+ * as it is paused, and is named in `paused`. A pool that names its credential serves that kind alone: Flex's API-key pool
1060
1073
  * never takes a Claude account. One that names none spans both, and a session placed on a key returns to a Claude
1061
1074
  * account once one can take its request.
1062
1075
  */
1063
1076
  private async pool(policyArg: IInferenceRoutingPolicy, signalArg: AbortSignal): Promise<{ accounts: IInferenceAccount[];
1064
- eligible: Set<string>; lapsed: Set<string>; tiers: readonly TInferenceCredential[] }> {
1077
+ eligible: Set<string>; lapsed: Set<string>; paused: Set<string>; tiers: readonly TInferenceCredential[] }> {
1065
1078
  const everyAccount = await this.options.accounts(signalArg);
1066
1079
  this.apiKeyAccounts = new Set(everyAccount.filter((account) => account.credential === 'api_key')
1067
1080
  .map((account) => account.id));
@@ -1074,7 +1087,9 @@ export class InferenceRouter {
1074
1087
  && !(policyArg.claudeCode && accountArg.credential === 'api_key' && !accountArg.claudeCode);
1075
1088
  const lapsed = new Set(everyAccount.filter((account) => inPool(account)
1076
1089
  && plugins.authswitchPlacement.authSwitchAccountLifecycle(account.lapsesAt, now) === 'lapsed').map((account) => account.id));
1077
- const allAccounts = everyAccount.filter((account) => inPool(account) && !lapsed.has(account.id));
1090
+ const paused = new Set(everyAccount.filter((account) => inPool(account) && !lapsed.has(account.id)
1091
+ && account.pausedAt !== null).map((account) => account.id));
1092
+ const allAccounts = everyAccount.filter((account) => inPool(account) && !lapsed.has(account.id) && !paused.has(account.id));
1078
1093
  const accounts = allAccounts.filter((account) => !policyArg.accountIds || policyArg.accountIds.includes(account.id));
1079
1094
  if (accounts.length > 64) throw new InferenceRoutingError(503, 'pool_too_large',
1080
1095
  'Select at most 64 accounts for this gateway.');
@@ -1085,21 +1100,38 @@ export class InferenceRouter {
1085
1100
  for (const id of this.cooldowns.keys()) if (!known.has(id)) this.cooldowns.delete(id);
1086
1101
  for (const id of this.modelCooldowns.keys()) if (!known.has(id)) this.modelCooldowns.delete(id);
1087
1102
  for (const id of this.noted.keys()) if (!known.has(id)) this.noted.delete(id);
1088
- return { accounts, eligible: new Set(allAccounts.map((account) => account.id)), lapsed, tiers };
1103
+ return { accounts, eligible: new Set(allAccounts.map((account) => account.id)), lapsed, paused, tiers };
1089
1104
  }
1090
1105
 
1091
1106
  /**
1092
1107
  * The pool for one request of a session served by `accountIdArg`, which it refuses when that account cannot serve
1093
1108
  * the session any more: one no longer eligible at all -- removed, signed out, or taken by a native tool -- left the
1094
1109
  * pool, and one the policy's account restriction leaves out is outside it, as the operator chose. Either way the
1095
- * session moves to an account of the pool. So it does from an account that lapsed. A plan the policy leaves out keeps
1096
- * the session waiting.
1110
+ * session moves to an account of the pool. So it does from an account that lapsed, and from one its owner paused
1111
+ * (`account_paused`). A plan the policy leaves out keeps the session waiting.
1112
+ *
1113
+ * A request that reaches no account only because its accounts are paused -- every account of the pool, or every one
1114
+ * the client's account restriction names, as Flex's chosen account is -- is refused as `accounts_paused`, which says
1115
+ * so and how to end it. Only a request is refused so: the model lists read the pool without it.
1097
1116
  */
1098
1117
  private async sessionPool(policyArg: IInferenceRoutingPolicy, signalArg: AbortSignal,
1099
1118
  accountIdArg: string | undefined): Promise<{ accounts: IInferenceAccount[]; eligible: Set<string>;
1100
1119
  tiers: readonly TInferenceCredential[] }> {
1101
1120
  const pool = await this.pool(policyArg, signalArg);
1121
+ if (!pool.accounts.length) {
1122
+ const paused = [...pool.paused].filter((idArg) => !policyArg.accountIds || policyArg.accountIds.includes(idArg));
1123
+ if (paused.length) {
1124
+ throw new InferenceRoutingError(503, 'accounts_paused', policyArg.accountIds
1125
+ ? `${paused.length === 1 ? 'The account this client uses is' : 'The accounts this client uses are'} paused in AGL `
1126
+ + 'Accounts, so AGL places nothing on ' + (paused.length === 1 ? 'it' : 'them') + '. Resume '
1127
+ + (paused.length === 1 ? 'it' : 'one') + ' there, or choose another account.'
1128
+ : 'Every account of this pool is paused in AGL Accounts, so AGL places nothing on them. Resume one there.');
1129
+ }
1130
+ }
1102
1131
  if (!accountIdArg) return pool;
1132
+ if (pool.paused.has(accountIdArg)) {
1133
+ throw new InferenceRoutingError(503, 'account_paused', 'The account serving this session is paused by its owner.');
1134
+ }
1103
1135
  if (pool.lapsed.has(accountIdArg)) {
1104
1136
  throw new InferenceRoutingError(503, 'account_lapsed', 'The account serving this session lapsed; its subscription ended.');
1105
1137
  }
@@ -2034,7 +2066,7 @@ export class InferenceRouter {
2034
2066
  public accountStatus(accountsArg: readonly IInferenceAccount[],
2035
2067
  heldArg: (accountIdArg: string) => plugins.authswitchAuthority.IAuthSwitchUsageSnapshot | undefined): IInferenceAccountStatus[] {
2036
2068
  const now = this.now();
2037
- const statuses = accountsArg.map((account): IInferenceAccountStatus => {
2069
+ const judge = (account: IInferenceAccount): IInferenceAccountStatus => {
2038
2070
  const apiKey = account.credential === 'api_key';
2039
2071
  // A key's usage is its month's spend, with the payment problem the account service holds on it.
2040
2072
  const held = heldArg(account.id);
@@ -2048,6 +2080,7 @@ export class InferenceRouter {
2048
2080
  lifecycle: placement.lifecycle, lapsesAt: account.lapsesAt,
2049
2081
  renewal: plugins.authswitchRenewal.authSwitchRenewal(account.renewsAt, now),
2050
2082
  priorityUntil: plugins.authswitchPriority.authSwitchPriorityUntil(account.priorityUntil, now),
2083
+ pausedAt: account.pausedAt,
2051
2084
  placementScore: placement.score, placementRank: null,
2052
2085
  lastResort: placement.eligibility === 'last_resort', claudeCode: account.claudeCode,
2053
2086
  readingSource: held?.observation ? 'headers' as const : held?.reading ? 'poll' as const : null,
@@ -2083,14 +2116,20 @@ export class InferenceRouter {
2083
2116
  : 'available (no usage reported)'}${this.modelRestText(account.id, held, now)}`,
2084
2117
  plan: limits.plan || null, headroom: limits.limit?.headroom ?? null, crossing: limits.limit?.crossing ?? [],
2085
2118
  resetAt: state === 'cooling' ? new Date(cooldown).toISOString() : limits.limit?.resetAt ?? null };
2119
+ };
2120
+ const statuses = accountsArg.map((account): IInferenceAccountStatus => {
2121
+ const judged = judge(account);
2122
+ // Paused by its owner (AGL-1933): it says so instead of what its usage would allow, and names no reset to wait for.
2123
+ return account.pausedAt === null ? judged : { ...judged, resetAt: null,
2124
+ stateText: `paused by the owner since ${account.pausedAt}; takes no new session until it is resumed` };
2086
2125
  });
2087
2126
  // Each provider's accounts that take a new session now, in the order placement takes them: a priority account first,
2088
- // then the best credential tier.
2127
+ // then the best credential tier. A paused account takes none.
2089
2128
  const order = inferencePlacementOrder((accountIdArg) => this.active.get(accountIdArg) ?? 0);
2090
2129
  const tiers = inferenceCredentialTiers(undefined);
2091
2130
  for (const provider of new Set(statuses.map((statusArg) => statusArg.provider))) {
2092
2131
  statuses.filter((statusArg) => statusArg.provider === provider && statusArg.state === 'available'
2093
- && statusArg.lifecycle !== 'lapsed')
2132
+ && statusArg.lifecycle !== 'lapsed' && !statusArg.pausedAt)
2094
2133
  .map((statusArg) => ({ status: statusArg, tier: tiers.indexOf(statusArg.credential), rank: { id: statusArg.id,
2095
2134
  priority: Boolean(statusArg.priorityUntil), score: statusArg.placementScore, lastResort: statusArg.lastResort,
2096
2135
  headroom: statusArg.headroom ?? unknownHeadroom } }))
@@ -159,7 +159,7 @@ export class InferenceService {
159
159
  const login = findAuthorityGatewayLogin(projection, account.id);
160
160
  return pool ? [{ id: account.id, label: account.label, revision: String(account.revision), providerId: pool.provider,
161
161
  credential: pool.credential, maxUsagePercent: account.maxUsagePercent, reserveLiftUntil: account.reserveLiftUntil, lapsesAt: account.lapsesAt,
162
- renewsAt: account.renewsAt, priorityUntil: account.priorityUntil, spendLimitMicroUsd: account.spendLimitMicroUsd, claudeCode: account.claudeCode, loginId: typeof login === 'string' ? null : login.id }] : [];
162
+ renewsAt: account.renewsAt, priorityUntil: account.priorityUntil, pausedAt: account.pausedAt, spendLimitMicroUsd: account.spendLimitMicroUsd, claudeCode: account.claudeCode, loginId: typeof login === 'string' ? null : login.id }] : [];
163
163
  });
164
164
  }
165
165
 
@@ -3,6 +3,7 @@ import type { IFleetEvent } from '../ts_interfaces/fleetworkers.js';
3
3
  import type { ITicketChange, ITicketObservation } from './classes.ticketstore.js';
4
4
  import { quoteAgentMessageHeaderText } from './functions.agentmessage.js';
5
5
  import { boardPumpActor } from './fleet/classes.boardpump.js';
6
+ import { workerIdentityActor } from './fleet/classes.ticketeffects.js';
6
7
 
7
8
  export interface ITicketNotifierOptions {
8
9
  /** Steers the live native session (`harness:nativeId`) with the notice; rejects when it was not admitted. */
@@ -124,8 +125,8 @@ export const ticketNoticeText = (changesArg: ITicketChange[], recipientArg: stri
124
125
  /**
125
126
  * Tells assignees about changes others make to their tickets, and the session that asked a question about its answer. Changes to one ticket for one session gather for a
126
127
  * short window and then go out as one notice, at most one per interval, steered into the live session. A session
127
- * never hears of its own changes, and nobody hears of the board pump's. Every change but the driver's own also goes to the
128
- * fleet event stream.
128
+ * never hears of its own changes, and nobody hears of the board pump's or of a notice that a worker calls without its
129
+ * identity. Every change but the driver's own also goes to the fleet event stream.
129
130
  */
130
131
  export class TicketNotifier {
131
132
  private readonly batches = new Map<string, ITicketNoticeBatch>();
@@ -146,7 +147,8 @@ export class TicketNotifier {
146
147
  // A reorder is the side effect of another ticket's move; the mover's ticket carries the notice.
147
148
  if (change.action === 'reordered') continue;
148
149
  // The board pump tells the driver through its own event; steering the assignee would start the work it must leave to the driver.
149
- if (change.actor.id === boardPumpActor.id) continue;
150
+ // A notice that a worker calls without its identity is for the owner: it would only wake the worker it is about.
151
+ if (change.actor.id === boardPumpActor.id || change.actor.id === workerIdentityActor.id) continue;
150
152
  if (change.actor.role !== 'driver' && change.origin === undefined) {
151
153
  // A comment's whole text is the comment, which the driver reads by its id.
152
154
  const comment = change.action === 'commented' ? change.changes.comment?.after as ITicketComment | undefined : undefined;
@@ -23,6 +23,14 @@ const mutableOperations = new Set<TTicketOperation>(['create', 'update', 'move',
23
23
  * entries it returns, whatever its `limit`, so a page cut by the byte budget does not read `limit` records.
24
24
  */
25
25
  export const ticketHistoryBatch = 16;
26
+ /**
27
+ * The gap a ticket placed at the end of a column leaves after the last one (AGL-1907). A ticket's `order` is a sparse,
28
+ * non-negative integer sort key: only its value relative to the other tickets of its column means anything, never a
29
+ * position or a count. A placement before another ticket takes the integer halfway into the gap before it.
30
+ */
31
+ export const ticketOrderStride = 1024;
32
+ /** The order range the first read of a run of tickets that leave no integer free covers; each further read doubles it, up to `ticketOrderRunSpan.maximum`. */
33
+ const ticketOrderRunSpan = { first: 16, maximum: 512 } as const;
26
34
 
27
35
  /** One change a committed ticket transaction made, or an edit it refused as stale. */
28
36
  export interface ITicketChange {
@@ -534,10 +542,65 @@ export class TicketStore {
534
542
  return await TicketModel.exact.findStoredOne({ id: ticketIdArg }, { session: sessionArg });
535
543
  }
536
544
 
537
- /** The tickets of one column, by id; the board's `ticket_column_order` index serves it. */
538
- private async columnTickets(columnIdArg: ITicket['columnId'], sessionArg: TSession): Promise<TTicketStored[]> {
539
- return await this.paged((afterArg) => TicketModel.exact.findStored({ filter: { 'ticket.columnId': columnIdArg,
540
- ...(afterArg ? { id: { $gt: afterArg } } : {}) }, sort: { id: 1 }, limit: 500, session: sessionArg }));
545
+ /**
546
+ * The ticket last in a column, `excludeArg` (the ticket being placed) left out: one document, `ticket_column_order`
547
+ * read backwards. The store keeps the orders of a column distinct, so the last order is the column's end.
548
+ */
549
+ private async lastInColumn(columnIdArg: ITicket['columnId'], excludeArg: string | undefined, sessionArg: TSession): Promise<TTicketStored | undefined> {
550
+ return (await TicketModel.exact.findStored({ filter: { 'ticket.columnId': columnIdArg,
551
+ ...(excludeArg === undefined ? {} : { id: { $ne: excludeArg } }) }, sort: { 'ticket.order': -1 }, limit: 1, session: sessionArg }))[0];
552
+ }
553
+
554
+ /**
555
+ * The order a ticket placed at the end of a column takes: `ticketOrderStride` after the last one's, or
556
+ * `ticketOrderStride` in an empty column.
557
+ */
558
+ private async columnEnd(columnIdArg: ITicket['columnId'], excludeArg: string | undefined, sessionArg: TSession): Promise<{ last?: TTicketStored; order: number }> {
559
+ const last = await this.lastInColumn(columnIdArg, excludeArg, sessionArg);
560
+ return { ...(last ? { last } : {}), order: (last?.ticket.order ?? 0) + ticketOrderStride };
561
+ }
562
+
563
+ /**
564
+ * Where a ticket goes before an anchor at order `anchorArg` when the ticket before it holds `previousArg` (−1 for none)
565
+ * and no integer is free between them: the shorter of two runs moves by one. Either the anchor and the tickets right
566
+ * above it move up to the first integer none of them holds, and the ticket takes the anchor's order (`step` 1), or the
567
+ * ticket before the anchor and those right below it move down to the first free integer from 0 on, and the ticket
568
+ * takes that one's order (`step` −1); with every integer from 0 to `previousArg` held, only the first is possible.
569
+ * `excludeArg`, the ticket being placed, is left out of both, so its own order is free on either side. Both runs are
570
+ * read by order range through `ticket_column_order`, nearest the anchor first, one range of each per round, each round
571
+ * twice the last (at most 512 orders). The rounds stop when the first run ends, which is the shorter, so the longer
572
+ * side is read no further than the shorter run needs, never to the column's end. A range holds every ticket of its orders.
573
+ */
574
+ private async orderShift(columnIdArg: ITicket['columnId'], previousArg: number, anchorArg: number, excludeArg: string,
575
+ sessionArg: TSession): Promise<{ order: number; step: 1 | -1; run: TTicketStored[] }> {
576
+ /** Each run: its tickets nearest the anchor first, the next order it reads, and whether that order is free (`ended`). */
577
+ const up = { run: [] as TTicketStored[], next: anchorArg, ended: false };
578
+ const down = { run: [] as TTicketStored[], next: previousArg, ended: false, blocked: previousArg < 0 };
579
+ const range = (orderArg: Record<string, number>, sortArg: 1 | -1) => TicketModel.exact.findStored({ filter: {
580
+ 'ticket.columnId': columnIdArg, 'ticket.order': orderArg, id: { $ne: excludeArg } }, sort: { 'ticket.order': sortArg }, session: sessionArg });
581
+ for (let span: number = ticketOrderRunSpan.first; ; span = Math.min(span * 2, ticketOrderRunSpan.maximum)) {
582
+ const upEnd = up.next + span;
583
+ for (const record of await range({ $gte: up.next, $lt: upEnd }, 1)) {
584
+ if (record.ticket.order > up.next) break;
585
+ up.run.push(record);
586
+ up.next = record.ticket.order + 1;
587
+ }
588
+ up.ended = up.next < upEnd;
589
+ if (!down.blocked) {
590
+ // Orders below 0 are not free: a run that reaches −1 cannot move down.
591
+ const downEnd = Math.max(down.next - span, -1);
592
+ for (const record of await range({ $lte: down.next, $gt: downEnd }, -1)) {
593
+ if (record.ticket.order < down.next) break;
594
+ down.run.push(record);
595
+ down.next = record.ticket.order - 1;
596
+ }
597
+ down.ended = down.next > downEnd;
598
+ down.blocked = !down.ended && down.next < 0;
599
+ }
600
+ // Both read as many orders this round, so a run still going is at least as long as one that ended.
601
+ if (up.ended && (!down.ended || up.run.length <= down.run.length)) return { order: anchorArg, step: 1, run: up.run };
602
+ if (down.ended) return { order: previousArg, step: -1, run: down.run };
603
+ }
541
604
  }
542
605
 
543
606
  private async paged<TRecord extends { id: string }>(pageArg: (afterArg: string | undefined) => Promise<TRecord[]>): Promise<TRecord[]> {
@@ -795,9 +858,11 @@ export class TicketStore {
795
858
 
796
859
  /**
797
860
  * Each operation reads what it decides on and nothing more: the listing operations (list, board, search, page, overview) read the whole board and every
798
- * open question; create the parent and the destination column's count; move the source and destination columns;
799
- * update the ticket, its parent and, when the project changes, its children; every other operation one ticket, and
800
- * get one page of its history or, with `commentId`, that one comment. The board document's revision transition in the caller orders every mutation.
861
+ * open question; create the parent and the last ticket of its column; move the ticket and, in the destination, the
862
+ * last ticket or the anchor and the ticket before it, plus, only when no integer is free between them, both sides of
863
+ * them a range at a time until the shorter run ends (never the column it leaves, which it does not write either);
864
+ * update the ticket, its parent and, when the project changes, its children; every other operation one ticket, and get
865
+ * one page of its history or, with `commentId`, that one comment. The board document's revision transition in the caller orders every mutation.
801
866
  */
802
867
  private async perform(methodArg: TTicketOperation, requestArg: TTicketRequest<TTicketOperation>, actorArg: ITicketActor | undefined,
803
868
  sessionArg: TSession, nowArg: string, sequenceArg: number,
@@ -849,7 +914,7 @@ export class TicketStore {
849
914
  const id = `AGL-${sequenceArg}`;
850
915
  const ticket: ITicket = { id, key: id, revision: 1, project: input.project, kind: input.kind ?? 'task', title: input.title,
851
916
  description: input.description ?? '', ...(input.parentId ? { parentId: input.parentId } : {}), columnId,
852
- order: await TicketModel.exact.count({ 'ticket.columnId': columnId }, { session: sessionArg }),
917
+ order: (await this.columnEnd(columnId, undefined, sessionArg)).order,
853
918
  priority: input.priority ?? 'normal', ...(input.assignee ? { assignee: input.assignee } : {}), labels: input.labels ?? [], links: [],
854
919
  ...(input.releasePlan ? { releasePlan: input.releasePlan } : {}),
855
920
  ...(input.maintenanceWindow ? { maintenanceWindow: input.maintenanceWindow } : {}),
@@ -1046,23 +1111,37 @@ export class TicketStore {
1046
1111
  if (ticket.columnId !== input.columnId) this.requireEvidence(ticket, input.columnId);
1047
1112
  // Landed code ships with the tag that holds it: closing its ticket would drop it from release and deploy tracking.
1048
1113
  if (ticket.columnId === 'landed' && input.columnId === 'closed') throw new TicketError('ticket_closed_landed', ticketErrorMessages.ticket_closed_landed);
1049
- const destination = (await this.columnTickets(input.columnId, sessionArg)).filter((recordArg) => recordArg.id !== ticketId)
1050
- .sort((leftArg, rightArg) => leftArg.ticket.order - rightArg.ticket.order);
1051
- const index = input.beforeTicketId === undefined ? destination.length : destination.findIndex((recordArg) => recordArg.id === input.beforeTicketId);
1052
- if (index < 0) throw new TicketError('ticket_move_anchor_invalid', 'The before-ticket must belong to the destination column.');
1053
- destination.splice(index, 0, current);
1054
- const source = ticket.columnId === input.columnId ? [] : (await this.columnTickets(ticket.columnId, sessionArg))
1055
- .filter((recordArg) => recordArg.id !== ticketId)
1056
- .sort((leftArg, rightArg) => leftArg.ticket.order - rightArg.ticket.order);
1057
- const changed: ITicket[] = [];
1058
- for (const group of [destination, source]) {
1059
- for (const [order, record] of group.entries()) {
1060
- const columnId = group === destination ? input.columnId : ticket.columnId;
1061
- if (record.ticket.order === order && record.ticket.columnId === columnId) continue;
1062
- const next = { ...record.ticket, columnId, order };
1063
- changed.push(await this.save(record, next, actorArg, sessionArg,
1064
- record.id === ticketId ? 'moved' : 'reordered', nowArg, trackArg, revisionArg));
1114
+ // Orders are sparse (AGL-1907): the column a ticket leaves is neither read nor written, and a place in the destination
1115
+ // costs the ticket's own write unless no integer is free before its anchor. A ticket already in place writes nothing.
1116
+ const sameColumn = ticket.columnId === input.columnId;
1117
+ // The order the ticket takes and, when no integer is free before its anchor, the run that moves by one to free it.
1118
+ let order: number;
1119
+ let shift: { step: 1 | -1; run: TTicketStored[] } = { step: 1, run: [] };
1120
+ if (input.beforeTicketId === undefined) {
1121
+ const end = await this.columnEnd(input.columnId, ticketId, sessionArg);
1122
+ if (sameColumn && (end.last === undefined || end.last.ticket.order < ticket.order)) return { tickets: [] };
1123
+ order = end.order;
1124
+ } else {
1125
+ const anchor = await this.ticket(input.beforeTicketId, sessionArg);
1126
+ if (anchor?.ticket.columnId !== input.columnId) {
1127
+ throw new TicketError('ticket_move_anchor_invalid', 'The before-ticket must belong to the destination column.');
1065
1128
  }
1129
+ const next = anchor.ticket.order;
1130
+ const previous = (await TicketModel.exact.findStored({ filter: { 'ticket.columnId': input.columnId, 'ticket.order': { $lt: next },
1131
+ id: { $ne: ticketId } }, sort: { 'ticket.order': -1 }, limit: 1, session: sessionArg }))[0]?.ticket.order ?? -1;
1132
+ if (sameColumn && previous < ticket.order && ticket.order < next) return { tickets: [] };
1133
+ if (next - previous >= 2) order = previous + Math.floor((next - previous) / 2);
1134
+ else {
1135
+ // No integer is free before the anchor: the shorter run on either side of it moves by one.
1136
+ const placed = await this.orderShift(input.columnId, previous, next, ticketId, sessionArg);
1137
+ order = placed.order;
1138
+ shift = placed;
1139
+ }
1140
+ }
1141
+ const changed = [await this.save(current, { ...ticket, columnId: input.columnId, order }, actorArg, sessionArg, 'moved', nowArg, trackArg, revisionArg)];
1142
+ for (const record of shift.run) {
1143
+ changed.push(await this.save(record, { ...record.ticket, order: record.ticket.order + shift.step }, actorArg, sessionArg,
1144
+ 'reordered', nowArg, trackArg, revisionArg));
1066
1145
  }
1067
1146
  await this.countOpenQuestions(trackArg, sessionArg, changed.map((ticketArg) => ticketArg.id));
1068
1147
  return { tickets: changed.map((ticketArg) => this.visible(ticketArg, actorArg, trackArg)) };