Repository navigation
perf(ai): consolidate short transaction boundaries - #312
Merged
Merged
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Current delivery · 2026-11-15
The write-transaction assessment is complete for the fixed workload. Its goal was to determine whether further safe consolidation is justified, not to require a lower count. A current-master integration recheck confirms 46 commits, 38 with writes, with complete attribution and unchanged model/tool/history and replay assertions. The transaction-boundary document now explains why none of the measured adjacent write boundaries can be transparently merged under the existing contracts. This is not a universal lower bound; no production change was made in the final evidence commit. The broader R3 workload/physical-I/O and designated R8 database-server and application acceptance remain separate, not marked passed.
Head
788a5b64is Ready; natural CI is pending at publication. Earlier Draft statements and measurements below are historical.Objective
Reduce repeated short transactions belonging to the same business operation, from the merged
776caf18baseline. Judge candidates from first principles: who needs each durable fact and when, atomicity, external effects/recovery, read/write relocation and lock cost. A lower count alone is not success. This PR also carries explicit confirmed Task-failure acceptance (R8); existing preload receipt capabilities (R4) are reused rather than reimplemented.Current slice: confirmed terminal read reuse; write target remains open
linktools-ai/docs/measurements/transaction-boundaries.md.wait()can reuse the same retained, fully confirmed local terminal-publication helper already used after polling. No new cache or owner. In the held-publication inline-result fixture, one successful late wait changes 3 SELECT / 2 read-only commits → 0 / 0; no receipt remains 3 / 2.nonetool-policy diagnostic: 34 total / 26 write commits. This is existing behavior with a different policy, not an optimization; the default fixed baseline remainsreplay_safe.Terminal content-read slice: duplicate owner rows
80c030f1removes a duplicate owner/additional-record role within one existing content-read query. It retains the same-store/key and physical payload-routing boundaries, fresh owner observation, content validation, hold reconciliation and CAS. No new cache, protocol or transaction.R3 slice: exact History window metadata
9bb77e84batches the transcript head and seek hint in their existing owner transaction for nonempty, positive-offset windows. No public API, durable format, cache policy, lock or transaction-boundary change.include_content=Falsestill suppresses content after projection. Broader R3 queries, storage growth and designated application validation are not complete.ad9d2c3153e412aa098dd76de61d877a854e14eaand082b09527f417fcea3c7adc9f6684e768592f626passed public start/wait, call/return identity and order, two-page exact reads, content-inclusive controls, same-version reopen, missing selectors and tenant rejection. The identical probe ran in the same Python/dependency environment: 2 cases passed on each pin. Warm exact reads confirm 12 → 11 SELECT and 7 → 7 read commits per query; transcript decoder input volume is unchanged. Cold reads also save one SELECT. This is a read-window comparison, not whole-execution, physical disk/network I/O, or write-transaction improvement.R8: explicit acceptance of confirmed partial Task failure
082b0952addsTaskEffectResolution("failed", error_code=..., safe_details=...)through the existing Task/Execution owners. The explicit graph-control request must retain the admitted principal, expected fence and idempotency identity; diagnostics are bounded to 8 KiB.failedremains recovery-required; this does not turn an ordinary exception or unknown effect into confirmed failure.TASK_NOT_READY. The owner must first use the existing explicitrun.cancel(...)operation and wait for drain/settlement, then retry failure acceptance. This patch does not automatically cancel siblings.R4: reuse existing structured Skill receipts
SkillReadReceiptsupport from #293 already exposes preload deliveries inHistory.read_model_interactions(...)viarequest["preload_skill_reads"], together with the enclosing execution/run/model-request identity.load_skillreads expose additional resource receipts throughHistoryItem.skill_read. Resources not delivered, or not actually entering the request, do not receive fabricated read receipts.Candidate findings
Admission/activation: early activation changes delayed-worker takeover; delaying it to the first Native request moves authority past model/context/capability preparation. No unchanged-contract consolidation is established.
Native/Execution terminal: current Native confirmation and
SnapshotSavedEventhappen before Runtime output validation/cleanup. Existing lifecycle/capability receipts do not supply a safe pending Native view or all-exit settlement protocol; simple staging is excluded.Final response/terminal snapshot: messages match, but step advances 3→4. A temporary counterfactual saves one descriptor INSERT per turn, no transaction; bodies already share a source. No production change proposed.
Terminal preparation: one read-only transaction per turn depends on real history/head/replay metadata. Eliminating it requires preparation/publication restructuring across owners, not blindly moving external preparation inside a write transaction.
Native producer CAS and tool-result/native-event publication already share their respective write transaction. There is no separate guard commit to delete in this measured path. These findings do not prove 38 is a universal minimum.
Additional Trace-on/tool-heavy check at
530df312, using the same two-turn semantic assertions and explicit synchronous Trace: all 6 tool-result recorder calls perform one write commit each; nested fallback tool-start calls already do no SQL. Of 18 tool-start invocations, only the 6 real pre-tool starts write. All 8 model-start and 8 model-complete recorder calls also perform one write commit each. No same-action duplicate write was established, so no extra staging/batching layer is proposed. This is a separate Trace-on configuration, not a reduction of the default 38 writes.For representative application comparisons, keep the declared tool effect policy fixed and count effect admission/settlement separately.
replay_safeis not effect-free; read-only hints alone do not justify removing durable effect boundaries.A separate one-Task SQLite probe at
e03710ccchecked the final dependency-hold release through the real service and retention owner. The action used 5 total commits / 2 write commits, 9 SELECT and 2 UPDATE. The first cleanup attempt returned false while the durable hold remained and used 2 read-only commits / 2 SELECT; the later attempt succeeded. This identifies read overhead, not a redundant write transaction. No reordering is proposed without preserving cleanup ownership and cancellation/failure settlement; the original 38-write workload is unchanged. The private bounded probe passed once; it is not distributed-backend or full-workload acceptance.Necessary boundaries and non-goals
No database transaction across model/tool calls or user hooks; preserve producer/CAS fences, same-version recovery, cancellation, unknown outcomes, deferred tools, authorization and observation visibility. Do not change
auto_recover, merge retention before late holds settle, or introduce a parallel model-fact owner. Useful small query projections remain allowed. Wider IO and application acceptance remain separate from this synthetic upstream fixture.Validation
Read-reuse slice: 65 focused receipt/retention/exact-context tests passed; final receipt suite with opt-in SQL measurement 15 passed (overlapping, not 80 distinct tests). Fixed default probe 1 passed, unchanged 46/38 and 31/129/44 SQL totals. Original replay/history/effect assertions retained.
Earlier separate effect-free diagnostic: 1 passed, differing policy explicitly recorded, not a candidate improvement.
Repository manage Ruff gate and
git diff --check: passed.Independent review of the read-reuse production change, regressions and measured scope passed with no must-fix. Public evidence and reproduction instructions are in the measurement document.
Prior exact head
fc92b8d6natural CI 43539839206: 21/21 success.Natural CI 43541287384 at
530df312exposed 3 distinct incomplete test fixtures across both Python versions: they bypassed construction and omitted the already-existing retained-publication default.52a9edb6adds thatNoneinitialization only; production code, authorization/timeout assertions and timeout values are unchanged. The 3 failures were reproduced before the fix; 135 focused tests passed afterward, including both complete affected files and real-construction receipt/result-read tests. Independent review passed.Prior head
52a9edb6natural pull-request CI 43542147907, attempt 1: 21/21 jobs success, completed at 2026-11-14 01:50:01 UTC. The Trace-on diagnostic also passed its 8-model/6-tool/16-history and replay assertions. No manual CI dispatch/rerun.R3 head
9bb77e84natural pull-request CI 43559195820: 21/21 jobs success.Prior exact head
082b0952natural pull-request CI 43559916299, attempt 1: 21/21 jobs success. No manual dispatch/rerun. The PR remains Draft because the broader R3 objective and designated acceptance are not closed.Prior head
80c030f1natural pull-request CI 43578018551 completed with 19 successful jobs, one failed runtime shard and its failed aggregate. The Python 3.15.2 shard reported onecancel_committimeout; 2,596 other tests in that shard passed. This was not treated as a green head or retried manually.Cancellation settlement correction
e03710ccregisters an already-cancelling worker in the existing cancellation-request set before its first settlement await, only when that exact task is still the installed worker. A later public cancellation drains the same settlement rather than cancelling it again. No new state, protocol, timeout or effect assumption is added.082b0952also fails the same regression withWAIT_TIMEOUTand an unknown cancellation result, so this is not attributed to the80c030f1returned-row optimization.CANCELLEDassertions remain. 27 joint-boundary/cancellation-quiescence tests and 15 focused remote-cancel, concurrent-hold, stale-worker and confirmed-Task-cancellation cases passed on Python 3.12.14. Architecture/Ruff gates and independent static review passed. No timeout was widened or assertion relaxed; Python 3.15 is left to natural CI.e03710ccnatural pull-request CI 43579471334 completed with 21/21 jobs successful, including both runtime Python matrices. No manual dispatch/rerun. This is a correctness correction, not another I/O improvement; the 38-write objective and wider acceptance remain open, and the PR remains Draft.本轮:持久 hold 释放前不做无效清理
同一真实 SQLite 小样例:总提交 5→3,SELECT 9→7,写提交仍为 2。释放持久 hold 和实际终态所有权移交顺序不变;原本过早发起、必然被 hold 阻止的数据库读不执行,先交还瞬态 claim,不丢失释放意图。34 项窄验证通过,包含失败/取消不占死 gate,独立静态复审未发现本切片必须项。当前 head
a8b7933512856eda49d7d9debbb77f8fa3540214仍 Draft,待该 head 自然 CI;不宣称原场景 38 次写提交目标已解决。修复
a8b79335的 CI 测试卡住43589739377 两个回归用例分别依赖错误替身:一处没有接受真实清理回调的
terminal_commit;另一处名为立即终态、实际只持久化 STARTED。两个用例随后无界等事件,掩盖错误。当前提交4bef82d71e1865b5e99f57fef7122a63d35a848d只修测试:持久化真实 SUCCEEDED 记录,匹配实际回调契约,断言 durable hold 已移除才启动清理,并在超时后释放和回收任务。失败已分别重现,官方局部入口运行三个文件,共 35 passed,独立静态复审闭环。未修改生产优化、未手动重跑 CI。最新 CI
43591283468 15/15 成功。实际 checkout 是
bc2ef50,日志确认该合成合并为 head4bef82d7+ 当时 master9a9fdecd。保留 Draft:这闭环的是清理顺序修复,整体写事务目标和真实多端数据库验收未由此证明。Write-count recheck on 2026-11-14
Independent reruns of the fixed SQLite two-turn probe at current master
a642b557and this head both passed. Both returned 31 SELECT, 129 INSERT, 44 UPDATE, 46 total commits and 38 write commits; model, tool, history and replay obligations remained unchanged. The earlier 5→3 focused hold scenario is not a reduction in this two-turn workload. Terminal publication already settles Session in the same commit. The later retention commit preserves the post-terminal dependency-hold window; repository instruction scope also must survive a failed execution barrier CAS. Neither boundary was removed. No new production change; the broader transaction target remains open.Pending replay original reads
On one real SQLite response with two replayed tool calls, original-message range reads dropped 2 → 1. Reuse is limited to the existing 32-candidate window; the per-call name/argument integrity checks, ordering, cursor freeze and filtering remain. The focused file passed locally (9 tests); exact-head natural CI is separate. This is an R3 read slice only, not a reduction in the two-turn 38 write commits.