Skip to content

Keep historical foreign-advert flags when archived nodes return - #2498

Merged
efiten merged 2 commits into
Kpa-clawbot:masterfrom
n30nex:codex/foreign-history-20261127
Dec 1, 2026
Merged

efiten merged 2 commits into
Kpa-clawbot:masterfrom
n30nex:codex/foreign-history-20261127

Conversation

@n30nex

@n30nex n30nex commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2496. Related to #730.

When an archived node returns with an ordinary advert, the upsert restores the foreign flag retained for that public key. A previously returned node recovers on its next advert. If it ages out first, retention preserves that evidence before replacing its archive row.

Rebased onto 1c5ec2fad, which includes the mobile first-frame correction in #2500. The two archive patches match the previously reviewed patches. In a database made by the old ingestor, the historical map filter showed only the returning flagged node after upgrade. Clearing it showed both ordinary controls too. The map suite passed 77/77 and both motion preferences cleared the bar by 20.5 px in the 40/40 navigation suite.

Each advert adds an indexed archive-key lookup. The earlier benchmark used 4,000 active and 30,000 archived nodes on these same SQL changes.

Operation, local median Before After
Active advert, WAL/FULL 1.89 ms 2.07 ms
Returning advert, WAL/FULL 2.41 ms 2.20 ms
Returning advert within a transaction 7.0 µs 40.5 µs
Archive 500 stale nodes 8.37 ms 8.85 ms

WAL/FULL includes variable disk-commit time. Rebased regression

@n30nex

n30nex commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Kent Beck Gate: PASS (test quality) on 4296502d6. The earlier tests reproduced both flag loss on return and retention overwriting the last archived flag. The fix passed against a database created by the old ingestor. Its historical map filter showed the returning flagged key, and clearing it restored all three fixture nodes. Final revision workflow

@n30nex

n30nex commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Could a maintainer rerun the failed jobs on 4296502d6? The browser shard measured a 37.5 px overlap after leaving Live during a resize. That navigation test, the frontend, and the server match master. The same browser suite passed 38/38 in three consecutive local runs.

The required Go build and tests and the ingestor race check passed. GitHub requires repository-admin rights for the retry I requested.

The first-frame overlap also reproduced on current master and is tracked separately in #2499.

@n30nex
n30nex force-pushed the codex/foreign-history-20261127 branch from 4296502 to 0e02b50 Compare November 29, 2026 17:13
@n30nex

n30nex commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Kent Beck Gate: PASS (test quality) at eec8b8157. The tests reopen an existing SQLite database, run retention and send an ordinary advert. Only the previously flagged node regained its flag. New nodes, ordinary archive rows and a legacy NULL flag stayed clear. The map filter showed the returning node and clearing the filter restored both controls.

@n30nex

n30nex commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

The retry on the old revision stayed at attempt 1. I rebased the two archive commits onto master after #2500 landed. Both patches compare equal to their previously reviewed versions. An existing database now restores the historical flag when an archived node returns. The map and mobile navigation checks passed locally, and all three browser shards passed on eec8b8157. Completed workflow

@n30nex
n30nex marked this pull request as ready for review November 29, 2026 18:06

@zfouts zfouts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at eec8b815. Approving.

  • The flag was already sticky for active nodes (MarkNodeForeign only sets it, and nothing clears it). This carries the same rule across archive and return, which matches node_visibility.go's "the ingestor only ever sets it".
  • UpsertNode is the only insert path into nodes and MoveStaleNodes the only one into inactive_nodes, so no write path is missed.
  • Mixing ?1 with plain ? is valid in SQLite: the plain ? after it continue from 8.
  • The UPDATE before the REPLACE in MoveStaleNodes repairs rows an older ingestor reactivated with the flag at 0.
  • Tests cover flagged, unflagged, legacy NULL, active flagged and brand-new keys, reopen a database from the old ingestor and run retention before return. The ingestor foreign, stale, upsert and retention tests pass locally.

Nits:

  1. Every advert upsert now looks up inactive_nodes (cmd/ingestor/db.go:1046-1048). The EXISTS sits in VALUES, so it runs before conflict detection for every advert, not just returning nodes. It's a primary-key lookup, and the PR's 1.89 to 2.07 ms measurement for active adverts makes it acceptable on the ingest path.
  2. A foreign flag can't be cleared now. The inactive_nodes row isn't deleted when a node returns (that predates this PR), so after an operator widens the geofilter, a node flagged once stays foreign. That was already true for active nodes; a sentence in the PR body would make it explicit.

FYI for merge order: #2396 (Postgres) rewrites the same node upsert and archive insert, so whichever lands second needs a manual port, and the EXISTS … ?1 form needs a Postgres translation. I'll handle that on the #2396 side if this lands first.

@efiten
efiten merged commit d8b7bba into Kpa-clawbot:master Dec 1, 2026
17 checks passed
zfouts added a commit to zfouts/CoreScope that referenced this pull request Dec 2, 2026
… and the advert reception changes to Postgres

Brings in 10 master commits: Kpa-clawbot#2366 (catalogue key tier), Kpa-clawbot#2497 (regions
count only received adverts), Kpa-clawbot#2498 (archived foreign-advert flags), Kpa-clawbot#2492
(observer comparison), Kpa-clawbot#2511, Kpa-clawbot#2513, Kpa-clawbot#2514, Kpa-clawbot#2517, Kpa-clawbot#2518, Kpa-clawbot#2519.

Conflicts:
- cmd/ingestor/approved_channels.go: both sides added a mutex to
  channelKeySet. One mu now serialises refresh, master's setCatalog and the
  branch's Close, and guards the users.db/Postgres accounts readers as well
  as master's approvedNames and catalogue tier.
- cmd/ingestor/db.go, nodes upsert: master's foreign_advert carry-over on
  top of the branch's qualified columns and lastSeenClampSQL. Master looked
  up the archived flag with ?1, which dbx.Rebind turns into $11 on Postgres;
  it is now a plain ? bound to the public key again, and the EXISTS is
  wrapped in CASE so Postgres stores 0/1 in the BIGINT column.
- cmd/ingestor/db.go, MoveStaleNodes: master's UPDATE that restores an
  archived foreign flag runs before the branch's portable moveStaleNodesSQL
  (not master's INSERT OR REPLACE ... SELECT *), with IS DISTINCT FROM 1
  instead of the SQLite-only IS NOT 1.

Ported to Postgres:
- catalog_keys (Kpa-clawbot#2366): pgschema migration 0004_catalog_keys.sql (same
  columns, CHECKs, defaults and key; LatestVersion 4), the table in
  sqlite_endstate.sql, and the worker's upsert sets updated_at from
  excluded.updated_at instead of strftime('%s','now').
- corescope-migrate copies catalog_keys and verify never prints
  catalog_keys.key_hex (channel secrets), for any store.
- GetNodes region filter (Kpa-clawbot#2497) and the observer comparison (Kpa-clawbot#2492) used
  IS NOT 'tx'; both use IS DISTINCT FROM 'tx'. The comparison's
  ORDER BY label COLLATE NOCASE is lower(<label expression>) on Postgres,
  which folds ASCII only under COLLATE "C", as NOCASE does.
- docs/catalogue-keys.md: the revert SQL on PostgreSQL.

Tests on both backends:
- The catalogue key tests that use a store and the Kpa-clawbot#2498 foreign-advert
  tests run on SQLite and Postgres (onBothStores; insertTx uses RETURNING).
- New dual tests for the observer comparison and the GetNodes region filter.
- pgschema: an upgrade from version 3 with data; the control migration tests
  no longer assume 3 is the latest version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zfouts added a commit to zfouts/CoreScope that referenced this pull request Dec 2, 2026
The SQLite-only forms master brought in this round (Kpa-clawbot#2492, Kpa-clawbot#2497, Kpa-clawbot#2498,
Kpa-clawbot#2366) and in the last one (Kpa-clawbot#2486) were only caught by Postgres test runs.
The ingestor's portable-SQL guard now also rejects IS NOT with a number,
numbered placeholders (dbx.Rebind turns ?1 into $11) and strftime; the
server gets a guard for IS NOT with a literal and numbered placeholders.
Both scanners have self-tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Historical foreign-advert flag disappears when an archived node returns

3 participants