Skip to content

fix: decisions name their full target; refuse stale-tab decisions on a reused port - #1729

Merged
backnotprop merged 7 commits into
mainfrom
fix/decision-target-identity
Oct 6, 2026
Merged

backnotprop merged 7 commits into
mainfrom
fix/decision-target-identity

Conversation

@backnotprop

Copy link
Copy Markdown
Owner

Problem

The pando-ops report: a reviewer approved releases-2026-10-04/QUESTIONS.md. The approval reached the agent as Plannotator: QUESTIONS.md — Approved.\n\nThe user approved., with no path in it. The agent took the File: line from an earlier feedback message about a different QUESTIONS.md and worked on the wrong file. The server's own records were correct.

Root causes:

  • Every host names a review by its base name: subjectFor in the mod, annotateSubject in Pi and OpenCode.
  • plannotatorDecisionHeading has no target.
  • The body of a bare approval names nothing (annotateHostRecord).

There is a second, separate bug. A stale tab on a reused port can approve a different file, because the decision POST carries no identity. A reused port happens with a fixed PLANNOTATOR_PORT, with remote mode's 19432, or when a random port is reused. Reproduced: the new server accepted { draftGeneration: N }.

Changes

1. Every decision names its full target, as the server that decided resolved it

  • CLI (apps/hook/server/decision-target.ts):
    • Adds target to HostResultRecord: the absolute file or folder, the URL, the bundle's files in order, the reviewed directory, patch file or PR URL, or the plan file. Annotate-last has no target.
    • Also adds target to the ready line (ServerReadyMetadata.target via setServerReadyTarget).
    • Also adds it to the non-strict annotate --json record and the opencode-review record. Both changes are additive.
    • Plain stdout (The user approved.) and the strict-gate record are unchanged.
  • Shared contract (packages/shared/plannotator-tool.ts; the mod copy stays byte-identical, guarded by tool.test.ts):
    • plannotatorDecisionHeading(subject, id, outcome, target?) adds a Target: <path> line after the heading. A bundle gets a Targets: line followed by one - <path> line per file.
    • plannotatorToolOpenedText(..., target?) adds the same line.
    • New: plannotatorTargetLines, plannotatorSameTarget, plannotatorDistinctSubjects.
  • Claude Code mod:
    • LaunchRecord.target comes from the ready line. For a CLI older than this change it falls back to the mod's own resolution of the words against the session directory, which privateDirArgv now prints with pwd.
    • When the result record has a target, the turn names that target.
    • If the record's target differs from the launch's, the mod writes one $.ui.log line saying so.
    • The launch passes PLANNOTATOR_HOST_REVIEW_ID.
  • Pi: the in-process registry stores target for annotate, review and plan reviews, and withDecisionHeading and the tool's opened text use it.
  • OpenCode 2 / CLI bridge:
    • The bridge reads the target from the ready line and from the JSON records.
    • The heading names it.
    • The annotate File: line now uses the CLI's resolved path instead of the raw words.
    • The launch passes PLANNOTATOR_HOST_REVIEW_ID.

2. Same-named open reviews are told apart

plannotatorDistinctSubjects gives each one the shortest path tail that is unique. Example: releases-2026-10-04/QUESTIONS.md and releases-2026-09-20/QUESTIONS.md. A subject such as changes in web keeps its words and becomes changes in a/app/web. The new names show in headings, the status line and toasts in the mod, Pi and OpenCode 2.

3. Stale-tab guard (session_mismatch)

  • Each plan, annotate and review server creates a random serverSession nonce when it starts. This covers Bun and the Pi mirrors.
  • The nonce is sent on /api/plan and on the diff payloads.
  • The editor and review editor send it back on approve, deny and feedback in the request body, and on /api/exit as ?serverSession=.
  • If the nonce does not match, the server answers 409 { code: "session_mismatch" } before it claims or settles anything. The tab then shows "This review was replaced — reload".
  • A request without the nonce (an older client) is still accepted. This is documented in packages/core/server-session.ts and in AGENTS.md.

4. plannotator sessions

  • SessionInfo gets reviewId (the pn- id) and target.
  • The table gets an id column and a full target column.
  • New --json option prints the list as a JSON array on stdout.
  • The help text and the core skill are updated.

Compatibility

  • Strict-gate output and exit codes are unchanged, and so is plain stdout.
  • The #1728 approve-with-note change is merged in. formatAnnotateOutcome now takes its notes context and the target through one parameter.
  • Older CLIs still work under the new mod: no target in the ready line or the record means the mod uses its own fallback.

Tests

  • apps/hook/hooks/mod/targets.test.ts:
    • Two launches of files with the same base name: each delivers its own full path, and the subjects are told apart.
    • An older CLI: the fallback path is used.
    • A record whose target differs: the record's target wins and the mod logs one line.
    • The pn- id reaches the CLI's environment.
  • apps/hook/server/host-result.test.ts and decision-target.test.ts: the target field on records.
  • apps/hook/server/annotate-host-result.test.ts: a real process checks the ready line, the registry, sessions --json, the table and the record.
  • packages/shared/plannotator-tool.test.ts: target lines, plannotatorDistinctSubjects and plannotatorSameTarget.
  • OpenCode 2 tool test and Pi tool test: two files with the same base name.
  • packages/server/server-session-guard.test.ts: 409 on a wrong nonce, accept on a match, accept when the nonce is missing. Covers Bun and Pi for plan, annotate and review.
  • ServerSessionReplacedBanner.test.tsx: DOM test, added to the DOM_TESTS list.

Results:

  • bun test on apps/hook, opencode-plugin, pi-extension and packages/{shared,server,core,ai}: 4337 pass, 2 skip, 0 fail.
  • DOM tests for editor and review-editor: 942 pass. The DOM allowlist guard passes.
  • bun run typecheck is clean.
  • Builds for review, hook and opencode are clean.
  • Mod harness (scripts/test-claude-code-mod.sh, with a temporary CLAUDE_CONFIG_DIR): 17 pass.

Not changed

  • Pi's plan approval and denial messages already name the plan file through their prompts and have no decision heading. They are left as they were; only the registry entry gained a target.
  • On OpenCode, plan review is a blocking tool result, so it has no heading to change.

…ion_mismatch)

Each plan, annotate and review server (Bun and Pi) issues a random
serverSession nonce, advertised on /api/plan and the diff payloads. The
editor and review editor echo it on every decision (body, or ?serverSession=
on /api/exit); a server holding a different nonce answers 409
{ code: "session_mismatch" } before claiming or settling anything, and the
tab shows a reload prompt. A decision without the field (older clients) is
still accepted.
…, list targets in sessions

A bare approval for releases-2026-10-04/QUESTIONS.md arrived as
'Plannotator: QUESTIONS.md — Approved.' with no path, and the agent took
the File: line of an earlier decision about a different QUESTIONS.md.

- The CLI names what it opened, in full, from its own state: target on the
  host result record, the ready line, the non-strict annotate --json and
  opencode-review records, and the sessions registry.
- plannotatorDecisionHeading/plannotatorToolOpenedText take the target
  (Target: line); shared contract + mod copy, Pi and OpenCode 2 pass it.
- The mod stores the target on its LaunchRecord (ready line, else its own
  resolution) as the fallback for older CLIs and logs when they differ.
- plannotatorDistinctSubjects tells same-named open reviews apart.
- plannotator sessions: pn- id + full target column, --json.
…dentity

# Conflicts:
#	AGENTS.md
#	apps/hook/server/annotate-host-result.test.ts
#	apps/hook/server/annotate-output.ts
#	apps/hook/server/host-result.test.ts
#	apps/hook/server/index.ts
…dentity

# Conflicts:
#	apps/hook/hooks/mod/controller.ts
#	packages/editor/App.tsx
…api/pr-action

- Both review servers put the ACTIVE target on the decision (the PR URL
  after an in-place /api/pr-switch, the workspace root, or the working tree
  the active diff reads); the CLI record, opencode-review and Pi use it, and
  a decision about another PR is headed with that PR
  (plannotatorDecisionSubject).
- The mod's old-CLI fallback target only takes what the words state exactly
  (URL, PR URL, absolute path, a review with no words); bare and relative
  names and review prose get no Target line.
- /api/pr-action echoes and checks the serverSession nonce in both runtimes.
- Docs: the non-strict --json dismissed record now carries target.
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.

1 participant