Skip to content

docs: RFC for agent-perceived latency improvements - #19

Closed
RT567 wants to merge 1 commit into
mainfrom
docs/agent-latency-improvements
Closed

RT567 wants to merge 1 commit into
mainfrom
docs/agent-latency-improvements

Conversation

@RT567

@RT567 RT567 commented Jul 9, 2026

Copy link
Copy Markdown

Summary

Design doc only — no scripts/ behavior changes in this PR. Written so it can be implemented directly from the doc by whoever (human or agent) picks it up next.

Two independent proposed edits to cut agent-perceived latency, both documented in full in docs/agent-latency-improvements.md:

  1. Stop paying for a redundant sentinel round trip on every single-shot op. eval-op, dispatch-op, trace-recent-op, console-tail-op, handler-source-op, and app-summary-op all call ensure-injected! unconditionally before doing the real work — which itself is a full cljs-eval browser round trip, even though re-injection is only ever needed once per hard page refresh. The doc specifies a with-optimistic-inject helper (try the real call first, only fall back to the existing ensure-injected! machinery on failure) that cuts this to one round trip in the common case, with a retry-safety proof (missing-runtime failures happen at CLJS analysis time, before any side effect ships to the browser, so retrying is safe even for dispatch-op) and a full call-count/exception-shape test-impact walk against all 57 existing tests/ops_smoke.bb deftests.

  2. A file-backed activity daemon for high-frequency polling. console-tail.sh / trace-recent.sh are pull-only, so an agent that polls repeatedly across a long debugging session pays a browser round trip per check, even though the runtime already buffers this data for free in-browser. The doc specifies a new daemon subcommand + scripts/daemon.sh wrapper that reuses the already proven pull-mode primitives (epochs-since, console-tail-since, the same combined-poll pattern watch-op already uses) as a long-lived background process appending to local EDN files — turning repeated reads into plain file reads instead of browser round trips. This deliberately sidesteps the streaming-via-:out mechanism sketched (and left "unproven") in docs/initial-spec.md §4.4, rather than trying to prove it.

STATUS.md's Near-term and Deferred sections now cross-link the doc.

Why a docs-only PR

Wanted a second pair of eyes (human or AI) on the design before touching scripts/ops.clj — particularly the retry-safety argument for edit 1 and the explicit scope-out of watch-op/tail-build-op (§1.4 in the doc), which have existing tests pinning an exact connection-reuse invariant that a naive global application of the optimistic-retry pattern would break.

Test plan

  • N/A for this PR — no scripts/ changes. npm test should be unaffected; not re-run here since nothing changed that it covers.
  • Doc's own §1.5/§2.8 double as the test plan for the follow-up implementation PR(s).

Two proposed edits, not yet implemented:

1. Every single-shot op (eval, dispatch, trace-recent, console-tail,
   handler-source, app-summary) unconditionally calls ensure-injected!
   before the real work, paying a full browser round trip to check a
   sentinel that's almost always already satisfied. An optimistic
   try-first-then-fix-on-failure helper cuts this to one round trip in
   the common case.

2. console-tail.sh/trace-recent.sh are pull-only, so an agent polling
   repeatedly across a session pays a browser round trip per check even
   though the runtime already buffers this data for free. A file-backed
   background daemon (reusing the existing proven pull-mode primitives,
   not the unproven :out-streaming sketch in docs/initial-spec.md §4.4)
   turns repeated reads into plain local file reads.

docs/agent-latency-improvements.md has the full design: exact code,
a retry-safety proof, a test-impact walk of the existing 57
ops_smoke.bb deftests, and an implementation checklist.
@RT567

RT567 commented Jul 9, 2026

Copy link
Copy Markdown
Author

Closing — meant to file this as an issue, not a PR. Filing the issue now with the same content.

@RT567 RT567 closed this Jul 9, 2026
@RT567
RT567 deleted the docs/agent-latency-improvements branch July 9, 2026 22:51
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.

1 participant