feat: edit prompts and retry responses #3

Merged
BlackHatMagic merged 7 commits from feat/retry-edit into master 2026-10-23 14:32:13 +00:00

PR Type Selection

  • 🎯 Feature - New capability or functionality

Summary

Adds the T3 Chat / Pi web bare-minimum message actions that were missing:

  • Edit on a user message: opens an editor and resends the edited prompt.
  • Retry on a Pi reply: regenerates from the preceding user prompt.

Both actions navigate Pi's native session tree in place, preserving the old branch in the session file and keeping the current session ID. Actions appear on hover/focus and are hidden while Pi is working. This also loads the active branch from get_entries, so displayed messages carry native entry IDs and raw user text across reloads.

None. Follow-up to the Pi Chat plugin and the user's report that retry/edit were missing.

Design Overview

  • Core idea: Use Pi's native tree navigation rather than RPC fork. A probe confirmed RPC fork responds successfully and then exits the Pi child process, which would break a long-lived sidebar session.
  • Data structures / algorithms: loadEntries() follows leafId through parentId to build the active branch and attaches tool results by toolCallId. ChatMessage now stores entryId and raw user text. reloadTranscript() refreshes authoritative entries after agent_settled and after navigation.
  • Interfaces added/changed: PiSession.editUser(entryId, text) and PiSession.regenerate(assistantKey); PiEditMessageModal; message action buttons; SessionHost.extensionPath; get_entries protocol types.

Implementation Notes

  • The plugin writes a small private pi-obsidian-tree.ts extension into its plugin folder and loads it with --extension. The extension registers /pi-obsidian-tree, validates a per-process nonce from PI_OBSIDIAN_NONCE, checks ctx.isIdle()/ctx.hasPendingMessages(), calls ctx.navigateTree(targetId, { summarize: false }), and reports the result through setStatus.
  • This mirrors the Pi web UI's native tree bridge. The extension is generated at runtime, so installing the plugin still only requires main.js, manifest.json, and styles.css.
  • get_commands is checked during hydration to enable the actions only when the extension loaded.
  • Navigation and retry are serialized with a revising guard. A stale transcript reload cannot overwrite a newly started prompt (epoch guard).
  • Rejected alternative: RPC fork/clone, because the child exits after the fork response and the plugin would have to restart the process and guess the new session state.
  • Version bumped to 0.2.0.

Testing Evidence

  • Added tests: tests/chat-state.test.ts covers active-branch loading, entry IDs, raw user text, tool-result attachment, and compaction summaries. tests/extension-source.test.ts imports the generated extension and verifies nonce enforcement, idle checks, and status reporting.
  • bun run check passes: typecheck + 21 tests.
  • bun run build passes.
  • Manual end-to-end with real Pi: started a session, sent ALPHA, Retry produced a new ALPHA branch, Edit changed the prompt to GAMMA and produced GAMMA. The session ID stayed unchanged and get_entries showed the old branch retained.
  • UI action rows checked at 380px sidebar width with hover reveal.

Documentation

  • README updated with Edit/Retry behavior, branching semantics, and the generated extension
  • Design doc added/updated
  • Code comments added where behavior is non-obvious

Checklist (Feature-Specific)

  • Issue(s) linked (or rationale if none)
  • Tests added and passing
  • No Lint / Style violations
  • No dead / Debug / Commented-Out code
  • Follows course integrity guidelines

Additional Notes

  • Review focus: generated extension loading/security, tree navigation correctness, branch reload races, and action visibility while streaming.
## PR Type Selection - [x] 🎯 **Feature** - New capability or functionality ## Summary Adds the T3 Chat / Pi web bare-minimum message actions that were missing: - **Edit** on a user message: opens an editor and resends the edited prompt. - **Retry** on a Pi reply: regenerates from the preceding user prompt. Both actions navigate Pi's native session tree in place, preserving the old branch in the session file and keeping the current session ID. Actions appear on hover/focus and are hidden while Pi is working. This also loads the active branch from `get_entries`, so displayed messages carry native entry IDs and raw user text across reloads. ## Related Issues None. Follow-up to the Pi Chat plugin and the user's report that retry/edit were missing. ## Design Overview - **Core idea:** Use Pi's native tree navigation rather than RPC `fork`. A probe confirmed RPC `fork` responds successfully and then exits the Pi child process, which would break a long-lived sidebar session. - **Data structures / algorithms:** `loadEntries()` follows `leafId` through `parentId` to build the active branch and attaches tool results by `toolCallId`. `ChatMessage` now stores `entryId` and raw user text. `reloadTranscript()` refreshes authoritative entries after `agent_settled` and after navigation. - **Interfaces added/changed:** `PiSession.editUser(entryId, text)` and `PiSession.regenerate(assistantKey)`; `PiEditMessageModal`; message action buttons; `SessionHost.extensionPath`; `get_entries` protocol types. ## Implementation Notes - The plugin writes a small private `pi-obsidian-tree.ts` extension into its plugin folder and loads it with `--extension`. The extension registers `/pi-obsidian-tree`, validates a per-process nonce from `PI_OBSIDIAN_NONCE`, checks `ctx.isIdle()`/`ctx.hasPendingMessages()`, calls `ctx.navigateTree(targetId, { summarize: false })`, and reports the result through `setStatus`. - This mirrors the Pi web UI's native tree bridge. The extension is generated at runtime, so installing the plugin still only requires `main.js`, `manifest.json`, and `styles.css`. - `get_commands` is checked during hydration to enable the actions only when the extension loaded. - Navigation and retry are serialized with a `revising` guard. A stale transcript reload cannot overwrite a newly started prompt (`epoch` guard). - Rejected alternative: RPC `fork`/`clone`, because the child exits after the fork response and the plugin would have to restart the process and guess the new session state. - Version bumped to 0.2.0. ## Testing Evidence - Added tests: `tests/chat-state.test.ts` covers active-branch loading, entry IDs, raw user text, tool-result attachment, and compaction summaries. `tests/extension-source.test.ts` imports the generated extension and verifies nonce enforcement, idle checks, and status reporting. - `bun run check` passes: typecheck + **21 tests**. - `bun run build` passes. - Manual end-to-end with real Pi: started a session, sent ALPHA, **Retry** produced a new ALPHA branch, **Edit** changed the prompt to GAMMA and produced GAMMA. The session ID stayed unchanged and `get_entries` showed the old branch retained. - UI action rows checked at 380px sidebar width with hover reveal. ## Documentation - [x] README updated with Edit/Retry behavior, branching semantics, and the generated extension - [ ] Design doc added/updated - [x] Code comments added where behavior is non-obvious ## Checklist (Feature-Specific) - [x] Issue(s) linked (or rationale if none) - [x] Tests added and passing - [x] No Lint / Style violations - [x] No dead / Debug / Commented-Out code - [x] Follows course integrity guidelines ## Additional Notes - Review focus: generated extension loading/security, tree navigation correctness, branch reload races, and action visibility while streaming.
Add hover actions to user and assistant messages. Edit opens a modal and
resends the edited prompt; Retry regenerates from the preceding user prompt.
Both use a generated private Pi extension to navigate the native session tree
in place, because RPC fork exits the child process. Load native entry ids and
the active branch from get_entries so actions survive reloads and retries.
Increment the transcript epoch when a retry or edit starts so a scheduled
agent-settled reload cannot overwrite the branch while navigation is in flight.
Surface edit/retry failures in the chat error banner.
Code-Reviewer left a comment

Pi code review

2 new actionable findings

  • [P2] Retry can resend an older prompt before transcript refresh — src/session.ts:392
  • [P2] Editing a skill prompt drops its skill instructions — src/chat-view.ts:568

Merged three candidate reviews of Edit/Retry via native Pi tree navigation; verified both surviving defects against current session, view, and chat-state code. No checks were run and live Pi behavior could not be exercised from this environment.

Change walkthrough
Area Files Changes
Other code (10) src/chat-state.ts, src/chat-view.ts, src/dialogs.ts, src/extension-source.ts (+6 more) Adds entryId/rawText and loadEntries() for active-branch transcript Adds Edit/Retry actions, preceding-user lookup, and edit modal wiring Adds PiEditMessageModal with empty-text validation Adds nonce-gated pi-obsidian-tree navigation extension
Documentation (1) README.md Documents Edit/Retry branching and generated extension
Tests (2) tests/chat-state.test.ts, tests/extension-source.test.ts Covers active-branch loading, entry ids, and summaries Covers nonce enforcement and idle checks for generated extension

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 15 files, +616/-17.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed df38299aee33ddb6957a15ab2a13fbcbc937169d with proxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:9392612537dda017d328829c3c6bbc3e01e8d2e96b85e5feabf4b2d4a9ab0259 --> ## Pi code review **2 new actionable findings** - **[P2] Retry can resend an older prompt before transcript refresh** — `src/session.ts:392` - **[P2] Editing a skill prompt drops its skill instructions** — `src/chat-view.ts:568` Merged three candidate reviews of Edit/Retry via native Pi tree navigation; verified both surviving defects against current session, view, and chat-state code. No checks were run and live Pi behavior could not be exercised from this environment. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (10) | `src/chat-state.ts`, `src/chat-view.ts`, `src/dialogs.ts`, `src/extension-source.ts` (+6 more) | Adds entryId/rawText and loadEntries() for active-branch transcript Adds Edit/Retry actions, preceding-user lookup, and edit modal wiring Adds PiEditMessageModal with empty-text validation Adds nonce-gated pi-obsidian-tree navigation extension | | Documentation (1) | `README.md` | Documents Edit/Retry branching and generated extension | | Tests (2) | `tests/chat-state.test.ts`, `tests/extension-source.test.ts` | Covers active-branch loading, entry ids, and summaries Covers nonce enforcement and idle checks for generated extension | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 15 files, +616/-17. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `df38299aee33ddb6957a15ab2a13fbcbc937169d` with `proxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3`. Automated advisory review; no project commands or tests were executed.
@ -524,0 +565,4 @@
event.preventDefault();
event.stopPropagation();
handler();
});
Collaborator

[P2] Editing a skill prompt drops its skill instructions

Edit prefills and resends from rendered text blocks instead of rawText, so saving an edit on a skill-expanded prompt resends bare user text without its skill wrapper.

Trigger: Send a skill invocation with accompanying user text, then open Edit on that user message and save.

Impact: Replacement request loses the selected skill name/location/content context, materially changing how Pi performs the task without user intent.

Evidence: chat-state.ts toMessage keeps skill blocks as only trailing userText while rawText preserves full messageText; chat-view.ts editMessage builds initial from blocks text and calls editUser(entryId,text) with bare text, while session.ts regenerate correctly reuses user.rawText.

**[P2] Editing a skill prompt drops its skill instructions** Edit prefills and resends from rendered text blocks instead of rawText, so saving an edit on a skill-expanded prompt resends bare user text without its skill wrapper. **Trigger:** Send a skill invocation with accompanying user text, then open Edit on that user message and save. **Impact:** Replacement request loses the selected skill name/location/content context, materially changing how Pi performs the task without user intent. **Evidence:** chat-state.ts toMessage keeps skill blocks as only trailing userText while rawText preserves full messageText; chat-view.ts editMessage builds initial from blocks text and calls editUser(entryId,text) with bare text, while session.ts regenerate correctly reuses user.rawText.
src/session.ts Outdated
@ -252,0 +389,4 @@
if (index < 0) throw new Error("That reply is no longer on the active branch.");
const user = [...this.state.messages.slice(0, index)]
.reverse()
.find((message) => message.role === "user" && message.entryId && message.rawText !== undefined);
Collaborator

[P2] Retry can resend an older prompt before transcript refresh

Preceding-user lookup skips user messages without entryIds instead of stopping at the immediate predecessor, so Retry on a newly completed response can select an older saved prompt and branch from the wrong turn.

Trigger: Complete a second or later prompt while an earlier user already has an entryId, then click Retry on the latest reply while its post-settlement get_entries refresh is still pending or has failed.

Impact: Pi regenerates an unrelated earlier request and removes the later conversation from the active branch instead of retrying the selected response.

Evidence: applyRecord creates streamed messages via toMessage without entryId; agent_settled clears busy and starts reloadTranscript asynchronously with errors swallowed, while canRevise is true immediately. Both PiChatView.precedingUser (src/chat-view.ts:544 skips users lacking entryId/rawText) and PiSession.regenerate search backward for a user with entryId, then navigateNative plus prompt with that older entryId/rawText.

**[P2] Retry can resend an older prompt before transcript refresh** Preceding-user lookup skips user messages without entryIds instead of stopping at the immediate predecessor, so Retry on a newly completed response can select an older saved prompt and branch from the wrong turn. **Trigger:** Complete a second or later prompt while an earlier user already has an entryId, then click Retry on the latest reply while its post-settlement get_entries refresh is still pending or has failed. **Impact:** Pi regenerates an unrelated earlier request and removes the later conversation from the active branch instead of retrying the selected response. **Evidence:** applyRecord creates streamed messages via toMessage without entryId; agent_settled clears busy and starts reloadTranscript asynchronously with errors swallowed, while canRevise is true immediately. Both PiChatView.precedingUser (src/chat-view.ts:544 skips users lacking entryId/rawText) and PiSession.regenerate search backward for a user with entryId, then navigateNative plus prompt with that older entryId/rawText.
- Stop preceding-user lookup at the nearest user turn; if it has no native
  entry yet, hide Retry instead of branching from an older prompt.
- Rebuild a skill invocation around edited user text so editing does not drop
  the skill instructions.
- Add tests for stale retry targets and skill prompt composition.
Code-Reviewer left a comment

Pi code review

1 new actionable finding

  • [P2] Composer sends can interleave with an unfinished Edit or Retry — src/session.ts:402
Earlier findings: 2 rechecked
  • Resolved: Retry can resend an older prompt before transcript refresh (src/session.ts:392, first reported in review #250) — precedingUserMessage in src/chat-state.ts now returns the nearest preceding user or undefined immediately without skipping unrefreshed turns, and both PiChatView.precedingUser and PiSession.regenerate use it to hide Retry or throw Wait for refresh; covered by does not skip past an unrefreshed user test.
  • Resolved: Editing a skill prompt drops its skill instructions (src/chat-view.ts:568, first reported in review #250) — PiChatView.editMessage now passes message.skill to editUser and PiSession.editUser rebuilds with composeSkillPrompt(skill, trimmed), restoring the <skill> wrapper; covered by rebuilds skill instructions test.

Merged three reviews of the Edit/Retry tree-navigation change at head 07cb0fd against base ce3ebf3. Verification was read-only code inspection without running tests or a live Pi session.

Change walkthrough
Area Files Changes
Other code (11) .gitignore, manifest.json, src/chat-state.ts, src/chat-view.ts (+7 more) Ignore the runtime-generated tree-navigation extension. Bump plugin version to 0.2.0. Load active native branch with entry IDs, preceding-user guard, and skill rebuild. Add Edit/Retry controls gated by revision availability.
Documentation (1) README.md Document Edit/Retry actions, branching, and extension loading.
Deployment & tooling (1) package.json Bump package version to 0.2.0.
Tests (2) tests/chat-state.test.ts, tests/extension-source.test.ts Cover branch loading, entry IDs, preceding-user, and skill reconstruction. Test command authorization, idle checks, and status reporting.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 15 files, +661/-18.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 07cb0fdf22aa8f8bdba4cbf11103dc47d2f54eb8 with proxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:f0024b6075a28b5b83e36b05c7ea8c09d697737446e940b41095bee3cadfb01a --> ## Pi code review **1 new actionable finding** - **[P2] Composer sends can interleave with an unfinished Edit or Retry** — `src/session.ts:402` <details> <summary>Earlier findings: 2 rechecked</summary> - **Resolved:** Retry can resend an older prompt before transcript refresh (`src/session.ts:392`, first reported in review #250) — precedingUserMessage in src/chat-state.ts now returns the nearest preceding user or undefined immediately without skipping unrefreshed turns, and both PiChatView.precedingUser and PiSession.regenerate use it to hide Retry or throw Wait for refresh; covered by does not skip past an unrefreshed user test. - **Resolved:** Editing a skill prompt drops its skill instructions (`src/chat-view.ts:568`, first reported in review #250) — PiChatView.editMessage now passes message.skill to editUser and PiSession.editUser rebuilds with composeSkillPrompt(skill, trimmed), restoring the &lt;skill&gt; wrapper; covered by rebuilds skill instructions test. </details> Merged three reviews of the Edit/Retry tree-navigation change at head 07cb0fd against base ce3ebf3. Verification was read-only code inspection without running tests or a live Pi session. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (11) | `.gitignore`, `manifest.json`, `src/chat-state.ts`, `src/chat-view.ts` (+7 more) | Ignore the runtime-generated tree-navigation extension. Bump plugin version to 0.2.0. Load active native branch with entry IDs, preceding-user guard, and skill rebuild. Add Edit/Retry controls gated by revision availability. | | Documentation (1) | `README.md` | Document Edit/Retry actions, branching, and extension loading. | | Deployment & tooling (1) | `package.json` | Bump package version to 0.2.0. | | Tests (2) | `tests/chat-state.test.ts`, `tests/extension-source.test.ts` | Cover branch loading, entry IDs, preceding-user, and skill reconstruction. Test command authorization, idle checks, and status reporting. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 15 files, +661/-18. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `07cb0fdf22aa8f8bdba4cbf11103dc47d2f54eb8` with `proxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3`. Automated advisory review; no project commands or tests were executed.
src/session.ts Outdated
@ -252,0 +399,4 @@
this.host.changed();
try {
await this.navigateNative(user.entryId, "Retrying response");
await this.prompt(user.rawText, "steer");
Collaborator

[P2] Composer sends can interleave with an unfinished Edit or Retry

The revising guard blocks concurrent Edit/Retry but ordinary composer prompt() has no revising check, so a composer message sent during the post-navigation transcript reload runs on the rewound branch and the revision then unconditionally sends its own replacement prompt as steer.

Trigger: Click Edit/Save or Retry, then send a composer message while the post-navigation get_entries reload is pending; a slow or large transcript widens the window and composer sends while busy are intentionally queued as steer/followUp.

Impact: The new composer request runs without the expected replacement turn in context, and the edited/retried instructions become steering input to that unrelated request, producing unintended agent work instead of independent turns.

Evidence: PiChatView.send() calls PiSession.prompt() directly with only empty-draft gating, and prompt() only bumps epoch without checking revising, while editUser/regenerate only check revising against each other. navigateNative awaits reloadTranscript after the branch change and doReloadTranscript merely skips load on busy/epoch change, but regenerate then still executes prompt(user.rawText, steer) and editUser executes prompt(prompt, steer). Extension idle checks occur before navigation and do not protect this later interval.

**[P2] Composer sends can interleave with an unfinished Edit or Retry** The revising guard blocks concurrent Edit/Retry but ordinary composer prompt() has no revising check, so a composer message sent during the post-navigation transcript reload runs on the rewound branch and the revision then unconditionally sends its own replacement prompt as steer. **Trigger:** Click Edit/Save or Retry, then send a composer message while the post-navigation get_entries reload is pending; a slow or large transcript widens the window and composer sends while busy are intentionally queued as steer/followUp. **Impact:** The new composer request runs without the expected replacement turn in context, and the edited/retried instructions become steering input to that unrelated request, producing unintended agent work instead of independent turns. **Evidence:** PiChatView.send() calls PiSession.prompt() directly with only empty-draft gating, and prompt() only bumps epoch without checking revising, while editUser/regenerate only check revising against each other. navigateNative awaits reloadTranscript after the branch change and doReloadTranscript merely skips load on busy/epoch change, but regenerate then still executes prompt(user.rawText, steer) and editUser executes prompt(prompt, steer). Extension idle checks occur before navigation and do not protect this later interval.
Keep ordinary prompts from interleaving with the post-navigation replacement
prompt of an Edit or Retry. The public prompt path now rejects revisions, the
replacement uses an internal send, the composer is disabled while revising,
and compaction is blocked during the same window.
Code-Reviewer left a comment

Pi code review

1 new actionable finding

  • [P2] New chat or restart during Edit/Retry can move replacement prompt to fresh session — src/session.ts:503
Earlier findings: 1 rechecked
  • Resolved: Composer sends can interleave with an unfinished Edit or Retry (src/session.ts:402, first reported in review #251) — src/session.ts:420 prompt() now throws when revising and src/session.ts:487 compact() does the same; src/chat-view.ts send() early-returns on isRevising and refreshSendButton disables send while revising, and revising remains true across navigateNative including reloadTranscript until the finally block.

Outside the diff

[P2] New chat or restart during Edit/Retry can move replacement prompt to fresh session

editUser/regenerate hold revising across navigateNative plus sendPrompt but newSession/restart have no revising check, so a New chat or Restart issued after navigation succeeds can run before the queued replacement prompt and send it on the new client.

Trigger: Click Edit Save or Retry, then before navigation plus reload completes use New chat view action, New chat command, Restart command, or settings New chat; busy is false during navigation so newChat busy confirmation does not block it.

Impact: The edited or retried prompt is lost from the intended branch and instead starts unintended agent work in the fresh session with possible vault reads or edits and model cost, plus stale-branch transcript or error pollution.

Evidence: src/session.ts editUser/regenerate set revising=true then call navigateNative then sendPrompt without snapshotting the client while sendPrompt uses this.client at call time; prompt() at line 420 and compact() at line 487 reject when revising but newSession() at line 503 and restart() at line 518 have no such guard; src/chat-view.ts newChat() only confirms on state.busy which is false while navigateNative sets status Editing/Retrying.

Suggested fix:

--- a/src/session.ts
+++ b/src/session.ts
@@ -503,6 +503,7 @@
   newSession(): Promise<void> {
+    if (this.revising) throw new Error("Wait for the current edit or retry to finish.");
     return this.enqueue(async () => {
@@ -518,6 +519,7 @@
   restart(): Promise<void> {
+    if (this.revising) throw new Error("Wait for the current edit or retry to finish.");
     return this.enqueue(async () => {

Location: src/session.ts:503 (outside the diff; posted here because it can't anchor inline).

Merged three candidate reviews of Edit/Retry tree navigation, transcript reloads, and UI gating; verified revision guards in current code. No execution environment was available, so Pi-side navigation and timing behavior were inferred from code and callers.

Change walkthrough
Area Files Changes
Other code (7) src/chat-state.ts, src/session.ts, src/extension-source.ts, src/chat-view.ts (+3 more) Adds active-branch loading with entry IDs, raw text, and retry helpers Adds tree-navigation extension loading, revising guards, and transcript reload Adds private nonce-checked tree-navigation extension source Adds Edit/Retry actions and revising-aware composer gating
Tests (2) tests/chat-state.test.ts, tests/extension-source.test.ts Covers branch loading, tool results, and retry helpers Covers extension nonce, idle checks, and status reporting

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 15 files, +678/-21.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 6c7f6202ffa98fbba70d1da2ffb3f3184ff5d7fd with proxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:8d5f87f929e250ff66cff275d2e39c8ce00be9fbf1bd831fe9decaba5e380d8f --> ## Pi code review **1 new actionable finding** - **[P2] New chat or restart during Edit/Retry can move replacement prompt to fresh session** — `src/session.ts:503` <details> <summary>Earlier findings: 1 rechecked</summary> - **Resolved:** Composer sends can interleave with an unfinished Edit or Retry (`src/session.ts:402`, first reported in review #251) — src/session.ts:420 prompt() now throws when revising and src/session.ts:487 compact() does the same; src/chat-view.ts send() early-returns on isRevising and refreshSendButton disables send while revising, and revising remains true across navigateNative including reloadTranscript until the finally block. </details> ### Outside the diff **[P2] New chat or restart during Edit/Retry can move replacement prompt to fresh session** editUser/regenerate hold revising across navigateNative plus sendPrompt but newSession/restart have no revising check, so a New chat or Restart issued after navigation succeeds can run before the queued replacement prompt and send it on the new client. **Trigger:** Click Edit Save or Retry, then before navigation plus reload completes use New chat view action, New chat command, Restart command, or settings New chat; busy is false during navigation so newChat busy confirmation does not block it. **Impact:** The edited or retried prompt is lost from the intended branch and instead starts unintended agent work in the fresh session with possible vault reads or edits and model cost, plus stale-branch transcript or error pollution. **Evidence:** src/session.ts editUser/regenerate set revising=true then call navigateNative then sendPrompt without snapshotting the client while sendPrompt uses this.client at call time; prompt() at line 420 and compact() at line 487 reject when revising but newSession() at line 503 and restart() at line 518 have no such guard; src/chat-view.ts newChat() only confirms on state.busy which is false while navigateNative sets status Editing/Retrying. Suggested fix: ```diff --- a/src/session.ts +++ b/src/session.ts @@ -503,6 +503,7 @@ newSession(): Promise<void> { + if (this.revising) throw new Error("Wait for the current edit or retry to finish."); return this.enqueue(async () => { @@ -518,6 +519,7 @@ restart(): Promise<void> { + if (this.revising) throw new Error("Wait for the current edit or retry to finish."); return this.enqueue(async () => { ``` Location: `src/session.ts:503` (outside the diff; posted here because it can't anchor inline). Merged three candidate reviews of Edit/Retry tree navigation, transcript reloads, and UI gating; verified revision guards in current code. No execution environment was available, so Pi-side navigation and timing behavior were inferred from code and callers. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (7) | `src/chat-state.ts`, `src/session.ts`, `src/extension-source.ts`, `src/chat-view.ts` (+3 more) | Adds active-branch loading with entry IDs, raw text, and retry helpers Adds tree-navigation extension loading, revising guards, and transcript reload Adds private nonce-checked tree-navigation extension source Adds Edit/Retry actions and revising-aware composer gating | | Tests (2) | `tests/chat-state.test.ts`, `tests/extension-source.test.ts` | Covers branch loading, tool results, and retry helpers Covers extension nonce, idle checks, and status reporting | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 15 files, +678/-21. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `6c7f6202ffa98fbba70d1da2ffb3f3184ff5d7fd` with `proxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3`. Automated advisory review; no project commands or tests were executed.
Prevent a New chat or Restart from stopping the Pi client after navigation has
already rewound the branch but before the replacement prompt is sent. Surface
the refusal as a warning from commands, the settings button, and view actions.
Code-Reviewer left a comment

Pi code review

2 new actionable findings

  • [P1] Hydrate hard-requires get_entries, breaking older Pi CLIs — src/session.ts:203
  • [P2] Manual compact can skip transcript refresh due to busy guard — src/session.ts:335
Earlier findings: 1 rechecked
  • Resolved: New chat or restart during Edit/Retry can move replacement prompt to fresh session (src/session.ts:503, first reported in review #254) — Head src/session.ts newSession() and restart() reject when revising is true before enqueuing lifecycle work, and src/chat-view.ts newChat()/restart() block on isRevising; replacement prompt can no longer land in a fresh session.

Merged three independent reviews of the Edit/Retry tree-navigation change at head 41502ce. Verification was read-only code inspection; Pi-side RPC behavior and live Obsidian runs could not be exercised.

Change walkthrough
Area Files Changes
Other code (11) .gitignore, manifest.json, src/chat-state.ts, src/chat-view.ts (+7 more) Ignores the runtime-generated tree-navigation extension. Bumps plugin version to 0.2.0. Adds loadEntries active-branch builder with entry IDs and raw user text. Adds hover Edit/Retry actions with revise-aware guards.
Documentation (1) README.md Documents Edit/Retry branching semantics and generated extension.
Deployment & tooling (1) package.json Bumps package version to 0.2.0.
Tests (2) tests/chat-state.test.ts, tests/extension-source.test.ts Tests branch loading, tool attachment, and retry guards. Tests generated extension nonce and idle checks.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 15 files, +699/-24.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 41502ce7e9454a1d4493a257b4ba617b986876b6 with proxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:ed1ebd734780ebf2ba877f4b684279fb7428365743dceffcdace16bba631feaf --> ## Pi code review **2 new actionable findings** - **[P1] Hydrate hard-requires get_entries, breaking older Pi CLIs** — `src/session.ts:203` - **[P2] Manual compact can skip transcript refresh due to busy guard** — `src/session.ts:335` <details> <summary>Earlier findings: 1 rechecked</summary> - **Resolved:** New chat or restart during Edit/Retry can move replacement prompt to fresh session (`src/session.ts:503`, first reported in review #254) — Head src/session.ts newSession() and restart() reject when revising is true before enqueuing lifecycle work, and src/chat-view.ts newChat()/restart() block on isRevising; replacement prompt can no longer land in a fresh session. </details> Merged three independent reviews of the Edit/Retry tree-navigation change at head 41502ce. Verification was read-only code inspection; Pi-side RPC behavior and live Obsidian runs could not be exercised. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (11) | `.gitignore`, `manifest.json`, `src/chat-state.ts`, `src/chat-view.ts` (+7 more) | Ignores the runtime-generated tree-navigation extension. Bumps plugin version to 0.2.0. Adds loadEntries active-branch builder with entry IDs and raw user text. Adds hover Edit/Retry actions with revise-aware guards. | | Documentation (1) | `README.md` | Documents Edit/Retry branching semantics and generated extension. | | Deployment & tooling (1) | `package.json` | Bumps package version to 0.2.0. | | Tests (2) | `tests/chat-state.test.ts`, `tests/extension-source.test.ts` | Tests branch loading, tool attachment, and retry guards. Tests generated extension nonce and idle checks. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 15 files, +699/-24. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `41502ce7e9454a1d4493a257b4ba617b986876b6` with `proxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3`. Automated advisory review; no project commands or tests were executed.
src/session.ts Outdated
@ -163,3 +201,3 @@
client.request({ type: "get_available_models" }),
client.request({ type: "get_available_thinking_levels" }),
client.request({ type: "get_messages" }),
client.request({ type: "get_entries" }),
Collaborator

[P1] Hydrate hard-requires get_entries, breaking older Pi CLIs

hydrate() requests get_entries without fallback; if Pi lacks that RPC the Promise.all rejects and doStart marks the session Pi unavailable, leaving chat unusable where get_messages previously worked.

Trigger: Start the plugin against a Pi binary without get_entries RPC (custom piPath, older Pi). Authors anticipate older versions via the navigateTree version check.

Impact: Full chat hydration fails and shows Pi unavailable instead of degrading to history without revise actions, blocking all use for affected users.

Evidence: Head src/session.ts hydrate does Promise.all with client.request get_entries with no catch while get_session_stats and get_commands have .catch fallbacks; base hydrate used get_messages. Head doStart catch sets status Pi unavailable and notifies on hydrate failure.

Suggested fix:

--- a/src/session.ts
+++ b/src/session.ts
@@
-      client.request({ type: "get_entries" }),
+      client.request({ type: "get_entries" }).catch(() => null),
@@
-    loadEntries(this.state, entries.entries, entries.leafId);
+    if (entries) {
+      loadEntries(this.state, entries.entries, entries.leafId);
+    } else {
+      const messages = await client.request({ type: "get_messages" });
+      loadHistory(this.state, messages.messages);
+    }
**[P1] Hydrate hard-requires get_entries, breaking older Pi CLIs** hydrate() requests get_entries without fallback; if Pi lacks that RPC the Promise.all rejects and doStart marks the session Pi unavailable, leaving chat unusable where get_messages previously worked. **Trigger:** Start the plugin against a Pi binary without get_entries RPC (custom piPath, older Pi). Authors anticipate older versions via the navigateTree version check. **Impact:** Full chat hydration fails and shows Pi unavailable instead of degrading to history without revise actions, blocking all use for affected users. **Evidence:** Head src/session.ts hydrate does Promise.all with client.request get_entries with no catch while get_session_stats and get_commands have .catch fallbacks; base hydrate used get_messages. Head doStart catch sets status Pi unavailable and notifies on hydrate failure. Suggested fix: ```diff --- a/src/session.ts +++ b/src/session.ts @@ - client.request({ type: "get_entries" }), + client.request({ type: "get_entries" }).catch(() => null), @@ - loadEntries(this.state, entries.entries, entries.leafId); + if (entries) { + loadEntries(this.state, entries.entries, entries.leafId); + } else { + const messages = await client.request({ type: "get_messages" }); + loadHistory(this.state, messages.messages); + } ```
src/session.ts Outdated
@ -252,0 +332,4 @@
const epoch = this.epoch;
const entries = await client.request({ type: "get_entries" });
// A new turn may have started while the request was in flight.
if (this.state.busy || epoch !== this.epoch) return;
Collaborator

[P2] Manual compact can skip transcript refresh due to busy guard

compact() now calls guarded reloadTranscript() which early-returns when busy is true, while compaction_start sets busy true without a clear on compaction_end. If Pi emits compaction events around the manual compact RPC, the post-compact reload is skipped and the view keeps pre-compaction messages while status shows Ready.

Trigger: Idle session with history, invoke Compact context; Pi emits compaction_start/end during the compact RPC.

Impact: User sees stale pre-compaction transcript with no compaction summary while status reports Ready, hiding that compaction occurred.

Evidence: Head src/chat-state.ts compaction_start sets busy true and compaction_end only sets status without clearing busy; head src/session.ts doReloadTranscript returns if state.busy, and compact() calls reloadTranscript where base did unconditional get_messages plus loadHistory.

**[P2] Manual compact can skip transcript refresh due to busy guard** compact() now calls guarded reloadTranscript() which early-returns when busy is true, while compaction_start sets busy true without a clear on compaction_end. If Pi emits compaction events around the manual compact RPC, the post-compact reload is skipped and the view keeps pre-compaction messages while status shows Ready. **Trigger:** Idle session with history, invoke Compact context; Pi emits compaction_start/end during the compact RPC. **Impact:** User sees stale pre-compaction transcript with no compaction summary while status reports Ready, hiding that compaction occurred. **Evidence:** Head src/chat-state.ts compaction_start sets busy true and compaction_end only sets status without clearing busy; head src/session.ts doReloadTranscript returns if state.busy, and compact() calls reloadTranscript where base did unconditional get_messages plus loadHistory.
- Fall back to get_messages when get_entries is unavailable, keeping the chat
  usable on older Pi versions without message actions.
- Track running and compacting separately so compaction_end clears the busy
  guard and the post-compact transcript reload actually runs.
- Block manual compaction during an active run and surface command failures.
Code-Reviewer left a comment

Pi code review

0 new actionable findings

No new actionable findings. Previously reported issues, if any, are tracked below.

Earlier findings: 2 rechecked
  • Resolved: Manual compact can skip transcript refresh due to busy guard (src/session.ts:335, first reported in review #256) — Head src/session.ts compact() sets compacting/busy then clears both (compacting=false, busy=state.running) before awaiting reloadTranscript(), so doReloadTranscript's busy guard no longer skips idle manual-compact refresh; head src/chat-state.ts compaction_end also clears compacting and derives busy from running.
  • Resolved: Hydrate hard-requires get_entries, breaking older Pi CLIs (src/session.ts:203, first reported in review #256) — Head src/session.ts hydrate() uses client.request get_entries with .catch(()=>null) and branches to loadEntries when present else get_messages+loadHistory, so missing get_entries no longer rejects Promise.all or fails hydration.

Merged three candidate reviews of the Edit/Retry tree-navigation PR; verified prior hydration and compact-refresh defects are fixed in head code via reads only, with no runnable checks.

Change walkthrough
Area Files Changes
Other code (11) src/session.ts, src/chat-state.ts, src/extension-source.ts, src/chat-view.ts (+7 more) Adds nonce-gated tree extension, Edit/Retry flows, and guarded transcript reloads with busy/compacting split. Loads active branch by leafId with entry IDs/raw text and tracks running separately from compacting. Generates private pi-obsidian-tree command enforcing nonce, idle, and version checks. Adds hover Edit/Retry actions gated by canRevise and blocks sends during revision.
Tests (2) tests/chat-state.test.ts, tests/extension-source.test.ts Covers branch loading, entry IDs, retry selection, skill prompt, and compaction state. Tests generated extension nonce enforcement, idle guard, and status reporting.
Documentation (1) README.md Documents Edit/Retry branching and runtime extension generation.
Deployment & tooling (1) package.json Bumps package version to 0.2.0.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 15 files, +755/-28.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 837a8d297ef5ff5787ba8b77efca95633bb12305 with proxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3. Automated advisory review; no project commands or tests were executed.

<!-- forgejo-pi-review:89e8d76701c9ba8b51414ab8ddb325e782a09fb0b6b0e01e0fff33938ab2e239 --> ## Pi code review **0 new actionable findings** No new actionable findings. Previously reported issues, if any, are tracked below. <details> <summary>Earlier findings: 2 rechecked</summary> - **Resolved:** Manual compact can skip transcript refresh due to busy guard (`src/session.ts:335`, first reported in review #256) — Head src/session.ts compact() sets compacting/busy then clears both (compacting=false, busy=state.running) before awaiting reloadTranscript(), so doReloadTranscript's busy guard no longer skips idle manual-compact refresh; head src/chat-state.ts compaction_end also clears compacting and derives busy from running. - **Resolved:** Hydrate hard-requires get_entries, breaking older Pi CLIs (`src/session.ts:203`, first reported in review #256) — Head src/session.ts hydrate() uses client.request get_entries with .catch(()=&gt;null) and branches to loadEntries when present else get_messages+loadHistory, so missing get_entries no longer rejects Promise.all or fails hydration. </details> Merged three candidate reviews of the Edit/Retry tree-navigation PR; verified prior hydration and compact-refresh defects are fixed in head code via reads only, with no runnable checks. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (11) | `src/session.ts`, `src/chat-state.ts`, `src/extension-source.ts`, `src/chat-view.ts` (+7 more) | Adds nonce-gated tree extension, Edit/Retry flows, and guarded transcript reloads with busy/compacting split. Loads active branch by leafId with entry IDs/raw text and tracks running separately from compacting. Generates private pi-obsidian-tree command enforcing nonce, idle, and version checks. Adds hover Edit/Retry actions gated by canRevise and blocks sends during revision. | | Tests (2) | `tests/chat-state.test.ts`, `tests/extension-source.test.ts` | Covers branch loading, entry IDs, retry selection, skill prompt, and compaction state. Tests generated extension nonce enforcement, idle guard, and status reporting. | | Documentation (1) | `README.md` | Documents Edit/Retry branching and runtime extension generation. | | Deployment & tooling (1) | `package.json` | Bumps package version to 0.2.0. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 15 files, +755/-28. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `837a8d297ef5ff5787ba8b77efca95633bb12305` with `proxy/glm-5.3-flash + proxy/gpt-6.1-sol + proxy/muse-spark-1.3 → proxy/muse-spark-1.3`. Automated advisory review; no project commands or tests were executed.
BlackHatMagic deleted branch feat/retry-edit 2026-10-23 14:32:13 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
BlackHatMagic/Pi-Obsidian!3
No description provided.