Skip to content

Scan only bridged attribution tail#1805

Merged
mikasenghaas merged 1 commit into
mainfrom
codex/v1-bridge-tail-spans
Jun 23, 2026
Merged

Scan only bridged attribution tail#1805
mikasenghaas merged 1 commit into
mainfrom
codex/v1-bridge-tail-spans

Conversation

@xeophon

@xeophon xeophon commented Jun 21, 2026

Copy link
Copy Markdown
Member

Overview

Reduce post-inference work for V1 bridged turns by computing prompt message spans from only the bridge-added attribution tail.

Why

Renderer bridges keep prior tokens verbatim and mark that reused portion with message_indices = -1. PendingTurn.prompt_message_spans() previously called message_token_spans() on the complete bridged attribution, forcing a synchronous Python pass over millions of reused entries even though the graph only needs spans for newly rendered messages. Reused messages already own their tokens in existing graph nodes.

What changed

Create a lightweight RenderedTokens view over message_indices[path_len:] and reuse its existing message_token_spans() behavior. The resulting tail-relative spans are offset by path_len, while reused prompt messages remain None. This preserves missing-message spans, internal scaffold attribution, and full-prompt coordinates without scanning the reused prefix.

Performance and resources

For 2,000,000 reused attribution entries plus a 110-entry tail:

  • synchronous wall time / event-loop stall: 28.208 ms → 4.927 µs per call
  • absolute time saved: 28.203 ms per call
  • speedup: 5,725× (99.983% less time)
  • attribution entries traversed: 2,000,110 → 110
  • traced live allocation at return: 652 B → 832 B
  • peak incremental traced allocation: 860 B → 1,096 B (+236 B)
  • retained traced allocation after releasing the result: 64 B → 64 B

The full attribution input, output shape, task count, and connection count are unchanged.


Note

Low Risk
Localized graph attribution helper change with intended behavior preserved; main effect is performance on long bridged prompts, not auth or data handling.

Overview
PendingTurn.prompt_message_spans() no longer runs message_token_spans() over the full bridged renderer attribution. It builds a RenderedTokens view on message_indices[path_len:] (the newly rendered tail only), derives spans from that slice, then returns None for each reused prefix message and shifts non-None tail spans by path_len so coordinates still match the full prompt.

This keeps the same span list shape and semantics for turn.commit() (via response_from_generate when bridged_turn is set) while avoiding a synchronous scan over millions of bridge-reused attribution entries marked unattributed in the prefix.

Reviewed by Cursor Bugbot for commit b422a14. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix PendingTurn.prompt_message_spans to scan only the bridged attribution tail

Previously, prompt_message_spans computed token spans across the entire prompt, including reused bridge tokens. It now slices message_indices from path_len onward, computes spans only for the tail, and offsets each non-None span by path_len to produce full-prompt-relative positions. The prefix and any reused bridge tokens are returned as None.

Macroscope summarized b422a14.

@macroscopeapp

macroscopeapp Bot commented Jun 21, 2026

Copy link
Copy Markdown

Approvability

Verdict: Needs human review

This change modifies how attribution spans are computed by slicing token indices and adjusting offsets. While the intent appears to be fixing attribution for reused bridge tokens, changes to core attribution logic can have subtle downstream effects and warrant human verification.

You can customize Macroscope's approvability policy. Learn more.

@xeophon xeophon changed the base branch from feat/nano-as-v1 to main June 23, 2026 04:10
@xeophon xeophon force-pushed the codex/v1-bridge-tail-spans branch from b72f5c3 to b422a14 Compare June 23, 2026 04:17
@xeophon xeophon requested a review from mikasenghaas June 23, 2026 04:26
@mikasenghaas mikasenghaas merged commit 00f70ea into main Jun 23, 2026
13 checks passed
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