Skip to content

fix(workspace): return the post-reposition node when assigning to a Space - #756

Merged
DeadWaveWave merged 1 commit into
DeadWaveWave:mainfrom
anhnt256:fix/725-reposition-created-node
Nov 26, 2026
Merged

DeadWaveWave merged 1 commit into
DeadWaveWave:mainfrom
anhnt256:fix/725-reposition-created-node

Conversation

@anhnt256

Copy link
Copy Markdown
Contributor

💡 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 #725.

When the Space explorer opens a file into a Space (or a document opens from a terminal link), repositionCreatedExplorerNode may move the created node to a free spot and write the new position to the store — but assignNodeToSpaceAndExpand was then called with the pre-move created object. The push-away replaces the store's copy of the created node with the createdNode it is given when that one has a usable rect, so it grew the Space and pushed neighbours around the node's old position while the node sat at the new one.

This PR has repositionCreatedExplorerNode return the node as stored after the reposition (the moved node, or the created node itself when it did not move), and both call sites — useSpaceExplorer.ts (image materialization) and useWorkspaceDocumentOpening.ts (document opening) — now hand that returned node to the push-away and return it to their callers, so the Space is grown and neighbours are pushed around the rect the node actually occupies.


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

Not applicable — this is a Small Change.


🔗 Co-change partners left untouched

  • src/contexts/workspace/presentation/renderer/components/workspaceCanvas/hooks/useInteractions.spaceAssignment.ts (assignNodeToSpaceAndExpand) — no change needed: the push-away itself is correct; only the node handed to it was stale.
  • The other assignNodeToSpaceAndExpand callers (useAgentLauncher, useCanvasImageImport, useFilesystemNodes, useInteractions.noteCreation, useInteractions.paneNodeCreation, useRoleActions, useTaskActions.agentSession.shared, useTaskNodeCreation) — no change needed: none of them calls repositionCreatedExplorerNode, so the stale-node pattern does not apply there.
  • src/contexts/workspace/presentation/renderer/utils/collision.ts (findNearestFreePositionOnRight) — no change needed: the scan itself returns the right spot; only its result was discarded by the callers.

✅ Delivery & Compliance Checklist

  • The local quick gate passes: pnpm verify:quick / pnpm pre-commit is green; any additional focused tests are reported above.
  • Full CI passes on the final revision before merge; local quick checks are not reported as full regression.
  • I have signed the CLA if required (see CLA.md).
  • 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).
  • 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).

📸 Screenshots / Visual Evidence

Not applicable — no UI change.

Verification (targeted gates run locally; full verify:quick left for pre-submit/CI)

  • New failing-first tests, then the fix (TDD red → green): repositionCreatedExplorerNode returns the moved node; the document-opening caller and the explorer image caller hand the push-away the moved rect.
  • Adjacent suites, 66 tests, all green:
    pnpm vitest run tests/unit/contexts/useSpaceExplorer.materializePlacement.spec.ts tests/unit/contexts/workspaceDocumentOpening.spec.tsx tests/unit/contexts/spaceAssignment.callers.documents.spec.tsx tests/unit/contexts/spaceAssignment.callers.spec.tsx tests/unit/contexts/workspaceSpaceAssignment.spec.ts tests/unit/contexts/spaceAssignment.document.spec.tsx
  • pnpm check (tsc) — clean.
  • oxlint --max-warnings=0 on the 6 touched files — 0 warnings, 0 errors.
  • prettier --check on the 6 touched files — clean.
  • pnpm test-gates:check — counts match the baseline.
  • node scripts/check-max-lines.mjs — all files within 1000 lines.
  • Note: pnpm impact could not run in this sandbox (fails with EMFILE: too many open files); the co-change section above was compiled by hand from the callers of the touched functions. The verify:quick box is left unchecked until that gate is run before submit.

@DeadWaveWave
DeadWaveWave merged commit a814afe into DeadWaveWave:main Nov 26, 2026
13 checks passed
@DeadWaveWave

Copy link
Copy Markdown
Owner

Merged, thanks @anhnt256. Checked: repositionCreatedExplorerNode now returns the node with the position it just wrote to the store, both callers hand that node to the push-away, and the new tests put the reposition and the push-away in the same scenario, as #725 asked. CI was green on the final revision, which was based on current main.

On the asset: a structural fix is stronger than a test here. createdNode was added in #326 because the push-away read a stale nodesRef projection. Since #647 the push-away reads the document when the write runs, so the parameter is now just a way for a caller to hand in a stale node. Removing it touches all eleven callers, which is beyond a bug fix, so it is tracked in #758. Your tests stay there as the regression for #725.

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.

Explorer and document opening hand the push-away the created node from before its reposition

2 participants