Skip to content

fix(assistant): reject same-draft topic reopens and align the notebook rules with the reopen contract - #6390

Open
ggbdpq wants to merge 1 commit into
apache:mainfrom
ggbdpq:fix/6388-notebook-reopen-rules
Open

ggbdpq wants to merge 1 commit into
apache:mainfrom
ggbdpq:fix/6388-notebook-reopen-rules

Conversation

@ggbdpq

@ggbdpq ggbdpq commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Two gaps in the notebook topic lifecycle from #6368:

  1. commitDraft could close a topic and reopen it in the same draft: the reopened pass ran after feedback resolution, and reopenTopic's seq guard passed against the rule the draft itself had just written. A judgement draft carrying a close decision, a note, a reopen, and a message on the same topic committed atomically and delivered the message in the same wake — overriding the user's just-expressed decision. A reopening whose governing rule was interpreted in the same draft is now rejected; reopens against earlier-wake rules are unchanged, and rejected drafts still roll back atomically.
  2. NOTEBOOK_RULES still said only explicit user feedback may reopen a topic, contradicting the wakeInput contract and the README (which describe the material-change semantics). The rules now state the material-change wording; the prompt-version hash picks up the new text, so existing worker Sessions receive it on their next wake.

Fixes #6388

Verification

Check Result
New regression a judgement cannot close a topic and reopen it in the same draft, red on parent (Missing expected exception — the draft committed atomically) green after fix
New prompt-contract test (material-change wording, not user-feedback wording) red on parent, green after
Ablation (revert notebook.ts + prompt.ts to parent, tests kept) both re-red
Boundary pin: a same-draft close only blocks reopens it governs, not rules from earlier wakes pass
notebook + topic-disposition + prompt suites 28/28
Official assistant suites (memory-network + index-initiative + proactive-matters) 281/281
Controller boundary (dist) 7/7
tsc -p packages/runtime-host --noEmit / biome format (changed files) / check:asf-headers clean / clean / pass

AI use

Authored with GLM-5.3-Flash (ZCode); the processing order, the reopenTopic guards, and the prompt-version hash coverage were re-verified line by line before filing #6388.

Checklist

  • Scope limited to the two gaps; the atomic-rollback behavior for duplicate reopens is pre-existing and untouched
  • Downstream README updated with the same-draft limitation
  • No new dependencies; no .github touches; no translator paths touched

Two gaps in the notebook initiative, both from apache#6368:

- commitDraft resolved user feedback (writing closed/deferred rules) before
  processing `reopened`, and reopenTopic only compares event seqs. A judgement
  draft could close a topic and reopen it in the same commit: notes appended
  earlier in that draft always postdate the governing feedback, so the "note
  recorded after the user feedback" guard passed against the very rule the
  draft itself had just written, overriding the user's fresh decision. The
  reopened pass now rejects a reopening whose governing rule was interpreted
  in the same draft; reopens judged against rules from earlier wakes are
  unchanged, and a rejected draft still rolls back atomically.
- NOTEBOOK_RULES still said only explicit user feedback may reopen a topic,
  contradicting the wakeInput contract and the README, which scope reopenings
  to a material change recorded in the notebook. The rules now match that
  contract; the prompt-version hash covers NOTEBOOK_RULES, so existing worker
  Sessions receive the corrected text on their next wake.

Fixes apache#6388

Generated-by: GLM-5.3-Flash (ZCode)
@ggbdpq

ggbdpq commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebase & full-chain verification refresh (2026-11-25)

Context: upstream main switched to the native/rust-preview line after 9175a2b8 (2026-11-22), removing the TypeScript app stack this fix targets. Per contributor decision, this PR is re-verified against the last TypeScript main tip 9175a2b8fc04edeac87423d90ff637bbdf4ad45d (2026-11-22) so it stays reviewable/mergeable when the TypeScript line returns.

Rebased onto 9175a2b8, 62d28ead731dd5cf3b9a168b07c1a5a6cf65aa38 → 9bd98ce394d9ae354786b433d063080167b86f15, force-pushed to the fork.

Check Result
Branch fix/6388-notebook-reopen-rules
Rebase clean (1 commit replayed onto 9175a2b)
git am 1 patch applies cleanly onto 9175a2b (throwaway worktree)
Tests via the package's esbuild loader: topic-disposition 10/10, prompt 3/3, notebook 15/15 = 28/28 (node --import scripts/assistant-test-loader.mjs --test test/<file>.test.ts)
Ablation notebook.ts + prompt.ts reverted to parent, tests kept → topic-disposition 9/10 with the new a judgement cannot close a topic and reopen it in the same draft red ('Missing expected exception.' — the draft committed atomically) and prompt 2/3 with the material-change wording contract red → fix re-applied → 28/28 green
Sibling sweep reopenTopic guards re-checked (notebook.ts :294-317: topic/reason presence, known topic, closed/deferred status, governing note-after-feedback) — the new same-draft rejection sits in commitDraft :392-396 and keys on sameDraftFeedback.has(current.feedbackId), so reopens against earlier-wake rules are untouched (the boundary pin passes inside the 10/10); reopenTopic has this single caller path
Real-path repro the regression drives the real draft commit path with close + note + reopen + message on one topic; unfixed = atomically committed and the message delivered in the same wake, fixed = rejected and rolled back

Attribution: original fix by @ggbdpq; rebase & verification refresh by GLM-5.3-Flash (ZCode).

@ggbdpq
ggbdpq force-pushed the fix/6388-notebook-reopen-rules branch from 62d28ea to 9bd98ce Compare November 24, 2026 17:59

This branch has not been deployed

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

Labels

effort/S Under 100 readable lines

Projects

None yet

1 participant