You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(mq): keep terminal receivers terminal on result settlement - #398
UPDATE threads SET work_state ='working'WHERE id = ?1AND work_state ='idle'AND agent_status ='active'AND EXISTS (SELECT1FROM thread_mq WHERE thread_id = ?1AND id = ?2)
AND EXISTS (SELECT1FROM threads WHERE id = ?3AND agent_status ='active')
No actionable comments were generated in the recent review.
Walkthrough
Local and remote settlement now promote a receiver from idle to working only when the receiver is active. Regression tests cover Error, Done, and Cancelled receivers and verify result insertion and child settlement.
Changes: Receiver settlement
Layer / File(s)
Summary
Guard receiver promotion during settlement peri-resources/src/sessions/remote/session_mq.rs, peri-resources/src/sessions/sqlite_store/session_data/mq.rs, peri-resources/src/sessions/remote/session_settlement_test.rs, peri-resources/src/sessions/sqlite_store/session_mq_terminal_test.rs, docs/design/thread-mq.md
Both receiver-promotion SQL statements now require the receiver to be active. Tests verify that finalization inserts the result and settles the child without changing a terminal receiver’s status or idle work state. The design document reflects the local SQLite condition.
KonghaYao/peri#339: Adds the child-terminal settlement path that this change updates.
KonghaYao/peri#382: Addresses terminal threads receiving working intent, including an overlapping terminal-settlement path.
Merge Risk: Minimal · up to 2e9f9
Settling a child result no longer changes a terminal receiver back to working. The result is still delivered and the child is still settled. No merge-blocking risk remains.
Security architecture risk: Minimal · up to 2e9f9
The change prevents completed, failed, or cancelled work from being marked for automatic resumption while preserving result delivery. It tightens an existing state check, and the reviewed changes introduce no material security risk.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The direct changed effect is confined to whether a designated receiver row gains working intent. The SQL still uses bound identifiers and requires the designated result row and active child; the added condition reduces eligible writes rather than expanding authority over additional threads.
Trust Boundaries and Controls
observed — Settlement retains writable-access and payload-ID validation before writes. Existing session-existence and foreign-message ownership checks remain in place, including remote batch guards that abort conflicting effects.
Resilience and Maintainability Implications
observed — The inspected queue selects messages by source and execution policy and hands them off using an execution-bound receive permit, not a working-state prerequisite. Thus result handoff remains separate from the durable automatic-resumption intent restricted by this PR.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: the receiver-promotion SQL now keeps terminal receivers terminal during result settlement. The raw summary confirms the guard added to PROMOTE_RECEIVER_ON_TERMINAL_SQL…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: the receiver-promotion SQL now keeps terminal receivers terminal during result settlement. The raw summary confirms the guard added to PROMOTE_RECEIVER_ON_TERMINAL_SQL and PROMOTE_RECEIVER_WORK_INTENT_SQL, plus tests for error, done, and cancelled targets. The title follows the conventional commit style and stays under the length guidance.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 2aefabe3-39e7-4dc2-96eb-40ad54dab77a
Commits
Reviewing files that changed from the base of the PR and between f530d26 and 2e9f9bd.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
MQ 结果结算的 receiver 提升语句只看 target
work_state = 'idle'、结果行存在与 childactive,不看 target 自身是否已终态。SQL 级可复现:terminal-root(error+idle)+ active-child + 结果行 → target 被改写成error+working,违反「终态线程的work_state是派生值」的一致性约束。SQL 改动
两条提升语句在原有
work_state = 'idle'、结果行存在与 childactive条件之外,增加 targetagent_status = 'active'守卫:PROMOTE_RECEIVER_ON_TERMINAL_SQL(peri-resources/src/sessions/sqlite_store/session_data/mq.rs:135-139)PROMOTE_RECEIVER_WORK_INTENT_SQL(peri-resources/src/sessions/remote/session_mq.rs:109-113)结果行照常接纳:终态 target 只失去「被提升为 working」这一效果,MQ 行、child 终态与同批其他写入不变。设计文档
docs/design/thread-mq.md§5.2 同步一句守卫语义。测试
sessions::sqlite_store::session_mq_tests::terminal_settlement::finalize_does_not_promote_a_terminal_receiversessions::remote::session_mq_tests::settlement_tests::remote_finalize_does_not_promote_a_terminal_receiver两者都对
error/done/cancelled+idle三种终态 target 断言:结果行数为 1、child 写入done+idle、target 的(agent_status, work_state)完全不变。回归有效性已实测:临时移除两条 SQL 守卫后,两条新测试分别失败为
("error", "working")(local 与 remote 一致);恢复守卫后通过。验证矩阵
test --locked -p peri-resources --lib -- sessions::sqlite_store::session_mq_tests::terminal_settlementtest --locked -p peri-resources --lib -- sessions::remote::session_mq_tests::test --locked -p peri-resources --lib -- sessions::resources::tests::mq::test --locked -p peri-resources --lib(完整)fmt --all -- --check./scripts/check-changed.shgit diff --check未覆盖项
settle_retained_mq结算路径。Summary by CodeRabbit