Deployment State Algorithms
Thirty original Python problems on model lifecycle, pinned version snapshots, fenced warmups, routing and resource plans, compatible cutovers and finite safety evidence. Preserve missing or ambiguous support while producing explicit state histories and optimal witnesses.
These problems are original practice. They are not questions from a named employer or a live hiring loop.
1.Replay model lifecycle transitions without applying failures
Write
registry_states(events),[model,verb]. Allowed transitions: create absent->draft; validate draft->tested; approve tested->approved; retire approved->retired; reset tested->draft. Any other transition is rejected without changing state. Return [sorted[model,state],rejected_event_indices]. Process input order; retired models remain present. No mutation.2.Switch a batch of aliases against one original snapshot
Write
switch_aliases(current,changes,versions). Current maps aliases to model versions. Changes[alias,expected,target];Noneexpected means absent,Nonetarget deletes an existing alias. Reject whole batch withNoneif an alias repeats, expectation differs from ORIGINAL current, deletion is absent, or nonnull target is outside versions. Else return updated copy. No partial result or mutation.3.Retain independent generation revision and readiness gaps
Write
sync_gaps(desired,observed). Desired{endpoint:[generation,model]}; observed[endpoint,generation,model,ready_bool]. For each sorted desired endpoint: zero rows =>[missing], >1 =>[ambiguous]even if equal. For one row collect generation,model,not-ready mismatches in that order. Return[endpoint,reasons]only for endpoints with reasons. Ignore unrequested endpoints. No mutation.4.Find a shortest capacity-preserving warm model switch
Write
warm_switch(sizes,capacity,initial,target), <=4 models, nonnegative bytes. Initially only initial loaded/warm/active. Load fits capacity; warm needs loaded; activate needs warm; unload forbids active and clears warmth. Goal only target loaded/warm/active. Actions verb:model. Return fewest actions then lexical sequence, orNoneif unknown/initial over capacity/impossible. No mutation.5.Route unexpired session pins without version fallback
Write
pinned_routes(routes,ready,pins,queries,now). Disjoint[lo,hi,model]routes use integer [lo,hi) buckets; gaps allowed. Pins{session:[model,expiry]}; queries[session,bucket]. Pin expiry>now overrides route. Return[model,status]per query: pinned/routed if ready, unready if selected but not ready,[None,missing]without route. Unready pins never fall back. No mutation.6.Minimize locked quota-constrained bucket reassignment
Write
bucket_migration(old,quota,locked), <=8 buckets, <=3 target models. Nonnegative quotas must sum tolen(old), elseNone. Assign exact quotas; locked indices retain old values. Return[fewest_changes,lexical_assignment]orNoneif infeasible. Old values may be outside quota, making locks impossible. Empty input allows [0,[]]. Compare the full assignment vector. No mutation.7.Bind ordered postprocessing signatures without guessing
Write
pipeline_bindings(initial,stages), initial labels orNone; stages[name,input_labels_or_None,output_labels_or_None]. Reasons in order: upstream if currentNone; input if inputNone; mismatch if both known sequences differ; output if outputNone. Any failure makes current=None; else current=declared output. Return[final_or_None,errors], errors[stage_index,reasons]. No mutation.8.Keep request model bindings across alias changes
Write
inflight_bindings(initial,events). Initial alias model; events[alias,model],[start,request],[finish,request,observed_model]. Start captures alias; duplicate active start rejected. Unknown finish rejected. Known finish closes request, accepted iff model matches captured value. Return [accepted_finish_ids,rejected_indices,sorted[active_request,model]]. Finished IDs reusable. No mutation.9.Fence asynchronous readiness by generation and model
Write
warmup_fences(events),[desire/ready,instance,nonnegative_generation,model]. New/higher desire sets generation/model and ready=False. Same-generation identical desire is a no-op; stale or conflicting desire rejected. Ready must match current generation AND model, then ready=True; otherwise rejected. Return [sorted[instance,generation,model,ready],rejected_indices]. No mutation.10.Require unique completion support for the drain barrier
Write
drain_ready(requests,receipts,cut,now),[unique_id,accepted]requests,[id,completed]receipts. Unknown ID/completed<accepted is invalid: index and ignore. Future receipts ignored. For accepted<cut requests, zero valid receipts<=now waits; >1 is ambiguous even if equal. Return [no_wait_or_ambiguity,sorted_wait_ids,sorted_ambiguous_ids,invalid_indices]. No mutation.11.Assign indivisible fallback cohorts within shared capacity
Write
fallback_assignment(cohorts,capacity,failed), <=6 cohorts{name:[positive_units,ordered_unique_models]}; capacity{model:nonnegative_units}. Assign one available nonfailed model per whole cohort. Cost=sum(units*ORIGINAL fallback rank). Return [minimum_cost,sorted[cohort,model]], ties by model vector in sorted cohort order;Noneif impossible. Empty cohorts allow [0,[]]. No mutation.12.Count safe cutover orders and retain an unsafe prefix
Write
cutover_orders(initial,allowed,steps,requires). Initial[model,feature]; allowed pairs. <=7 steps{id:[component_0_or_1,new_value]}, requires{id:parents}. Unknown step/cycle =>None. Count full dependency orders whose EVERY state is allowed. Return[safe_count,unsafe_prefix_or_None], shortest unsafe prefix then lexical; invalid initial gives []. Empty order counts once. No mutation.13.Infer release candidates from all request component reads
Write
snapshot_candidates(releases,components,reads). Releases {release:{component:revision}}; reads[request,component,revision]. Return sorted[request,sorted_candidates,sorted_missing_required]. EVERY read must match a declared release entry, even unrequired components. Missing: required names never read. Conflicting reads match none; partial reads may match many. No guessing or mutation.14.Find joint windows of latest unexpired promotion evidence
Write
promotion_windows(observations,required,revision,start,end), start<=end. Rows[gate,revision,time,expiry,ok], integer time<=expiry. Per gate choose latest matching time<=t; tied latest rows unsupported. Require unique, ok, t<expiry; expired rows never fall back. Return maximal half-open intervals in [start,end) with ALL required gates supported. No gates supports horizon. No mutation.15.Batch consecutive versions with explicit oversize barriers
Write
version_batches(queue,max_count,max_tokens), positive limits; rows[id,model,positive_tokens]. Batch consecutive same-model requests within count/total-token limits. Oversized request rejects its ID and flushes current batch, retaining a barrier even between same-model neighbors. Otherwise start a new batch only when needed by model/bounds. Return[batches_of_ids,rejected_ids]. No mutation.16.Choose a deadline-feasible batch under padded work limits
Write
deadline_batch(requests,now,overhead,capacity), <=10[unique_id,model,deadline,positive_tokens], nonnegative integer limits. One-model batch finish=now+overhead+max_tokens; every deadline>=finish. Padded work=count*max_tokens<=capacity. Choose largest count, least padding waste, earliest finish, model, sorted IDs. Return[model,IDs,finish,padded_work]orNoneif none feasible. No mutation.17.Plan weighted cache misses while preserving pinned models
Write
cache_plan(sizes,costs,capacity,initial,pinned,requests), <=4 models/8 requests, positive sizes/nonnegative costs. Initial fits; pins initially resident. Hits do nothing. Miss evicts any nonpinned residents, loads only request. Minimize (load_cost,eviction_count,lex_events). Events i:evict:model sorted per miss then i:load:model. Return[cost,events],Noneif invalid/impossible. No mutation.18.Account for shared bases adapters and session state
Write
resident_bytes(versions,bases,active). Versions{version:[base,adapter_bytes]}, bases{base:bytes}; active[version,sessions,bytes_per_session], nonnegative integers. One adapter per active version, one copy per used base, even with zero sessions. Session bytes count every row. Return[base_bytes,adapter_bytes,session_bytes,total], orNonefor unknown referenced version/base. No mutation.19.Choose precision profiles under declared additive limits
Write
precision_profile(layers,memory_budget,error_budget), <=6 layers{name:<=3 [positive_bits,bytes,error]}, unique bits/nonnegative integer bytes/error. Pick one per layer; sums fit budgets. Maximize minimum bits, then sum bits, then minimize bytes, then lexical bits in sorted layer order. Return[bits,bytes,error]orNone. Empty layers [[],0,0]. Supplied additive error model only. No mutation.20.Audit every attempted shadow write even when denied
Write
shadow_writes(events), rows[branch,operation,resource,outcome]. Branch live/shadow; operation read/write/delete; outcome pending/denied/applied/aborted. Report every shadow write/delete attempt, regardless of outcome, grouped as sorted[resource,input_indices]. Live operations and shadow reads are ignored. This audits declared records only, not real side-effect enforcement. No mutation.21.Find a supported serialization of finite alias operations
Write
alias_history(initial,operations), <=7{id:[start,end,read,observed] or [start,end,cas,expected,new,success_bool]}, integer start<=end, string/Nonevalues. End<other start forces precedence; equality overlaps. Read sees current. CAS succeeds iff expected=current; only success changes value. Return lexical full order matching results/precedence, orNone. Empty gives []. No mutation.22.Propagate simultaneous invalidation through dependencies
Write
invalidation_rounds(dependencies,changed),{output:input_names}. Round 0 is sorted distinct changed names, including undeclared roots. Each next round contains all not-yet-invalid outputs with any input in the previous round. Apply a round simultaneously; cycles terminate by invalidating each name once. Return nonempty sorted rounds, or [] for empty changed. No mutation.23.Count compatible interleavings of fixed upgrade sequences
Write
skew_paths(models,features,allowed), nonempty ordered lists length<=9; allowed[model,feature]pairs. Start at indices (0,0), advance one index at a time until both last; all visited pairs allowed. Return[path_count,lexical_actions_or_None], actions model:i/feature:j with entered index. Repeated version labels remain distinct positions. No path gives[0,None]. No mutation.24.Retain models required by active pins and inflight work
Write
retain_versions(desired,pins,inflight,now). Desired/inflight version lists; pins[session,version,expiry]integer times. Active iff expiry>now. Retain desired UNION inflight UNION all active pin versions. Session ambiguous iff >1 distinct active version; retain every such version. Return[sorted_retained,sorted_ambiguous_sessions]. Repeated same-version pins add no ambiguity. No mutation.25.Recompute stream prefixes under generation fences
Write
stream_prefix(events),[key,generation,offset,delta], integer generation/offset>=0, delta integer. Higher generation resets; reject lower. Keep distinct deltas per current-generation offset. Prefix from 0 stops at missing/ambiguous; total=sum prefix deltas. Return [sorted[key,generation,next,total,ambiguous_offsets],stale_indices], sorted offsets. Conflicts retract prefix. No mutation.26.Audit declared adapter owner scope base and expiry evidence
Write
adapter_access(adapters,leases,requests,now). Adapters{id:[owner,base]}, leases{token:[owner,allowed_ids,expiry]}, requests[owner,adapter,token,base]. Failures[index,reasons], ordered: adapter/lease if missing; expired if known expiry<=now; owner if known owner differs; scope if known lease excludes adapter; base if known base differs. Opaque claims, no authentication. No mutation.27.Schedule bounded warmups with a complete optimal witness
Write
warmup_schedule(tasks,workers), <=6{id:[positive_integer_duration,parents]}, workers 1/2. Unknown parent/cycle =>None. Tasks cannot split; each worker runs one at a time, parents finish before start. Minimize makespan, then lexical rows[id,worker,start,finish]sorted by id, worker IDs 0..workers-1. Start times nonnegative. Return[makespan,rows]; empty tasks [0,[]]. No mutation.28.Retain gate outcomes and reachable support failures
Write
decision_outcomes(nodes,start,facts). Nodes{id:[leaf,decision] or [test,fact,true_node,false_node]}, decisions strings. Facts bool/None; missing/Noneunknown. Consider all consistent unknown-fact assignments: repeated fact keeps one value. Return sorted possible decisions. Any possible run reaching missing node/cycle givesNone, despite other leaves. Ignore impossible branches. No mutation.29.Find a minimum-fault deployment failure witness
Write
failure_witness(initial,edges,safe,budget). Edges[unique_id,source,target,fault_cost_0_or_1], budget>=0. Outside safe is unsafe. Find path to unsafe with cost<=budget, minimizing fault cost, edge count, lexical edge IDs. Return[cost,edge_ids]orNone. Initial unsafe [0,[]]; zero-cost cycles allowed. Finite model only, no real-system guarantee. No mutation.30.Compute a controlled safety region and action certificate
Write
safe_region(states,safe,actions), unique states; actions{state:[[unique_action,possible_targets]]}. Unknown targets unsafe. Safe states without actions win as terminals. Others need an action with nonempty targets ALL winning. Return [sorted_winning,sorted[state,lexical_valid_action]for winning nonterminals], greatest safe winning set. Cycles may win; no liveness claim. No mutation.