Repository navigation
Description
What to build
Give the Waterfall and whole Trace export one implementation of record-derived Trace ancestry and Session attachment. They already promise consistent ancestry, but each adapter reconstructs it independently. Keep the current CLI and Console behavior while making changes to those rules local to the Trace module.
This is one standalone Ticket: the shared traversal, both existing adapters, and their contract tests fit one session. No parent or preparatory Ticket is needed.
Acceptance criteria
- The Waterfall and whole Trace export consume one Trace ancestry interface. Their separate recursive record traversals and Session normalization/deduplication are removed; neither adapter decides dispatch ancestry or Session ownership.
- Existing Command, Run and stage identities remain unchanged. Child Ticket runs and dispatched Commands retain the stage selected by the current dispatch-parent rule, with the existing Run fallback.
- Each normalized Session identity is attached once per selected subtree: descendants claim Sessions before ancestors, the first stage referencing the Session owns it, and an inventory-only Session falls back to its owning Run. Preserve the readable path for conversation links as well as the normalized identity used for deduplication.
- A Waterfall selection still shows the selected record subtree using its actual outer Command identity and the selected record's root display facts. Whole Trace export still includes the entire owning Command, including siblings when selected through a child Ticket.
- Preserve Waterfall ordering, live replay, displayed times/status, stable span JSON fields and partial-file handling. Preserve export's record preorder, sorted Session-file order, timestamp validation, duplicate-ID/Trace/reference validation, and missing-file errors. Retained Session requests, including unknown fields and their recorded parents, remain byte-for-byte unchanged.
- Tests through the shared interface cover nested dispatch and child ancestry, an ancestor and descendant inventory naming the same Session, reused Sessions across stages, former and current filenames naming one Session, inventory-only Sessions, and distinct Commands with equal start stamps. Retain observable CLI/Console and export parity checks rather than keeping tests of deleted traversal helpers.
- Add or extend output checks for selected-subtree versus whole-owner behavior and for the intentional distinction between Waterfall's display attachment and retained export parents. Check valid live, died and ended records without replacing either adapter's malformed/partial-input policy.
- Update the domain-to-code index for ownership of Trace ancestry and its tests. Run focused Trace export and Console span tests, then the repository's affected-tests selector against main.
Blocked by
None (can start immediately).
Decisions
Design tree, round 1: scope and seam
- Deepen the existing Trace module, restricted to record ancestry and Session attachment. The recent ancestry correction in commit
bb63be85and the whole-Command export parity test show that these rules already have two callers that must agree. Session recording, call lifecycle, OTLP encoding and Waterfall presentation remain in their current modules because those responsibilities vary independently. - Use one internal, read-only interface with two existing adapters. The Waterfall and whole Trace export are the real adapters at this seam. A new trait, callback protocol, filesystem abstraction or persisted graph would add interface without leverage; the existing Session inventory and temporary filesystem fixtures suffice.
Design tree, round 2: inputs, result and ownership
- Take a selected Command-record subtree and its actual owning Command identity. These are separate inputs because a selected child in the Waterfall retains the outer Command's identity, whereas export deliberately starts at the whole owner. Keep selection resolution in the callers and derive identity with the existing Trace context calculations; do not change hashes or storage ownership.
- Return an ordered sequence of borrowed record-node facts and exact Session attachments. Include node kind, existing ID and parent ID, source Command/stage references and owning context; Session attachments also carry the readable path, normalized identity and first referencing stage when present. Borrow the original facts so callers retain raw timestamps and display metadata. This result hides the traversal without imposing either adapter's output representation.
- Make the traversal own attachment rules, preserving current order. Emit the Command root, a Run and its stages, then each dispatched subtree followed by child subtrees, then that Run's remaining Sessions. Reuse the existing Session inventory, normalize before deduplication, let descendants claim first, select the earliest matching stage and fall back to the Run. These ordering constraints are part of the interface's behavior, not caller obligations.
Design tree, round 3: projection and compatibility
- Keep adapter-specific timing, errors and output inside each adapter. Waterfall tolerates unknown record times; export requires timestamps that fit OTLP nanoseconds. Preserve the existing stage-time calculation and raw references rather than introducing a shared parse/error policy. Waterfall emits the shared sequence in its current order; export projects only record ancestors and copies unique Session files in normalized-path order.
- Treat Session attachment as display ancestry, never permission to rewrite retained evidence. Waterfall currently places even an older retained Session under the first stage that names it. Export must instead preserve original requests and validate their recorded parents. It consumes attachments to select files, not to replace parents. Keep live call replay, incomplete trailing-request handling and the two-file export requirements in their respective adapters.
- Keep the change reversible and use established domain terms. Trace, Command, Ticket run, stage and Session trace already describe the work. No glossary definition or ADR change is needed: this extraction preserves ADR 0019's trace format and ADR 0016's read-only Console behavior. Update only the navigation documentation that identifies the owning module.
Testing decisions
- The interface is the test surface. Exercise ancestry and attachment outcomes through the same read-only interface the two adapters call, with temporary record/Session files using the existing inventory behavior. Do not add tests coupled to recursion helpers or internal collections; delete any such tests displaced by the extraction.
- Keep end-to-end evidence at both output seams. The existing nested Pickup/Spec/Ticket export test already checks exported parent IDs against the CLI span tree, and Console span tests pair CLI output with routes. Preserve them, and extend coverage only for the selection and retained-parent distinctions above. This verifies that removing duplicated implementation preserves user-visible contracts.
Review validation at main head 4601b980: the existing Trace export tests passed (3), the Console span tests passed (2), and the affected-tests selector reported no changed files. These establish the current contracts; implementation must run validation again after the refactor.
All design branches are settled; the dependency category is local-substitutable because Session inventory uses the filesystem and already supports temporary fixtures.
Architecture review
Strength: Strong · Dependencies: local-substitutable
Files: src/logs/trace.rs, src/logs/trace/ancestry.rs (new), src/logs/spans.rs, src/logs/export.rs, src/logs/spans/session.rs, tests/export_trace.rs, tests/console/spans.rs, docs/code-navigation.md
Before
flowchart LR
W["Waterfall adapter"] -->|identities| T["Trace module"]
E["Trace export adapter"] -->|identities| T
W -.->|rebuild ancestry| C["Command records"]
E -.->|rebuild ancestry| C
W -.->|attach Sessions| S["Session inventory"]
E -.->|deduplicate Sessions| S
classDef leak stroke:#dc2626,stroke-width:2px;
class W,E leak;
After
flowchart LR
W["Waterfall adapter"] -->|ancestry| T["Trace module"]
E["Trace export adapter"] -->|ancestry| T
T --> C["Command records"]
T --> S["Session inventory"]
classDef deep stroke-width:3px;
class T deep;
Problem: The Trace module is shallow for retained readers: ancestry and Session ownership leak across its seam into both adapters, as the coordinated fix in bb63be85 demonstrates.
Solution: Deepen the Trace module so one interface owns record ancestry and Session attachment while each adapter keeps its output implementation.
Wins
- Depth: one interface, two adapters
- Locality: attachment rules stay together
- Leverage: both views share fixes
- Delete duplicated ancestry traversal
Deletion test: Deleting the deep module would redistribute ancestry, normalized Session ownership and first-stage attachment across both adapters.
Coverage: No open issue proposes this deepening; adjacent issues address retention, Model evidence, Inbox behavior or Waterfall phone positioning.
Activity