Fix the batch settlement report for a sync job
Your task
A TypeScript sync job caught every push error, returned null and filtered the nulls out, so failed financial records disappeared without a trace. An AI described it as "logged and skipped". The replacement reports one row per item, success or failure, so a reconciliation job can account for every record.
An assistant wrote settle_batch(item_ids, outcomes). It is in the editor. It has a bug. Find it and fix it.
Input and output:
item_ids: the items in the batch, in order. Ids may repeat or be empty.outcomes: the result of pushing each item, in the same order:"ok"or"err:<reason>". The list may be shorter or longer thanitem_ids.- Return one row per item, in order:
"<id>=ok"or"<id>=failed:<reason>".
Rules the tests check:
- An item with no outcome (the list ran out) is
"<id>=failed:no-result". Outcomes past the last item are ignored. - An outcome of exactly
"ok"is"<id>=ok". Nothing else counts as success:OKorokdo not. - An outcome starting with
"err:"is"<id>=failed:<reason>", where the reason is the rest of the text. An empty reason becomesunknown. - Any other outcome is
"<id>=failed:unknown".
Examples
settle_batch(item_ids: list[str], outcomes: list[str]) -> list[str]Example 1
Input
settle_batch(["tx1", "tx2", "tx3"], ["ok", "err:timeout", "ok"])Output
["tx1=ok", "tx2=failed:timeout", "tx3=ok"]Example 2
Input
settle_batch(["tx1", "tx2"], ["ok"])Output
["tx1=ok", "tx2=failed:no-result"]