Skip to content

fix(tracing): release owned recorders on instance teardown - #504

Open
SaKaNa-Y wants to merge 2 commits into
devframes:mainfrom
SaKaNa-Y:fix/owned-tracing-teardown
Open

SaKaNa-Y wants to merge 2 commits into
devframes:mainfrom
SaKaNa-Y:fix/owned-tracing-teardown

Conversation

@SaKaNa-Y

@SaKaNa-Y SaKaNa-Y commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Closing a devframe or Hub while its local recorder was active left it subscribed to Node's diagnostics channel. If a replacement recorded the same channel in the same process, both instances captured the next call. Setup could leave the same subscription behind if it started recording and then threw.

initDevframe() and initHub() now register tracing cleanup when they create a context, before setup runs. A Hub that still serves that context can read the stopped channels and clear their history.

On close or setup failure
  Instance's own context    Stop local recording, close streams, and publish the stopped state.
                            Detach listeners from external recorders.
  Caller-supplied context   Leave tracing with the caller.

Evidence

  • Instance replacement. Before this change, both instances captured the next call, which returned 123. After the change, only the replacement captured it. For both entry points, a setup failure released the local subscription and preserved the original error.
  • Shared context. An earlier version of the fix stopped the recorder but still advertised its closed stream to a second Hub. Subscribing to that ID produced DF0030. With this change, the second Hub's SSE client read recording: false, no streamId, and one buffered record. Clearing history through RPC changed the count to zero.

Merge Danger

Door: Two-way. Reverting restores the previous cleanup behavior.

Blast Radius: Tracing. Stopping an external recorder would make its owner miss later calls. The close tests confirm that both an attached tool and the owner of a borrowed context can keep recording.

Register tracing cleanup when an instance acquires its context so close and setup failure both release local recording and relay subscriptions. Keep independently owned recorders and caller-supplied Hub contexts active.
@vercel

vercel Bot commented Nov 21, 2026

Copy link
Copy Markdown

@SaKaNa-Y is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

👁️‍🗨️ Review this pull request with grouped, summarized diffs at:
👉 https://pulls.review/gh/devframes/devframe/504?from=github-actions[bot]

raw result

💭 analyzed by vercel-ai-gateway/anthropic/claude-sonnet-5
🕰️ 2026-11-28 07:14 UTC
🔗 head d90959d
🤖 automated by pulls.review

{
  "headSha": "d90959d0f9c931799479e0761613d65cfbee350a",
  "result": {
    "overallSummary": "Fixes a tracing bug where closing or failing to set up a devframe/Hub instance could leave its local recorder subscribed to Node's diagnostics channel, causing duplicate captures when a replacement instance recorded the same channel. The fix registers tracing cleanup at context-creation time (before setup runs) so both clean close and setup failure release owned subscriptions, while channels still owned by a caller-supplied (borrowed) context are left intact and their stopped state is published for any hub still watching them.",
    "groups": [
      {
        "key": "tracing-lifecycle",
        "label": "Tracing lifecycle cleanup",
        "summary": "Ensures a devframe/Hub instance releases the tracing recorder it owns when its context is created locally, on both normal close and setup failure, while leaving tracing alone when the context was supplied by the caller. Adds detach/dispose bookkeeping in `DevframeTracingHostImpl` so attached sources are unsubscribed (not stopped) and local channels are stopped, streams closed, and their stopped state published for any hub still borrowing the context.",
        "category": "core",
        "filePaths": [
          "packages/devframe/src/node/host-tracing.ts",
          "packages/devframe/src/node/instance-shell.ts",
          "packages/devframe/src/adapters/initiate.ts",
          "packages/hub/src/node/initiate.ts"
        ],
        "critical": true,
        "fileNotes": [
          {
            "path": "packages/devframe/src/node/host-tracing.ts",
            "text": "`dispose()` stops locally-owned channels and detaches external sources without stopping them; it also keeps publishing channel updates to a borrowing hub via `publishClosedChannels` until that hub itself disposes.",
            "critical": true
          },
          {
            "path": "packages/devframe/src/node/instance-shell.ts",
            "text": "`ownTracing()` registers the context's tracing host for cleanup before setup runs, so a setup-time throw still releases the subscription via the new `init().catch(...)` and `close()` paths."
          }
        ]
      },
      {
        "key": "tracing-tests",
        "label": "Tracing lifecycle tests",
        "summary": "Adds coverage for the new teardown behavior: reattachment during unsubscribe, instance replacement scenarios, setup-failure cleanup, and borrowed-context handling across both devframe and Hub entry points.",
        "category": "tests",
        "filePaths": [
          "packages/devframe/src/node/__tests__/host-tracing.test.ts",
          "packages/hub/src/node/__tests__/tracing-lifecycle.test.ts"
        ]
      },
      {
        "key": "api-snapshot",
        "label": "API snapshot update",
        "summary": "Generated type snapshot update reflecting the new `ownTracing` method on `InstanceShellApi`.",
        "category": "other",
        "filePaths": [
          "tests/__snapshots__/tsnapi/devframe/internal.snapshot.d.ts"
        ]
      }
    ],
    "schemaVersion": 1,
    "source": "llm",
    "generatedAt": "2026-11-28T07:14:30.451Z",
    "model": "vercel-ai-gateway/anthropic/claude-sonnet-5",
    "locale": "en"
  }
}

Publish the local recorder's final state when its owner closes. A hub sharing the context can still read and clear history, so mirror later channel metadata changes without reopening recording or streams.
@SaKaNa-Y
SaKaNa-Y marked this pull request as ready for review November 28, 2026 07:38

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant