Skip to content

Complete deterministic clearing, bounty and order contracts (#71–#73) - #103

Closed
LIghtJUNction wants to merge 24 commits into
mainfrom
fix/market-71-73
Closed

LIghtJUNction wants to merge 24 commits into
mainfrom
fix/market-71-73

Conversation

@LIghtJUNction

@LIghtJUNction LIghtJUNction commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Scope

Refs #71, #72, #73. Implementation against the authoritative design, with shared financial transaction invariants. Do not merge or close these issues until the current combined-head full CI succeeds.

  • [P1] 确定性清算、银行边界、报价兑换与 Entitlement #71: named immutable ledger legs, pure integer clearing policy, owner-account credential scope (including idempotent replay), physical-console money bank fund with two separate confirmations before PIN unlock, versioned offer snapshots and a real Registry-backed hosting_bytes_v1 entitlement. money.redeem@1 keeps its published input/short code; @2 adds pending redemption. Pending/settle/refund and purchase recovery share the ledger transaction. Empty offers and zero issuance remain the defaults; buying capacity does not grant authorization.
  • [P1] Bounty 预托管与官方 PoP 奖励闭环 #72: shared current bounty projections, consistent pause/max_claims/budget rules, current-key/subject/nonce/expiry proof checks, atomic claim+budget+receipt+Event+minimal Inbox, and official isolated market_e2e. The selftest parses the real console command, mints/funds 20 MSG, pre-escrows/claims 10, buys the fixed text+hello.txt bundle for 5, verifies buyer=5/bank=15/escrow=0/supply=20, and retries without a second payment. PoP is explicitly NOT human or Sybil resistance.
  • [P1] Sale Order/Escrow 完整状态机与客观退款 #73: immutable signed quote/PaymentIntent, unpaid quotes and stock checked at funding, finite append-only order transitions, offline-seller automatic site delivery, objective evidence/timeout refunds, explicit sealed-manual and service acceptance, buyer-only history/delivery, and restore tests while money remains in escrow. Automatic policy settlement does NOT mark a buyer as having claimed delivery; delivery.claim is separately signed and never moves money.

Integration and verification

Current combined head: c765205, incorporating main 4a9378d without overwriting its eleven non-overlapping changed files. This retains the CI-only #104 collection repair and complete four-shard evidence gate, the parallel TUI/restore/retry improvements, and the Registry's owned/local-only schema validation.

Current-head required CI: 36352563634 — pending verification. It must run every collected core test, all real transports/tokenizer conformance and the installable build under Python 3.15, PostgreSQL 16 and Valkey. No test allowlist, skipped failing tests, xfail or longer timeout was introduced.

The complete earlier CI on 5d7b575 ran 1,038 tests: 1,031 passed, 7 failed, 0 skipped. The seven failures were six legacy SELECT * comparisons across legitimate additive columns and one obsolete doctor expectation. Commit b8d3e3b fixes those expectations without weakening the invariants: every original legacy column/receipt, sequence, supply and balance is compared, new defaults are checked separately, and rollback must restore the exact old schema. Doctor has both successful and failed clearing-inspection cases, never claims market_e2e, and may not change financial, identity, event, audit or result rows. The previously suspected Git ingress failure did not reproduce in the complete correctly provisioned run.

Focused local evidence for the market/test-fix tree on disposable Python 3.13 / PostgreSQL 17: 51 market tests, 26 migration/config tests, 18 collection/shard-gate tests, and 2 official isolated selftest tests all passed. These separate groups do not replace the target-environment combined-head CI above.

Compatibility / boundaries

Migration adds typed purchase escrow, named ledger legs, order quote/deadline facts and append-only order events without rewriting historical signed receipts. Existing escrow-v1 orders retain explicit acceptance; new automatic behavior requires a versioned policy. CLI, configuration sample, bootstrap/doctor/selftest and docs are updated together.

docs/MARKET_CLEARING.md documents commands, limits and irreversible delivery points. Email endpoint ownership/SMTP and large delivery transport remain #74; arbitration panels/quorum/appeals/signed split decisions remain #75. Subjective disputes stay held unless the seller refunds; unsupported facilities fail closed. Production gate #84 remains separate. No deployment, production mint/funding, live bank registration or live offers were performed.

The temporary source/dependency export workflow is NOT included in this feature branch.

LIghtJUNction and others added 7 commits September 28, 2026 03:43
…bitration

Implement #73, #74 and #75. Preserve signed v1 semantics; centralize escrow releases, immutable v2 checkout, automatic unclaimed delivery, buyer-bound optional email, real Transfer, fixed-panel signed decisions, recovery roots and isolated selftest. Local new market matrix: 26 passed; migration matrix: 21 passed; TLS log matrix: 5 passed. Production is untouched.
Refs #71, #72, #73. Add named ledger legs, console bank funding, bounded hosting redemption, proof-of-possession bounty and versioned escrow delivery/refund state machines. Includes isolated selftest, migration, recovery and authorization regressions. Candidate requires complete PR CI before merge; no production changes.
Copilot AI lite review requested due to automatic review settings September 27, 2026 20:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-09-27T20:47:44.625990Z b213f29 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…ation

Preserve all 21 paths changed by #101 and all 31 market paths; compare verified there are no overlapping paths. Reuse exact published blobs, no rewritten implementation or temporary workflow. Full merged-head CI is required before merging #102.
Refs #71, #72, #73, #104. Preserve current main and all market changes; reuse the six reviewed CI-only blobs from ae64f40. Remove the conftest alias collision and require all four disjoint test partitions, conformance and build. No application semantics or production effects change in this integration.
…gration

Refs #71, #72, #73. Fix all seven observed CI failures without dropping historical assertions: capture every pinned legacy column and verify additive market defaults separately; distinguish read-only clearing inspection from the isolated market E2E. Add a negative inspection case and assert doctor never writes market, identity, event, audit or result rows.

The complete 5d7b575 CI ran 1038 tests: 1031 passed and 7 failed in these two expectations. Focused local verification after this change: 51 market tests and 26 migration/config tests passed on Python 3.13/PostgreSQL 17. The required complete Python 3.15/PostgreSQL 16/Valkey CI remains authoritative.

Copy link
Copy Markdown
Contributor Author

Continuation for #71–#73 is now at b8d3e3b.

Integrated the CI-only #104 commit rather than duplicating its fix. The real Python 3.15 / PostgreSQL 16 / Valkey CI on 5d7b575 ran all 1,038 core tests: 1,031 passed, 7 failed, 0 skipped. All seven failures were in two stale expectations: six old-backup comparisons used SELECT * across legitimate additive market columns; one doctor expectation treated an actual read-only clearing inspection as a configuration-only pass. The earlier collection failure is gone, and the previously suspected Git ingress failure did not reproduce in this complete run.

The new commit preserves comparison of every pinned legacy field, sequence, supply, balances and historical receipt, and separately checks additive defaults/no fabricated order events or purchases. Fault-injection rollback still requires the exact original schema. Doctor now has positive and failed-inspection cases, checks all money/bounty/order feature results against market_clearing, never claims market_e2e, and asserts no financial/identity/event/audit/result rows changed. No application authorization, money policy, production state or historical signed data was changed to make tests pass.

Focused local verification: 51 market tests passed and 26 migration/config tests passed on disposable Python 3.13 / PostgreSQL 17. These do not substitute for the target environment. Current-head full CI is 36352138041, including all four complete partitions, conformance and package build. Do not merge or close the issues based on the local counts while that gate is pending.

The helper source/dependency export workflow remains on its separate disposable branch, not in this PR.

…lel fixes

Refs #71, #72, #73. Include main 4a9378d: the eleven files changed since the shared ae64f40 ancestor do not overlap market changes. Preserve their exact blobs, including Registry schema ownership/local reference policy, TUI recovery, safe restore configuration, effect retry tests and dependency declaration. Retain both parents and rerun complete combined CI; prior isolated/local results are not evidence for this combined tree.
Refs #71, #72, #73. Preserve main b1ac767's exact worker and regression-test blobs. This enforces expired notification lease deadlines without altering market contracts. Keep both parents so the final complete CI covers the same source tree that will be merged, rather than relying on separate branch successes.

Copy link
Copy Markdown
Contributor Author

Final integration head is now ae1d940, tree 45ddcbe724197e6371daecf7448831724588a976. It includes main b1ac767 and preserves #109's exact two lease-fencing blobs. This supersedes the prior c765205 gate; cancelled/superseded runs must not count as successful evidence.

Required complete current-head CI: 36352976244. Before the final two-file main update, the exact c765205 combined tree additionally passed 117 local integration tests, including new Registry/TUI/backup/retry checks, market contracts, purchase recovery, money configuration and the official isolated selftest. The local source was reconstructed from pinned build artifacts and matched the Git tree hash, not assumed to match by branch name. The final ae1d940 tree has also been hash-verified locally and its affected notification/market regressions are running.

No force push, test exclusion, protection bypass, production operation or issue closure was performed. The PR description's final verification block will be replaced with completed exact-head evidence before merging.

LIghtJUNction and others added 7 commits September 28, 2026 05:51
…ntegrate main

Merge main through 4a9378d, preserving market notification/recovery hooks.
Reject absent, substituted and unavailable case rationale bytes before voting
or escrow execution; retain the exact reason across backup and restore.

The missing-rationale regression fails against 0b88bbf and passes with the
fix. Integrated PostgreSQL regression: 126 passed, zero skips. Harden the
four-shard CI gate to verify actual node IDs and reject skipped evidence.

Verified source tree: 95fe3ff.
Integrate b1ac767 and synchronize the order-only email projection when the
current worker discovers its own lease expired. Do not requeue expired work,
claim goods, alter settlement or override a disabled buyer endpoint.

The new real-checkout regression fails on the previous merge candidate:
email_status stays queued while the job is uncertain. Cover finish/retry
and enabled/disabled endpoint combinations with no outbound mail.

Source tree: 98058a6.
…fication

Integrate main 3cdcae4: keep its version-2 manifest and msg.nodeid identity
format, all new identity/class/parameter regressions, plus this PR's
skip/duplicate-ID rejection and actual two-shard completeness test.

No application source changes. Real combined CI/fixture regression:
29 passed, zero skips. Source tree matches local 901703a.
Previously verified f9fba26 business tree: 145 integrated PostgreSQL tests,
24 transport tests, 8 conformance tests and build/install smoke passed.
Refs #71, #72, #73. Preserve the existing market implementation and add seven regression cases for changed historical facts, corrupt additive defaults, immutable ledger legs, missing market schema and the real isolated market selftest. Ensure interrupted migrations leave no new market tables and doctor cannot run a transaction selftest.
…ored snapshots

Preserve orders.buy@1/@2; move the new lifecycle to @3. Share the protected escrow debit boundary, retain both immutable journals and all worker completion fences. Bind restored checkout/payment/delivery facts and honor disabled SMTP. Refs #73, #74, #75.

Copy link
Copy Markdown
Contributor Author

Conflict resolution complete. The branch now contains current main through #102's integrated head. For overlapping #73 code, the newer #102 delivery/order/test implementation wins; #103 keeps #71/#72 clearing, bounty, entitlement and related tests. money.py retains v2 deterministic/named-leg policy while also preserving the order-escrow _ESCROW_WRITE fence. Status docs were reconciled so the older #73 text no longer contradicts #102.

Copy link
Copy Markdown
Contributor Author

2026-09-28 审计与并行交接:本 PR 归任务 B,C 为唯一串行合并负责人,当前 main 已前进到 acc542ab7cbb6983c1e44d294e116d2b0eb6ed68(已合入 #102、#105)。分工和更新后的剩余验收见 #71/#72/#80/#81/#83。

已独立校验运行 36384344964 的 shard0 产物 SHA-256/JUnit,确认至少两类失败:tests/test_market_73.py 的 _sale(..., policy=...) 参数不兼容,以及 tests/test_money_config.py::test_market_selftest_features_require_the_actual_isolated_flow 的 selftest 非成功。其余分片仍需本任务完整读取;不能删断言、跳过或用内部局部 selftest 代替官方命令闭环。

先与 #102 的市场实现整合:保留 orders.buy@1/@2 的原义及完整 @3、受保护 escrow debit、买家绑定交付/邮件、确定性仲裁、不可变签署账本与恢复。不要将旧重复 order_engine 或过时 CI/fixture 修复直接覆盖 main,也不要放宽未知 ledger 引用拒绝。代码共享接线和旧迁移语义分别与 C/A 对齐。

旧 body 的 c765... 与旧 CI 不代表当前 head 9dc0d3d...;解冲突/修复后需完整最终 head CI,再交 C 以 expected head SHA 合并。#73–75 已关闭,不重复重建或声称未实现。没有生产注资/发行、部署或真实 SMTP 授权。本轮尚未修改/合并本 PR。

Copy link
Copy Markdown
Contributor Author

A→B 源码交叉核验交接(仅Refs,不合并、不将源码阅读当现场验收)。审查版本 9dc0d3db8a78a9bd1b99ca2bfb5ef97e1934b730:

  1. storage/market_migration.py 的 money_purchases.escrow_account 是 NOT NULL FK→ledger_accounts;purchase_escrow 没有伪造 Subject。postgres.py 初始化在同一 advisory-lock 事务内先 market 再 legacy ledger migration。ledger_migration.py 的 escrow source/type 与这些字段一致;未知 body 表仍fail-closed。store_order_events.actor 为身份引用,receipt_refs 为历史财务引用;原有 receipts 不应为迁移重写。
  2. admin/money.py 的 MoneyAdmin.execute 在 app.load 前 require_local_console;bank_fund 的 bank_add/transfer 两份摘要确认均先于unlock,expected supply/root/subject/role状态再进交易用例。A 没有修改该共享入口,也没有加入环境变量/TTY/回环/PIN参数替代。

A实际修复现在在 #116(stacked on #112,head c97a528),新security/root_files.py提供描述符级0600/no-follow/单链接读取和Root rotation lock,完整preflight/检查点实现及契约在独立模块。C串行组合时需保留这里market DDL先后关系,并跑该组合head的真实旧库迁移/回滚与bank fund双确认拒绝用例。A 的新head专项Recovery safety已成功,但不覆盖本PR尚未组合的所有变更;真实物理控制台和实际生产旧库材料仍缺,不能宣称联合现场验收。

Copy link
Copy Markdown
Contributor Author

Superseded by #119. The still-useful #71/#72 slices have been carried into the current serial integration branch, while the older #73 implementation is intentionally not restored. Closing this stale PR before branch cleanup.

@github-actions
github-actions Bot deleted the fix/market-71-73 branch September 28, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants