Repository navigation
fix(trace): pair each command.end with its own start by sequence number - #51
Merged
Merged
Conversation
The trace reader paired command.start and command.end by segment:writer_pid:command in one slot. FFI host threads can run the same command on one session at overlapping times, so start A, start B, end A, end B reported a false "Unpaired command.end", and start A, start B, end B with A crashed hid A's lost end. command.end now carries command_seq, the seq of the scope's own command.start, and the reader pairs a sequenced end only with that start. Ends from older traces have no command_seq; they close one open start of the same segment, writer pid and command, so overlapping legacy scopes pair by count instead of overwriting each other. The two modes are the explicit CommandPairing state, held apart in OpenCommands so a legacy end never closes a start that a sequenced end claims. The HTML viewer grouped ends by a blind stack pop across writers; it now closes the frame the same rules pick. The unpaired-start warning names the start's seq. CommandScope moves to its own file to keep context/mod.rs under the size cap. The field is additive and documented in the traces guide. Upstream register item 16 in `vercel-labs#602`.
gshost1
added a commit
that referenced
this pull request
Nov 8, 2026
Review of the command_seq pairing found the viewer and reader disagreeing and the reader naming a start it could not know. The viewer's legacy fallback closed any open frame with the same name, including a start that a later end claims by command_seq. Its grouping now lives in viewer_group.js with the reader's rules: a claimed pre-pass, claimed starts close only by seq, legacy ends close the oldest unclaimed start of the same writer and command. viewer_group.test.js covers it with node --test, in the same form as viewer_filter.test.js. Legacy ends closed the newest start, and the unpaired warning then named that bucket's leftover seq as if it were known. Legacy ends now close the oldest start, and a bucket latches "ambiguous" once an end had to choose among several. Its leftovers are reported as paired by count with no seq. A seq is named only when every pairing was forced. The claimed set stays a separate pass: a legacy end can come before the sequenced end that claims a start of the same command, so one pass could not leave that start alone. The mixed-format test covers that case. CommandScope is re-exported from lib.rs, as AGENTS.md requires, instead of from context. Its start goes through a CommandContext method like its end. The scope tests share a temp-trace guard that removes the file on drop.
gshost1
added a commit
that referenced
this pull request
Nov 8, 2026
gshost1
added a commit
that referenced
this pull request
Nov 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The trace reader paired
command.startandcommand.endby command name in one slot per segment and writer pid. FFI host threads in one process can run the same command on one session at overlapping times, sostart A, start B, end A, end Breported a false "Unpaired command.end", andstart A, start B, end Bwith A lost hid A's missing end. CLI and MCP are not affected (one pid per command). This pairs each end to its own start. Ledger row STATE-7.State before and after
Keeping the two kinds apart means an old-format end never closes a start that a new-format end will claim.
What changed
seqof the line it wrote.CommandScopekeeps its start's seq and writes it oncommand.endascommand_seq(left out if the start was not written). Start and end both go throughCommandContext(trace_recordedfor the start).crates/core/src/context/command_scope.rs:CommandScopemoved out ofcontext/mod.rs(the edit tookmod.rspast 400 lines; also one type per file);contextdeclares itpub(crate) mod, andlib.rsre-exportsCommandScope(AGENTS.md: onlylib.rsre-exports).src/dispatch/scope_end.rsimports it from the crate root.crates/core/src/trace/trace_read/: the pairing above (open_commands.rs,count_bucket.rs); two passes, because one pass would let an old-format end close a start a later end claims by seq (seeOpenCommandsdocs).trace_read/viewer_group.js, which applies the same claimed pre-pass and oldest-first rule as the reader;html.rsloads it beforeviewer.js.apps/docs/content/docs/guides/traces.mdx:command_seqin the event table and the example line.TempTraceguard replaces eight copies of temp-trace boilerplate incontext_scope_tests.rs.Trace format: one additive field,
command_seqoncommand.end.Prior art: none upstream; item 16 of the open upstream issue
#602register.How tested
mainoverlapping_same_command_scopes_pair_without_warning(audit sketch: start, start, end, end; old and new format)lost_end_of_an_overlapped_scope_is_reported_against_its_start(both orders)a_legacy_end_leaves_alone_a_start_that_a_later_end_claims_by_seq(mixed formats; also the unwritten-start variant)legacy_ends_pair_by_count_and_name_a_start_only_when_forcedsequenced_end_does_not_pair_with_a_different_startcommand_seqoverlapping_scopes_name_their_own_start_in_command_endviewer_group.test.js(node --test, 5 cases: by seq, lost end, mixed formats, oldest-first, another writer)Gates on head
e00bec80(main42b97e61merged in): fmt, clippy-D warnings, source-rule and architecture scripts, core Windows check, Win32 leakage check,cargo tree, host-set tests 4832 passed, 0 failed. Re-cycled ontomain0a5ff966(fork PRs #47 and #49 changedcrates/core/src/lib.rs) as19bc64c7: gates green (4892 passed, 0 failed), CI 13/13 green. The viewer test passes locally (node --test: 5 pass); CI does not run it yet (see What's left).Performance
One extra integer per
command.endline and one extra pass over the events when reading a trace.Risks
command_seqand falls back to counting; it is reported as unpaired, as before.What's left
.github/workflows/ci.ymlchange, which this machine's token cannot push (noworkflowscope). The "Embedded visual viewer tests" step should runnode --test src/visual_debug/viewer_filter.test.js crates/core/src/trace/trace_read/viewer_group.test.js.Merge rule: rule 3.
mainmoved to d921b52 (PR #53:src/tests/cli_process.rs,src/tests/cli_process_support.rs) after this head's CI; neither file overlaps this PR, and neither is an always-overlap file.