Skip to content

Identifiers minted from crypto/rand make a replay diverge from its recording, and three replay checks are weakened for it #856

Closed

Description

@scttfrdmn

Substrate mints most of its identifiers from crypto/rand, so a recorded run and its replay produce different identifiers. This is the shared prerequisite of #833 and #817, and no issue covers it.

grep across non-test emulator/ code: 78 generate* functions, in 31 files that import crypto/rand. Nearly all draw from it directly.

What it blocks, concretely

#833 — authorization fidelity. A stream containing a mid-stream CreateAccessKey or AssumeRole mints a different AKIA…/session token on replay. The recorded Authorization header then names a key that is absent from replayed state, resolvePrincipal returns nil, and CheckAccess fails open the instant reqCtx.Principal == nil:

	if reqCtx.Principal == nil {
		return nil
	}

(emulator/authz.go:151-153)

So a replay of a recorded stream would authorize everything — the opposite of the fidelity #833 asks for — and it would do so silently.

#817 — body comparison. Any create whose response carries a generated identifier diverges, so a strict body differ reports a mismatch on essentially every mutating event. Criterion 3 of #817 assumes the opposite.

State-hash validation. As of the v0.115.0 reporting work, IncludeStateHashes is honoured and ValidateState actually runs. A stream containing any create now reports a state_hash_after mismatch, because the state key or record contents embed the freshly minted identifier. That is the correct answer — the divergence is real — but it means state validation is only useful once identifiers are reproducible.

The convention already exists in two places and was never generalised

  • CloudFormation derives its stack and change-set UUIDs from account + region + name (docs/services.md:1414-1418), specifically so a redeploy and a replay mint the same value.
  • error_protocol.go:10-14 states the principle outright: substrateRequestID = "SUBSTRATE" is a fixed constant because "an error body has to be byte-identical across two replays of one recorded run".
  • Config rules do the same (configservice_rules.go:412): "AWS mints an opaque config-rule-xxxxxx; substrate derives it by hash so replaying …".

So the design question is not whether to derive rather than randomise, but what to derive from, given that the same operation may legitimately be called twice in one run with identical inputs (two CreateAccessKey calls for one user must produce two distinct keys).

The design question this issue has to answer first

A pure hash of the request is wrong for exactly that reason. The candidate inputs, and what each costs:

Source Reproducible? Distinguishes repeat calls? Notes
account + region + name yes n/a (name is the discriminator) works for named resources; CFN's approach
hash(request) yes no two identical creates collide
hash(request + event sequence) yes yes needs the plugin to see the sequence number, which it does not today
a seeded PRNG per stream yes yes needs a seeded source threaded to every mint site; ReplayEngine.RandInt64 already exists (replay.go:642) but is reachable by nothing
a monotonic per-namespace counter in state yes yes reproducible because it is state, which replay resets; needs a state write per mint

Note that ReplayEngine already carries a seeded rng and exposes RandFloat64/RandInt64 (replay.go:629-647), and ReplayConfig.RandomSeed is plumbed — but no plugin can reach any of them, because a plugin holds no reference to the replay engine. That is the missing wiring, whichever source is chosen.

Whether the answer is one mechanism for all 78 sites or a per-shape choice (ARNs and names derived from inputs; opaque tokens from a seeded source) is the first decision, and it should be made before either replay issue is scheduled.

Acceptance criteria

  • A written decision on the identifier source, recorded where the existing conventions are (docs/services.md, alongside the CloudFormation UUID note) rather than only in code.
  • A single seam every mint site goes through, so the answer cannot be given two ways in two plugins — the same "one builder, so they cannot drift" structure SQS state keys disagree: the tagging API and the authorizer address queue:<name>, the plugin writes queue:<account>/<name> #826 established for ARNs.
  • Two identical create calls in one run still produce distinct identifiers. This is the criterion a naive hash(request) fails, and it must be a test.
  • Recording a stream and replaying it produces byte-identical identifiers, asserted through a real state_hash_after comparison (which the v0.115.0 work makes possible).
  • The 78 sites are enumerated in the issue or a checklist so the migration is auditable rather than "mostly done".
  • Scoped explicitly: which identifier kinds are in scope (ARNs, resource IDs, opaque tokens, request IDs, ETags, session tokens) and which are deliberately left random, with the reason.

Also worth deciding here: MemoryStateManager.List returns Go map iteration order with no sort (state.go:80-97), across 118 non-test state.List( call sites. That makes two identical ListBuckets requests differ within one run, independent of identifier minting. It is a smaller fix (sort in List, once) and arguably belongs in this issue since it has the same symptom and the same two dependents; it is recorded here so it is not researched a third time.

Filed as the prerequisite for #833 and #817 during the v0.115.0 replay-reporting research.

Activity

  1. added this to the v0.116.0 milestone on Sep 14, 2026
  2. added
    type: bug
    on Sep 14, 2026
  3. scttfrdmn commented on Sep 15, 2026

    @scttfrdmn
    OwnerAuthor

    Deferred out of v0.116.0 to v0.117.0. Three corrections to this issue's premises, verified against the tree at bd1dca7, plus what v0.116.0 discharged.

    The central claim does not hold: this issue's cheap form unblocks nothing

    The issue positions itself as the prerequisite of #833. It is not, in the scoping it proposes.

    Deriving an identifier from its inputs (option i, S/M) cannot serve #833, because #833 needs CreateAccessKey (iam_plugin.go:1475) and AssumeRole (sts_plugin.go:285, :506) reproducible, and neither has a unique-name input to derive from. Both are in the collision class, where identical inputs must legitimately yield distinct identifiers. Seven such sites are verified:

    • two access keys for one user
    • RunInstances with MaxCount > 1 (ec2_plugin.go:665-667)
    • two snapshots of one volume
    • two SendMessages with one body
    • two AssumeRoles with one session name
    • two multipart uploads on one key
    • two identical Athena queries

    The in-tree counter-argument is already written down. iamSLRTaskUUID's doc comment (iam_service_linked_roles.go:245-249): "deriving one would make two deletions of the same role collide on a single ID."

    So the real dependency chain is the full seam (option ii), which is L, not the M this issue implies.

    The inventory is wrong in four places

    • 75 generate* functions, not 78.
    • 66 are crypto/rand-backed, but "nearly all draw from it directly" is wrong twice: ~40 call rand.Read/rand.Int inline and 26 go through one choke point, randomHex (ec2_types.go:489, 40 call sites). That choke point is the good news in this issue — it is the difference between 66 edits and 40.
    • Nine are not crypto/rand at all: three already deterministic (ec2_plugin.go:3703, kinesis_plugin.go:880, secretsmanager_types.go:57), five wall-clock (eventstore.go:929, :934, parser.go:823, replay.go:633, s3_plugin.go:3008), one math/rand (organizations_plugin.go:302).
    • Minting not named generate* is missing from the issue entirely: randomHex, stsGenerateSecret/stsGenerateToken (sts_plugin.go:631, :640), iamSLRTaskUUID (iam_service_linked_roles.go:250), S3 version IDs (s3_plugin.go:927, :1200), SESv2 MessageId (sesv2_plugin.go:243), and Omics' clock-seeded PRNG (omics_plugin.go:38).

    Two shortcuts are closed, and one of #817's premises falls with them

    • Event.Sequence is not reachable at mint time. It is assigned inside RecordEvent (eventstore.go:289, pipeline step 8); minting happens at step 5. A sequence-derived identifier is not available where it would be needed.
    • TimeController.Now() advances by wall-clock elapsed (types.go:245-250), so a tc.Now() component is not deterministic. This independently falsifies Replay: deep-compare response bodies during verification #817's stated premise that "bodies carry simulated-clock times, which are reproducible." Recorded there too.

    A hard prerequisite that was not filed: #886

    resetState resets only the StateManager (replay.go:656-664) and PluginRegistry has no reset hook (types.go:334-365), so the two atomic counters (s3_plugin.go:927/:1200, sesv2_plugin.go:20) survive a reset and a second replay in one process diverges from the first. Filed as #886. It is a prerequisite of this issue's full seam, and v0.116.0's CLI wiring (#855) made it reachable from substrate replay rather than only from a hand-built engine.

    What v0.116.0 shipped toward this

    Two of this issue's real prerequisites, both required by #817 regardless of which minting option is eventually chosen, and neither dependent on that choice:

    The structural model when option (ii) is taken

    #510 is the closed precedent for this class ("FaultController: the PRNG is shared across rules, so Probability determinism depends on request ordering"), and NewFaultController(cfg, seed) (fault.go:157) with per-rule ruleRNGs (fault.go:188-199) is the shape to copy.

    Test blast radius, for the record

    ~45 shape assertions (HasPrefix on i-, vol-, AKIA, …) and ~5 length assertions. Zero tests assert a minted value, because they structurally cannot today. Preserving prefix and length — as cfnNameSuffix's fixed 12 (cfn_physical_name.go:115) and cfgsvcMintRuleID's fixed 6 already do — breaks essentially nothing. That is the reassuring half of an L-sized change.

  4. modified the milestones: v0.116.0, v0.117.0 on Sep 15, 2026
  5. scttfrdmn commented on Sep 16, 2026

    @scttfrdmn
    OwnerAuthor

    Moved to the v0.118.0 milestone, and the hardest structural piece of it is done.

    Discharged this release: #886. The blocker filed out of this issue's own analysis in v0.116.0 was
    that PluginRegistry had no reset hook, so a plugin holding mutable state on its own struct survived
    resetState — meaning even fully deterministic minting would diverge on a second replay in one process.
    v0.117.0 added the ResettablePlugin capability and wired it into both ReplayEngine.resetState and
    POST /v1/state/reset, clearing the state manager first and the plugins second. The three plugins that
    mint from struct-local state — S3Plugin.versionSeq, SESv2Plugin.msgSeq, OmicsPlugin.rng — are
    reset with it. That is one of the two reasons this issue was sized L; the lifecycle hook no longer
    has to ship as part of it.

    Unchanged, and still the reason it is deferred: the seam itself. 66 crypto/rand-backed minters,
    ~40 of them inline and 26 through one choke point (randomHex, 40 call sites), plus the minting
    that is not named generate* at all and so is absent from this issue's inventory — stsGenerateSecret
    / stsGenerateToken, iamSLRTaskUUID, S3 version IDs, the SESv2 MessageId, and Omics' clock-seeded
    PRNG. Two shortcuts remain closed off: Event.Sequence is assigned inside RecordEvent, after the
    point a handler mints, so it is not reachable at mint time; and TimeController.Now() advances by
    wall-clock elapsed, so a tc.Now() component is not deterministic either.

    Also still standing, and the thing this issue must decide first: the collision class. Seven verified
    sites must yield distinct identifiers from identical inputs — two access keys for one user,
    RunInstances with MaxCount>1, two snapshots of one volume, two SendMessages with one body, two
    AssumeRoles with one session name, two multipart uploads on one key, two identical Athena queries.
    iamSLRTaskUUID's own doc comment is the in-tree argument: "deriving one would make two deletions of
    the same role collide on a single ID."
    So deriving from inputs (the cheap option) unblocks neither
    #833 nor #817, both of which need CreateAccessKey and AssumeRole reproducible. NewFaultController(cfg, seed) with its per-rule RNGs remains the structural model for the full seam.

  6. modified the milestones: v0.117.0, v0.118.0 on Sep 16, 2026
  7. scttfrdmn commented on Sep 17, 2026

    @scttfrdmn
    OwnerAuthor

    Moved to the v0.119.0 milestone. Nothing in v0.118.0 touched the seam, but the release produced one
    data point worth carrying, because it is evidence about the payoff rather than the cost.

    #819's AWS Config arm turns on a derived minter, and it is the first place the benefit shows up
    somewhere other than replay.
    cfgsvcMintRecorderID derives a configuration recorder's ID by
    SHA-256 over (account, Region, name), truncated to a fixed 8 characters — the same shape
    cfnNameSuffix and cfgsvcMintRuleID already use. Because of that, a recorder's ARN is identical
    across a redeploy, and so is a rule's, which is minted from the rule name the same way.

    That is what made #819's clobber/removal assertion writable for Config and unwritable for ten of the
    twelve types before it. The reconciliation's two safeguards can only be observed on a second
    deployment — a caller's own tag is preserved by comparing it against what the stack previously
    propagated, and a withdrawn stack tag is removed only when the stored value still matches — and an
    UpdateStack re-creates every resource in the template. A type whose create mints a fresh identity is
    therefore never revisited at the record a caller could have tagged, so the assertion has nothing to
    assert against. A KMS key is the clean example: its update mints a new key, which is why that
    spelling's defect had to be covered through an exported accessor instead.

    So the argument for this issue is not only "a recorded run replays identically". It is also that a
    derived identifier is what makes an update path testable at all, and there are behaviours — both of
    this one's safeguards among them — that are unobservable without one.

    It does not shrink the issue, and it does not touch the collision class. A configuration recorder
    is one per account and Region and a Config rule's name is unique within one, so both have a
    unique-by-construction input to derive from. That is exactly what the seven collision sites do not
    have — two access keys for one user, RunInstances with MaxCount>1, two snapshots of one volume, two
    SendMessages with one body, two AssumeRoles with one session name, two multipart uploads on one
    key, two identical Athena queries — so this is a demonstration of the easy half, not a precedent for
    the hard one. Everything in the previous comment stands: 66 crypto/rand minters with 26 behind
    randomHex, the minting not named generate* and therefore absent from this issue's inventory,
    Event.Sequence unreachable at mint time, and TimeController.Now() advancing by wall-clock elapsed.

  8. removed this from the v0.118.0 milestone on Sep 17, 2026
  9. 16 remaining items

  10. added a commit that references this issue on Sep 26, 2026
  11. scttfrdmn commented on Sep 26, 2026

    @scttfrdmn
    OwnerAuthor

    Tier 4 shipped — identity, keys and certificates (PR #1287, f56717d)

    Eight generators across seven services move onto IDMint: Cognito (both the user-pool and the
    identity-pool API), IAM Identity Center, KMS, ACM, Secrets Manager, WAFv2, and API Gateway's API
    keys. rand.Read draw sites: 23 → 15.

    Every rendering is byte-for-byte what the crypto/rand version produced. Where the choice was
    between IDMint.UUID and IDMint.HexUUID, the API model was consulted each time and settled nothing
    in three cases — API_ApiKey publishes no length and no pattern on either id or value,
    API_KeyMetadata.KeyId publishes 1–2048 and no pattern, CertificateArn's pattern admits either
    form — so per #671 the existing rendering stays. WAFv2 is the one place the model speaks, and it is
    indifferent to the RFC 4122 nibbles, so UUID() preserves what was recorded.

    What this tier taught

    Not every value that must be derived is an identifier. Three of the eight are values a caller
    hands back, which is what puts them in scope:

    • A WAFv2 LockToken must be returned to UpdateWebACL, so a re-minted one answered a recorded
      update with WAFOptimisticLockException instead of the recorded success.
    • A Secrets Manager version ID is the quietest break found so far: GetSecretValue reports an unknown
      VersionId by omitting SecretString rather than by refusing, so a replay answered a recorded
      read with a 200 that had silently lost a member — not a refusal any assertion would notice
      without Differences.
    • A KMS GenerateDataKey stub data key is observed twice in one response, as Plaintext and wrapped
      into CiphertextBlob. A recorded Decrypt was never affected: substrate's ciphertext carries its
      own plaintext, so the break was in the create, not the read.

    One service was minting another's identifiers. CreateApiKey reached into generateACMCertID for
    both UUID-shaped strings it returns, so a change to ACM's rendering would have silently moved API
    Gateway's. Worth grepping for on the remaining tiers.

    The tier's replay assertion was shown non-vacuous by reverting generateVersionID to randomHex: 21
    differences, comprising VersionId majors on three operations, the lost SecretString, and a
    state-hash cascade through the rest of the stream.

    Gaps filed rather than folded in

    Keeping each tier shape-preserving is what lets its tests rest on "the rendering is unchanged", so:

    The 15 that remain

    Analytics — athena_plugin.go:694, glue_plugin.go:864 (via randomHex),
    timestream_plugin.go:355 (via randomHex), opensearch_plugin.go:1002,
    redshiftdata_plugin.go:252, quicksight_plugin.go:297.

    CI/CD — codebuild_plugin.go:364, codedeploy_plugin.go:426 and :437,
    codedeploy_types.go:70, codepipeline_plugin.go:407.

    Long tail — ssm_plugin.go:1040, ram_plugin.go:457, backup_plugin.go:461,
    bedrock_runtime_plugin.go:317.

    Then three that are not ordinary tiers:

    1. cfn_deployer.go:4265 — needs the deployer to thread a request ID through, which is also the work
      that lets IDMint's own crypto/rand fallback (ids.go:115) be removed.
    2. Deleting randomHex (ec2_types.go:500, with its rand.Read at :502) once its four callers are
      gone.
    3. ec2_plugin.go:879 (an AIPA… instance-profile ID minted inside a describe) and EC2 key-pair
      material, which needs a deterministic reader into the key generator rather than a derived
      string — both their own issues rather than part of a tier.
  12. added 2 commits that reference this issue on Sep 26, 2026
  13. scttfrdmn commented on Sep 26, 2026

    @scttfrdmn
    OwnerAuthor

    Tier 5 shipped — the analytics family (PR #1288)

    Seven generators across six services now derive from IDMint: an Athena query execution ID, a
    Redshift Data statement ID, a Glue job-run ID, a Timestream QueryId, an OpenSearch document _id
    and _scroll_id (one generator, two kinds of value), and a QuickSight ingestion ID and response
    RequestId. Every rendering is byte-for-byte the one crypto/rand produced.

    What this tier taught

    An analytics identifier names a submission, not a resource. That is the difference from the four
    tiers before it: there is no caller-chosen name to fall back on, so the minted handle is the only
    way to reach what was submitted. Athena is the extreme — GetQueryExecution, GetQueryResults and
    StopQueryExecution all key on the one ID StartQueryExecution returned — and the refusals are
    per-service: InvalidRequestException (Athena), ResourceNotFoundException (Redshift Data),
    EntityNotFoundException (Glue), a not_found 404 for an OpenSearch document, and
    search_context_missing_exception for a scroll cursor.

    Timestream is in the stream for the opposite property. Its QueryId reaches no later call —
    CancelQuery ignores the ID it is given and answers an empty body — so a fresh draw there costs a
    body difference rather than a refusal. It is still a difference, and it is what makes a recorded
    Query replay with zero differences at all.

    The published alphabet decided two renderings, not a preference. API_query_Query constrains
    QueryId to [a-zA-Z0-9]+, which excludes the hyphen, so Timestream is 32 unbroken hex
    characters; API_ExecuteStatement documents Redshift Data's Id as a UUID and publishes the dashed
    pattern, so that one keeps its hyphens. Neither constrains a position, so both are indifferent to the
    RFC 4122 version and variant bits — which is why HexUUID satisfies the published pattern and
    deriving these preserved the exact rendering rather than quietly setting two nibbles (#671). Athena's
    QueryExecutionId publishes \S+, which decides nothing; Glue's JobRunId admits nearly any text,
    so the jr_ prefix stays as the service's own convention.

    One service in the family publishes no AWS pattern at all. OpenSearch's document and scroll APIs
    are the domain's own REST interface, not the es/opensearch control plane, so substrate's sixteen
    URL-safe base64 characters are a convention it keeps rather than a constraint it meets (real
    OpenSearch generates a wider 20-character Flake ID; substrate's was always narrower and #856 is not
    where that changes). This is where IDMint.Base64URL comes from: a document ID travels in a URL
    path, so - and _ are the alphabet and + and / are not.

    The cross-service borrow the tier-4 comment said to grep for turned up again. CreateDataSet
    drew its SPICE ingestion ID from the generator that mints the RequestId every QuickSight response
    carries. An ingestion ID is a handle a recorded DescribeIngestion URL contains, where a request ID
    is observed once and never sent back — so one function serving both meant a change to how a request
    ID renders would have silently moved the identifier a recorded path depends on. Split, same as
    ACM/API Gateway. That is two instances in two tiers; it is worth grepping for on every remaining
    tier.

    Non-vacuity

    Reverting the Athena minter alone produces 38 differences and two refused reads out of the
    19-request stream
    — the same check tier 4 ran with generateVersionID.

    Census after tier 5

    11 non-test rand.Read( sites and 2 randomHex callers remain (the counters in ids.go:64
    and ec2_types.go:498 are updated to match):

    Tier Sites
    6 — CI/CD codebuild_plugin.go:364 (build ID, HexUUID), codedeploy_plugin.go:426 and :437 (application and deployment-group IDs, HexUUID), codedeploy_types.go:70 (d- + 9 uppercase alphanumerics, Chars), codepipeline_plugin.go:407 (execution ID — the one site that already sets the RFC 4122 bits, so it wants IDMint.UUID rather than HexUUID)
    7 — long tail ssm_plugin.go:1040, ram_plugin.go:457, backup_plugin.go:461, bedrock_runtime_plugin.go:317
    8 — the deployer cfn_deployer.go:4265 (randomHex(16)), which needs the deployer to thread a request id — the work that removes IDMint's own crypto/rand fallback at ids.go:115
    then delete randomHex (ec2_types.go:500) once its last caller moves

    Two sites stay out of the tiering and want their own issues: ec2_plugin.go:879, an AIPA… instance
    profile ID minted inside a describe rather than at create time, and EC2 key-pair material, which
    needs a deterministic reader into the key generator rather than a derived string.

  14. added a commit that references this issue on Sep 26, 2026
  15. scttfrdmn commented on Sep 26, 2026

    @scttfrdmn
    OwnerAuthor

    Tier 6 (CI/CD) is merged — PR #1289, squash commit 2c90f4e. 6 draw sites remain on crypto/rand.

    Site Rendering Provenance
    codepipeline_plugin.go execution ID IDMint.UUID The family's only published pattern, and the only site that already set the RFC 4122 bits
    codebuild_plugin.go build ID IDMint.HexUUID Build.id: String, min length 1, no pattern
    codedeploy_plugin.go application + deployment-group IDs IDMint.HexUUID Neither publishes a pattern or length constraints
    codedeploy_types.go deployment ID IDMint.Chars(9, A-Z0-9) Observed: the page's own sample response is d-IIMHK0NHC

    What this tier taught

    A tier can have no unbounded-draw site. Every one of the five operations mints exactly once, so
    the ordinal-on-a-batch assertion tiers 1–5 each made had nothing to bite on. What replaced it is a
    rendering assertion — the version nibble and variant bits on a pipeline execution ID, ^d-[A-Z0-9]{9}$
    on a deployment ID — because that is the property this family could actually get wrong. Worth keeping
    in mind for the remaining tiers: pick the test from where the tier's risk is, not from the template.

    "Published pattern" and "constrains the rendering" are different questions. CodePipeline publishes
    [0-9a-f]{8}-[0-9a-f]{4}-…, which looks like it pins a UUID and pins nothing about the version
    position. The pattern is satisfied by HexUUID too. The reason that site keeps UUID is not the model
    at all — it is that the crypto/rand code set those two nibbles, so dropping them would change bytes a
    consumer may be validating. #671 decides whether to invent a constraint; the no-byte-changes rule
    decides which rendering where the model is silent, and here they point at different methods for
    sites in the same family.

    Reading AWS's own sample response is not the borrow #671 forbids. CreateDeployment publishes no
    pattern for deploymentId, but the page shows d-IIMHK0NHC. That is observed provenance from the
    authoritative source, not a bound lifted from a sibling operation, and it is all the reference offers.
    docs/services.md had been calling that shape published — corrected in this PR.

    An underived ID does not always produce a refusal. BatchGetBuilds reports an unknown build ID
    under buildsNotFound in a 200 with an empty builds list, so a re-minted build ID answered a
    consumer's wait-for-buildStatus loop with nothing to wait on rather than failing it. That is the
    stalls-rather-than-fails shape, and it is the third distinct failure mode this migration has found
    after outright refusal and the silently-missing-member one (Secrets Manager's SecretString).

    Non-vacuity, checked numerically as in the tiers above: reverting generateCodeDeployDeploymentID
    alone to a seedless mint produces 10 differences and one refused read out of the 12-request stream,
    with DeploymentDoesNotExistException on the recorded GetDeployment and cascading state_hash_before/
    state_hash_after divergence through CodePipeline.

    Remaining

    Tier Sites
    7 — the long tail ssm_plugin.go:1040 (command ID), ram_plugin.go:457 (resource-share ID), backup_plugin.go:461 (plan, version and selection IDs — four call sites, two of them in one CreateBackupPlan request, which gives this tier its ordinal test back), bedrock_runtime_plugin.go:317 (model-invocation job ID). All four render the HexUUID shape today
    8 — the deployer cfn_deployer.go:4265 via randomHex, which needs the deployer to thread a request ID through its internal contexts. This is the work that lets IDMint's crypto/rand fallback at ids.go:115 be removed, after which randomHex (ec2_types.go:500) can be deleted

    Two sites still want issues of their own rather than a tier: ec2_plugin.go:879 (an AIPA… instance-profile
    ID minted inside a describe, which is a bug independent of derivation) and EC2 key-pair material,
    which needs a deterministic reader into the key generator rather than a derived string.

  16. added a commit that references this issue on Sep 26, 2026
  17. scttfrdmn commented on Sep 26, 2026

    @scttfrdmn
    OwnerAuthor

    Tier 7 — the long tail — merged

    PR #1290. Four generators across four unrelated services: an SSM Run Command CommandId, the
    identifier inside a RAM resourceShareArn, AWS Backup's BackupPlanId/VersionId/SelectionId
    (four call sites), and a Bedrock batch-inference job ID.

    Three keep the rendering their draw site produced, because their pages publish no pattern (#671).
    Bedrock's does not, and it is the one shape change in the whole migration: jobArn is published
    as arn:aws:bedrock:{region}:{account}:model-invocation-job/[a-z0-9]{12} and jobIdentifier as that
    ARN or a bare [a-z0-9]{12} — the alphabet excludes the hyphen and the length is twelve, so the
    36-character UUID substrate minted satisfied neither. The no-byte-changes rule protects a rendering
    the model permits; it cannot protect one the model forbids.

    Backup gave the tier back the ordinal assertion tier 6 had to do without: CreateBackupPlan is the
    only draw site in the tree that mints twice in one request. Non-vacuity: reverting that minter alone
    produces 14 differences and 3 refused reads out of a 10-request stream, because a selection is
    stored under its plan ID and a re-minted plan strands the selection too.

    What is left, and it is not what the counter says

    The TODO(#856) counter now reads 2 draw sites: randomHex (one caller) and IDMint's own
    seedless fallback. Both numbers are true about literal rand.Read call sites and both understate the
    remaining surface, because the fallback is reached through every internal dispatch that builds a
    RequestContext without an IDs mint
    :

    Site What mints from crypto/rand because of it
    cfn_deployer.go:4592 (dispatch) every identifier of every resource in every CloudFormation stack
    apigateway_plugin.go:1631 the Lambda invocation an API Gateway proxy integration makes
    lambda_plugin.go:1620 / :1692 an ESM's SQS ReceiveMessage (which mints receipt handles) and the invoke it drives
    cfn_deployer.go:4265 (deploySSMAssociation) an AWS::SSM::Association physical ID, the one remaining randomHex caller

    The replay side is already right: replay.go:482 seeds every replayed event from its recorded
    request ID, and the deployer records each internal dispatch as its own event. So the divergence in a
    CloudFormation stream is entirely on the recording side — the recording drew randomly, the replay
    derives, and the two disagree.

    Which makes tier 8 a different shape from tiers 1–7. It is not "move four more generators"; it is:

    1. Give each of those four contexts a mint. Three of them can take NewIDMint(reqCtx.RequestID)
      directly, since the request ID is recorded and the replay reuses it.
    2. The deployer needs more than that. A recorded CreateStack is also an event, so a replay
      re-runs the whole deployment as well as replaying each internal event — and a re-run calls
      generateRequestID() for each internal dispatch, which is wall-clock. So the deployer's internal
      request IDs have to be derived from the outer request's mint rather than generated, which is
      what makes a re-deployment reproduce itself.
    3. Then randomHex and the seedless fallback can both go, and NewIDMint("") stops being a
      supported state.

    That third step is the one this issue has been aiming at, and step 2 is the reason it could not
    happen earlier. I will file the analysis as the tier-8 plan before writing any of it.

  18. scttfrdmn commented on Sep 26, 2026

    @scttfrdmn
    OwnerAuthor

    Tier 8 plan — the internal dispatch paths, and a correction to the comment above

    Two things I got wrong in the comment above, found by reading the code rather than the counter.

    The seedless fallback cannot be deleted, and should not be. IDMint's nil-receiver and
    empty-seed paths are a public affordance, not a migration artefact: a consumer writing a plugin test
    constructs &emulator.RequestContext{AccountID: …, Region: …} by hand — substrate's own
    ram_plugin_test.go, backup_plugin_test.go and dozens of others do exactly that — and every one of
    those contexts has a nil IDs. Removing the fallback would turn each into a panic. generateRequestID
    also draws through NewIDMint(""), and the request ID is the seed, so it must stay random by design.
    So tier 8 ends with the fallback documented as intentional and reached by nothing that a replay
    observes, rather than deleted.

    randomHex has one blocker that is not the deployer. Its second caller mints an AIPA… instance
    profile ID inside the item builder shared by RunInstances and DescribeInstances, so two describes
    of one instance report two different IDs. That is a fidelity bug rather than a derivation one and it
    is now #1291; randomHex goes when both it and the deployer are done.

    What tier 8 actually changes

    The deployment walk is already deterministic — DeployWithOptions sorts its entries by
    (typePriority, logicalID) before dispatching — so a single mint per deployment reproduces the same
    sequence of internal request IDs on a re-run of the same template. That is what makes this tractable
    without threading a logical ID through every dispatch site.

    1. StackDeployer gains a mint and WithDeployerMint, and deployerFor passes reqCtx.IDs, so a
      stack's deployment derives from the request that asked for it. client.go's in-process deployer
      seeds one from a fresh request ID: its outer call is not a recorded AWS request, so a random seed
      there is harmless — the internal events it records carry the derived IDs a replay reuses.
    2. dispatch derives each internal request ID from that mint instead of calling
      generateRequestID(), and sets IDs: NewIDMint(thatID) on the context it dispatches. Both halves
      are needed and they fix different failures: setting IDs makes a replayed internal event
      reproduce its recording, and deriving the request ID makes a replayed outer CreateStack —
      which re-runs the whole deployment — reproduce it too.
    3. deploySSMAssociation mints from the deployer's mint, which removes randomHex's deployer caller.
    4. The other three internal-dispatch contexts get IDs: NewIDMint(reqCtx.RequestID):
      apigateway_plugin.go:1631 (a proxy integration's Lambda invoke) and lambda_plugin.go:1620/:1692
      (an ESM's SQS ReceiveMessage, which mints receipt handles, and the invoke it drives).

    Verification

    The regression test is the one this issue has never been able to write: record a stack with a handful
    of resources, replay the stream with ValidateState, and assert zero differences — including on the
    outer CreateStack event, whose state_hash_after covers every resource identifier in the stack.
    Non-vacuity the usual way, by reverting one of the two halves of step 2 and counting what breaks.

  19. added a commit that references this issue on Sep 26, 2026
  20. scttfrdmn commented on Sep 26, 2026

    @scttfrdmn
    OwnerAuthor

    Tier 8 — the internal dispatch paths

    Merged as #1293. This is the tier the draw-site counter could not have found, and it is
    the largest single correction in the issue.

    What was wrong. Every earlier tier migrated a generator. Counting generators answers the
    wrong question: a plugin whose minters are all migrated still publishes random identifiers if it
    is called with nothing to derive from. Substrate has four internal dispatch sites — a
    RequestContext built in-process rather than parsed off the wire — and the CloudFormation
    deployer is one of them. Deploying a stack turns each resource into an internal EC2, IAM or S3
    request, built with a fresh generateRequestID() and no mint, so every plugin it reached took
    IDMint's seedless fallback.

    The consequence: every identifier of every resource in every CloudFormation stack was
    undirected randomness, while the counter read "2 draw sites remaining" — because StackDeployer
    contains no rand.Read call of its own. A replayed DescribeStackResources reported four
    different PhysicalResourceId values in a 200, and CreateStack's state_hash_after never
    matched, because that hash covers all of them.

    What fixed it — two changes, two different failures.

    1. dispatch sets IDs: NewIDMint(requestID). This makes a replayed internal event reproduce.
    2. WithDeployerMint derives the internal request id from the mint of the request that asked for
      the deployment. This makes a replayed outer CreateStack reproduce — replaying it re-runs the
      whole deployment, so the internal ids have to come out the same way twice. Reproducible because
      DeployWithOptions already sorts by type priority then logical id, never by map iteration.

    Both halves measured by reverting each alone against the new replay test: 7 differences
    without the mint, 6 without the derived request id. In both cases the replay reported every
    event as a success — the silent-wrong-answer class, not a visible failure.

    Three things fell out of the same seam. DetectStackDrift was answering a
    StackDriftDetectionId that was substrate's internal req-… string verbatim, a shape no AWS
    reference describes, in an element a consumer hands back to DescribeStackDriftDetectionStatus;
    it is now UUID-shaped within the published maximum length of 36 (observed from the page's own
    sample, 2f2b2d60-df86-11e7-bea1-500c2example). deploySSMAssociation was the deployer's last
    randomHex caller. And an API Gateway proxy integration now carries a derived mint into the
    Lambda invocation it dispatches.

    Deliberately out. The other two internal dispatch sites are both in the Lambda ESM poller.
    Its dispatches come from a wall-clock ticker and are recorded nowhere, so there is no recorded id
    to derive from and a seed there would be no more reproducible than the fallback — #1292, with an
    in-code note at the site.

    The regression test this issue could not previously write now exists: record a four-resource
    stack over three services, replay with ValidateState, assert zero Differences,
    TotalEvents == SuccessEvents and StateValid true — including on the outer CreateStack.

    Where the issue stands

  21. scttfrdmn commented on Sep 30, 2026

    @scttfrdmn
    OwnerAuthor

    The draw-site migration is complete

    randomHex is deleted. Its last caller was the AIPA… instance-profile id EC2 minted inside a
    describe, which #1291 resolved out of IAM state instead — so no plugin draws an identifier from
    crypto/rand, and IDMint.bytes's own seedless fallback is the only read of it left in the tree.

    A correction to #1291's own text while I am here: it was filed expecting randomHex to keep one
    caller, the CloudFormation deployer. The deployer never called it. Tier 8 gave the deployer's
    internal dispatch a derived mint rather than moving a draw, so the deployer's randomHex use had
    already gone by the time #1291 was reached, and the count of "2 remaining draw sites" in the tier-7
    changelog entry was one site plus the fallback, not two sites. The entry is corrected in the same
    ## [Unreleased] section rather than left to be read as history.

    Why that fallback stays. A nil or seedless mint is what a hand-built RequestContext carries,
    and that is how every plugin unit test constructs one — substrate's and a consumer's. Removing the
    fallback would make those panic or mint a constant, and a constant collides two resources onto one
    id. generateRequestID also draws through it, because the request id is the seed and #866 settled
    that it stays wall-clock and recorded rather than derived.

    What is still not derived, and why each one is not a gap

    Closing

    Every acceptance criterion is met, and each is ticked above with where it landed:

    • The decision is written in docs/services.md, in its own section beside the CloudFormation UUID
      note it generalises, and in the ids.go preamble.
    • The single seam is IDMint on RequestContext.IDs; a helper minting without a request context in
      scope takes the mint as a parameter rather than reaching for a package-level source, which is what
      keeps the answer from being given two ways.
    • Two identical creates producing distinct identifiers is the ordinal, and it is a test — one
      RunInstances with MaxCount=3 publishes three distinct instance ids.
    • Record-and-replay byte-identity is asserted through state_hash_after and StateValid, twice
      over and in a second process.
    • The site census was enumerated tier by tier in the comments above, and the last count is zero.
    • The in-scope and deliberately-random kinds are scoped in the section above and in the docs.
    • The MemoryStateManager.List ordering question the issue folded in was already answered — List
      sorts, and state.go now carries a note saying Identifiers minted from crypto/rand make a replay diverge from its recording, and three replay checks are weakened for it #856 asked for it explicitly.

    EC2 key-pair material is not one of the deliberately-random kinds; it is a fidelity gap with a
    different mechanism — a deterministic io.Reader into the key generator, not a call to Hex — so it
    is split out as #1296 rather than held here. #1292 stays open by design.

  22. added a commit that references this issue on Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: replaypriority: mediumtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions