@aragon-agent/cli 0.6.64 → 0.6.66

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/CHANGELOG.md CHANGED
@@ -27,9 +27,35 @@ were written.
27
27
  with any other input cancelling. **Migration:** use `team_stop` (or `/team stop all`) to end a team
28
28
  that outlived its turn, because a later `Esc` no longer does it. Both changes are deliberate: one `Esc`
29
29
  used to mean "clear my mind", and it must not be able to throw away two hours of work.
30
+ - **The Gene Bank's token budget no longer rations anything: it only meters.** `gene.dailyTokens`
31
+ (rolling 24 h) and `gene.curatorTaskTokens` (per task) used to be hard gates, and a nine-minute burst of
32
+ killed attempts could freeze the whole pipeline - the reviewer included - for a day, so experience that
33
+ happened meanwhile was never reviewed and the queue sat parked until the window slid. Adding, revising
34
+ and retiring genes now never waits for a budget. A positive `gene.dailyTokens` / `gene.curatorTaskTokens`
35
+ is **ignored** (including the old `800000` / `80000` an earlier build wrote into your `config.json`),
36
+ `/gene status` shows `Tokens: N used in the last 24 hours (no daily limit)`, and every token is still
37
+ recorded in the run log. What still stops a runaway is unchanged or internal: 20 turns and 240 s per
38
+ task, an internal 400 000-token valve per task (not a setting), the three-failure circuit breaker, and at
39
+ most two attempts for a task that keeps overrunning. **Migration:** `gene.dailyTokens = 0` still means
40
+ "do not spend anything" and still pauses learning. If you deliberately lowered either number to cap
41
+ spending, set `ARAGON_GENE_BUDGET_ENFORCED=1` in the environment to bring the old ceilings back (it is
42
+ an environment variable on purpose, not a setting). Proposals an old build had parked for a budget window
43
+ are woken the first time a curator takes the lease.
30
44
 
31
45
  ### Fixed
32
46
 
47
+ - **Ctrl+Q no longer says "No genes yet" about a library that holds genes.** The default view is your user
48
+ scope plus the current project, published genes only; with 20 genes in the library (3 published in other
49
+ projects, 17 rejected) it showed an empty list and invited you to write the first one. The empty state now
50
+ says what the whole library holds of that type and in which statuses, what this view shows, the way to
51
+ see the rest, and why the curator is paused when it is. `A` switches the list between this project and
52
+ every project (the title says which), the key reference lists it, and the desktop gene list offers
53
+ "Show all projects" and "Include rejected and archived" in the same place. `aragon gene list` marks any
54
+ non-published row with its status (`(rejected)`, `(archived)`), and a plain listing that finds nothing says
55
+ where the genes are instead of "No genes.".
56
+ - **A pause left in the log by one curator no longer outlives it.** A budget pause written by an old holder
57
+ stayed on the activity chip until some item was claimed, so an empty queue showed `curator paused` for good;
58
+ a new lease holder now clears it and logs its own pause if one applies.
33
59
  - **A team run that hit `[Agent] idle watchdog fired` no longer stays dead.** When the model went quiet for
34
60
  the whole idle window (210 s by default), or the retry ladder gave up on a transport failure, the run was
35
61
  over and nothing started another one: the screen said `N steps left; the run ended with an error.
@@ -98,6 +124,41 @@ were written.
98
124
 
99
125
  ### Added
100
126
 
127
+ - **Tiered reconnect: a dropped connection now has three gears instead of one.** Ten fast
128
+ retries and then a dead run was the old behaviour, and it is the wrong shape for the outages
129
+ people actually have. The ladder is now fast, then steady, then a hold: **tier 1** is the fast
130
+ ladder exactly as it shipped (10 tries, 1 s doubling to 30 s, equal jitter, 240 s budget, no
131
+ number changed); **tier 2** takes over when tier 1 gives up and tries once a minute, ten
132
+ times; **tier 3** takes over when tier 2 gives up and tries every five minutes, forever — until it reconnects, you press `Esc`, you send a message, or an
133
+ optional cap you set is reached. The hand-over happens INSIDE one request, so nothing is
134
+ replayed and nothing is re-planned: the conversation, the tool results, the todo list and the
135
+ context stay exactly where they were, and the cost is one re-sent request instead of a re-run
136
+ turn.
137
+
138
+ What you see changed with it: the retry card says which tier it is in (`slow retry 2/10`,
139
+ `attempt 4` with no denominator in the last tier), a long countdown reads `4m12s` instead of
140
+ `252s`, the status line carries a live clock (`Reconnecting 2/10 in 42s`), one notice is
141
+ written when each tier starts (and says "then it gives up" rather than promising a tier that
142
+ `bounded` mode does not have), and a run that recovers across tiers settles as
143
+ `recovered after 13 retries`. Tier 3 offers `Esc to stop waiting`, because by then there is no
144
+ request to cancel — only a wait.
145
+
146
+ Six new keys and three new `/retry` verbs: `retry.reconnect` (`auto` | `full` | `bounded` |
147
+ `off`), `retry.slowIntervalMs`, `retry.slowAttempts`, `retry.holdIntervalMs`,
148
+ `retry.holdMaxMinutes` (`0` = no cap, the default) and `retry.stickyRung` (off by default:
149
+ a request that just recovered in a slow tier starts there for the next two minutes, so a
150
+ twenty-minute outage does not cost four minutes of fast retries on every turn);
151
+ `/retry reconnect <mode>`, `/retry slow <secs>`, `/retry hold <minutes>`, and a `/retry show`
152
+ that reads every number it prints from the live config. **No CLI flag was added**: the shape
153
+ of the ladder is a lasting preference, not a per-invocation one, and `--no-retry` /
154
+ `retry.reconnect: off` remain the two ways to say "one tier, as before".
155
+
156
+ Deliberate boundaries: `aragon -p` and `aragon exec` default to **two** tiers (nobody is there
157
+ to press `Esc`, and a pipeline that waits forever is a worse failure than a clear error);
158
+ subagents **never** escalate, because their requests never carry a ladder and a stuck child
159
+ must not hold a whole fan-out open; every attempt is billed, so the README, `/retry show` and
160
+ the desktop hints all say that a long outage costs close to full price.
161
+
101
162
  - **Prompt profiles: the red team block's wording now lives in an editable Markdown file.** The
102
163
  `<redteam_mode>` block was two halves in one place; now it is two halves in two homes. The **fact**
103
164
  half - the authorization line, `What this mode changes`, the closing boundary sentence - stays in
package/README.md CHANGED
@@ -961,7 +961,7 @@ ignores them rather than rejecting the library):
961
961
  | `/redteam [status\|on\|off\|scope <one line>\|prompt [...]]` | **Red team / security mode.** `/redteam status` prints five lines (effective state, scope, what the confirmation gate is doing, what this mode does NOT lift, and which prompt profile is supplying the wording) in any session, including `--no-redteam`. `on` needs the liability waiver accepted first (`Ctrl+R` opens it); a turn in flight defers the arming to its end, while `off` takes effect immediately and is never refused. `scope` declares the engagement boundary in one line (refused above 200 characters or across lines); no argument clears it. `prompt` manages the editable prompt profile: `status`, `builtin`, `<slug>`, `<path>`, `reload`, `validate [<path>]`, `init [<slug>]`. See [Red team and security mode](#red-team-and-security-mode) and [Prompt profiles](#prompt-profiles) |
962
962
  | `/team [on [n]\|off\|status]` / `/team [-n <n>] [--parts a,b,c] [--read-only] <brief>` | **Force team mode and start now.** `/team <brief>` arms forced team mode and submits that work as a normal turn: the lead analyses and plans it, then calls `task` — the directive, the `<forced_team_mode>` prompt block and a mechanical end-of-turn gate all say so. `/team on [n]` arms (optionally with a count) without submitting, `/team off` leaves - both take effect when the turn ends if one is running - and `/team` reports. The configuration it used to carry (team switch, width, concurrency, supervisor, subagent model) lives in `Settings > Team` |
963
963
  | `/todo [on\|off\|panel on\|off\|follow <mode>\|acceptance on\|off\|reset\|clear\|continue]` | Todo planning: status, the on/off switch, the rail, follow-through, acceptance criteria, and picking an unfinished plan back up |
964
- | `/retry [show\|on\|off\|max <n>]` | API retry: the effective ladder, the on/off switch, the retry count. Takes effect **in the running session**, children included |
964
+ | `/retry [show\|on\|off\|max <n>\|reconnect <mode>\|slow <secs>\|hold <minutes>]` | API retry: the effective ladder (all three tiers, read from the live config), the on/off switch, the fast-tier retry count, the ladder's shape, the slow tier's interval and the optional whole-ladder cap. Takes effect **in the running session**, children included |
965
965
  | `/fast [on\|off\|model <id>\|provider <id>\|same\|review <n\|off>]` | Fast model tier: status and this session's totals, the on/off switch, which model, the review cadence |
966
966
  | `/compact [status\|on\|off\|threshold <n>\|keep <n>\|history\|show <n>\|<instructions>]` | Context compaction: occupancy and this session's totals, the on/off switch, when it fires, how much it keeps. With free text, compacts now and tells the summarizer what to pay attention to |
967
967
  | `/context` | What the context gauge is showing: occupancy split into measured and estimated, the window and **where it came from**, how stale the measurement is, compaction's actual state, and what the session-spend readout includes |
@@ -3881,6 +3881,12 @@ env / `.env` → CLI flags**.
3881
3881
  | `retry.resumeRun` | `true` | Re-run a run the **engine** interrupted - the idle watchdog fired (`[Agent] idle watchdog fired`) or the retry ladder gave up on a transport failure - instead of leaving it dead. Host-side: it redoes a **run** (`controller.continue()`, no message added) where the ladder above retries a **request**, so it never reaches the engine's `RetryPolicy`. Needs no todo plan and ignores `todo.followThrough`. Waits 15 s, then 45 s, then 120 s (cancel with `Esc`), announces the stall and its stage, and is switched off by `retry.enabled: false` / `retry.maxRetries: 0` as well. A rate limit, a rejected key, a context overflow, a run you stopped with `Esc` and a stall that began while a tool was running (unpaired tool calls in the history) are never recovered. `aragon -p` / `aragon exec` get one recovery, 15 s grace. |
3882
3882
  | `retry.maxRunResumes` | `3` | Back-to-back recoveries before control goes back to you, clamped to `[0, 10]`. Cleared by any run that ends without an error. `0` disables recovery and is a real value here, not a typo for the default. |
3883
3883
  | `retry.maxRunResumesPerPrompt` | `10` | Recoveries per prompt, clamped to `[0, 50]`, however well the runs in between went. Cleared **only** by you typing, so a link that dies every other turn still reaches it. `0` disables recovery. |
3884
+ | `retry.reconnect` | `"auto"` | The shape of the reconnect ladder. `auto` = the full three tiers in the app and two tiers under `aragon -p` / `aragon exec`; `full` and `bounded` pin it either way; `off` keeps the fast tier and refuses to escalate. `/retry reconnect <mode>` changes it for the running session. |
3885
+ | `retry.slowIntervalMs` | `60000` | Tier 2's interval, clamped to `[15000, 900000]`. Flat — no multiplier, no jitter — so the countdown on the card is exactly the wait that happens. |
3886
+ | `retry.slowAttempts` | `10` | Tier 2's attempts, clamped to `[0, 30]`. The first attempt of a tier waits too, so `10` means ten waits. `0` is a real value here: it means **do not escalate at all**. |
3887
+ | `retry.holdIntervalMs` | `300000` | Tier 3's interval, clamped to `[60000, 900000]`. Below a minute it would just be tier 2 again, so that is the floor. |
3888
+ | `retry.holdMaxMinutes` | `0` | Cap on the **whole ladder's** wall clock, in minutes, clamped to `[0, 1440]`, counted from the request's first failure — so it **includes** the ~14 minutes the first two tiers can spend. `0` (the default) means no cap: keep trying every five minutes until it reconnects. `/retry hold <minutes>` sets it; `/retry hold 0` clears it. |
3889
+ | `retry.stickyRung` | `false` | Start a request that just recovered in a slow tier at that tier instead of at the fast one, for a two-minute window. Off by default: it changes the rhythm you see, so it ships disabled. |
3884
3890
  | `skills.enabled` | `true` | Master switch for the skill system. |
3885
3891
  | `skills.requireApproval` | `true` | Require a human to approve `skill_install` / `skill_create`. |
3886
3892
  | `skills.catalogMaxBytes` | `6000` | Level 1 catalog ceiling, in UTF-8 **bytes**, clamped to `[500, 40000]`. |
@@ -3900,6 +3906,53 @@ env / `.env` → CLI flags**.
3900
3906
  | `log.redactSecrets` | `true` | Run every record through redaction. Setting it to `false` is the one way to get credentials onto disk, so it prints a warning and has no settings-screen entry. |
3901
3907
  | `log.previewChars` | `512` | How much user content `debug` keeps per field, clamped to `[0, 8192]`. `trace` is never truncated. |
3902
3908
 
3909
+ #### The reconnect ladder
3910
+
3911
+ A dropped connection used to mean ten fast retries and then a dead run. The retries
3912
+ are now **tiered**, and each tier answers a different kind of outage:
3913
+
3914
+ | Tier | Pace | Ends after | Answers |
3915
+ |---|---|---|---|
3916
+ | 1 (fast) | 1 s doubling to 30 s, with jitter | 10 tries or a 240 s budget | a blip: a WiFi hand-off, a 529, a proxy restart |
3917
+ | 2 (slow) | one try every `retry.slowIntervalMs` (1 min) | `retry.slowAttempts` tries (10) | a short outage: a base-station swap, an office proxy reboot |
3918
+ | 3 (hold) | one try every `retry.holdIntervalMs` (5 min) | never — until it reconnects, you press `Esc`, you send a message, or the optional `retry.holdMaxMinutes` cap is reached | a long outage that outlasts a laptop lid |
3919
+
3920
+ The hand-over happens **inside one request**: nothing is replayed and nothing is
3921
+ re-planned, so the conversation, the tool results, the todo list and the context all
3922
+ stay exactly where they were. The worst case before the slow tier starts is about
3923
+ 14 minutes (≈181 s + 660 s); after that it is one attempt every five minutes,
3924
+ forever.
3925
+
3926
+ Three consequences worth knowing before you rely on it:
3927
+
3928
+ - **It is not free.** Every attempt re-sends the request and is billed again. Long
3929
+ outages are charged close to full price — do not count on prompt caching, whose
3930
+ TTL is five minutes and therefore sits on the boundary of tier 3's interval. Set
3931
+ `retry.holdMaxMinutes` if you want a hard ceiling; `0` (the default) means "keep
3932
+ trying until it works".
3933
+ - **`Esc` and a new message both stop a wait.** A run stuck in tier 2 or 3 can end
3934
+ the wait two ways: `Esc` aborts the run, and typing a message stops the wait and
3935
+ sends that message immediately (it is not queued — a queue would deliver it only
3936
+ after the wait, which could be five minutes).
3937
+ - **Pipelines get two tiers.** `aragon -p` and `aragon exec` default to `bounded`
3938
+ because nobody is there to press `Esc`, and a CI job that waits forever on a
3939
+ regional outage is a worse failure than a clear error. Subagents never escalate at
3940
+ all: they share the lead's provider registry but their requests never carry a
3941
+ ladder, so a stuck child cannot hold a whole fan-out open.
3942
+
3943
+ Two more details, both off by default or invisible until you need them:
3944
+
3945
+ - **`retry.stickyRung`** remembers the tier a request recovered in and starts the
3946
+ next request there for two minutes (`retry.stickyRung: true`). Without it, a link
3947
+ that stays down for twenty minutes costs four minutes of already-known-useless
3948
+ fast retries on *every* turn. It is off by default because it changes the rhythm
3949
+ you see, and a recovery on the fast ladder clears it immediately.
3950
+ - **The card and the status line say which tier you are in** — `slow retry 2/10`,
3951
+ then `attempt 4` with no denominator once waiting has no end — and `/retry show`
3952
+ prints the whole ladder from your live config, so it can never describe a
3953
+ configuration you do not have.
3954
+
3955
+
3903
3956
  Byte, not character: `ToolExecutor` truncates at 100 000 **bytes**, so a
3904
3957
  character-based budget would be roughly triple its nominal size for CJK text
3905
3958
  and would get cut mid-tag.
@@ -126,6 +126,19 @@ export interface ControllerDeps {
126
126
  * mid-run, and the sentence is guidance rather than a contract.
127
127
  */
128
128
  todoPanelCapable?: boolean;
129
+ /**
130
+ * Which host is running, for the ONE decision that genuinely depends on it: how
131
+ * many retry tiers a request gets (tiered-reconnect §4.4 / D-6).
132
+ *
133
+ * `'interactive'` (the default) = the full ladder, because a human can press Esc
134
+ * or type. `'headless'` = two tiers, because nobody is there — a CI job that
135
+ * waits forever on a regional outage is a worse failure than a clear error.
136
+ *
137
+ * NOT a second config system: the six `retry.*` keys still decide the shape; this
138
+ * only answers the `'auto'` case. `-p` and `exec` pass `'headless'`; everything
139
+ * else keeps the default, so every existing caller is byte-identical.
140
+ */
141
+ reconnectMode?: 'interactive' | 'headless';
129
142
  /**
130
143
  * The `aragon exec` tool policy (cli-integration-surface §4.2).
131
144
  *
@@ -469,6 +482,37 @@ export declare class AgentController {
469
482
  * answer cannot change between the tool array and the prompt that describes it.
470
483
  */
471
484
  private readonly toolImagesEnabled;
485
+ /**
486
+ * Which host this controller serves, for the ladder's SHAPE only
487
+ * (tiered-reconnect §4.4). Read once, at construction: a session does not change
488
+ * hosts, and a value that could change mid-run would make "two tiers" mean
489
+ * different things in two requests of one conversation.
490
+ */
491
+ private readonly reconnectMode;
492
+ /**
493
+ * Which tier the last request recovered in (tiered-reconnect §4.9), so the NEXT
494
+ * request does not spend four minutes re-learning that the fast ladder is not
495
+ * working. Process-local, read only when `retry.stickyRung` is on.
496
+ */
497
+ private readonly reconnectMemory;
498
+ /** The tier the CURRENT request is retrying in; 1 until an escalation happens. */
499
+ private retryTierThisRun;
500
+ /**
501
+ * The provider/model pair a sticky memory belongs to (tiered-reconnect §4.9).
502
+ * Comparing it is what makes a switch of model invalidate the memory instead of
503
+ * starting the new model at the old model's tier.
504
+ */
505
+ private currentModelRef;
506
+ /**
507
+ * Follow the ladder one stream event at a time, so a RECOVERY knows which tier it
508
+ * happened in (tiered-reconnect §4.9).
509
+ *
510
+ * CORE SENDS NO "recovered" EVENT — a successful request simply ends in `done` —
511
+ * so the tier of a recovery has to be remembered from the last `retry_scheduled`
512
+ * of the same request. That is the same derivation the reducer uses for its
513
+ * card, done here because the sticky memory belongs to the process, not to a view.
514
+ */
515
+ private observeRetryTier;
472
516
  /**
473
517
  * What the CURRENT prompt's `<image_input>` block was written for: the model and the support
474
518
  * answer together (`provider/model:support`). The block names the model, so a switch between
@@ -1326,6 +1370,15 @@ export declare class AgentController {
1326
1370
  */
1327
1371
  clearTodos(): void;
1328
1372
  getRetryConfig(): RetryConfig;
1373
+ /**
1374
+ * Which ladder shape this host gets (tiered-reconnect §4.4 / D-6).
1375
+ *
1376
+ * READ-ONLY, and it exists so the difference between a terminal and a pipeline is
1377
+ * OBSERVABLE: `-p` / `exec` are bounded, the TUI and the desktop are full, and the
1378
+ * failure this prevents (a CI job waiting forever on a regional outage) has no
1379
+ * other symptom. `/retry show` and the desktop's diagnostics can also report it.
1380
+ */
1381
+ getReconnectMode(): 'interactive' | 'headless';
1329
1382
  /**
1330
1383
  * Adopt a new retry config for this session AND PUSH IT INTO THE REGISTRY.
1331
1384
  *
@@ -11,6 +11,8 @@ import { buildImageInputBlock } from './image-input-prompt.js';
11
11
  import { isImageCapabilityRefusal } from '@aragon-agent/tui/model/agent/image-refusal';
12
12
  import { Agent, IMAGE_TOKEN_ESTIMATE, initProviders, ModelRegistry, } from '@aragon-agent/core';
13
13
  import { clampCompactionConfig, clampFastConfig, clampRetryConfig, clampGeneConfig, clampMemoryConfig, clampTeamConfig, clampTodoConfig, isAdapterProvider, toRetryPolicy, } from '@aragon-agent/tui/model/config/schema';
14
+ import { resolveEscalationPolicy } from '@aragon-agent/tui/model/config/reconnect';
15
+ import { ReconnectMemory } from './reconnect-memory.js';
14
16
  import { resolveModelProfileState } from '@aragon-agent/tui/model/config/model-profile-resolution';
15
17
  import { makeGetApiKey } from '../config/load.js';
16
18
  import { updatePersistedConfig } from '../config/store.js';
@@ -446,6 +448,53 @@ export class AgentController {
446
448
  * answer cannot change between the tool array and the prompt that describes it.
447
449
  */
448
450
  toolImagesEnabled = process.env.ARAGON_TOOL_IMAGES !== '0';
451
+ /**
452
+ * Which host this controller serves, for the ladder's SHAPE only
453
+ * (tiered-reconnect §4.4). Read once, at construction: a session does not change
454
+ * hosts, and a value that could change mid-run would make "two tiers" mean
455
+ * different things in two requests of one conversation.
456
+ */
457
+ reconnectMode;
458
+ /**
459
+ * Which tier the last request recovered in (tiered-reconnect §4.9), so the NEXT
460
+ * request does not spend four minutes re-learning that the fast ladder is not
461
+ * working. Process-local, read only when `retry.stickyRung` is on.
462
+ */
463
+ reconnectMemory = new ReconnectMemory();
464
+ /** The tier the CURRENT request is retrying in; 1 until an escalation happens. */
465
+ retryTierThisRun = 1;
466
+ /**
467
+ * The provider/model pair a sticky memory belongs to (tiered-reconnect §4.9).
468
+ * Comparing it is what makes a switch of model invalidate the memory instead of
469
+ * starting the new model at the old model's tier.
470
+ */
471
+ currentModelRef() {
472
+ return { providerId: this.config.provider, modelId: this.config.model };
473
+ }
474
+ /**
475
+ * Follow the ladder one stream event at a time, so a RECOVERY knows which tier it
476
+ * happened in (tiered-reconnect §4.9).
477
+ *
478
+ * CORE SENDS NO "recovered" EVENT — a successful request simply ends in `done` —
479
+ * so the tier of a recovery has to be remembered from the last `retry_scheduled`
480
+ * of the same request. That is the same derivation the reducer uses for its
481
+ * card, done here because the sticky memory belongs to the process, not to a view.
482
+ */
483
+ observeRetryTier(event) {
484
+ if (event.type === 'retry_scheduled') {
485
+ if (event.tier !== undefined)
486
+ this.retryTierThisRun = event.tier;
487
+ return;
488
+ }
489
+ if (event.type !== 'done')
490
+ return;
491
+ // `stickyRung` off means nobody asked for a memory, so nothing is recorded: a
492
+ // session that never flips the switch pays nothing for this feature.
493
+ if (!this.config.retry.stickyRung)
494
+ return;
495
+ this.reconnectMemory.recordRecovery(this.currentModelRef(), this.retryTierThisRun);
496
+ this.retryTierThisRun = 1;
497
+ }
449
498
  /**
450
499
  * What the CURRENT prompt's `<image_input>` block was written for: the model and the support
451
500
  * answer together (`provider/model:support`). The block names the model, so a switch between
@@ -561,6 +610,9 @@ export class AgentController {
561
610
  this.todoRegistered = config.todo.enabled;
562
611
  this.todoEnabled = config.todo.enabled;
563
612
  this.todoPanelCapable = deps.todoPanelCapable === true;
613
+ // Default `'interactive'`: a host that never heard of this dep keeps the full
614
+ // ladder, which is what the TUI and the desktop both want.
615
+ this.reconnectMode = deps.reconnectMode === 'headless' ? 'headless' : 'interactive';
564
616
  this.todos = this.todoRegistered
565
617
  ? new TodoStore(Date.now, () => this.isTodoAcceptanceEnabled())
566
618
  : null;
@@ -1381,6 +1433,32 @@ export class AgentController {
1381
1433
  ...(this.governance.isRegistered() ? { gov_dispatch: 0 } : {}),
1382
1434
  },
1383
1435
  },
1436
+ // TIERED RECONNECT (tiered-reconnect §4.4). THE ONLY PLACE IN THE WHOLE
1437
+ // REPOSITORY THAT WRITES THIS FIELD (AC-12 pins it with a source scan, and
1438
+ // `team/subagent.ts` is asserted to have neither this nor `retryEscalation`).
1439
+ //
1440
+ // A CLOSURE, NOT A VALUE, and that is the difference from `setRetryPolicy`
1441
+ // next door: the tier-1 policy is pushed twice because it is a VALUE the
1442
+ // registry stores, while this is a FUNCTION the engine calls once per run, so
1443
+ // `/retry reconnect off` takes effect on the next request with no restart and
1444
+ // no second push.
1445
+ //
1446
+ // `deps.reconnectMode === 'headless'` is what makes `-p` / `exec` bounded by
1447
+ // default: two tiers, because nobody is there to press Esc.
1448
+ resolveEscalation: () => {
1449
+ const policy = resolveEscalationPolicy(this.config.retry, {
1450
+ headless: this.reconnectMode === 'headless',
1451
+ });
1452
+ if (policy === null)
1453
+ return null;
1454
+ // STICKY START TIER (§4.9). Off by default, and its absence is what makes a
1455
+ // session that never turns it on byte-identical to one without the feature:
1456
+ // `startRung === undefined` means "begin at tier 1", which is the default.
1457
+ const startRung = this.config.retry.stickyRung
1458
+ ? this.reconnectMemory.startRungFor(this.currentModelRef())
1459
+ : undefined;
1460
+ return startRung === undefined ? { policy } : { policy, startRung };
1461
+ },
1384
1462
  });
1385
1463
  // --- Context compaction, part 2: AFTER the Agent exists -----------------
1386
1464
  //
@@ -1434,8 +1512,12 @@ export class AgentController {
1434
1512
  // The Gene Bank's feed (learner ledger, usage, evaluation). Never throws.
1435
1513
  // `abortRequested` is still in force here: it is cleared at the NEXT `agent_start`.
1436
1514
  this.gene?.onAgentEvent(event, this.abortRequested);
1437
- if (event.type === 'agent_start')
1515
+ if (event.type === 'agent_start') {
1438
1516
  this.abortRequested = false;
1517
+ this.retryTierThisRun = 1;
1518
+ }
1519
+ if (event.type === 'message_update')
1520
+ this.observeRetryTier(event.streamEvent);
1439
1521
  if (event.type === 'message_update' && event.streamEvent.type === 'error') {
1440
1522
  this.learnImageRefusal(event.streamEvent.error);
1441
1523
  }
@@ -3472,6 +3554,17 @@ export class AgentController {
3472
3554
  getRetryConfig() {
3473
3555
  return this.config.retry;
3474
3556
  }
3557
+ /**
3558
+ * Which ladder shape this host gets (tiered-reconnect §4.4 / D-6).
3559
+ *
3560
+ * READ-ONLY, and it exists so the difference between a terminal and a pipeline is
3561
+ * OBSERVABLE: `-p` / `exec` are bounded, the TUI and the desktop are full, and the
3562
+ * failure this prevents (a CI job waiting forever on a regional outage) has no
3563
+ * other symptom. `/retry show` and the desktop's diagnostics can also report it.
3564
+ */
3565
+ getReconnectMode() {
3566
+ return this.reconnectMode;
3567
+ }
3475
3568
  /**
3476
3569
  * Adopt a new retry config for this session AND PUSH IT INTO THE REGISTRY.
3477
3570
  *
@@ -16,6 +16,20 @@ import { advanceBudget, chargeResume, decideFollowThrough, emptyBudget, emptyRes
16
16
  function pauseMs(ms) {
17
17
  return new Promise((resolve) => setTimeout(resolve, ms));
18
18
  }
19
+ /**
20
+ * The wait, as a piped consumer reads it: `8s`, `1m00s`, `5m00s`.
21
+ *
22
+ * Minutes matter now that a wait can be five of them (tiered-reconnect §4.6.7):
23
+ * `waiting 300s` is technically true and useless, and the CLI's other duration
24
+ * formatter is a `Glyphs`-aware UI module this file deliberately does not import.
25
+ */
26
+ function formatWait(ms) {
27
+ const seconds = Math.max(0, Math.round(ms / 1000));
28
+ if (seconds < 60)
29
+ return `${seconds}s`;
30
+ const minutes = Math.floor(seconds / 60);
31
+ return `${minutes}m${String(seconds % 60).padStart(2, '0')}s`;
32
+ }
19
33
  /** Run a single prompt headlessly and resolve with the process exit code. */
20
34
  export async function runHeadless(controller, prompt, options = {}) {
21
35
  const out = options.stdout ?? process.stdout;
@@ -59,12 +73,19 @@ export async function runHeadless(controller, prompt, options = {}) {
59
73
  // `aragon -p | jq`; a retry line on it would corrupt every consumer.
60
74
  // Not `--quiet`-gated, unlike the tool lines: a three-minute pause with
61
75
  // no explanation anywhere is not a "compact" run, it is a hang.
62
- retryCount = se.attempt;
76
+ //
77
+ // THE CUMULATIVE COUNT (tiered-reconnect §4.6.7 / P2-7), not `attempt`:
78
+ // `attempt` restarts at 1 in every tier, so a recovery in tier 2 would
79
+ // otherwise be reported as "2 retries" after eleven minutes of waiting.
80
+ retryCount = se.totalAttempts ?? se.attempt;
81
+ // The tier rides the same line, because `[retry 2/10]` alone cannot say
82
+ // WHICH 2/10 - the fast tier's or the one-minute tier's.
83
+ const tierTag = se.tier !== undefined && se.tier > 1 ? ` tier ${se.tier}` : '';
63
84
  // The em dash is a literal because `agent/headless.ts` is the CLI's one
64
85
  // documented glyph-scanner exemption: `aragon -p` does no capability
65
86
  // probe, so there is no `Glyphs` set to read here.
66
- err.write(`\n[retry ${se.attempt}/${se.maxRetries}] ${se.errorType} — ` +
67
- `waiting ${Math.round(se.delayMs / 1000)}s\n`);
87
+ err.write(`\n[retry ${se.attempt}/${se.maxRetries}${tierTag}] ${se.errorType} — ` +
88
+ `waiting ${formatWait(se.delayMs)}\n`);
68
89
  }
69
90
  else if (se.type === 'stream_restart') {
70
91
  // The partial answer already on stdout is about to be replayed. Saying so
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Sticky starting tier — remember the tier a request just recovered in
3
+ * (tiered-reconnect §4.9, step 8 of the implementation order).
4
+ *
5
+ * THE PROBLEM IT SOLVES, in one sentence: on a link that is down for twenty minutes,
6
+ * every NEW request would spend its first four minutes re-learning what the previous
7
+ * request already proved — that the fast ladder does not work right now. A turn can
8
+ * contain five requests, so that is twenty minutes of waiting for a fact we knew.
9
+ *
10
+ * PROCESS-LOCAL BY DESIGN. Nothing here is persisted and nothing is a `ViewState`
11
+ * field: a tier is a property of the network at this moment, and a stale one loaded
12
+ * from disk tomorrow would be worse than no memory at all (the same argument
13
+ * `RetryPolicy` makes about its own, non-persisted state).
14
+ *
15
+ * OFF BY DEFAULT (`retry.stickyRung: false`), and the switch is checked by the
16
+ * caller, so a session that never flips it is byte-identical to one built before
17
+ * this module existed.
18
+ *
19
+ * NO DEPENDENCIES, NO TIMERS, NO I/O: `now` is injected, exactly like `TodoStore`'s
20
+ * clock, so the window can be tested without waiting two minutes.
21
+ */
22
+ import type { RetryTierId } from '@aragon-agent/core';
23
+ /** How long a recovery keeps steering new requests at the slow tier. */
24
+ export declare const RECONNECT_MEMORY: {
25
+ /**
26
+ * TWO MINUTES. Long enough to cover the next request of the same turn and the
27
+ * user reading one answer; short enough that a network which came back from a
28
+ * lunch break does not silently skip the fast ladder.
29
+ */
30
+ readonly stickyMs: 120000;
31
+ };
32
+ /** Which provider/model a memory belongs to; a change invalidates it. */
33
+ export interface ReconnectRef {
34
+ providerId: string;
35
+ modelId: string;
36
+ }
37
+ /**
38
+ * One record, and the two questions asked of it.
39
+ *
40
+ * A CLASS rather than two module-level functions so a test — and, one day, a second
41
+ * controller in one process (the host spawns several) — cannot share state by
42
+ * accident. Mutable on purpose: this is a memo, and a "pure" version would have to
43
+ * thread a value through the request path, which is precisely where the escalation
44
+ * policy travels and where a second source of truth would be born.
45
+ */
46
+ export declare class ReconnectMemory {
47
+ private readonly now;
48
+ private last;
49
+ constructor(now?: () => number);
50
+ /**
51
+ * Record that a request that had retried at least once finally got its answer.
52
+ *
53
+ * `rung === 1` CLEARS the memory rather than storing tier 1: a recovery during the
54
+ * fast ladder is evidence that the network is fine, and leaving an older "we are
55
+ * in the slow tier" record in place would overrule the fresher evidence.
56
+ */
57
+ recordRecovery(ref: ReconnectRef, rung: RetryTierId): void;
58
+ /**
59
+ * The tier a new request should start from, or `undefined` for the default (1).
60
+ *
61
+ * Returns `undefined` for a different provider/model, for a record older than
62
+ * `stickyMs`, and for no record at all — every one of which means "behave exactly
63
+ * as you would without this feature".
64
+ */
65
+ startRungFor(ref: ReconnectRef): RetryTierId | undefined;
66
+ /** Forget everything (a new conversation, or a provider switch the user forced). */
67
+ reset(): void;
68
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Sticky starting tier — remember the tier a request just recovered in
3
+ * (tiered-reconnect §4.9, step 8 of the implementation order).
4
+ *
5
+ * THE PROBLEM IT SOLVES, in one sentence: on a link that is down for twenty minutes,
6
+ * every NEW request would spend its first four minutes re-learning what the previous
7
+ * request already proved — that the fast ladder does not work right now. A turn can
8
+ * contain five requests, so that is twenty minutes of waiting for a fact we knew.
9
+ *
10
+ * PROCESS-LOCAL BY DESIGN. Nothing here is persisted and nothing is a `ViewState`
11
+ * field: a tier is a property of the network at this moment, and a stale one loaded
12
+ * from disk tomorrow would be worse than no memory at all (the same argument
13
+ * `RetryPolicy` makes about its own, non-persisted state).
14
+ *
15
+ * OFF BY DEFAULT (`retry.stickyRung: false`), and the switch is checked by the
16
+ * caller, so a session that never flips it is byte-identical to one built before
17
+ * this module existed.
18
+ *
19
+ * NO DEPENDENCIES, NO TIMERS, NO I/O: `now` is injected, exactly like `TodoStore`'s
20
+ * clock, so the window can be tested without waiting two minutes.
21
+ */
22
+ /** How long a recovery keeps steering new requests at the slow tier. */
23
+ export const RECONNECT_MEMORY = {
24
+ /**
25
+ * TWO MINUTES. Long enough to cover the next request of the same turn and the
26
+ * user reading one answer; short enough that a network which came back from a
27
+ * lunch break does not silently skip the fast ladder.
28
+ */
29
+ stickyMs: 120_000,
30
+ };
31
+ /**
32
+ * One record, and the two questions asked of it.
33
+ *
34
+ * A CLASS rather than two module-level functions so a test — and, one day, a second
35
+ * controller in one process (the host spawns several) — cannot share state by
36
+ * accident. Mutable on purpose: this is a memo, and a "pure" version would have to
37
+ * thread a value through the request path, which is precisely where the escalation
38
+ * policy travels and where a second source of truth would be born.
39
+ */
40
+ export class ReconnectMemory {
41
+ now;
42
+ last = null;
43
+ constructor(now = Date.now) {
44
+ this.now = now;
45
+ }
46
+ /**
47
+ * Record that a request that had retried at least once finally got its answer.
48
+ *
49
+ * `rung === 1` CLEARS the memory rather than storing tier 1: a recovery during the
50
+ * fast ladder is evidence that the network is fine, and leaving an older "we are
51
+ * in the slow tier" record in place would overrule the fresher evidence.
52
+ */
53
+ recordRecovery(ref, rung) {
54
+ if (rung <= 1) {
55
+ this.last = null;
56
+ return;
57
+ }
58
+ this.last = { providerId: ref.providerId, modelId: ref.modelId, rung, at: this.now() };
59
+ }
60
+ /**
61
+ * The tier a new request should start from, or `undefined` for the default (1).
62
+ *
63
+ * Returns `undefined` for a different provider/model, for a record older than
64
+ * `stickyMs`, and for no record at all — every one of which means "behave exactly
65
+ * as you would without this feature".
66
+ */
67
+ startRungFor(ref) {
68
+ const memory = this.last;
69
+ if (!memory)
70
+ return undefined;
71
+ if (memory.providerId !== ref.providerId || memory.modelId !== ref.modelId) {
72
+ return undefined;
73
+ }
74
+ if (this.now() - memory.at > RECONNECT_MEMORY.stickyMs)
75
+ return undefined;
76
+ return memory.rung;
77
+ }
78
+ /** Forget everything (a new conversation, or a provider switch the user forced). */
79
+ reset() {
80
+ this.last = null;
81
+ }
82
+ }