feat(agent,web): Trajectory pane with complete context capture and request inspection - #1157
Draft
ChrAlpha wants to merge 94 commits into
Draft
feat(agent,web): Trajectory pane with complete context capture and request inspection#1157ChrAlpha wants to merge 94 commits into
ChrAlpha wants to merge 94 commits into
Conversation
ChrAlpha
marked this pull request as draft
September 5, 2026 06:54
chen-ran
force-pushed
the
feat/context-usage-viz
branch
3 times, most recently
from
September 7, 2026 20:19
9cb6824 to
b7b4408
Compare
Provider attempts are clocked at the provider seam (dispatch, first content part, finish-step) and published as step_start/step_end events carrying the request's usage and timing. The observer forwards parts like Twilight ranges them so a cancelled provider still completes its blocked send.
Each native tool execution records started/ended wall clock under its call ID; the timing rides tool_call_end events and the persisted tool-call part through the existing execution metadata registry.
A step trace tracker takes finished provider steps inside the commit barrier and stores them as step_trace metadata on each assistant row, mirroring the reasoning timing path. Tool execution timing and terminal usage are observed on the public event wire, which every runtime shares, and the lifecycle snapshot gains a fixed-size run_trace rollup read at terminal time.
Persisted assistant rows expose their step_trace as UITurn.step_traces anchored to the row's first block, tool blocks carry execution_timing, and the live run view appends the same UIStepTrace per finished request so a subscriber sees timing and usage while the turn is still running.
Steering interleaved at the terminal snapshot and context prepared before a later step both persist a context_injection marker, and the history projection surfaces it so readers can tell injected context from the person's request.
The lifecycle list accepts an opaque before cursor bound to (created_at, run_id) and returns next_cursor while older run-keyed rows remain, so a long session pages in fixed-size summaries instead of widening one request. The spec and SDK pick up the cursor together with the run trace, step trace, execution timing, and context injection fields.
The runtime projection appends step_trace_appends onto the live run view and drops them on reset; normalized turns keep step traces, tool execution timing, and the context injection marker so any view can read them.
The lifecycle list joins the run ledger so each summary names the turn it wrote into, giving readers an exact join to history turns instead of guessing from assistant message ids.
Older lifecycle pages follow the server's next_cursor and accumulate beside the refreshable first page, replacing the 50-to-200 limit jump.
A dockview Trajectory tab reads the session's shared transcript window and lifecycle summaries: an overview strip with input, model, and tool lanes (duration or sequence scale, model bars split at first token), a virtualized ledger of system, user, context, assistant, reasoning, and tool rows in transcript order, a local inspector for the selected record, and a window-scoped stats line that omits anything never sampled.
… filtering - release the observed stream when the consumer leaves after cancel - discard finished steps a retry regenerates; fold the run rollup at commit - stamp injected user messages at the source so steering survives filtering - align step traces by assistant ordinal across empty-row filtering - bound each trace by its last block id; keep run_trace off per-row copies - clock external tool calls from their arrival at the transcript boundary
The first page keeps the plain session scan; only continuations carry the (created_at, run_id) predicate, so the planner never sees a nullable cursor.
- page lifecycle summaries only when the older page joins the loaded anchor - keep the ledger anchored while older rows prepend; memoize row building - continue turn numbering into the live turn; TTFT from the earliest sampled step - rem-based virtual rows, load-older gating, error toasts, aria selection - keep the pane alive across tab switches; close it with its deleted session
A wall-clock step between two readings produced a first token 305ms before its request in a live run. Every mark after the anchor now adds the clock's monotonic elapsed time instead of re-reading the wall clock.
isPanelAllowed had no trajectory case, so every layout restore closed the panel on reload.
The lifecycle page keeps only rolled-up counts; the trajectory inspector reads the content-light audit of one run on demand, after confirming the run belongs to the authorized session.
- the strip is DSH's row map: one segment per ledger record on its lane over the whole loaded window, duration or equal width, click focuses the row - every turn leads with its system prompt and the context the manifest injected: rules, tool usage, skills, memory recall, history with its selection, tool definitions, mutations, and per-step reselection - the inspector explains system and history rows with the run's per-fragment audit - the context inspector dialog folds into the trajectory
ChrAlpha
force-pushed
the
feat/trajectory-view
branch
from
September 9, 2026 01:27
d5ee3ee to
2f69352
Compare
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.
Summary
Adds a Trajectory dock pane for inspecting how a conversation reaches the model: collected and selected context, prepared provider input, captured HTTP request bodies, model request timing and usage, tool execution, and compaction history. It replaces the Context Lifecycle Inspector with Open Trajectory in the session info panel.
#1118 has merged. This PR targets
mainwith only the Trajectory history: all 93 original Trajectory commits retain their order, authorship and messages, followed by one migration/test compatibility commit. The former context-usage commits and stack merge commits have been removed from the PR range.Changes
workspace_read; content reads verify the stored hashes and report completeness.Database
0148_context_fragment_textsadds per-bot injected text storage;0149_context_trajectoryadds session-owned capture events and content. These follow main's0147_context_lifecycle_selection_decisions. The canonical schema and generated SQL/API/SDK contracts are updated.Validation
The checks below ran on the previous head. The history rewrite preserves its exact Git tree;
git range-diff, commit metadata checks, and tree equality were verified after rebasing:config: falseandenvDir: false.go testpassed for the affected context, application, native runtime, tools, contextview, models, handlers, and database packages.go test -tags integration ./internal/db -run '^TestContext(Trajectory|Fragment|Lifecycle)' -count=1: 7 top-level tests passed on an isolated PostgreSQL 18 instance, including eight capture/reset race orderings. The race-test deadline starts after database migration setup.sqlc diff, focused ESLint, migration-version uniqueness, andgit diff --checkpassed.Authenticated live-provider E2E and browser QA were not rerun for this update. Earlier smoke runs do not validate the newly added capture paths.
Known limits
step_index; the pane separates requests by their run/capture identity.QA