Skip to content

Fix: containerAttachState telemetry incorrectly shows "Detached" during container load#26539

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/initialize-attachment-data-state
Draft

Fix: containerAttachState telemetry incorrectly shows "Detached" during container load#26539
Copilot wants to merge 2 commits intomainfrom
copilot/initialize-attachment-data-state

Conversation

Copy link
Contributor

Copilot AI commented Feb 25, 2026

When Container.load() creates a new Container instance for loading an existing attached container, early telemetry logs reported containerAttachState: "Detached" — incorrect since the container was never in a detached state.

Description

attachmentData was initialized to { state: AttachState.Detached } at field declaration, meaning every container — including those loading existing attached documents — started life reporting Detached until the load flow set Attached at line ~1617.

Fix: Initialize attachmentData to undefined when loadProps is provided (i.e., loading scenario), reflecting a genuinely unknown state during the brief pre-load window.

Key changes:

  • container.ts: attachmentData is now AttachmentData | undefined. Initialized to { state: Detached } only when loadProps === undefined (new container creation paths). attachState getter returns AttachState | undefined. Updated serialize(), getPendingLocalState(), and attach() to guard against undefined. Cast getAttachState lambda passed to ContainerContext as AttachState (safe — context is instantiated only after attachmentData is set).
  • IContainer.attachState (container-definitions): Type widened to AttachState | undefined to match the new semantics.
  • FluidContainer.attachState (fluid-static): Retains AttachState return type via non-null assertion — FluidContainer is only surfaced to callers after load completes, so undefined is never observable here.
  • API report and type validation updated accordingly.

Breaking Changes

IContainer.attachState is now AttachState | undefined (was AttachState). This is a backward-incompatible change to the @legacy @beta interface. Callers that assign an IContainer to a variable typed against the old interface will need to handle undefined.

FluidContainer.attachState (@public) is unchanged — still returns AttachState.

Reviewer Guidance

  • The undefined state is only observable on the raw IContainer object during the internal load flow. By the time Container.load() resolves and callers receive the container, attachState is always Attached.
  • The as AttachState cast in getAttachState (ContainerContext config) and the ! in FluidContainer are safe by construction but worth a second look.
  • The serialize() guard now throws on undefined attachmentData with the same UsageError as the attached/closed cases — message is slightly imprecise for that path but the path is unreachable via public API.
Original prompt

Initialize attachmentData to an "unknown" or "undefined" state, rather than "Detached". The problem is, when creating a new instance of Container class for loading an attached container, the first few logs wrongly show containerAttachState prop as Detached.

Once you've made the change and commited, push the branch to the markfields fork, and open a PR.

Created from VS Code.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

… fix early telemetry logging

Co-authored-by: markfields <12305068+markfields@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix initial attachmentData state to avoid 'Detached' value Fix: containerAttachState telemetry incorrectly shows "Detached" during container load Feb 25, 2026
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.

2 participants