fix(backfill): the byo-stamp scan read config as an object; it is a Map - #948
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The dry run caught this, which is the only reason it's a commit and not an incident.
What happened
configis{ type: Map, of: Mixed }(AgentRegistry.ts:235), so on a live Mongoose documentconfig.runtimeisundefined. The scan omitted.lean(), so every row filtered out on a property that cannot exist. Against production:With
--applyit 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
.lean(), plus aruntimeOfreader that handles both shapes, so a caller passing a live document degrades to a correct read instead of a silently empty one.updateOnewith 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.Next
Re-run the dry run after this merges. Expect ~200 candidates, and the two already-stamped seats to show under
already stampedrather than0. Only then--apply.🤖 Generated with Claude Code
https://claude.ai/code/session_01XeUH4HVDsDHYPsHJthXjB8