Registry Mirror
Skip to content

Conversation

@aomalov

@aomalov aomalov commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2197. Diagnosis and the per-session pin by @aomalov; a maintainer follow-up commit narrowed the fix so nothing changes for existing users.

The bug

startPlannotatorServer names the history project with detectProjectName(), which reads git rev-parse --show-toplevel from process.cwd(). The plan CLI inherits the session's current directory, so a shell cd into a nested git clone between two submits writes the next version to history/<other-repo>/<slug>/001.md, and the Versions tab never opens. Same class as #1679, on the project half of history/{project}/{slug}.

The fix: pin a plan's project per session

  • ServerOptions.sessionTag (claude-code:<id>): the mod sends its session id on claude-mod-plan's stdin (sessionId, falling back to PLANNOTATOR_SESSION_TAG); the classic PermissionRequest hook uses the payload's session_id, Claude Code origin only (never Gemini).
  • pinPlanProject(sessionTag, slug, detected) (packages/shared/storage.ts) keys a pin by (session, date-free slug, the part resolveHistorySlug matches on). When this session saved this plan within the 48 h continue window and that project still holds the chain, the resubmit uses that project wherever the cwd is now (root → clone, clone → root, clone → clone). Otherwise the current folder's project is used and recorded. Each save and in-session revision refreshes the pin.
  • Storage: <data dir>/plan-projects/<host>/<session id>.json, 0700 folders, a 0600 file written whole (temp + rename), at most 50 plans per session, expired entries dropped, session files untouched for 7 days swept. The session id is validated (charset, length, no ..) before it names a file; a missing or corrupt file, or a pinned project that is not one path segment, is ignored and never fails a submit. uninstall --purge removes plan-projects/.

What does not change

  • A new plan's history project is always the current folder's, exactly as before; the earlier session-root default (projectRoot) was dropped.
  • A different session, a different plan (another heading), and every host without a session (OpenCode, Pi, Codex, Gemini, Copilot, Droid, Vibe) behave as on main. Same session and same heading count as the same plan, as within one project already.
  • Only the history key (and so the feedback archive record that names that version) follows a pin; plan file trust, linked docs, /api/doc, projectRoot on /api/plan, repoInfo and the sessions/ label keep the cwd.
  • Old CLI + new mod: sessionId is ignored. New CLI + old mod: PLANNOTATOR_SESSION_TAG or nothing.

Tests

  • apps/hook/server/plan-history-session.test.ts: the CLI as real processes, with a scratch data dir and NO_BROWSER, against a workspace repository holding two clones:
    • workspace → clone, clone → workspace and clone → clone continue the chain (version 2, previousPlan = v1) through both the mod and the classic hook, and the two paths share one session's pins;
    • another session's same-heading plan at the root does not pull in a new plan in a clone;
    • a new plan from a clone lands under the clone;
    • two sessions with the same heading in one project behave as on main;
    • a corrupt pin file is ignored;
    • no session gives main's layout and writes no pin.
  • pinPlanProject unit tests in packages/shared/storage.test.ts (keying, 0600, gone chain, expiry, corrupt file, unsafe tags, cap). The mod's stdin carries sessionId (controller.test.ts).
  • Docs: Plan Version History in docs/agent-guides/server-and-storage.md, the stdin in claude-code-mod.md.

🤖 Generated with Claude Code

aomalov and others added 2 commits October 26, 2026 13:49
…gent changes directory (backnotprop#2197)

Fixes backnotprop#2197.

Plan history was keyed by the git repo of the process cwd at each submit, so a
shell cd into a nested repo between submits started a new history at version 1
and the UI showed no previous versions.

- Name the history project from the session's project root: $.session.root()
  in the mod, CLAUDE_PROJECT_DIR in the classic hook.
- Pin each plan's project per (session, date-free slug) on first save, so /cd or a
  worktree move mid-plan keeps later versions in the same history.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eep the cwd's project (backnotprop#2197)

Drop the session-root default (projectRoot from $.session.root() /
CLAUDE_PROJECT_DIR): a new plan's history project stays the current
folder's, exactly as before. Keep the per-session pin, hardened:
keyed by (session, date-free slug), session id validated before it names
a file, one 0600 JSON file per session written atomically, pins live for
the 48 h continue window and only while the pinned project holds the
chain, at most 50 per session, stale session files swept, a corrupt file
ignored. The mod sends its session id on claude-mod-plan's stdin.

Co-authored-by: aomalov <12465803+aomalov@users.noreply.github.com>
@aomalov

aomalov commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Heads-up: I saw #2199 after opening this, and it covers #2197 in a way that keeps where new plans land unchanged, so it's the better base. Feel free to close this one.

The one piece here #2199 lists as not covered is a plan started inside a nested clone and resubmitted from the root or another clone. pinPlanProject handles that: it records, per session and date-free slug, the project a plan was first saved under (~/.plannotator/plan-projects/). If that case is worth covering, take it from this branch or I can rebase it onto #2199 as a small follow-up, whichever you prefer.

The one red check here (Pi extension AI runtime, Windows) is a review-workspace symlink test that hit its 5 s timeout and then EBUSY on temp cleanup; it passes on main and on #2199 and isn't touched by this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plan history loses its Versions tab when the agent changes directory into another git repo between submits

2 participants