microsoft / microsoft/FluidFramework

[code-simplifier] refactor: small clarity tweaks in chunk cursor + device spec

Open
#27,136 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

agentic-workflows automation code-quality refactoring
Dominant language
TypeScript
Stars
4.9k
Forks
586
Avg merge
1d 15h
Merged PRs (30d)
146

Description

Overview

This PR applies small readability/consistency tweaks to code that was recently modified, without changing behavior.

Files Simplified
  • packages/dds/tree/src/feature-libraries/chunked-forest/basicChunk.ts
    • Rename an internal variable to better reflect meaning (halfHeightnodeDepth).
    • Remove a non-null assertion in getStackedFieldKey() by using explicit ?? oob() checks.
  • packages/runtime/container-runtime/src/containerRuntime.ts
    • Update the (now-stale) comment above getDeviceSpec() to reflect that navigator is required (browser or Node 22+).
    • Make the deviceMemory cast more explicit via a local navigatorWithDeviceMemory variable.
Changes Based On
  • #27084 (tree chunk cursor changes)
  • #27116 / #27010 (Node 22+ navigator assumptions and related updates)
Testing

Validation could not be executed in this runner because the available Node version is v20.20.2, while the repo requires >=22.22.2.

Commands attempted
  • pnpm install --frozen-lockfile
  • pnpm run build:fast
  • pnpm run test
  • pnpm run lint
  • pnpm run format:repo
Review Focus
  • Confirm no behavior changes (all changes are local refactors / comment updates).
  • Confirm the stack indexing logic remains unchanged.

References: §24823297965

Generated by Code Simplifier ·

To install this agentic workflow, run

gh aw add github/gh-aw/.github/workflows/code-simplifier.md@94662b1dee8ce96c876ba9f33b3ab8be32de82a4
  • expires on Apr 24, 2026, 7:52 AM UTC

[!NOTE]
This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch code-simplifier/2026-04-23-clarity-73956383e7a63872.

Click here to create the pull request

To fix the permissions issue, go to SettingsActionsGeneral and enable Allow GitHub Actions to create and approve pull requests.

Show patch preview (72 of 72 lines)
From c2598056b8c63c09d6078d725629f3de07791f07 Mon Sep 17 00:00:00 2001
From: GitHub Copilot <223556219+Copilot@users.noreply.github.com>
Date: Thu, 23 Apr 2026 07:50:01 +0000
Subject: [PATCH] refactor: small clarity tweaks

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 .../feature-libraries/chunked-forest/basicChunk.ts    | 11 ++++++-----
 .../runtime/container-runtime/src/containerRuntime.ts |  8 +++++---
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/packages/dds/tree/src/feature-libraries/chunked-forest/basicChunk.ts b/packages/dds/tree/src/feature-libraries/chunked-forest/basicChunk.ts
index 4ebaa68..08b0e63 100644
--- a/packages/dds/tree/src/feature-libraries/chunked-forest/basicChunk.ts
+++ b/packages/dds/tree/src/feature-libraries/chunked-forest/basicChunk.ts
@@ -178,13 +178,13 @@ export class BasicChunkCursor extends SynchronousCursor implements ChunkedCursor
 	 * their length should always equal the number of node levels traversed.
 	 */
 	private assertChunkStacksMatchNodeDepth(): void {
-		const halfHeight = this.getNodeOnlyHeightFromHeight();
+		const nodeDepth = this.getNodeOnlyHeightFromHeight();
 		assert(
-			this.indexOfChunkStack.length === halfHeight,
+			this.indexOfChunkStack.length === nodeDepth,
 			0x51c /* unexpected indexOfChunkStack */,
 		);
 		assert(
-			this.indexWithinChunkStack.length === halfHeight,
+			this.indexWithinChunkStack.length === nodeDepth,
 			0x51d /* unexpected indexWithinChunkStack */,
 		);
 	}
@@ -199,8 +199,9 @@ export class BasicChunkCursor extends SynchronousCursor implements ChunkedCursor
 
 	private getStackedFieldKey(height: number): FieldKey {
 		assert(height % 2 === 0, 0x51f /* must field height */);
-		// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-		return this.siblingStack[height]![this.indexStack[height]!] as FieldKey;
+		const siblingsAtHeight = this.siblingStack[height] ?? oob();
+		const indexAtHeight = this.indexStack[height] ?? oo
... (truncated)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read packages/dds/tree/src/feature-libraries/chunked-forest/basicChunk.ts and packages/runtime/container-runtime/src/containerRuntime.ts, focusing on assertChunkStacksMatchNodeDepth(), getStackedFieldKey(), and getDeviceSpec(). Use Node 22.22.2 or newer, then run the listed build, test, lint, and formatting commands; done means the clarity changes preserve behavior and validation passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
backend, distributed-systems
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.