Skip to content

Make Foundry sync hold up: reconnects, journals, kits, maps and player requests - #314

Merged
keyxmakerx merged 2 commits into
mainfrom
claude/project-thread-0mefcy
Nov 13, 2026
Merged

keyxmakerx merged 2 commits into
mainfrom
claude/project-thread-0mefcy

Conversation

@keyxmakerx

@keyxmakerx keyxmakerx commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Requested by Key Maker · project thread

Fixes: none
Security implication: security fix. Players no longer see the names of pages they can't open in mention links, a map's GM layer row is no longer written where players can read it, players can no longer flood the GM's client (and its API key) with stash, crafting or shop requests, and a map picture copied into the world's files follows who may see it.
Consumer-verified: Chronicle internal/plugins/maps/drawing.go Token (bar1_value, bar1_max) and Layer.LayerType; internal/plugins/media/signed_url.go SignedURLTTL = 15 * time.Minute; internal/plugins/calendar/service.go real-time refusal text "tracks real-world time"; internal/plugins/syncapi/middleware.go RequireCampaignMatch 403 "api key not authorized for this campaign".
Foundry compatibility: not run in a live Foundry world; checked with the unit tests and the two-sided bench (fake Foundry, real Chronicle). Live click-paths below.
Mockup: n/a (no new UI; players lose a status dot that was always red)

What this changes

A full check of the Foundry functionality: four reviews read the module and Chronicle's sync side by area, each finding was confirmed in the code, and the bench ran against Chronicle main and against #2134 (keyxmakerx/Chronicle). These are the fixes that were small and safe; the larger gaps are filed.

  • Reconnect after saving settings (api-client.mjs). applyConnection closes the old socket and opens a new one at once; the old socket's onclose arrived later and set _ws = null and disconnected on the live connection, which could show "Connection lost", leave the dot red, and after a click on the dot open a second socket that delivered every event twice. Each handler now acts only while its socket is still this._ws.
  • Players' status dot (module.mjs). Only the GM connects, so a player's dot always read disconnected, and clicking it called connect() with no key, retrying every 30 s. _addStatusIndicator now returns for non-GMs.
  • Hidden page names in mentions (_mention-links.mjs). The module reads with an owner key, so mention text is the real name. A player now sees "a hidden page" (CHRONICLE.Mentions.Hidden) for a page they can't open here, as Chronicle shows it.
  • Stray "Overview" heading pushed to Chronicle (journal-sync.mjs). Text before the first heading becomes a page named "Overview" (or "Content" with no headings); _joinTextPages wrapped it in <h2>Overview</h2> on push, adding a section to the Chronicle page on every Foundry edit. The first page with one of those names now goes back as lead text. Page names in added headings are escaped.
  • The GM's own kit swap undone (actor-sync.mjs, _identity-item-plan.mjs). Every Chronicle apply compared the actor's kit/ancestry item with Chronicle's pick and replaced it, so a kit the GM swapped in Foundry was deleted by the next unrelated Chronicle change. The picks last applied are kept in the actor flag identityApplied, and a field is swapped only when Chronicle's pick changed since. A failed swap keeps the older pick so it is retried.
  • Map pictures expiring (map-sync.mjs, picture-store.mjs, _blank-picture.mjs). Pages kept Chronicle's signed link (15 minutes), refreshed only when the GM opened a viewer. A map's own picture is now copied into the world with the existing PictureStore (cookieless, Chronicle host only, 25 MB cap). Over the cap or on a failed copy the link is kept and retried on the next sync or GM viewer open. World files are served to anyone with the address, so:
    • the copy is made only once a player can open the map's journal (_playersCanSee, LIMITED or better); sharing the journal copies it then, and a map no player can open keeps the link;
    • when a map gains a shadow, the copy is overwritten with a one-pixel blank of the same name and format (PictureStore.retire), since Foundry can't delete files, and the store forgets it. The page flag retiredPictures makes a later session, which finds the blank file, write the real picture back if the shadow is removed;
    • the GM's own view of a newly shadowed map takes a fresh link, not the blanked file.
  • GM layer row in player flags (_map-flag-filter.mjs). isLayerSafeForPlayerFlags drops layer_type: 'gm' (and rows with no type), matching what Add a player-eyes crawl; fix two viewer-visibility gaps Chronicle#2140 does for player listings.
  • Token hit points (map-viewer.mjs). The viewer read max_hp/current_hp, which Chronicle never sends; it now reads bar1_max/bar1_value.
  • Real-time calendar refusal (_date-push-rejection.mjs). /real.?time/ did not match Chronicle's "tracks real-world time", so the backstop paused date push with the months-and-leap-days notice.
  • Player request limits (stash-sync.mjs, crafting-relay.mjs, shop-room-window.mjs). Each now uses the quest board's makeAskLimiter (30 per 10 s per player) before calling Chronicle with the GM's key.
  • Test connection (_connection-test.mjs). A 403 for a key made for another campaign says so (WrongCampaign) instead of "missing a permission"; a 200 that isn't JSON (a sign-in page in front of Chronicle) is NotChronicle, not "Campaign found"; the unreachable message now covers Chronicle being down and https-to-http.

Honest deviations

  • The mention fix is what is drawn. The saved page still holds the mention as Chronicle sent it; that is tracked privately.
  • A picture over 25 MB keeps the expiring link, as before.
  • Un-sharing a map journal later does not blank its copy; players who could open it have already loaded it. Only a new shadow blanks it.
  • Replacing a file by uploading to the same name is Foundry's documented behaviour, not run here; the live check below covers it.
  • The identity fix starts from an empty record on existing actors, so the first Chronicle apply after updating still behaves as before for each actor (one more swap at most).
  • bench/actors.bench.mjs "two Chronicle changes applied at once" now also clears identityApplied in its reset, since the reset simulates Chronicle's kit being new.

Not fixed here, filed: #308 (duplicated journal or actor keeps its link), #309 (request timeouts, catch-up retry, revoked key), #310 (smaller gaps). The biggest remaining risk is the existing #292: "Pull only" and "Push only" are saved but ignored.

Why

Key Maker asked for a deep check that all the Foundry functionality works and is solid.

Test plan

  • node --test tools/test-*.mjs: 1688 pass, 0 fail, 4 skipped (was 1669 on main)
  • tools/check-comment-clutter.sh: OK
  • CHRONICLE_DIR=../Chronicle bench/run.sh on main before the change: 42/42
  • CHRONICLE_DIR=<Chronicle #2134> bench/run.sh with the change: 41/42; the one failure was the reset described above. After that fix and the new scenario, bench/run.sh actors: 11/11
  • After the map picture follow-up, CHRONICLE_DIR=../Chronicle bench/run.sh maps on Chronicle main: 3/3 (the bench's maps carry no pictures, so the copy itself is covered by the unit tests)
  • New tests: stale socket close, mention label for players, lead text round trip, recorded identity picks, GM layer filter, map picture copy (copied, reused, retried, cookieless; not copied for an unshared journal, copied on sharing, blanked on a new shadow and on a shadowed row, a failed blank reported, written back after the shadow goes in a later session), a blank picture per format and retire refusing paths outside its folder, real-time refusal text, wrong-campaign and sign-in-page connection tests, relay limits; bench scenario "a kit the GM swaps in Foundry survives a later Chronicle edit to another field"
  • CI passes
  • Live checks in Foundry v14 (operator):
    • Settings → Connection: change the API key and Save twice in a row → the dot ends green, no "Connection lost" toast, and a Chronicle edit appears once.
    • Log in as a player → no Chronicle dot in the sidebar.
    • In Chronicle, write "@" + a GM-only page inside a page players can see; sync; as the player open the journal → the link reads "a hidden page"; as the GM it shows the name.
    • In Foundry, edit a synced journal whose Chronicle page starts with a paragraph before its first heading → in Chronicle no "Overview" heading appears.
    • Swap a hero's kit by hand in Foundry, then change the hero's HP in Chronicle → the new kit stays.
    • Resync All Maps, wait 20 minutes, open a map shared with a player as that player, who never opened it → the picture shows.
    • As the GM, open a map journal shared with a player and copy its picture address (right-click the image → copy image address; it ends in chronicle-media/<id>.<ext>). Add a shadow to that map in Chronicle. Open the address in a private browser window → blank, not the map. Broken: the full map still shows.
    • A map journal no player can open → its picture address is still a Chronicle link (/media/…?sig=…).
    • Settings → Connection with a campaign id other than the key's → Test connection says the key belongs to a different campaign.

Tenet self-check

  • T-B1 security: map pictures fetched cookieless from the Chronicle host only (PictureStore), copied only for journals a player can open and blanked when the map is shadowed; no new trust in payloads; GM-only names kept off player screens and flags
  • T-B2 plugin isolation: module only
  • T-B3 production UI: no new UI; one notice and two Test connection lines reworded, one new warning if a blank can't be written
  • T-B4 dual-audience docs: .ai.md (maps, picture store, mentions) and TESTING.md (map picture checks) updated

Generated by Claude Code

Fixes found by reading the whole module and running the two-sided bench:

- A socket replaced by Save settings no longer clears or reconnects the
  new one when its close arrives late (stale handlers now check they are
  still the current socket).
- Players no longer get the status dot: it always read disconnected and
  clicking it opened a keyless socket that retried every 30 seconds.
- Mentions of pages a player can't open show "a hidden page", not the name.
- Text before the first heading goes back to Chronicle without a sync-made
  "Overview"/"Content" heading; page names in added headings are escaped.
- An identity item (kit, ancestry) the GM swapped in Foundry is left alone
  until Chronicle's pick changes; the picks last applied are kept on the
  actor.
- A map's own picture is copied into the world through PictureStore, since
  Chronicle's signed links expire after 15 minutes.
- The GM layer row is kept out of player flags; tokens read hit points from
  bar1_value/bar1_max.
- Chronicle's real-time refusal ("tracks real-world time") is recognised.
- Stash, crafting and shop requests from players are limited per player,
  like quest requests.
- Test connection names a key for another campaign, and a page that isn't
  Chronicle; the unreachable message covers mixed content.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CZefPfJdwbn2k1DtGMYyod
@keyxmakerx keyxmakerx self-assigned this Nov 12, 2026
Security fix. A map's picture copied into the world's files stayed at the
same address after the GM shadowed part of the map, and was copied even
for a map journal no player could open. Now:

- The picture is copied only once a player can open the map's journal;
  sharing the journal copies it then. Other maps keep the short-lived link.
- When a map gains a shadow, the copy is overwritten with a one-pixel
  blank picture of the same name and format (Foundry can't delete files),
  and the store forgets it. The page records the id, so if the shadow is
  removed in a later session the real picture is written back.
- The GM's own view of a newly shadowed map takes a fresh link instead of
  the blanked file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CZefPfJdwbn2k1DtGMYyod
@keyxmakerx
keyxmakerx merged commit 4bcd9dd into main Nov 13, 2026
4 checks passed
@keyxmakerx
keyxmakerx deleted the claude/project-thread-0mefcy branch November 13, 2026 00:34
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