Skip to content

fix(backfill): the byo-stamp scan read config as an object; it is a Map - #948

Merged
lilyshen0722 merged 1 commit into
mainfrom
fix/backfill-map-read
Aug 14, 2026
Merged

fix(backfill): the byo-stamp scan read config as an object; it is a Map#948
lilyshen0722 merged 1 commit into
mainfrom
fix/backfill-map-read

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

The dry run caught this, which is the only reason it's a commit and not an incident.

What happened

config is { type: Map, of: Mixed } (AgentRegistry.ts:235), so on a live Mongoose document config.runtime is undefined. The scan omitted .lean(), so every row filtered out on a property that cannot exist. Against production:

installs scanned:      545
already stamped:       0     ← two seats were demonstrably stamped
push webhooks skipped: 0
candidates to stamp:   0     ← ~200 are candidates

With --apply it would have written nothing and printed success — the migration-reports-success-and-writes-nothing failure this file already warned about, arriving through a different door than the one guarded.

The actual lesson

This is the same Map-vs-object defect just fixed in the install intro (#947). I wrote this script before diagnosing that one and never came back to it. The fix got applied where the bug was found rather than everywhere the shape is read — which is how one root cause ships twice.

The fix

  • Scan uses .lean(), plus a runtimeOf reader that handles both shapes, so a caller passing a live document degrades to a correct read instead of a silently empty one.
  • Write switched to updateOne with a dotted $set. The rows are lean so there's no document to save; a dotted path writes one key without rewriting the whole config, so a concurrent install touching another key isn't clobbered; and it sidesteps Mixed-path dirty tracking entirely.
  • The counter reports what the DB says it modified, not what the loop intended — the exact gap that let the first version look successful.

Next

Re-run the dry run after this merges. Expect ~200 candidates, and the two already-stamped seats to show under already stamped rather than 0. Only then --apply.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8

The dry run caught this, which is the only reason it is a commit and not an
incident.

`config` is `{ type: Map, of: Mixed }` (AgentRegistry.ts:235), so on a live
Mongoose document `config.runtime` is undefined. The scan omitted `.lean()`,
so every row filtered out on a property that cannot exist. Against production:

  installs scanned:      545
  already stamped:       0     <- two seats were demonstrably stamped
  candidates to stamp:   0     <- ~200 are candidates

With `--apply` that would have written nothing and printed success — the
migration-reports-success-and-writes-nothing failure this file already warned
about, arriving through a different door than the one guarded.

This is the same Map-vs-object defect just fixed in the install intro (#947).
I wrote this script before diagnosing that one and never came back to it,
which is the actual lesson: the fix was applied where the bug was found rather
than everywhere the shape is read.

Scan now uses `.lean()`, plus a `runtimeOf` reader that handles both shapes so
a caller passing a live document degrades to a correct read instead of a
silently empty one.

Write switched to `updateOne` with a dotted `$set`: the rows are lean so there
is no document to save, a dotted path writes one key without rewriting the
whole config (a concurrent install touching another key is not clobbered), and
it sidesteps Mixed-path dirty tracking entirely. The counter now reports what
the DB says it modified rather than what the loop intended.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8
@lilyshen0722
lilyshen0722 merged commit aaf29f4 into main Aug 14, 2026
11 checks passed
@lilyshen0722
lilyshen0722 deleted the fix/backfill-map-read branch August 14, 2026 07:02
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