Skip to content

Issue #46: round completion境界でseat-relative RoundEvidenceをdeliveryする - #47

Merged
lisbun merged 1 commit into
mainfrom
claude/lisjong-engine-issue-46-0wpz2m
Aug 29, 2026
Merged

lisbun merged 1 commit into
mainfrom
claude/lisjong-engine-issue-46-0wpz2m

Conversation

@lisbun

@lisbun lisbun commented Aug 29, 2026

Copy link
Copy Markdown
Owner

Closes #46

目的

局をFINISHEDにした最後のsuccessful transactionがRoundProgressFactを生じない場合(terminal ron等)、既存on_deliveryは呼ばれないまま次のloopでsettle_active_round()がactive RoundStateをclearする。そのため、ResponseEpochClosedEvidence / RoundEndedEvidenceまで含むcomplete final evidenceをconsumerが取得する境界が存在しなかった。この欠落だけを埋める。

採用したAPI shape

SeatRoundEvidence
    viewer_seat: Seat
    evidence: tuple[RoundEvidence, ...]        # build_round_evidence()の結果そのもの

RoundEvidenceCompletion
    prevailing_wind / hand_number / dealer_seat / honba   # MatchState.position由来
    projections: tuple[SeatRoundEvidence, ...]            # tuple(Seat)順の4件

build_round_evidence_completion(match_state) -> RoundEvidenceCompletion
run_hanchan(..., on_round_evidence_complete=callback)
  • viewerごとに複数回呼ぶ形ではなく、局ごと1回のimmutable valueにした。exactly-once contractとviewer順序の決定性が値そのもので固定でき、consumerがviewer単位のcallbackを再集約する必要がないため。
  • SeatRoundEvidenceでviewer identityを明示し、docstringで「bundle全体はsingle-player safeなglobal-public objectではない」ことを明記した。
  • evidence生成は既存build_round_evidence(round_state, viewer_seat)の再利用だけで、新しいevent interpretationをdriverへ複製していない。
  • round identityはMatchState.positionのplayer-safeな位置情報のみ。round_ordinal / seed / random provenanceは持たない。
  • build_round_evidence_completion()はactive roundがFINISHEDでなければfail closedで拒否する。

Delivery timing

final round transaction commit
    -> RoundPhase.FINISHED
    -> build_round_evidence() x tuple(Seat)
    -> on_round_evidence_complete(RoundEvidenceCompletion)   # 局ごと1回
    -> callback return
    -> MatchState.settle_active_round()
    -> round completion fact(既存on_delivery)-> 次局 / match completion

callbackはsettlementより前に呼ばれるため、例外時は精算前の状態で停止する(retry / silent skipなし、成功済みtransactionのrollbackなし)。既存on_deliveryのbatch内容・順序・timingは変更していない。

変更ファイル

  • src/lisjong_engine/round_evidence_completion.py(新規): value contractとbuild_round_evidence_completion()
  • src/lisjong_engine/driver.py: on_round_evidence_complete optional callbackと_deliver_round_evidence()
  • tests/test_round_evidence_completion.py(新規): 27 tests
  • docs/architecture.md: 本境界のsectionを追加

Tests

Issue記載のacceptance criteriaを固定した。

  • callback未指定/指定時のexecution・result・selector呼出順序・on_delivery batchの同一性
  • completed roundごとにexactly once、精算前delivery(callback時点でactive roundは未clear、historyはn-1件)
  • delivered valueが同じfinished RoundStateへのbuild_round_evidence()と一致
  • ron(ResponseEpochClosedEvidence(RON) + RoundEndedEvidence)/ tsumo / exhaustive draw / abortive draw(九種九牌)でterminal evidenceを欠落しない
  • viewer-private draw tileが他viewerへ漏れない
  • ロン可能なまま見逃した2席のevidenceが完全一致する(capability / hidden pass / 見逃しフリテン / ReactionResolutionの非漏洩)
  • payloadにRoundState / MatchState / RoundEvent / ReactionResolution / Tile / provenance field名が現れない再帰check
  • viewer order・delivery valueのdeterminism(same seed / same selectors)
  • callback例外の伝播と、精算・次局へ進まないこと

品質確認

python -m ruff format --check .   -> 118 files already formatted
python -m ruff check .            -> All checks passed!
python -m unittest discover -s tests -v  -> Ran 1436 tests, OK(CPython 3.14.0rc2、base 1409 + 新規 27)
git diff --check                  -> 差分なし

Non-goals

外部runtime dependency、generic transaction observer / event bus、RoundEvidence / RoundProgressFact / RoundCompletionFactのsemantic変更、on_deliveryへのempty batch追加、Arena / HandBelief / dataset依存はいずれも導入していない。


Generated by Claude Code

局を`FINISHED`にした最後のtransactionが`RoundProgressFact`を生じない場合、
既存`on_delivery`は呼ばれず、次のloopの`settle_active_round()`でactive
`RoundState`が失われるため、`ResponseEpochClosedEvidence` /
`RoundEndedEvidence`まで含むcomplete evidenceを取得できなかった。

`round_evidence_completion.py`へ、viewerごとのseat-relative projectionを
viewer identity付きで束ねるimmutable value(`SeatRoundEvidence` /
`RoundEvidenceCompletion`)と、終局済みactive roundからそれを構築する
`build_round_evidence_completion()`を追加する。evidenceは既存
`build_round_evidence()`をそのまま再利用し、新しいevent interpretationを
driverへ複製しない。round identityは`MatchState.position`由来の
player-safeな位置情報だけを持つ。

`run_hanchan()`へoptionalな`on_round_evidence_complete`を追加し、
`RoundPhase.FINISHED`確定後・`settle_active_round()`前に局ごとちょうど
1回だけ同期deliveryする。callback例外はfail-fastで伝播し、精算・次局へ
進まない。既存`on_delivery`のobservable semanticsと`RoundEvidence` /
`RoundProgressFact` / `RoundCompletionFact`は変更しない。

Closes #46

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Pgnw2xnX4TC7VMAjsDPsVS
@lisbun
lisbun merged commit 2c5ba39 into main Aug 29, 2026
1 check passed
@lisbun
lisbun deleted the claude/lisjong-engine-issue-46-0wpz2m branch August 29, 2026 05:38
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.

Expose complete seat-relative RoundEvidence at round completion boundary

2 participants