WIP: agent session restore (never-merge) #22
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/agent-session-restore"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
DO NOT MERGE — never-merge feature branch for fork-side review.
Implements agent-session-restore off vanilla
mainper the anti-duplication spec (/tmp/research-restore-dupes.md§2, authoritative over the PRD where they differ).What it does:
LIVE_AGENT_HEARTBEAT_MS=5min+ confirmed working/waiting state + PTY liveness probe when provable + quit/sleep/tab-open skips + resumable/placeable gates, 48h horizon).duplicate-provider-sessionskip — zero duplicate PTYs.buildColdRestoreAgentResumeStartupreturns null for claimed paneKeys (sync registry + pushed claims + pre-spawn IPC guard); allstartFreshColdRestoreAgentResumearms inherit it.void restoreAgentSessionsOnStartup()inlaunchServeModeafter provider readiness (fire-and-forget, never-throw) + post-verify restart reissue (idempotent) + Save barrier (runAgentSessionSavecheckpoint → hook-flush → store-flush, sidebar Save agents fan-out,runtime.saveActiveSessionsRPC).terminal.restoreAgentSessionsRPC ({maxAgeMs, dryRun}, bare{}keeps startup semantics) +orca agent restore [--max-age-ms] [--dry-run] [--json]CLI.session_id) +hermes --resume <id>argv, verified viahermes --help(--resume SESSION); hermes added toRESUMABLE_TUI_AGENTS.Acceptance (research §2.7): 3 live agents restore as fresh blank panes; quit/slept/dead rows skip with
quit-parked/parked/not-livereasons; second pass spawns nothing; zero scrollback repaint.Base:
40716d702e9(origin/main). Commit:9dabd2abefc.Agents often answer a failed session/prompt with a generic JSON-RPC message ("Internal error") and keep the real reason in error.data. Only OMP and Grok had hooks that read it, so OpenCode and future ACP agents showed the bare message. The prompt error detail now reads, for every ACP agent: the agent's hook, else string data, else data.details, else the message. Other structured data is metadata and is ignored. OMP's details hook and Grok's string-data branch are now covered by that rule and removed.* fix(native-chat): underline a file path only once its workspace confirms it exists Chat underlined any path-shaped text, so an example path an agent made up (`src/app.ts`) looked clickable and a click said "File not found". The terminal already checks a path on its host before underlining it; chat now goes through that same code: the terminal's path finder, one shared resolve-and-check step (terminal-file-link-target.ts), and the same longest-match rule. The terminal's hover and click fallback use the shared step too. Fixes STA-9683 * fix(native-chat): recheck every shown file link when a turn ends or the host returns Chat only forgot "missing" answers at turn end, so a file deleted or renamed during a turn kept its underline, and a path the host could not answer stayed plain until the message remounted. Each answer now records the recheck generation it was asked in. A turn end, or a reconnect / re-pair of the host answering for the workspace, starts a new generation and re-asks only the paths shown by mounted messages; old answers keep showing until the host replies, and only messages whose answer changed re-render. A reply to an older question cannot overwrite a newer answer. A host that cannot answer keeps the previous answer and is retried three times with backoff, ending when no message shows the path or at the next recheck. While an SSH workspace's connection is unresolved, paths are treated as unknown instead of being checked on this machine, and the chat starts over once the connection resolves. * fix(native-chat): keep main's file-path shape rules and check existence on top Chat detection goes back to main's rules: a candidate needs a folder plus a rooted prefix, a line suffix or an extension, and prose spans are split into tokens as before. Bare names and folders are not underlined, and ordinary prose no longer sends word prefixes to the host. Existence is required on top, so the underlined set only shrinks compared with main. A rooted spaced span ("/Users/me/repo/src/x.ts to use src/app.ts") now also offers its tokens, so both real paths link; a real spaced rooted path still wins as the longest one that exists. Tests: bare names and folders stay plain even when they exist, slash tokens and versions stay plain when everything exists, `My Notes.md:7` is rejected by shape, explicit links and fenced code never reach the existence check, plus the rooted-then-relative and longest-span cases. * fix(native-chat): catch up file links answered before subscribe; tighter recheck triggers - A message renders (and asks) before it subscribes; an answer landing in between was never shown. Each message records the answer its render used, and on subscribe it re-renders if the answer differs and re-asks outdated paths. A failure for a path no message shows yet no longer arms a retry. - A rooted path ending a sentence ("/Users/me/r/a.ts.") inside a longer span now links, with the punctuation kept outside the link. Unrooted spans are unchanged, matching main. - The checker takes the workspace's SSH connection id and decides "connection not known yet" from it, so the provider memo needs no lint suppression. - SSH reconnects recheck only when the connection reaches connected or gets a new generation, not on every intermediate status. * fix(native-chat): never check a network share outside the workspace without a click Chat checks every path in a finished reply on its own. On Windows, a local check of a path like \\server\share\a.ts or //server/share/notes.md opens an SMB connection to that server and sends the user's credentials, and agent text can be steered by prompt injection. Such a path is now never asked about and stays plain text, unless it is inside the workspace or is a known workspace root. WSL paths (\\wsl$, \\wsl.localhost) and checks made by an SSH or remote runtime host are unaffected. Terminal hover and click behaviour is unchanged. * chore: restore main's copy of structured-agent-session-queued-mutations.ts The merge commit's format hook dropped one blank line in this unrelated file. Committed without the hook so the file matches main byte for byte. * refactor(native-chat): own the file-link checker in NativeChatView, not each chat view The provider now sits where NativeChatView picks the chat view, and derives the file-link context from the tab id. The two chat views keep only a one-line turn-end hook, since only they know whether a turn is running. Same lifetime as before: inside the session-keyed owner for structured chats, and per resolution for terminal-backed ones. No behaviour change; it keeps NativeChatResolvedView under its line limit after main's find-in-chat. * fix(native-chat): refuse network shares on SSH hosts too; allow only the workspace's WSL distro - The "no network share outside the workspace" rule now applies to SSH targets as well: a Windows SSH host's relay would otherwise stat //server/share/... and open SMB with no click. Remote runtime paths stay exempt, since they are always inside the worktree. - WSL paths are allowed only for the workspace's own distro (from the pane runtime or the worktree path, via the same helper the path mapping uses), after `..` is normalized, so `//wsl.localhost/../x` or another distro is refused. - Drop the \\?\UNC\ chat test case: the real detector never produces it. * refactor(terminal): keep file-link host path helpers out of the open flow terminal-file-link-target imported its pure path helpers from terminal-file-open-routing, which also opens files and so loads worktree activation, launch and the agent catalog. Since NativeChatView now hosts the chat file-link checker, that chain reached tests that render NativeChatView with a minimal i18n mock (native-chat-view-file-drop.test.tsx failed in CI). getTerminalFileContext, mapTerminalFilePath, terminalLinkWslDistro and terminalPathWslDistro move unchanged to terminal-file-path-mapping.ts; terminal-file-open-routing imports and re-exports them, so its callers and their mocks are unchanged.9dabd2abefacd02a2ad2View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.