Files
TheTree_mock/docs/plans/original-completion-2026-10-02/checkpoints/d05-decision-draft-r01/callsite-audit.json
T

62 lines
22 KiB
JSON

{
"scope": "Current static source excerpts; not executed boundary acceptance",
"functions": [
{
"path": "autoload/simulation_runtime.gd",
"file_sha256": "d52a995ae715542bbc550f68d35889540658275d12e04ae0b21ac276f5843f39",
"function": "_complete_service_transaction",
"start_line": 11707,
"excerpt": "func _complete_service_transaction(\n\tservice: ServiceInstance,\n\trequest: ServiceRequest,\n\tfacility: FacilityInstance,\n\tabsolute_minute: int\n) -> Variant:\n\t# A sale is only observable after its inventory, rewards and cleanliness\n\t# effects commit. Rollback removes provisional receipts before scope exit.\n\teconomy_service.begin_notification_scope()\n\tvar result: Variant = _apply_service_transaction(service, request, facility, absolute_minute)\n\tif result is bool and result:\n\t\t_state.set_resource(&\"gold\", economy_service.get_balance(PLAYER_CASH_ACCOUNT))\n\teconomy_service.end_notification_scope()\n\treturn result\n\n"
},
{
"path": "autoload/simulation_runtime.gd",
"file_sha256": "d52a995ae715542bbc550f68d35889540658275d12e04ae0b21ac276f5843f39",
"function": "_apply_service_transaction",
"start_line": 11723,
"excerpt": "func _apply_service_transaction(\n\tservice: ServiceInstance,\n\trequest: ServiceRequest,\n\tfacility: FacilityInstance,\n\tabsolute_minute: int\n) -> Variant:\n\tfor guest_id: StringName in service.guest_ids:\n\t\tvar guest := guest_service.get_guest(guest_id)\n\t\tif guest == null:\n\t\t\tcontinue\n\t\tif guest.state != GuestRuntime.State.RECEIVING_SERVICE \\\n\t\t\tor guest.current_service_id != service.service_id \\\n\t\t\tor guest.target_facility_id != facility.instance_id:\n\t\t\treturn CommandResult.failed(\n\t\t\t\tCommandResult.Code.TRANSACTION_APPLY_FAILED, 0,\n\t\t\t\t\"Guest and Facility service ownership do not match.\"\n\t\t\t)\n\t\tif guest.transition_tick == absolute_minute \\\n\t\t\tand guest.transitions_this_tick >= GuestService.MAX_TRANSITIONS_PER_TICK:\n\t\t\treturn CommandResult.failed(\n\t\t\t\tCommandResult.Code.TRANSACTION_APPLY_FAILED, 0,\n\t\t\t\t\"Guest transition budget is exhausted for this minute.\"\n\t\t\t)\n\tvar inventory_before := inventory_service.create_snapshot()\n\tvar economy_before := economy_service.create_snapshot()\n\tvar state_before: Dictionary = _state.create_snapshot()\n\tif not service.inventory_reservations.is_empty():\n\t\tvar consumed := inventory_service.consume_reservations(\n\t\t\tservice.inventory_reservations,\n\t\t\tStringName(\"service.consume.%s\" % service.service_id),\n\t\t\tabsolute_minute\n\t\t)\n\t\tif not bool(consumed.get(&\"ok\", false)):\n\t\t\treturn CommandResult.failed(CommandResult.Code.TRANSACTION_APPLY_FAILED, 0, \"Reserved service inventory could not be consumed.\", consumed)\n\n\tif service.price_snapshot > 0:\n\t\tvar payer_account := _guest_wallet_account(request.guest_ids[0])\n\t\tvar revenue_account := _facility_revenue_account(facility.instance_id)\n\t\tif not economy_service.has_account(payer_account) or not economy_service.has_account(revenue_account):\n\t\t\tinventory_service.restore_snapshot(inventory_before)\n\t\t\treturn CommandResult.failed(CommandResult.Code.NOT_FOUND, 0, \"A service settlement account is missing.\")\n\t\tvar sale_entries: Array = [\n\t\t\tLedgerEntry.new().configure(\n\t\t\t\t&\"\", absolute_minute, revenue_account, payer_account,\n\t\t\t\tservice.price_snapshot, &\"SERVICE_SALE\", facility.instance_id\n\t\t\t),\n\t\t\tLedgerEntry.new().configure(\n\t\t\t\t&\"\", absolute_minute, PLAYER_CASH_ACCOUNT, revenue_account,\n\t\t\t\tservice.price_snapshot, &\"SERVICE_CASH_SWEEP\", facility.instance_id\n\t\t\t),\n\t\t]\n\t\tvar payment := economy_service.post(\n\t\t\tsale_entries,\n\t\t\tStringName(\"service.payment.%s\" % service.service_id)\n\t\t)\n\t\tif not payment.is_success():\n\t\t\tinventory_service.restore_snapshot(inventory_before)\n\t\t\teconomy_service.restore_snapshot(economy_before)\n\t\t\t_state.restore_snapshot(state_before)\n\t\t\treturn payment\n\n\tvar definition := definition_registry.get_facility(facility.definition_id)\n\tif definition != null:\n\t\tfor item_id: StringName in _sorted_name_keys(definition.inventory_outputs):\n\t\t\tvar output := inventory_service.add_stack(\n\t\t\t\tfacility.local_inventory_id,\n\t\t\t\titem_id,\n\t\t\t\tint(definition.inventory_outputs[item_id]),\n\t\t\t\tservice.quality_snapshot,\n\t\t\t\t-1,\n\t\t\t\tabsolute_minute\n\t\t\t)\n\t\t\tif not bool(output.get(&\"ok\", false)):\n\t\t\t\tinventory_service.restore_snapshot(inventory_before)\n\t\t\t\teconomy_service.restore_snapshot(economy_before)\n\t\t\t\t_state.restore_snapshot(state_before)\n\t\t\t\treturn CommandResult.failed(CommandResult.Code.TRANSACTION_APPLY_FAILED, 0, \"Facility outputs could not be committed.\", output)\n\tvar progression_before: Dictionary = {}\n\tif definition != null and definition.faith_per_service > 0:\n\t\tprogression_before = progression_service.create_snapshot()\n\t\tvar next_faith := int(progression_service.metrics[&\"faith_lifetime\"]) + definition.faith_per_service\n\t\tif not progression_service.update_metrics({&\"faith_lifetime\":next_faith}) or not _state.apply_resource_deltas({&\"faith\":definition.faith_per_service}):\n\t\t\tinventory_service.restore_snapshot(inventory_before)\n\t\t\teconomy_service.restore_snapshot(economy_before)\n\t\t\t_state.restore_snapshot(state_before)\n\t\t\tprogression_service.restore_snapshot(progression_before)\n\t\t\treturn CommandResult.failed(CommandResult.Code.TRANSACTION_APPLY_FAILED, 0, \"Service Faith reward could not be committed.\")\n\tif definition != null and definition.cleanliness_decay_per_service > 0:\n\t\tif not facility_cleanliness.record_use(facility.instance_id, service.service_id, definition.cleanliness_decay_per_service):\n\t\t\tinventory_service.restore_snapshot(inventory_before)\n\t\t\teconomy_service.restore_snapshot(economy_before)\n\t\t\t_state.restore_snapshot(state_before)\n\t\t\tif not progression_before.is_empty(): progression_service.restore_snapshot(progression_before)\n\t\t\treturn CommandResult.failed(CommandResult.Code.TRANSACTION_APPLY_FAILED, 0, \"Facility cleanliness could not be committed.\")\n\treturn true\n"
},
{
"path": "autoload/simulation_runtime.gd",
"file_sha256": "d52a995ae715542bbc550f68d35889540658275d12e04ae0b21ac276f5843f39",
"function": "_advance_elevators",
"start_line": 12679,
"excerpt": "func _advance_elevators(minute: int) -> void:\n\tvar queued_before: Dictionary = {}\n\tfor trip: Dictionary in elevators.get_report()[&\"trips\"]:\n\t\tif trip[&\"state\"] == PathService.ELEVATOR_REQUEST_QUEUED:\n\t\t\tqueued_before[trip[&\"request_id\"]] = true\n\tfor shaft: Dictionary in elevators.get_report()[&\"shafts\"]:\n\t\tvar powered := int(_state.get_resource(&\"mana\")) > 0\n\t\tfor module_id: StringName in shaft[&\"module_ids\"]:\n\t\t\tvar state := mana_network_service.get_consumer_state(module_id)\n\t\t\tif state not in [ManaNetworkService.ConsumerState.ACTIVE, ManaNetworkService.ConsumerState.DEGRADED]:\n\t\t\t\tpowered = false\n\t\t_apply_elevator_arrivals(elevators.set_powered(shaft[&\"shaft_id\"], powered, minute), minute)\n\t_apply_elevator_arrivals(elevators.advance_one_minute(minute), minute)\n\tfor trip: Dictionary in elevators.get_report()[&\"trips\"]:\n\t\tif trip[&\"state\"] == PathService.ELEVATOR_REQUEST_BOARDED and queued_before.has(trip[&\"request_id\"]):\n\t\t\tvar payload := trip.duplicate(true)\n\t\t\tpayload[&\"boarded_at\"] = minute\n\t\t\tpayload[&\"wait_minutes\"] = minute - int(trip[&\"enqueued_at\"])\n\t\t\t_publish_actor_event(&\"ELEVATOR_BOARDED\", &\"elevators\", [trip[&\"actor_id\"], trip[&\"shaft_id\"]], payload)\n\n"
},
{
"path": "autoload/simulation_runtime.gd",
"file_sha256": "d52a995ae715542bbc550f68d35889540658275d12e04ae0b21ac276f5843f39",
"function": "_apply_elevator_arrivals",
"start_line": 12700,
"excerpt": "func _apply_elevator_arrivals(arrivals: Array[Dictionary], minute: int) -> void:\n\tfor arrival: Dictionary in arrivals:\n\t\tvar actor_id := StringName(arrival[&\"actor_id\"])\n\t\tif not path_service.has_actor_projection(actor_id):\n\t\t\tcontinue\n\t\tvar previous: Vector3i = path_service.get_actor_projected_cell(actor_id)\n\t\tvar cell: Vector3i = arrival[&\"cell\"]\n\t\tvar entity_id := StringName(String(actor_id).trim_prefix(\"guest:\").trim_prefix(\"staff:\"))\n\t\tvar guest := guest_service.get_guest(entity_id) if String(actor_id).begins_with(\"guest:\") else null\n\t\tvar staff := staff_service.get_staff(entity_id) if String(actor_id).begins_with(\"staff:\") else null\n\t\tif guest == null and staff == null:\n\t\t\t_report_path_integration_failure(actor_id, entity_id, &\"elevator\", previous)\n\t\t\tcontinue\n\t\tif not path_service.project_actor_position(actor_id, cell, minute):\n\t\t\t_report_path_integration_failure(actor_id, entity_id, &\"elevator\", previous)\n\t\t\tcontinue\n\t\tif guest != null:\n\t\t\tguest_service.record_path_success(guest.guest_id, cell, minute)\n\t\telse:\n\t\t\tstaff.current_cell = cell\n\t\t_movement_credits[actor_id] = {&\"credit\": 0, &\"updated_at\": minute}\n\t\t_publish_actor_event(&\"ELEVATOR_ARRIVED\", &\"elevators\", [actor_id, entity_id], arrival)\n\n"
},
{
"path": "autoload/simulation_runtime.gd",
"file_sha256": "d52a995ae715542bbc550f68d35889540658275d12e04ae0b21ac276f5843f39",
"function": "_advance_staff_rescue",
"start_line": 13000,
"excerpt": "func _advance_staff_rescue(minute: int) -> void:\n\tfor task: StaffTask in staff_service.get_tasks():\n\t\tif task.task_type not in [&\"rescue_pickup\", &\"rescue_transport\"] or task.is_terminal():\n\t\t\tcontinue\n\t\tvar patient := staff_service.get_staff(task.target_entity_id)\n\t\tvar carrier := staff_service.get_staff(task.assigned_staff_id)\n\t\tvar invalid := patient == null or patient.state != StaffRuntime.State.INCAPACITATED\n\t\tif not task.assigned_staff_id.is_empty():\n\t\t\tinvalid = invalid or carrier == null or not carrier.can_take_shift() or carrier.current_task_id != task.task_id\n\t\tif task.task_type == &\"rescue_transport\":\n\t\t\tvar clinic := facility_service.get_instance(task.rescue_facility_id)\n\t\t\tinvalid = invalid or carrier == null or clinic == null or clinic.operation_state != FacilityInstance.OperationState.OPERATING\n\t\t\tif patient != null and carrier != null:\n\t\t\t\tinvalid = invalid or patient.current_cell != carrier.current_cell\n\t\tif invalid:\n\t\t\tif carrier != null and elevators.get_actor_trip(_staff_path_actor_id(carrier.staff_id)).get(&\"state\", &\"\") == PathService.ELEVATOR_REQUEST_BOARDED:\n\t\t\t\tcontinue # Keep the pair aboard until a real or emergency landing.\n\t\t\tstaff_service.cancel_task(task.task_id, &\"RESCUE_INTERRUPTED\", minute)\n\t\t\tif patient != null: elevators.cancel_actor(_staff_path_actor_id(patient.staff_id))\n\t\t\tif carrier != null: elevators.cancel_actor(_staff_path_actor_id(carrier.staff_id))\n\tfor patient: StaffRuntime in staff_service.get_staff_members():\n\t\tif not _defense_lock_owner(patient.staff_id, &\"DEFENDER\").is_empty():\n\t\t\tcontinue\n\t\tif patient.health > 0 and patient.state != StaffRuntime.State.INCAPACITATED:\n\t\t\tcontinue\n\t\tif not patient.current_task_id.is_empty():\n\t\t\tstaff_service.cancel_task(patient.current_task_id, &\"STAFF_COLLAPSED\", minute)\n\t\tif patient.state != StaffRuntime.State.INCAPACITATED or patient.state_reason.is_empty():\n\t\t\tpatient.transition_to(StaffRuntime.State.INCAPACITATED, &\"STAFF_COLLAPSED\", minute)\n\t\t\t_publish_actor_event(&\"STAFF_COLLAPSED\", &\"staff_service\", [patient.staff_id], {&\"cell\": patient.current_cell})\n\t\tif patient.current_cell.z == WorldService.LAYER_FRONT and patient.state_reason != &\"COLLAPSE_WITNESSED\":\n\t\t\tfor guest: GuestRuntime in guest_service.get_guests():\n\t\t\t\tif _authority_line_of_sight(guest.current_cell, patient.current_cell, {}):\n\t\t\t\t\tif progression_service.update_metrics({&\"reputation\": maxi(int(progression_service.metrics[&\"reputation\"]) - 1, 0)}):\n\t\t\t\t\t\tpatient.state_reason = &\"COLLAPSE_WITNESSED\"\n\t\t\t\t\t\t_publish_actor_event(&\"STAFF_COLLAPSE_WITNESSED\", &\"staff_service\", [patient.staff_id, guest.guest_id], {})\n\t\t\t\t\tbreak\n\t\tvar pending := false\n\t\tfor task: StaffTask in staff_service.get_tasks():\n\t\t\tif task.task_type in [&\"rescue_pickup\", &\"rescue_transport\"] and task.target_entity_id == patient.staff_id and not task.is_terminal():\n\t\t\t\tpending = true\n\t\tif not elevators.get_actor_trip(_staff_path_actor_id(patient.staff_id)).is_empty():\n\t\t\tcontinue\n\t\tif pending or _rescue_destination(patient.current_cell).is_empty():\n\t\t\tcontinue\n\t\tstaff_service.create_task(&\"rescue_pickup\", 95, minute, {\n\t\t\t&\"target_entity_id\": patient.staff_id, &\"target_cell\": patient.current_cell,\n\t\t\t&\"required_role_tags\": [&\"medic\"], &\"task_tags\": [&\"rescue\"],\n\t\t\t&\"estimated_minutes\": 30, &\"interrupt_level\": 0, &\"emergency\": true,\n\t\t})\n\n"
},
{
"path": "scripts/supply/supply_management_service.gd",
"file_sha256": "e4ad420191020485c027004f64bb00fad9da195fe956ef10dc0c787412018f7f",
"function": "_purchase_paid",
"start_line": 83,
"excerpt": "func _purchase_paid(runtime: Variant, warehouse_id: StringName, item_id: StringName,\n\tquantity: int, minute: int, ledger_key: StringName, command_id: int = 0, record_auto_attempt: bool = false) -> CommandResult:\n\t# Shared transaction only; internal replenishment does not enqueue a command.\n\tvar quote := preview_purchase(runtime, warehouse_id, item_id, quantity)\n\tif not bool(quote[&\"ok\"]):\n\t\treturn _purchase_failure(command_id, StringName(quote[&\"reason\"]), quote)\n\tvar facility: FacilityInstance = runtime.facility_service.get_instance(warehouse_id)\n\tvar item := SupplyCatalog.get_item(item_id)\n\tvar inventory_before: Dictionary = runtime.inventory_service.create_snapshot()\n\tvar economy_before: Dictionary = runtime.economy_service.create_snapshot()\n\tvar plans_before: Dictionary = runtime.auto_purchase_plans.create_snapshot() if record_auto_attempt else {}\n\tvar stocked: Dictionary = runtime.inventory_service.add_stack(facility.local_inventory_id, item_id, quantity, 100, minute + int(item[&\"shelf_life_minutes\"]), minute, int(item[&\"unit_weight\"]))\n\tif not bool(stocked.get(&\"ok\", false)):\n\t\truntime.inventory_service.restore_snapshot(inventory_before)\n\t\truntime.economy_service.restore_snapshot(economy_before)\n\t\treturn _purchase_failure(command_id, &\"INVENTORY_ERROR\")\n\tvar memo: StringName = SupplyAutoPurchasePlans.receipt_memo(item_id, quantity, int(item[&\"unit_price\"]), int(quote[&\"total_cost\"])) if record_auto_attempt else &\"supply_purchase\"\n\tif quote.has(&\"purchase_quote\"):\n\t\tmemo = PurchaseQuoteV2.receipt_memo(quote[&\"purchase_quote\"])\n\tvar paid: CommandResult = runtime.economy_service.transfer(&\"PLAYER_CASH\", runtime.OPERATING_EXPENSE_ACCOUNT, int(quote[&\"total_cost\"]), minute, &\"OPERATING_EXPENSE\", warehouse_id, ledger_key, memo, &\"\", false)\n\tif not paid.is_success():\n\t\truntime.inventory_service.restore_snapshot(inventory_before)\n\t\truntime.economy_service.restore_snapshot(economy_before)\n\t\treturn _purchase_failure(command_id, &\"PAYMENT_FAILED\")\n\tvar recorded := true\n\tif record_auto_attempt:\n\t\tif quote.has(&\"purchase_quote\"):\n\t\t\trecorded = runtime.auto_purchase_plans.record_attempt(warehouse_id, item_id, minute, CommandResult.succeeded(0, {&\"transaction_id\": paid.details[&\"transaction_id\"], &\"quantity\": quantity, &\"purchase_quote\": quote[&\"purchase_quote\"], &\"total_cost\": quote[&\"total_cost\"]}), runtime.economy_service)\n\t\telse:\n\t\t\trecorded = runtime.auto_purchase_plans.record_attempt(warehouse_id, item_id, minute, CommandResult.succeeded(0, {&\"transaction_id\": paid.details[&\"transaction_id\"], &\"quantity\": quantity, &\"unit_price\": item[&\"unit_price\"], &\"total_cost\": quote[&\"total_cost\"]}), runtime.economy_service)\n\tif not recorded:\n\t\truntime.inventory_service.restore_snapshot(inventory_before)\n\t\truntime.economy_service.restore_snapshot(economy_before)\n\t\treturn _purchase_failure(command_id, &\"PAYMENT_FAILED\")\n\tif not runtime.economy_service.commit_transaction_notification(StringName(paid.details[&\"transaction_id\"])):\n\t\truntime.inventory_service.restore_snapshot(inventory_before)\n\t\truntime.economy_service.restore_snapshot(economy_before)\n\t\tif record_auto_attempt:\n\t\t\truntime.auto_purchase_plans.restore_snapshot(plans_before, runtime.facility_service, runtime.economy_service, minute)\n\t\treturn _purchase_failure(command_id, &\"PAYMENT_FAILED\")\n\tquote.merge({&\"warehouse_id\": warehouse_id, &\"item_id\": item_id, &\"quantity\": quantity, &\"transaction_id\": paid.details[&\"transaction_id\"]})\n\treturn CommandResult.succeeded(command_id, quote)\n\n"
},
{
"path": "scripts/operations/operations_coordinator.gd",
"file_sha256": "871a248ee101b6df543fd5cf0440b5d4b0f02c21fa145a99f0687888c1bc6f90",
"function": "_process_daily_close",
"start_line": 1125,
"excerpt": "func _process_daily_close(boundary_minute: int) -> CommandResult:\n\tvar completed_day := _financial_day_for_boundary(boundary_minute)\n\tif _day_summaries.has(completed_day):\n\t\tvar replay := _success({&\"day\": completed_day})\n\t\treplay.is_replay = true\n\t\treturn replay\n\tvar payload := {\n\t\t&\"operation\": &\"DAILY_CLOSE\",\n\t\t&\"day\": completed_day,\n\t\t&\"boundary_minute\": boundary_minute,\n\t\t&\"period_start_minute\": get_financial_period_start(completed_day),\n\t\t&\"period_end_minute_exclusive\": boundary_minute,\n\t\t&\"idempotency_key\": \"daily-close:%d\" % completed_day,\n\t\t&\"prior_arrears_total\": _arrears_total,\n\t\t&\"steps\": [\n\t\t\t&\"FINALIZE_PENDING_SERVICES\",\n\t\t\t&\"AGGREGATE_LEDGER_CATEGORIES\",\n\t\t\t&\"RECONCILE_LEDGER\",\n\t\t\t&\"GENERATE_FACILITY_PROFIT_LOSS\",\n\t\t\t&\"DETECT_ANOMALIES\",\n\t\t\t&\"BUILD_DAY_SUMMARY\",\n\t\t\t&\"EVALUATE_LOSS_STREAK_AND_BANKRUPTCY\",\n\t\t],\n\t}\n\tvar transaction := _run_boundary_transaction(\n\t\t_daily_close_boundary,\n\t\tpayload,\n\t\t_default_daily_apply_result()\n\t)\n\tif not bool(transaction[&\"ok\"]):\n\t\treturn _transaction_boundary_failure(\n\t\t\ttransaction, &\"DAILY_CLOSE\", boundary_minute, &\"DAILY_CLOSE_FAILED\"\n\t\t)\n\tvar applied: Dictionary = transaction[&\"result\"]\n\tvar normalized := _normalize_daily_result(applied)\n\tif not bool(normalized[&\"ok\"]):\n\t\tvar rollback := _rollback_boundary_result(\n\t\t\t_daily_close_boundary,\n\t\t\tpayload,\n\t\t\ttransaction.get(&\"token\", null)\n\t\t)\n\t\tif not _boundary_result_succeeded(rollback):\n\t\t\t_enter_external_quarantine(\n\t\t\t\t&\"DAILY_CLOSE\", boundary_minute, &\"RESULT_SCHEMA\", &\"DAILY_CLOSE_RESULT_INVALID\"\n\t\t\t)\n\t\t\treturn _boundary_failure(\n\t\t\t\t\"EXTERNAL_ROLLBACK_FAILED\",\n\t\t\t\t{&\"operation\": &\"DAILY_CLOSE\", &\"phase\": &\"RESULT_SCHEMA\"}\n\t\t\t)\n\t\treturn _boundary_failure(\n\t\t\t\"DAILY_CLOSE_RESULT_INVALID\",\n\t\t\t{\n\t\t\t\t&\"reason\": normalized[&\"error\"],\n\t\t\t\t&\"rollback_ok\": true,\n\t\t\t}\n\t\t)\n\n\tvar result: Dictionary = normalized[&\"result\"]\n\tvar category_totals: Dictionary = result[&\"category_totals\"]\n\tvar net_profit := _net_profit(category_totals)\n\tvar previous_profit := net_profit\n\tif _day_summaries.has(completed_day - 1):\n\t\tprevious_profit = int((_day_summaries[completed_day - 1] as Dictionary)[&\"net_profit\"])\n\tvar rolling := _rolling_profit_with(net_profit)\n\tvar arrears := int((result[&\"settlement\"] as Dictionary)[&\"arrears_total\"])\n\tvar prior_streak := 0 if completed_day == _legacy_history_last_day + 1 else _consecutive_insolvency_count\n\tvar consecutive := prior_streak + 1 if net_profit < 0 else 0\n\tvar future_terminal := _terminal_state\n\tif consecutive >= int(_config[&\"bankruptcy_close_count\"]):\n\t\tfuture_terminal = TERMINAL_BANKRUPT\n\tvar reconciliation_difference := int(result[&\"reconciliation_difference\"])\n\tvar summary := {\n\t\t&\"day\": completed_day,\n\t\t&\"period_start_minute\": get_financial_period_start(completed_day),\n\t\t&\"period_end_minute_exclusive\": boundary_minute,\n\t\t&\"closed_at\": boundary_minute,\n\t\t&\"category_totals\": category_totals,\n\t\t&\"net_profit\": net_profit,\n\t\t&\"previous_day_delta\": net_profit - previous_profit,\n\t\t&\"seven_day_average\": rolling[&\"quotient\"],\n\t\t&\"seven_day_average_detail\": rolling,\n\t\t&\"facility_profit_loss\": result[&\"facility_profit_loss\"],\n\t\t&\"anomalies\": result[&\"anomalies\"],\n\t\t&\"reconciliation_difference\": reconciliation_difference,\n\t\t&\"balanced\": reconciliation_difference == 0,\n\t\t&\"settlement\": result[&\"settlement\"],\n\t\t&\"arrears_total\": arrears,\n\t\t&\"consecutive_insolvency_count\": consecutive,\n\t\t&\"terminal_state\": String(future_terminal),\n\t}\n\n\t# Commit coordinator state only after the external apply result and every\n\t# derived summary field have passed validation.\n\t_day_summaries[completed_day] = summary\n\t_arrears_total = arrears\n\t_consecutive_insolvency_count = consecutive\n\tif reconciliation_difference != 0:\n\t\tpause_requested = true\n\t\t_pause_reason = &\"LEDGER_IMBALANCE\"\n\t\t_append_alert({\n\t\t\t&\"code\": &\"LEDGER_IMBALANCE\",\n\t\t\t&\"minute\": boundary_minute,\n\t\t\t&\"day\": completed_day,\n\t\t\t&\"difference\": reconciliation_difference,\n\t\t\t&\"automatic_correction\": false,\n\t\t})\n\tif net_profit < 0:\n\t\t_append_alert({&\"code\": &\"LOSS_STREAK\", &\"minute\": boundary_minute,\n\t\t\t&\"day\": completed_day, &\"net_profit\": net_profit, &\"consecutive_count\": consecutive})\n\tif arrears > 0:\n\t\t_append_alert({\n\t\t\t&\"code\": &\"ARREARS_REMAIN\",\n\t\t\t&\"minute\": boundary_minute,\n\t\t\t&\"day\": completed_day,\n\t\t\t&\"arrears_total\": arrears,\n\t\t\t&\"consecutive_count\": consecutive,\n\t\t})\n\tif future_terminal != _terminal_state:\n\t\tvar old_state := _terminal_state\n\t\t_terminal_state = future_terminal\n\t\t_append_alert({\n\t\t\t&\"code\": &\"BANKRUPT\",\n\t\t\t&\"minute\": boundary_minute,\n\t\t\t&\"day\": completed_day,\n\t\t\t&\"arrears_total\": arrears,\n\t\t\t&\"consecutive_count\": consecutive,\n\t\t})\n\t\t_queue_notification(\n\t\t\t&\"terminal\",\n\t\t\t[old_state, _terminal_state, &\"CONSECUTIVE_LOSSES\"]\n\t\t)\n\t_queue_notification(&\"daily\", [summary.duplicate(true)])\n\treturn _success(summary)\n\n"
}
],
"observations": [
"Elevator power combines reserve and consumer state before arrival projection.",
"Rescue invalid pair cancellation is deferred while carrier remains boarded.",
"Supply purchase pays when source warehouse stock is added, not at delivery completion. Payment failure restores snapshots."
],
"D05_approved": false,
"original_unit_complete": false
}