Repository navigation
Description
Summary
Surface the C# file path, line number, and method name of every span's emission site in the Workbench detail panel, with one-click handoff to the user's editor (VS Code / Cursor / Rider / Visual Studio / custom) and an inline react-syntax-highlighter preview.
Design doc: claude/design/Profiler/10-profiler-source-attribution.md
Why a v2
Closes the loop on #293 (closed). The v1 attempt was logically correct end-to-end but predated the #294 typed-event source-generator refactor. Pre-refactor, source attribution required 98 hand-written BeginXxxWithSiteId overload pairs, 98 ref-struct edits, and 98 codec method changes (mostly mechanical, but with enough non-uniform shapes to defeat regex scripts and stall the work).
After #294 landed, the producer side collapses to:
-
One field on
TraceSpanHeader(ushort SourceLocationId). -
One signature change on
MakeHeaderto thread the literalsiteId. -
One block change in
TraceEventGenerator.Emitto emit a siblingBeginXxx_WithSiteId(ushort siteId, args)factory uniformly across all[TraceEvent]structs. -
One block in
TraceEventGenerator.EmitEncoderMethodsto write the optional flag-bit + 2 bytes whenHeader.SourceLocationId != 0. -
A small finite set of hand-written codecs (
EmitEncoder = falseevents) get the same flag/bytes addition.
Wire format, manifest, Workbench Options, EditorLauncher, inline preview, repo-relative paths — unchanged from v1 and largely lift-and-shift from feature/293-profiler-source-attribution.
Total estimated effort: ~5.5 dev-days (vs. v1's 11.5), with about half being direct port from the v1 branch.
Approach
Capture (build-time): Roslyn IIncrementalGenerator + C# 14 stable interceptors. SourceLocationGenerator discovers every TyphonEvent.Begin* invocation in the Typhon.Engine compilation, sorts by (file, line, column), assigns deterministic ushort site IDs (1-based; 0 = unknown source), emits per-call-site [InterceptsLocation] wrappers that forward to the matching Begin*_WithSiteId overload (also generator-emitted). Zero hot-path cost — literal ushort move; no runtime registry, no shared state, no allocation.
Validated end-to-end on Typhon's exact toolchain (.NET 10 SDK 10.0.203 + Microsoft.CodeAnalysis.CSharp 5.3.0) during v1 — confirms no dotnet/roslyn#82780 regression for our setup.
Wire format: reserve SpanFlags bit 1 (SpanFlagsHasSourceLocation = 0x02); 2-byte u16 SourceLocationId after the optional trace context. Backward-compatible — old readers ignore unknown flags.
Manifest:
-
File: trailer section in
.typhon-trace, two new offsets inTraceFileHeader(file format version5 → 6) -
Cache: new
CacheSectionId.SourceLocationTable, bumpChunkerVersion -
Live TCP: single
FileTable+SourceLocationManifestframe in the init handshake — no delta frames (table is fixed at compile time)
UI:
-
ProfilerDetail.tsx"Source" row —file:line · method -
Open in editor —
POST /api/profiler/open-in-editor→ serverProcess.Startper OS:-
VS Code:
vscode://file/{abs}:{line}(Windows: registry handler; macOS: viaopen) -
Cursor:
cursor://file/{abs}:{line} -
Rider:
rider*.exe/rider --line N {abs}(no Toolbox / project-name dependency) -
Visual Studio:
devenv /Edit "{abs}" /Command "Edit.GoTo {line}"(Windows-only) -
Custom: argv template,
{file}/{line}/{column}substituted as discrete argv elements (no shell)
-
-
Show inline — lazy-loaded
react-syntax-highlighter(Prism, ~50 KB) renders ±20 lines with the emission line highlighted
Workbench Options system: schema-driven (WorkbenchOptions, EditorOptions, ProfilerOptions), file-backed JSON at OS user-data folder, atomic write + FileSystemWatcher hot-reload (200 ms debounce), GET/PUT/PATCH /api/options, Zustand client store with optimistic-PATCH mutations.
Workspace root: auto-detected by walking up from CWD looking for .git (file or directory — accommodates submodules and worktrees). User can override via Options → Profiler.
Roadmap
7 phases, ~5.5 dev-days end-to-end. Phase 1+2 (engine work) can run in parallel with Phase 5+6+7 (Workbench work) once Phase 3+4 is settled.
-
Phase 1 — Producer side (~1d):
TraceSpanHeader.SourceLocationIdfield;MakeHeadersignature;TraceEventGeneratorfactory pair emission + optional 2-byte field inEmitEncoderMethods; hand-written codec audit + updates;TraceRecordHeaderflag/helpers; round-trip tests -
Phase 2 — Source generator + interceptors (~1d): port
SourceLocationGeneratorfrom v1 branch;Directory.Build.props(<TyphonRepoRoot>,<DeterministicSourcePaths>,<PathMap>);<InterceptorsNamespaces>opt-in inTyphon.Engine.csproj; determinism + interceptor sanity tests -
Phase 3 — File / cache manifest (~1d): port
SourceLocationManifestEntry,TraceFileWriter.WriteSourceLocationManifest+RewriteHeader,TraceFileReader.TryReadSourceLocationManifest,TraceFileHeaderoffsets + version bump (5 → 6); cache section +ChunkerVersionbump; wireFileExporterto emit manifest at session close -
Phase 4 — Live stream (~0.5d): port
LiveFrameType.FileTable+SourceLocationManifest; wireTcpExporterinit handshake; WorkbenchAttachSessionRuntime+useProfilerSourceLocationshook;GET /api/sessions/{id}/profiler/source-locationsendpoint -
Phase 5 — Workbench Options system (~1d, lift-and-shift):
WorkbenchOptions,OptionsStore,OptionsController,SystemController;useOptionsStore,OptionsPanel,EditorForm,ProfilerForm; "Open Options" command-palette entry -
Phase 6 — Source row + editor handoff (~0.5d, lift-and-shift): port
EditorLauncher(Windows + macOS adapters,LaunchResult);ProfilerSourceController(workspace-root,open-in-editor,sourceendpoints with path-traversal guard);useSourceLocationStore;ProfilerDetail.tsxSource row -
Phase 7 — Inline preview (~0.5d, lift-and-shift): port
SourcePreviewPanel.tsx; lazy-loadedreact-syntax-highlighter; bundle-split verification
Acceptance
-
Selecting a span in the Workbench shows its emission
file:line · method(across all kinds, since the centralizedTraceSpanHeaderfield gives uniform coverage) -
Open in editor opens the corresponding file at the right line in VS Code, Cursor, and Rider on Windows + macOS (Linux deferred — explicit non-goal in v2)
-
Show inline preview renders syntax-highlighted ±20 lines with the emission line highlighted
-
Site IDs are byte-identical across two builds of the same source (golden-file test)
-
Loading a pre-feature
.typhon-tracefile (v5 or older) works unchanged via re-record (the v6 bump intentionally invalidates older files; documented behavior) -
Workbench launched from inside the working tree resolves relative paths automatically (no manual workspace-root config required)
-
Options edited via the Options panel persist across Workbench restarts; out-of-band JSON edits are picked up via hot-reload
-
Per-emission overhead vs current baseline is unmeasurable (literal
ushortmove only)
Cleanup plan (post-merge)
After this issue is closed and the implementation is on main:
-
Old design doc —
claude/design/observability/09-profiler-source-attribution.mdwas committed only on the v1 branch (feature/293-profiler-source-attribution) and was never merged tomainofclaude/. There is therefore nothing to delete frommain; the doc disappears when the v1 branch is deleted (next bullet). If the v1 design seems worth preserving onmainfor historical reference rather than relying on the branch, theclaude/CLAUDE.mdconvention is to copy it toclaude/archive/observability/with a leading note pointing at the v2 doc. Optional. -
Old branch
feature/293-profiler-source-attribution(Typhon root +claude/) — delete from origin once Phases 5/6/7 have lifted the reusable Workbench code across:git -C <typhon-root> push origin --delete feature/293-profiler-source-attribution git -C claude push origin --delete feature/293-profiler-source-attribution
-
Obsolete tools — the
tools/scripts/convert_typhon_factories.pyand ~10 sibling Python scripts on the old branch should not be ported. The post-Refactor TyphonEvent emission: header struct + source generator + codec consolidation #294 architecture eliminates the bulk conversion entirely.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
Solved #302 (#303)