Skip to content

Add live trajectory inspector - #17

Open
aalvsz wants to merge 5 commits into
NVlabs:mainfrom
aalvsz:trajectory-inspector
Open

aalvsz wants to merge 5 commits into
NVlabs:mainfrom
aalvsz:trajectory-inspector

Conversation

@aalvsz

@aalvsz aalvsz commented Sep 11, 2026

Copy link
Copy Markdown

Adds an opt-in live trajectory widget and a metadata-only session log so users can follow model requests, tools, and compaction as an agent runs. /trajectory toggles the view. Prompts, assistant text, tool arguments, and tool output are omitted.

Validation on Pi 0.84.2:

  • 149 automated tests pass, plus typecheck and package validation.
  • 50 matched cases (100 real SDK sessions, 300 tool executions): identical provider-request hashes and expected outputs in both arms.
  • Mean local elapsed time: 7.81 ms disabled, 12.70 ms enabled. Paired overhead: mean +4.89 ms, p95 +12.34 ms. This is observability overhead, not a speed or accuracy improvement.
  • Real interactive CLI display/toggling and a live-model file-read smoke passed. Long-run, resume, HTTP 503 retry, cancellation, and native compaction checks passed through Pi's runtime.

See the method and results and all 50 measured pairs. The reproducible benchmark uses a deterministic local HTTP provider; the live-model check is a separate single smoke test.

@aalvsz
aalvsz marked this pull request as draft September 11, 2026 13:10
@aalvsz
aalvsz marked this pull request as ready for review September 11, 2026 13:23

@gaoanze888 gaoanze888 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the unusually thorough benchmark and lifecycle validation. I ran npm run check locally (18 files / 145 tests, typecheck, and package dry-run all passed), then added adversarial lifecycle probes. Two correctness gaps remain before the trajectory can be treated as authoritative:

  1. A retryable HTTP response finalizes the whole logical request too early. after_provider_response updates and clears the single active request on the first callback. Pi providers can invoke the response callback for a retryable 429/5xx and then succeed on a later attempt. With the event sequence before_provider_request → HTTP 429 → HTTP 200, the durable request span ends permanently as error / HTTP 429; the 200 has no active span to update. Please retain the logical request across retryable attempts or model attempts separately, and add a 429 → 200 regression.

  2. Failed/cancelled compactions remain running forever. The compaction span is closed only by session_compact, but Pi does not emit that extension event when native compaction throws or is cancelled. A later session_before_compact overwrites the reference, leaving the earlier durable record unmatched. I reproduced session_before_compact → agent_settled → shutdown with no update for the running span. Please choose a representation that does not promise a completion hook the public extension API cannot provide (for example an attempt/info record, or an explicit fallback closure), and cover failure/cancellation plus a later successful compaction.

These are important because an observability feature that reports a recovered request as failed or leaves completed attempts running can send debugging in the wrong direction. The concurrent tool-call pairing and the normal transport-error fallback looked correct in my review.

A separate product-level question for maintainers: the widget tail is bounded, but events.jsonl has no retention/rotation policy. The submitted benchmark measures about 8.8 KiB for very short sessions, so long-running trajectories should have an explicit storage bound or documented retention policy before this is recommended broadly.

@aalvsz

aalvsz commented Sep 12, 2026

Copy link
Copy Markdown
Author

Addressed both lifecycle findings:

  • Logical requests now remain active across response callbacks and finish on assistant completion, with turn-end as a fallback. The last HTTP status is retained. Added 429 → 200 and 503 → 200 regressions, including durable-log assertions.
  • Compaction starts are informational attempts, followed by a separate success record only when Pi emits session_compact. Missing failure/cancellation callbacks can no longer leave a running span or be mistaken for success. Added incomplete-attempt/shutdown regressions and real SDK checks for native failure and cancellation, each followed by a successful compaction.
  • Documented retention explicitly: the widget is bounded, but the ledger has no automatic rotation or size cap. Hiding the widget does not stop logging; recording can be disabled for subsequent invocations, and session logs can be archived/deleted after stopping the session.

Validation: npm run check passes (18 files / 149 tests, typecheck, package dry-run). All seven real SDK lifecycle scenarios pass, including the two new compaction paths.

@gaoanze888 gaoanze888 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed the follow-up at f75131d5d. Both requested lifecycle fixes are addressed: request spans remain open through retry-related response callbacks and close on assistant completion with a turn-end fallback; compaction starts are now informational attempts and only session_compact emits a separate success record, so failure/cancellation cannot leave a running span. npm run check is green (18 files / 149 tests, typecheck, package dry-run), and the retention limitation is now explicit in the docs. One wording nuance: provider callback granularity is provider-dependent (the bundled OpenAI/Anthropic retry helper may expose only the final response), so “individual response attempts” should not be read as universal; this is non-blocking for the corrected lifecycle behavior.

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.

2 participants