Skip to content

A mapped listing ends when the member that holds its cursor is absent, proved on results recorded from an open-source wiki's protocol server - #2383

Open
zlareb1 wants to merge 2 commits into
mainfrom
fix/mapped-cursor-member-absent
Open

zlareb1 wants to merge 2 commits into
mainfrom
fix/mapped-cursor-member-absent

Conversation

@zlareb1

@zlareb1 zlareb1 commented Dec 6, 2026 •

Copy link
Copy Markdown
Member

Related: #1189
Related: #1190
Related: #1232

Changelog category (leave one):

  • Improvement

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

The source worker's mapped reader ends a listing when a member on the path to its cursor is absent or null at any depth, so a read mapping can list a server that leaves out the whole member that holds its cursor on the last page. source_worker/mappings/wiki.json is a reference mapping for an open-source wiki's protocol server, and a test reads it on results recorded from that server.

Why

The mapped reader was proved on results built by hand for a made-up server. Recorded from a protocol server Loom did not write, one shape did not fit. The server holds its next cursor three keys down (truncation.continueWith.value) and leaves out the whole truncation member on a listing's last page and on an empty listing. The reader took only the last key of next_cursor_path as optional, so it read the first page and refused the last page and the empty scope with protocol.

A listing's cursor was already optional. Servers commonly leave out the member that holds it, so this is the same rule read along the whole path, and no new mechanism. The mapping format does not change.

Scope and risk

  • The reader (source_worker/loom_source_worker/readers/mcp_mapped.py). _cursor reads next_cursor_path: a member that is absent or null at any depth means that no page follows. A member that is present and is not an object where the path goes on, and a cursor that is not a string, refuse with protocol as before. The optional paths of an item (title, link, revision, modified time) still go through _optional, where only the last key may be absent.
  • The reference mapping (source_worker/mappings/wiki.json, id wiki). It pins the server's listing tool and its fetch tool by the digests the server advertised. The scope is a user, the listing is by change and by time, an id is a page's name, and a removal is the fetch's not-found answer. The listing names changes, not pages, so the mapping declares it not complete and nothing is retired by absence. It names no denied matcher: the wiki had no page its reader may not read, so no denial was recorded.
  • The recording (source_worker/tests/fixtures/mapped/wiki/). A wiki made for the run, in a container, held 53 short made-up pages and one long one by one made-up user, and a second user with no change. The recorder wrote the two tool definitions, a listing of two pages (50 and 4 changes), the listing of what changed since (4), the empty scope, a document, a missing one, one the server cut at its size cap, and expected.json. The wiki ran under a made-up https origin on a reserved example name, so every link in the files is on that origin and no file holds an address of the machine. The directory's README.md names the server, its version and the image once, with the commands that repeat the recording.
  • The stand-in channel (source_worker/qualification/stand_in_channel.py). Stdio starts a server as a local process. Channel stands between the reader and it as an account host's channel does: it lists the server's tools as advertised (29 here, of which the mapping pins 2) and raises too_large for a result over its cap, reconnect_required when the account needs a sign-in, server_off when the server is not enabled and tool_not_allowed for a tool the host's policy refuses. It holds no error text of any host, and the package does not import it.
  • The recorder's scrub is completed (source_worker/qualification/record_mapped.py). The first recording still held every page's name: the server's link spells it with _ for a space, and the recorder replaced an id only as written. spellings adds the two ways a link spells a value (percent-encoded, or _ for a space) to the replacement and to the check that stops the recorder when a call still holds a value. test_the_recorder_replaces_an_id_as_a_link_spells_it failed first on a written file that held both spellings.
  • Decisions made while building, for the reviewer to check:
    • The channel's four refusals return no result, so the recording holds no file for them. They are cases of the proof test: Channel over the recorded results in each state. The same four states were also run against the live server, with the same codes.
    • The committed recording was made with the server's content cap set to 4,096 bytes, so the cut page's file is 10 KB. At the server's default of 75,000 bytes the same call was recorded first and measured: the result is 152,009 bytes as the reader counts it (the text is in both the text block and the structured content) and has the same members. The mapping's max_result_bytes of 400,000 is set from that measurement, with room for a page whose text doubles when it is written as JSON.
    • tools.json holds the two definitions as advertised, parameter descriptions included, because the digest covers the input schema. One description names a public site as an example of an argument. Removing it would change the digest the mapping pins.
    • The results keep the wiki's row numbers (pages, revisions, users) and the times of its changes. The recorder never replaces a number. The docs now say so, and that such a server is recorded from a workspace made for the recording.
    • The server writes links on the wiki's own origin only when it can read the wiki's settings, which it refuses for a local address unless that address is trusted. The directory's note names the setting. Without it the links carry the local address.
    • Stdio waits on the server's pipe without a deadline. It is used by a person who records, never by the package or a test.
  • Left alone: the host backend, the engine and the mapping format. No op, table, setting or server file changes. The hand-built example recording is unchanged.
  • What could break: a mapping whose next_cursor_path has more than one key ends its listing where a member above the cursor is absent or null; before, it refused with protocol. A server that left such a member out in the middle of a listing would end it early, as a server that leaves out the cursor itself already does. No read mapping in the repository had such a path before this change.

Compatibility, rollout and rollback

  • Wire: none. No op, field, error code, table, migration or setting is added or changed.
  • Mapping format: unchanged. No key is added, and the digest of an existing mapping is the same.
  • Rolling upgrade: no rule changes. A worker one release behind refuses a listing whose cursor member is absent with protocol, as before: the turn ends with that error and is retried.
  • Operator steps: none.
  • Rollback: reverting removes the reference mapping, the recording, the stand-in and the tests, and restores the last-key rule for the cursor. Nothing is stored by this change.

Tests

  • The three reader tests were written first, in source_worker/tests/test_mapping_proof.py, over the hand-built recording with the cursor moved two members down:
    • test_a_listing_ends_when_the_cursor_member_is_absent (7 cases). On the unchanged reader 4 failed with protocol: the member absent, null or empty, and the member under it null.
    • test_a_cursor_member_of_the_wrong_type_still_refuses (7 cases): a string, a list or a number where an object is expected, at both depths, and a number as the cursor. Every value is falsy on purpose.
    • test_an_item_field_keeps_the_last_key_rule: an absent last key of a title path reads as no title; an absent or null member above it refuses.
    • The last two pass before and after. With the cursor rule loosened to take any empty value as absent and applied to the title path, 7 of their 8 cases fail.
  • Over the recorded directory, with the reference mapping:
    • test_the_reference_mapping_pins_the_recorded_definitions.
    • test_the_reference_mapping_reads_what_the_recording_expects: the reader produces expected.json, every field of every listed change and of the fetched document.
    • test_the_recorded_listing_ends_where_the_server_leaves_its_cursor_member_out: two pages of 50 and 4, the second asked for by the first page's cursor, no truncation member on the last page, the changed listing and the empty scope.
    • test_the_recorded_missing_page_is_gone_and_the_cut_page_is_too_large.
    • test_no_fixture_holds_an_upstream_id_or_name, now run over both recordings. It also fails when a file holds a link on another origin than the mapping approves, and for the wiki when a change names a page or a user that is not a neutral value.
    • test_a_refusal_of_the_channel_reaches_the_engine_by_its_code (one case per refusal): the reader raises the channel's code, removed answers unknown, and only a result's size is judged after the call.
    • With the reader's one call put back to _optional, 9 tests of the file fail with protocol: the 4 cases above and 5 tests of the recorded directory.
  • The recording, repeated with the final code into another directory, equals the committed files.
  • python -m pytest -q source_worker/tests, serially as the package's workflow runs it: 618 passed, 28 subtests passed. The run before it had one failure in an unchanged file, test_enrollment_http.py::test_a_grant_outside_its_scope_is_denied_before_lookup[issued-ahead]. Its parameter is a time ten seconds ahead that is computed at collection, so it fails when the test starts later than that. It passes alone and in its file.
  • ruff format --check source_worker, ruff check source_worker, mypy --strict source_worker/loom_source_worker (no issues in 20 source files), make typecheck (0 errors).
  • tests/unit/test_package_contracts.py, test_op_transport_contract.py, test_tunable_constants.py, test_store_names_refused.py, test_degraded_unnoted.py, test_public_copy.py, test_doc_links.py, test_agent_instructions.py and tests/analyzer, on the tree merged with main: 616 passed, 12 skipped, 1 failed. The failure is test_degraded_unnoted.py::test_every_broad_handler_notes_its_fallback_or_says_why_it_need_not, which names server/code/app/review_brief.py::_rebuild. That handler is main's, and this change touches no server file, so it is not changed here.
  • npx --yes prettier@3.9.9 --check on the two docs pages and the directory's note, and Biome's format check on source_worker: no change.
  • Not run: the full unit suite and the integration suite (CI runs them). tests/integration/test_assigned_source_turn.py reads the hand-built recording, whose cursor path has one key, through the reader. No generator applies to this change.
  • The head holds main at ff9e20291, merged without a conflict. main changed no file under source_worker/ and neither of the two docs pages since the branch started, so the worker suite was not run again after the merge.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. Checked by installing the server at its pinned version and calling its tools against a wiki made for the run, by reading the server's code for where its cursor, its link origin and its size cap come from, by writing each test before the code and watching it fail, by loosening the new rule and watching the two guard tests fail, and by repeating the recording with the final code.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump), the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py) and the standalone skill bundles (python3 scripts/codegen/standalone_skills.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.
  • I signed the Contributor License Agreement (CLA) if CLA assistant requested a signature.

🤖 Generated with Claude Code


Note

Medium Risk
Listing pagination behavior changes for multi-key next_cursor_path mappings: absent/null intermediates end the list instead of raising protocol, which could truncate listings if a server omits members mid-sequence. Scope is confined to the source worker reader and test/qualification tooling, not auth or stored data.

Overview
The mapped reader now treats a listing as finished when any segment along next_cursor_path is missing or null, not only the final cursor key. That supports servers (e.g. MediaWiki MCP) that nest the continue token under truncation.continueWith.value and omit the whole truncation object on the last page or empty listings. Pagination uses a new _cursor helper in mcp_mapped.py instead of the old last-key-only optional read.

This PR adds source_worker/mappings/wiki.json as a reference mapping for @professional-wiki/mediawiki-mcp-server, plus a recorded fixture tree under tests/fixtures/mapped/wiki/ and docs on how to re-record it. Qualification tooling grows stand_in_channel.py (Stdio + Channel) so recordings can run through a local stdio server with host-like refusals (reconnect_required, server_off, tool_not_allowed, too_large).

The recorder spellings() now neutralizes IDs in plain text and common link forms (percent-encoding and _ for spaces), and skips numeric IDs. test_mapping_proof.py covers nested-cursor edge cases, replays both example and wiki fixtures, and asserts channel error codes propagate unchanged.

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

zlareb1 and others added 2 commits December 6, 2026 10:20
…, proved on results recorded from an open-source wiki's protocol server

A server may leave out the whole member that holds its cursor on a
listing's last page and on an empty listing. The mapped reader took only
the last key of next_cursor_path as optional, so it read the first page of
such a listing and refused the last one with protocol.

For next_cursor_path alone, a member that is absent or null at any depth
means that no page follows. A member that is present and is not an object
where the path goes on, and a cursor that is not a string, still refuse
with protocol. The optional paths of an item keep their rule: only the
last key may be absent. The mapping format is unchanged.

source_worker/mappings/wiki.json is the reference mapping for an
open-source wiki's protocol server. source_worker/tests/fixtures/mapped/wiki
holds what that server answered for a wiki of made-up pages. It was
recorded through source_worker/qualification/stand_in_channel.py, which
stands in for an account host's tool channel: it lists the server's tools
as advertised and raises the reader's code for a result over its cap, a
sign-in that is needed, a server that is not enabled and a tool that is
not allowed. The proof test reads the recording with the reference mapping
and puts the channel in each refusing state.

The recorder replaces an id as a link spells it as well: percent-encoded,
or with _ for a space. A wiki's link holds the page's name in that
spelling, which the recorder left in the written files.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
main changed no file of this branch.

Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vercel

vercel Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Dec 6, 2026 10:27am UTC
loom-telemetry Ready Ready Preview Dec 6, 2026 10:27am UTC

Request Review

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3448a90. Configure here.

for known in sorted(self._values, key=len, reverse=True):
value = value.replace(known, self._values[known])
for spelling in spellings(known):
value = value.replace(spelling, self._values[known])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Scrub splits percent-encoded values

Medium Severity

scrub applies spellings with the raw value first. quote encodes % as %25, so that raw value is a prefix of its percent-encoded spelling. The first replace tears the encoded form apart, the later spelling no longer matches, and the hold check looks only for the original spellings, so the recording keeps a broken link.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3448a90. Configure here.

for known in sorted(self._values, key=len, reverse=True):
value = value.replace(known, self._values[known])
for spelling in spellings(known):
value = value.replace(spelling, self._values[known])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Underscore spellings alias other ids

Medium Severity

scrub still orders values by raw length, then replaces every spellings form, including space turned into _. A link spelling that is exactly some other upstream value is replaced with the first value's neutral id, so two different ids become one token in the recording.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3448a90. Configure here.

This branch has not been deployed

No deployments
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