Commit graph

13 commits

Author SHA1 Message Date
Juan Ibiapina
0a60e18cc3
fix(coding-agent): start new sessions in the cwd's default directory
SessionManager.open() without a session directory used the file's
folder for new sessions. When the session's cwd differs from the project
the folder belongs to, for example after choosing "continue in current
cwd" at the missing-cwd prompt, pi treated that folder as a custom
--session-dir: /resume All listed only that folder, the resume hint
added --session-dir, and /new, /fork and /clone saved into the old
project's folder.

For a file in the sessions directory, open() now uses the default
directory of the session's cwd. Files elsewhere, such as in a custom
--session-dir, keep their folder.
2026-10-29 12:31:57 +01:00
robopipi[bot]
807a5c051f
fix(coding-agent): keep session memory in line with the file when a write fails (#11486)
When writing a session entry failed (ENOSPC, EBUSY, ETIMEDOUT on network
drives), `SessionManager._appendEntry` had already added the entry to
memory and made it the current leaf. The process kept running, and the
next entry written to disk pointed to a parent that was not in the file.
On resume, pi follows the history only back to that gap: everything
before it disappears. In #11460 that also dropped the first system
message, which declares the tools, so resume turned off every built-in
tool.

`_appendEntry` now undoes the in-memory append if writing fails, then
rethrows. The error reaches the caller as before; later entries chain to
the last entry actually on disk.

Reports of this problem:
- #11460: ENOSPC; resume dropped all built-in tools.
- #10166: failure injected with EBUSY; the next entry on disk points to
a missing parent.
- #10661: ETIMEDOUT on Windows + NFS; resumed sessions showed only the
last few messages. That report also describes NUL holes in the file,
which this change does not address.

**Testing**
- Two tests in `test/session-manager/file-operations.test.ts` make
writes fail with real file permissions: a read-only session file (failed
append) and a read-only session directory (failed first file creation).
They check that the entry is not kept, the leaf is unchanged, the next
entry chains to the last written one, and the reopened session's branch
contains both entries. Both fail without the change and pass with it.
- `test/session-manager/` and `test/default-tools-setting.test.ts` pass
(140 tests).
- `npm run check` passes.

Fixes #11460

Requested by @davidbrai

Co-authored-by: triagent <triagent@localhost>
2026-10-27 15:58:08 +01:00
David Brailovsky
ff72faba28 fix(coding-agent): save new session file at the first user message
A new session was only written to disk once the first assistant message
existed. If pi exited during the first turn (Ctrl+C twice while streaming,
or the process was killed), the user's prompt was lost and the session
never appeared in /resume.

The file is now created as soon as the session has a user or assistant
message. A session with only setup entries (model, thinking level) still
stays in memory, so starting pi and quitting without chatting leaves no
file. Forking uses the same rule through a shared helper, so the two paths
cannot drift apart and write the header twice (#1672).

closes #10000
2026-09-25 16:27:51 +02:00
Armin Ronacher
dfbf793b78 feat(coding-agent): load session picker progressively 2026-09-20 00:48:26 +02:00
David Brailovsky
0b5ee5d8b3 fix(coding-agent): repair unterminated session files
Append a newline after loading a valid session so subsequent entries cannot fuse with an unterminated tail.\n\nFixes #8345
2026-08-26 12:07:30 +02:00
Armin Ronacher
f1c587dde3 fix(coding-agent): avoid duplicate session reads
fixes #6793
2026-07-19 20:18:49 +02:00
Mario Zechner
0d145e895c fix(coding-agent): shorten invalid session error
Follow-up to #6002
2026-06-25 15:20:08 +02:00
Mario Zechner
543710f643 fix(coding-agent): reject invalid session files
closes #6002
2026-06-25 15:16:18 +02:00
Mario Zechner
3911d6f5cd fix(coding-agent): stream large session files
Some checks are pending
CI / build-check-test (push) Waiting to run
closes #5231
2026-05-30 21:21:42 +02:00
Armin Ronacher
4b4641c6b0 fix(coding-agent): scope custom session dir lookups 2026-05-28 23:25:33 +02:00
Mario Zechner
2e02c74dcb chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
Mario Zechner
ef5149fdf6 Fixes #933 2026-01-25 02:51:05 +01:00
Mario Zechner
beb70f126d Refactor session manager: migration chain, validation, tests
- Add migrateV1ToV2/migrateToCurrentVersion for extensible migrations
- createSummaryMessage now takes timestamp from entry
- loadEntriesFromFile validates session header
- findMostRecentSession only returns valid session files (reads first 512 bytes)
- Remove ConversationEntry alias
- Fix mom context.ts TreeNode type

Tests:
- migration.test.ts: v1 migration, idempotency
- build-context.test.ts: 14 tests covering trivial, compaction, branches
- file-operations.test.ts: loadEntriesFromFile, findMostRecentSession
2025-12-30 22:42:18 +01:00