Skip to content

refactor(workspace): a Space assignment takes its node from the document (S7 PR 1, #758) - #762

Merged
DeadWaveWave merged 2 commits into
mainfrom
claude/canvas-s7-assign-from-document
Nov 27, 2026
Merged

DeadWaveWave merged 2 commits into
mainfrom
claude/canvas-s7-assign-from-document

Conversation

@DeadWaveWave

@DeadWaveWave DeadWaveWave commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

💡 Change Scope

  • Small Change: Fast feedback, localized UI/logic, low-risk.
  • Large Change: New feature, cross-boundary logic, runtime-risk (persistence, IPC, lifecycle, recovery).

📝 What Does This PR Do?

Fixes #758. Part of #761 (S7 of #647): this is S7's PR 1.

A Space assignment now measures the node the document holds, never a copy its caller passes. A caller can no longer make the push-away lay out a rect the node does not occupy.

  • assignNodeToSpaceAndExpand (workspaceCanvas/hooks/useInteractions.spaceAssignment.ts) loses its createdNode parameter. Its recipe takes the node from the document by createdNodeId when the write runs.
    • If the document no longer holds the node (it was closed meanwhile), the recipe returns the document unchanged: no membership, no snapshot Space added, no growth, no push.
    • A node without a usable rect still gets membership, and the stored nodes are laid out, as the old fallback did.
    • hasUsableLayoutRect is gone.
  • assignAgentNodeToTaskSpace (useTaskActions.agentSession.shared.ts) loses assignedNode the same way.
  • The 12 call sites in 11 files, plus the task run and resume callers, drop the argument.
  • repositionCreatedExplorerNode (fix(workspace): return the post-reposition node when assigning to a Space #756) keeps its return value: its two callers return the placed node to their own callers, and workspaceDocumentOpening.spec asserts it. Only its comments changed.

What changes at runtime:

  1. A node moved or resized between its creation and its assignment is measured where the document holds it. Before, it was measured where the caller's object said, which was Explorer and document opening hand the push-away the created node from before its reposition #725. fix(workspace): return the post-reposition node when assigning to a Space #756 fixed the two callers that reposition; this closes the channel for every caller.
  2. A node closed before its assignment runs changes nothing. Before, its id was added to the Space and the caller's copy was laid out, so the Space could grow and push its neighbours for a window that no longer existed.

Nothing else changes: every caller already wrote its node before assigning (checked below), so in every other case the stored node and the caller's object are the same.


🏗️ Large Change Spec (Required if "Large Change" is checked)

1. Context & Business Logic

The Spec is #761 (S7 of #647): Decision 9, Invariant 2, "#758: the design", and the Plan's "PR 1" in its first comment. The issue itself is #758, written by the repository owner. Its "To check first" and "Guard" items are both done here.

2. State Ownership & Invariants

The workspace document owns the node. A Space assignment computes from the document when its write runs, and from nothing else (Invariant 2 of #761).

  • A node the document holds is laid out at its stored rect.
  • A node the document does not hold is not assigned, grown around or pushed for.

Risks that were checked:

3. Verification Plan & Regression Layer

  • Tests written first, each red on the base for its reason:

    • A moved node: spaceAssignment.document.spec "measures the node the store holds when it moved after creation". It replaces the row that pinned the override; on the base, the stale copy's rect was laid out.
    • A removed node: "a node removed before the write leaves the document unchanged" and "adds no snapshot Space either", at store level. Also "hands the store a recipe that returns the document as given when the node is missing". The recipe-level test is needed because the store prunes ids of nodes it does not hold, so membership is only visible at the recipe.
    • workspaceSpaceAssignment.spec: the row that passed a caller copy now measures from the store.
    • The type test hooks/useInteractions.spaceAssignment.spec.ts, under src/ so that pnpm check compiles it. Two @ts-expect-error lines with the reason, one for each removed parameter. On the base they failed with TS2578 (unused directive).
  • The precondition guard, green on the base. For each call site, the mocked assignment records what the document held when it was called, and the test asserts that the node was there. The pane terminal and the three task-agent sites (run, reused linked agent, resume) run their real functions in a new file, spaceAssignment.callers.direct.spec.tsx.

  • The Explorer and document opening hand the push-away the created node from before its reposition #725/fix(workspace): return the post-reposition node when assigning to a Space #756 tests keep their intent in a stronger form: they assert the document holds the node at the placed position when the assignment runs, instead of comparing the caller's object.

  • Specs whose mocked creator returned a node the document did not hold now seed the document, since a missing node is now a no-op. They are taskRoleHarness, the three createTerminalNodeAtFlowPosition specs and spaceMountLaunchContext.

  • Mutations (7, all killed):

    • the recipe falls back to a caller copy;
    • a missing node still gets membership;
    • a missing node still grows and pushes;
    • a missing node still writes;
    • the note, task-resume and filesystem callers each assign before creating.
  • Review. An independent review approved the change with nothing to change in src. It probed BASE and HEAD with the same calls:

    • for a gone node, HEAD writes nothing, with no notification, flush or layout sync;
    • a stored node without a finite rect is laid out as BASE's fallback did;
    • 3000 random layouts with today's callers gave 0 differences.

    It also checked the precondition at all 15 call sites itself, and 15 of 15 too-early mutations were killed. The second commit adds two of its proposals:

    • The creators themselves: every creator of the real node store has written its node to the document when it returns or resolves (10 creators). The caller guard used stand-in creators, so it proved the call order only. A creator whose write is deferred fails this test.
    • An exact key check in the type test. A @ts-expect-error is consumed by any error on its line, so createdNode?: string passed pnpm check before. Now it fails with TS2344.

    It also fixes the second directive's reason, which named the wrong parameter.

    Not taken: a row pinning the layout of a created node without a finite rect. It would pin an accidental behaviour, a non-finite rect stopping its Space from growing, rather than an intended one; the row that pins membership stays.

  • Local runs besides the quick gate in the checklist:

    • The whole unit suite: 49276 passed, 0 failed.
    • E2E on d044c66b: 17 Desktop files, 29 passed. The second commit changes tests only. One test is skipped by a test.skip that exists on main (space-explorer.spec.ts:17). The files are:
      • spaces.auto-resize-on-create, node-create.push-away, spaces.note-avoid-overlap, creation-collapsed-space;
      • space-explorer, .layout, .media, .operations;
      • filesystem-drop-position, filesystem-nodes, image-paste;
      • tasks.create-run, tasks.agent-session-menu, tasks.double-click-create;
      • agent-launcher, roles, terminal-links.documents.

🔗 Co-change partners left untouched

  • src/contexts/workspace/presentation/renderer/components/workspaceCanvas/hooks/useAgentNodeLifecycle.ts (with src/contexts/workspace/presentation/renderer/components/workspaceCanvas/hooks/useTaskActions.agentSession.run.ts, 6/10): it launches and restarts agents but never assigns a node to a Space. It calls neither function whose parameter this PR removes.

✅ Delivery & Compliance Checklist

  • The local quick gate passes: pnpm verify:quick / pnpm pre-commit is green; any additional focused tests are reported above. On 7280f216 (on main at 67412e77): 32 files; the repository checks, lint (0 warnings), format and typecheck pass; 1556 related unit tests passed and 131 skipped by declarations that exist on main (this change adds no skip); 374 native recovery contract tests passed; 17 E2E tests passed with 1 skipped by a declaration that exists on main.
  • Full CI passes on the final revision before merge; local quick checks are not reported as full regression. CI run on 7280f216: every job passed on its first attempt. No manual macOS run: the Spec's Plan marks this PR as not needing one (no rendering, terminal or platform path changes).
  • I have signed the CLA if required (see CLA.md). The commits were written in a Claude Code cloud session and carry the repository owner's git identity as author, at the owner's request.
  • I have locked down the behavior with the strongest asset that fits, in this order: type or structure, mechanical check, runtime assertion, scenario test (or explicitly stated why none applies).
    • Type: the parameter cannot be passed again; the type test fails pnpm check if it comes back, as a directive or as a key.
    • Scenario tests: the moved-node and removed-node tests, the per-caller precondition guard, and the creators test.
  • I have strictly adhered to the DEVELOPMENT.md architectural boundaries.
  • I have attached a screenshot or screen recording (if this touches the UI).
  • I have updated the documentation accordingly (if adding a feature or changing a contract). The function's doc comment states the contract; no DEVELOPMENT.md change is needed for this step.

📸 Screenshots / Visual Evidence

Not applicable: no visual change is intended.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VeCRdryKK6NJBHjH889un3

DeadWaveWave and others added 2 commits November 27, 2026 11:23
…ument (#758)

assignNodeToSpaceAndExpand loses its createdNode parameter. Its recipe reads
the node by createdNodeId when the write runs, so a node that moved or grew
after its creator returned it is measured where the document holds it.
A node that the document no longer holds changes nothing: no membership, no
snapshot Space, no growth, no push. A node without a usable rect gets
membership and the stored nodes are laid out as before.

assignAgentNodeToTaskSpace loses assignedNode, and the 12 call sites drop the
argument. repositionCreatedExplorerNode still returns the placed node: its two
callers return it to their own callers.

Tests: a moved node is measured from the store, a removed node leaves the
document unchanged (also at the recipe, because the store prunes ids of nodes
it does not hold), a type test that createdNode and assignedNode are gone,
and a guard in the caller specs that the document held the node when each
caller assigned it. Specs whose mocked creator did not write its node now
have the document hold it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VeCRdryKK6NJBHjH889un3
…ved keys exactly

Review round for S7 PR 1:
- Every creator of the real node store has written its node to the document when it returns or
  resolves (10 creators). The caller guard proved only the call order, with stand-in creators.
- The type test also checks that neither `createdNode` nor `assignedNode` is a key of the
  parameter: a `@ts-expect-error` is consumed by any error on its line, so an optional
  `createdNode?: string` passed `pnpm check` before.
- The second directive names `assignedNode`, the parameter it is about.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VeCRdryKK6NJBHjH889un3
@DeadWaveWave
DeadWaveWave merged commit 3c5ce87 into main Nov 27, 2026
14 checks passed
@DeadWaveWave
DeadWaveWave deleted the claude/canvas-s7-assign-from-document branch November 27, 2026 12:35
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.

Space assignment: take the created node from the document, drop the caller-supplied createdNode

1 participant