Skip to content

fix(daemon): Resolve deep links by ref and bound workspace payloads - #5359

Merged
Sinity merged 2 commits into
masterfrom
fix/bounded-read-payloads
Sep 21, 2026
Merged

Sinity merged 2 commits into
masterfrom
fix/bounded-read-payloads

Conversation

@Sinity

@Sinity Sinity commented Sep 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

A deep link now resolves by reference in exactly one page request at any depth,
and /api/stack and /api/compare serve a declared window per session instead
of every message of every session.

Both honour the 2026-09-21 ruling: the 50-page walk was removed, not raised, and
the workspace window is a reported default with no maximum and an explicit
whole-transcript escape — not a cap.

polylogue-i5vqc — resolve by ref, don't walk

At head, a deep link past 50 * pageSize reports "The linked message could not be
located within the paged transcript"
— a valid, resolvable ref reported as
unlocatable — and a target inside 50 pages fetches and retains every preceding
message.

around=<message id> is now a declared query parameter on the existing messages
read-view capability, so /api/sessions/:id/read?view=messages and
/api/sessions/:id/messages both accept it. No new route was added: a second
route would have needed its own RouteContract and OpenAPI declaration for a second
way to ask the same question. It is one request, not locate-then-fetch.

around is sugar over the existing coordinate, not new window semantics —
test_deep_link_window_matches_the_offset_window_it_resolves_to proves an around
window is byte-for-byte the window you get by asking for the offset it reports.

polylogue-o0zju — the bead undercounted the sites by three

It named only build_stack_payload → _do_get_session. At head there are four
payload builders, two per mode: _handle_stack/_handle_compare branch on
_web_reader_archive_root() into _do_archive_stack/_do_archive_compare (the
archive-backed production route whenever the tiers exist) versus
workspace_routes.handle_stack/handle_compare (database-backed). The workspace SSR
shell is a third caller of the archive pair.

Fixing only the bead's path would have left the actual production route
unbounded.
All four are fixed and both envelopes report the served window; each
session payload's message_count/total still carries its true length.

Why this is a declared window and not a cap

WORKSPACE_MESSAGE_WINDOW = 50 is the default of an explicit limit — the
served (limit, offset) is reported on both envelopes, limit=0 requests the whole
transcript and is honoured, and there is no maximum, so no request is silently
clamped. Where a request is unanswerable the route refuses rather than truncates:
a message reference the session does not contain is 404 message_not_found (never
page zero under the caller's reference), and around alongside a continuation is
400 invalid_request because they name two different windows.

Mutation 8 is the test that distinguishes the two: turning the default into a ceiling
(limit = min(raw_limit, 50)) reddens
test_stack_reports_true_totals_for_an_explicit_whole_transcript_request with
assert 50 is None.

A measured correction to the closure model, worth carrying forward

The ref→offset contract did not require editing archive/query/transaction.py
(IN). The reason is a fact the standing caveat does not state:

The closure is reachability from the lowering/materializer/replay-routing
roots — not "imports a closure member".

operations/transcript_window.py imports six symbols from transaction.py and still
measures out. So importing the transaction vocabulary is free; only editing
transaction.py would have converted this leaf. The new locator therefore lives in
operations/message_locator.py (out) and takes the archive reader as a parameter.

All 13 changed non-bundle files measure out, measured twice — at the original
base and again after the rebase. The leaf stays rebuild-safe.

Anti-vacuity — eight mutations executed, and one test strengthened because a

mutation exposed it

Mutation Red
Accept around but ignore it 3 red — the route answered page zero for a resolvable deep reference, and an unresolvable one silently answered with a window of someone else's messages
Locator counts lexicographically by message_id instead of (position, variant_index) 3 red — landed on a wrong-but-plausible page; the silent-wrong-answer a "returns 200" test cannot see
Restore the 50-page walk 2 red, but toHaveBeenCalledTimes(1) still passed because the mock returned the target on call 1 — the exact vacuity the bead warned about
(3b) Same walk against a strengthened test whose loader returns the target only for an around window reproduces the real defect: Unable to find an element with the text: The deep-linked message, status reading "could not be located within the served window" after 50 fetches
Drop limit/offset from the three archive get_session calls the stack ships the window the view renders, not the session — assert 2000 == 25
DB-backed loader ignores its declared window assert 2000 == 25
Builders call the loader with limit=None catches a builder that accepts a window then discards it
Remove the around+continuation refusal assert 404 == 400
Make the declared window a ceiling assert 50 is None

Rather than accept the vacuous pass on mutation 3, the lane strengthened the test so
only an around window can contain the target, then re-ran the mutation to a real
red. That is the right handling and is called out here so a reviewer sees it.

Parity, pagination, cancellation

  • test_transcript_window_differential.py 5/5 — the same (ref, limit, offset) still
    names the same rows on all four surfaces, and around goes through the same
    read_transcript_window_sync route rather than a second window owner
  • Two-route parity: both message-window routes return identical ids and the
    identical resolved offset
  • Pagination: next_offset == offset + limit, windows tile without overlap;
    continuation parity 5/5, token still minted by window_result
  • Cancellation: test_web_reader.py 139/139, including client-disconnect abort on the
    limit is None full-composition branch this change preserves

Verification

devtools verify --quick exit 0, all 25 gates (post-rebase) · devtools render all --check exit 0, zero out of sync (two surfaces were regenerated mid-change:
OpenAPI and the webui client) · focused 9-module selection 340/340 passed ·
devtools gate webui exit 0 (tsc, vitest 33/33, client contracts 8/8, builds).

New reds: none. Every selected suite was green at the pre-change baseline in this
worktree and at head, so no inheritance proof was needed and none is claimed for
suites outside this scope.

Residuals

  • around is HTTP-only. operations/read_contracts.py SessionReadRequest still
    takes only limit/offset, so CLI read --view messages, the MCP read tool and the
    Python API cannot express "the window around this message". read_contracts.py is
    out, so it is a rebuild-safe follow-up — left out because a declared-operation
    field is a wider contract change than this leaf authorised.
  • Cost asymmetry, no regression. On the archive-backed production route the locate
    is two indexed counts and the window composes at the storage layer, so the deep link
    is genuinely O(page). On the DB-backed fallback the payload is bounded (mutation
    5 proves it) but the read still composes the whole transcript — as it already did on
    every page before this change; the single composition is reused rather than doubled.
  • Prefix-sharing lineage children fall back to full composition in the locator,
    because only the composed transcript can number them. That mirrors the constraint
    read_archive_session_page already documents; a follow-up bounding the lineage case
    fixes both at once.
  • The compare envelope's total still means "number of pairs", now window-sized; each
    side's own total carries the true length. A reader interpreting it as a session
    length was already wrong, but the window makes that misreading cheaper.

Closes polylogue-i5vqc, polylogue-o0zju.

🤖 Generated with Claude Code

https://claude.ai/code/session_015WCh9YW3cRfsg3CZBKU7Fq

Summary by CodeRabbit

  • New Features
    • Read session messages using an around message ID to jump directly to its surrounding window.
    • Stack and compare views now support bounded message windows while preserving full session totals.
    • Session views display the loaded message range and continue paging from the selected window.
  • Bug Fixes
    • References to messages outside a session now return a clear not-found error instead of showing the first page.
    • Invalid requests combining an anchor and continuation are rejected with an appropriate error.

Sinity and others added 2 commits September 21, 2026 18:35
Two read paths answered with payloads sized by the session rather than by
what the view asked for.

polylogue-i5vqc: the web reader honoured a `#msg-<id>` deep link by walking
up to 50 pages from the SSR offset. A target past that ceiling made a valid,
resolvable reference report as "could not be located within the paged
transcript", and a target inside it still fetched and retained every
preceding message. The message-window routes now accept `around=<message
id>`, resolve it to the offset of the window that holds it through the
indexed composed-transcript order, and report that offset back; the island
issues exactly one page request whatever the target's depth. A reference the
session does not contain is refused with `message_not_found` instead of
being answered with page zero, and `around` alongside a continuation is
refused rather than silently preferring one.

polylogue-o0zju: `/api/stack` and `/api/compare` serialized every message of
every referenced session. Both now serve a declared `(limit, offset)` window
per session and report it on the envelope, while each session's
`message_count`/`total` still carries its true length. `limit=0` is the
explicit whole-transcript request, so the default window is a declared
parameter rather than a cap.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015WCh9YW3cRfsg3CZBKU7Fq
`around` is now part of the `messages` read-view capability, so the OpenAPI
document and the generated TypeScript client carry it rather than leaving it
an undocumented query parameter. The island test makes the `around` request
the only one that can contain the target, reproducing the archive behaviour a
sequential walk fails against, and the database-backed session loader gets its
own bounded-window test.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015WCh9YW3cRfsg3CZBKU7Fq
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-21T17:00:39.555273Z 4f5f12a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Sinity
Sinity enabled auto-merge (squash) September 21, 2026 16:52
@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 6c53f706-d134-44fb-9715-45999a7afc79

📥 Commits

Reviewing files that changed from the base of the PR and between 5398a7e and 4f5f12a.

⛔ Files ignored due to path filters (9)
  • polylogue/daemon/static/dist/api-DIMqXuwv.js is excluded by !**/dist/**
  • polylogue/daemon/static/dist/api-VIh9cM_e.js is excluded by !**/dist/**
  • polylogue/daemon/static/dist/archive-overview-DUoVHuHm.js is excluded by !**/dist/**
  • polylogue/daemon/static/dist/manifest.json is excluded by !**/dist/**
  • polylogue/daemon/static/dist/observability-d0sVwsqO.js is excluded by !**/dist/**
  • polylogue/daemon/static/dist/search-BvgsMUI6.js is excluded by !**/dist/**
  • polylogue/daemon/static/dist/session-list-KGOA_-Qr.js is excluded by !**/dist/**
  • polylogue/daemon/static/dist/session-read-BOS1zR8-.js is excluded by !**/dist/**
  • polylogue/daemon/static/dist/session-read-ly9Gi_VU.js is excluded by !**/dist/**
📒 Files selected for processing (13)
  • devtools/render_openapi.py
  • docs/openapi/search.yaml
  • polylogue/archive/viewport/profiles.py
  • polylogue/daemon/compare.py
  • polylogue/daemon/http.py
  • polylogue/daemon/workspace_routes.py
  • polylogue/operations/message_locator.py
  • tests/unit/daemon/test_bounded_read_payloads.py
  • webui/src/api/generated.ts
  • webui/src/contracts/session-read.ts
  • webui/src/islands/session-read.test.tsx
  • webui/src/islands/session-read.tsx
  • webui/src/lib/api.ts
 _____________________________________________________________________________
< I took both the red pill and the blue pill. Now I'm stuck in a code review. >
 -----------------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f5f12aa14

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/daemon/http.py Resolved
Comment thread polylogue/daemon/workspace_routes.py Resolved
@Sinity
Sinity merged commit 6fdaeb0 into master Sep 21, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the fix/bounded-read-payloads branch September 21, 2026 17:02
@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at ef10e59):

Resolving the fixed, stale and refuted threads; tracked threads stay open.

@Sinity

Sinity commented Sep 29, 2026

Copy link
Copy Markdown
Owner Author

Closing out open Codex review threads on this PR (evidence checked against master at 0914f89):

  • P2 polylogue/daemon/http.py:5338: Fixed on master (checked at 0914f89): _accept_message_window_anchor now rejects around combined with a continuation or a nonzero offset (polylogue/daemon/http.py:4899).

Resolving every thread listed; confirmed defects are fixed under the named bead.

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