The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(3.0.7): the run ledger keeps an earlier ledger, tests do not depend on the CI machine
purple2aa5efa312ae
diff --git a/e2e/mac-persona-walk.spec.ts b/e2e/mac-persona-walk.spec.tsindex 4cd0ced6..2d8f36a5 100644--- a/e2e/mac-persona-walk.spec.ts+++ b/e2e/mac-persona-walk.spec.ts@@ -420,7 +420,11 @@ test('power user: the closed model picker tells 4-bit, 8-bit and Turbo apart, anawait bootCreate(page, { ...MAC, mlx: { installedImages: ['sd-turbo', 'qwen-image-2.1-4bit', 'qwen-image-2.1-8bit', 'qwen-image-2.1-turbo'], mfluxEngineInstalled: true } })const chip = page.locator('button[aria-haspopup="listbox"]').last()const name = chip.locator('span.truncate')- for (const width of [1440, 1024, 760]) {+ // 760 px is measured with the Mac's own font. The Linux runner of the+ // release gate draws the same names wider, so there the narrow width proves+ // nothing about a Mac and is left out.+ const widths = process.platform === 'darwin' ? [1440, 1024, 760] : [1440, 1024]+ for (const width of widths) {await page.setViewportSize({ width, height: 900 })for (const pack of ['MLX Qwen-Image 2.1 4-bit', 'MLX Qwen-Image 2.1 8-bit', 'MLX Qwen-Image 2.1 Turbo 8-bit']) {await chip.click()diff --git a/src-tauri/src/commands/plugin_rea.rs b/src-tauri/src/commands/plugin_rea.rsindex f0c43897..ae35fdbc 100644--- a/src-tauri/src/commands/plugin_rea.rs+++ b/src-tauri/src/commands/plugin_rea.rs@@ -308,7 +308,9 @@ mod tests {std::fs::create_dir_all(&bin).unwrap();std::fs::write(bin.join("node"), b"").unwrap();}- let dirs = manager_node_dirs(&home);+ // Only the version folders under this home: the fixed folders after+ // them (Homebrew, /usr/local/bin) belong to the machine running the test.+ let dirs: Vec<_> = manager_node_dirs(&home).into_iter().filter(|d| d.starts_with(&home)).collect();let names: Vec<String> = dirs.iter().map(|d| d.parent().unwrap().file_name().unwrap().to_string_lossy().into_owned()).collect();assert_eq!(names, ["v24.15.0", "v22.1.0", "v20.18.0"]);}diff --git a/src-tauri/src/commands/video.rs b/src-tauri/src/commands/video.rsindex 8a45db7a..57650aa7 100644--- a/src-tauri/src/commands/video.rs+++ b/src-tauri/src/commands/video.rs@@ -2146,7 +2146,7 @@ pub fn video_generate(state: &AppState, args: &Value) -> CmdResult {}// Before anything is loaded: a model larger than the memory does not// fail, it swaps until the Mac stops answering.- if let Some(refusal) = memory_refusal(entry, crate::commands::system::total_memory_bytes()) {+ if let Some(refusal) = memory_refusal(entry, machine_memory_bytes()) {return Err(bad_request(refusal));}let quant = entry.family == ltx2mlx::FAMILY;@@ -2161,7 +2161,7 @@ pub fn video_generate(state: &AppState, args: &Value) -> CmdResult {entry.name, entry.talking_gb)));}- if let Some(refusal) = talking_needs_more_memory(entry, crate::commands::system::total_memory_bytes()) {+ if let Some(refusal) = talking_needs_more_memory(entry, machine_memory_bytes()) {return Err(bad_request(refusal));}}@@ -2510,6 +2510,23 @@ pub fn video_cancel(state: &AppState, _args: &Value) -> CmdResult {// ── helpers ───────────────────────────────────────────────────────────+// The memory of this machine. A test sets it per thread, so the runs that+// check it do not depend on the machine the tests run on (CI runners have+// 7 GB). Outside tests the cell stays 0 and is never read.+thread_local! {+ static TEST_MEMORY_BYTES: std::cell::Cell<u64> = const { std::cell::Cell::new(0) };+}++fn machine_memory_bytes() -> u64 {+ if cfg!(test) {+ let set = TEST_MEMORY_BYTES.with(|m| m.get());+ if set > 0 {+ return set;+ }+ }+ crate::commands::system::total_memory_bytes()+}+/// The sentence a generation is refused with on a Mac that has less memory/// than the model needs, or `None` when it fits (or nothing could be measured).///@@ -4120,6 +4137,8 @@ mod tests {#[test]fn talking_character_runs_on_the_4_bit_pack_with_its_own_download() {let _turn = empty_models_root();+ // The checks below are about the parts, not the memory: a 64 GB Mac.+ TEST_MEMORY_BYTES.with(|m| m.set(64 * 1_073_741_824));let q4 = entry("ltx-2.3-q4");// Only the entry a real run talked on, and only on the second engine.let talking: Vec<&str> = CATALOG.iter().filter(|c| talks(c)).map(|c| c.id).collect();diff --git a/src/lib/__tests__/run-ledger-keeps-an-earlier-ledger.test.ts b/src/lib/__tests__/run-ledger-keeps-an-earlier-ledger.test.tsnew file mode 100644index 00000000..4862e9b0--- /dev/null+++ b/src/lib/__tests__/run-ledger-keeps-an-earlier-ledger.test.ts@@ -0,0 +1,38 @@+// Release gate 19.10.2026: a run whose persisted chain carried the ledger of+// its cut on the first kept message lost those lines when "continue" trimmed+// that message away. The new ledger takes them over, oldest first.+import { describe, expect, it } from 'vitest'+import { runLedger, splitLedger } from '../context-decay'++const call = (path: string) => ({+ role: 'assistant' as const,+ content: '',+ tool_calls: [{ id: path, type: 'function', function: { name: 'file_read', arguments: JSON.stringify({ path }) } }],+})++describe('runLedger with an earlier ledger', () => {+ it('a dropped message that carries a ledger hands its lines on', () => {+ const earlier = runLedger([call('src/a.ts'), call('src/b.ts')])!+ const first = { ...call('src/c.ts'), content: `${earlier}\n\nstep` }+ const ledger = runLedger([first, call('src/d.ts')])!+ const lines = splitLedger(ledger).lines+ expect(lines).toEqual(['file_read: src/a.ts', 'file_read: src/b.ts', 'file_read: src/c.ts', 'file_read: src/d.ts'])+ })++ it('a ledger on the pinned task is merged, not repeated', () => {+ const earlier = runLedger([call('src/a.ts')])!+ const split = splitLedger(`walk the tree\n\n${earlier}`)+ expect(split.task).toBe('walk the tree')+ const ledger = runLedger([call('src/b.ts')], split)!+ expect(ledger.match(/\[Run ledger\]/g)).toHaveLength(1)+ expect(splitLedger(ledger).lines).toEqual(['file_read: src/a.ts', 'file_read: src/b.ts'])+ })++ it('the count of older steps adds up across ledgers', () => {+ const many = Array.from({ length: 45 }, (_, i) => call(`src/f${i}.ts`))+ const earlier = runLedger(many)!+ expect(earlier).toContain('- (5 older steps)')+ const next = runLedger([{ ...call('src/x.ts'), content: earlier }])!+ expect(next).toContain('- (6 older steps)')+ })+})diff --git a/src/lib/context-decay.ts b/src/lib/context-decay.tsindex 704d5db2..986f00b5 100644--- a/src/lib/context-decay.ts+++ b/src/lib/context-decay.ts@@ -448,10 +448,47 @@ function ledgerArg(args: unknown): string {* drop point moves: between trims every request keeps the same prefix and the* upstream cache keeps hitting.*/-export function runLedger(dropped: DecayMessage[]): string | null {+const LEDGER_HEAD = '[Run ledger] Earlier steps of this run were removed from the context to save cost. They were already done, do not repeat them unless something changed:'+const LEDGER_TAIL = 'Continue from where the run stands now.'++/**+ * Splits a ledger the task already carries off its text. A second trim in+ * the same run drops the pinned task with the old ledger on it; its lines+ * have to go into the new ledger, or the steps of the first trim are gone+ * (box run d307-l: a run trimmed twice lost files 0 to 14 from its ledger).+ */+export function splitLedger(content: string): { task: string; lines: string[]; skipped: number } {+ const at = content.indexOf(LEDGER_HEAD)+ if (at === -1) return { task: content, lines: [], skipped: 0 }+ const task = content.slice(0, at).replace(/\n+$/, '')const lines: string[] = []- const seen = new Set<string>()+ let skipped = 0+ for (const raw of content.slice(at + LEDGER_HEAD.length).split('\n')) {+ if (!raw.startsWith('- ')) continue+ const older = /^- \((\d+) older steps\)$/.exec(raw)+ if (older) { skipped += Number(older[1]); continue }+ lines.push(raw.slice(2))+ }+ return { task, lines, skipped }+}++export function runLedger(dropped: DecayMessage[], earlier: { lines: string[]; skipped: number } = { lines: [], skipped: 0 }): string | null {+ const lines: string[] = [...earlier.lines]+ const seen = new Set<string>(lines)+ let skippedBefore = earlier.skippedfor (const m of dropped) {+ // A dropped message can carry a ledger of its own: the persisted chain+ // puts the ledger of its cut on its first kept message+ // (codex/hidden-history.ts). Its lines come first, in their order.+ if (typeof m.content === 'string' && m.content.includes(LEDGER_HEAD)) {+ const inner = splitLedger(m.content)+ skippedBefore += inner.skipped+ for (const line of inner.lines) {+ if (seen.has(line)) continue+ seen.add(line)+ lines.push(line)+ }+ }if (m.role !== 'assistant') continuefor (const tc of toolCallsIn(m)) {const name = callName(tc)@@ -465,12 +502,12 @@ export function runLedger(dropped: DecayMessage[]): string | null {}if (lines.length === 0) return nullconst kept = lines.length > LEDGER_MAX_LINES ? lines.slice(-LEDGER_MAX_LINES) : lines- const skipped = lines.length - kept.length+ const skipped = lines.length - kept.length + skippedBeforereturn [- '[Run ledger] Earlier steps of this run were removed from the context to save cost. They were already done, do not repeat them unless something changed:',+ LEDGER_HEAD,...(skipped > 0 ? [`- (${skipped} older steps)`] : []),...kept.map((l) => `- ${l}`),- 'Continue from where the run stands now.',+ LEDGER_TAIL,].join('\n')}@@ -505,10 +542,13 @@ export function trimWorkingHistory<T extends DecayMessage>(if (firstUser && !tail.includes(firstUser)) {// The ledger rides on the pinned task instead of being a message of its// own: two user messages in a row break strict chat templates.- const ledger = runLedger(rest.slice(0, drop))- out.push(ledger && typeof firstUser.content === 'string'- ? { ...firstUser, content: `${firstUser.content}\n\n${ledger}` }- : firstUser)+ if (typeof firstUser.content === 'string') {+ const { task, ...earlier } = splitLedger(firstUser.content)+ const ledger = runLedger(rest.slice(0, drop), earlier)+ out.push(ledger ? { ...firstUser, content: `${task}\n\n${ledger}` } : firstUser)+ } else {+ out.push(firstUser)+ }}out.push(...tail)return out