You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by "testikun (via GitHub)" <gi...@apache.org> on 2026/09/03 06:42:51 UTC
[PR] fix(runtime): deduplicate in-flight context compaction [maka]
testikun opened a new pull request, #4624:
URL: https://github.com/apache/maka/pull/4624
## Summary
- coalesce identical concurrent history compaction requests per runtime session
- preserve the existing context-budget high-water trigger and provider overflow recovery
- keep fail-open/no-op behavior and durable status diagnostics unchanged
## Verification
- `npm --workspace @maka/core run build`
- `npm --workspace @maka/storage run build`
- `npm --workspace @maka/runtime run typecheck`
- `npm --workspace @maka/runtime run build`
- `npx biome check packages/runtime/src/ai-sdk-compaction.ts packages/runtime/src/__tests__/ai-sdk-backend.test.ts`
- all 63 `mid-turn-capacity-backend` tests
- focused in-flight deduplication test
Fixes #4360
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
Re: [PR] fix(runtime): deduplicate in-flight context compaction [maka]
Posted by "testikun (via GitHub)" <gi...@apache.org>.
testikun commented on PR #4624:
URL: https://github.com/apache/maka/pull/4624#issuecomment-5534409839
继续修正了一处并发边界:
- 去重 fingerprint 现在同时包含 checkpoint intent(phase、mid-turn head anchor、Memory extraction boundary),只有会产生相同 checkpoint 语义的请求才共享 provider summarizer Promise。
- 不同 Memory boundary 或 mid-turn intent 不会错误复用同一物理调用结果。
- 仍保留每个调用方独立的 checkpoint/ledger 记录;实际 provider usage 按一次物理 summarizer call 记录,避免重复计费。
- Runtime 构建通过;ai-sdk-backend 单文件测试 221 项全部通过。
- 新提交:`04d427ff4`。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
Re: [PR] fix(runtime): deduplicate in-flight context compaction [maka]
Posted by "testikun (via GitHub)" <gi...@apache.org>.
testikun commented on PR #4624:
URL: https://github.com/apache/maka/pull/4624#issuecomment-5535261899
Addressed the review findings on cb8ff3daa.\n\n- Rebased onto current ; the removed path is gone and the compaction test now uses the supported policy.\n- Coalescing now shares only the physical summarizer call. Each caller keeps an independent abort wait; one caller stopping no longer cancels work still needed by another caller, and the shared provider signal is cancelled only after all consumers detach.\n- Concurrent callers that produce the same effective checkpoint now record the already-durable checkpoint object, preserving one checkpoint ID and preventing an orphaned rider ID; the existing forward-progress authority remains .\n- Removed the forwarding wrapper and centralized folded-run-header filtering before fingerprinting.\n\nVerification on the rebased head: Runtime typecheck, Biome, Runtime build, and the focused compaction tests passed (including 11 model-history tests and the coalescing regression).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
Re: [PR] fix(runtime): deduplicate in-flight context compaction [maka]
Posted by "testikun (via GitHub)" <gi...@apache.org>.
testikun commented on code in PR #4624:
URL: https://github.com/apache/maka/pull/4624#discussion_r3930646856
##########
packages/runtime/src/history-compact-checkpoint-coordinator.ts:
##########
@@ -145,3 +153,35 @@ export class HistoryCompactCheckpointCoordinator {
this.cleanups.set(sessionId, tracked);
}
}
+
+function hasSameEffectiveCoverage(
Review Comment:
Implemented in cb8ff3daa. The durable-checkpoint race now reuses the already-current checkpoint object for an equivalent concurrent fold, so the rider records the same checkpoint ID instead of advancing the session pointer to a second ID. The comparison ignores only identity and timestamp fields and retains the full checkpoint shape, while canReplaceHistoryCompactCheckpoint remains the authority for forward progress. Verified with Runtime typecheck, build, and focused model-history tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
Re: [PR] fix(runtime): deduplicate in-flight context compaction [maka]
Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han closed pull request #4624: fix(runtime): deduplicate in-flight context compaction
URL: https://github.com/apache/maka/pull/4624
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
Re: [PR] fix(runtime): deduplicate in-flight context compaction [maka]
Posted by "testikun (via GitHub)" <gi...@apache.org>.
testikun commented on PR #4624:
URL: https://github.com/apache/maka/pull/4624#issuecomment-5534475646
已继续处理并重新提交。
- 已合并 GitHub 当前最新 `apache/main`,解决目标分支冲突。
- 适配最新 compaction contract:保留 effective-history summarizer/provider-call 边界去重,并将 checkpoint intent(phase、mid-turn head anchor、Memory extraction boundary)纳入 fingerprint。
- 每个并发 Turn 仍保留自己的 checkpoint/ledger 记录;相同语义只共享一次物理 summarizer 调用,避免重复计费。
- Runtime 构建通过;最新主线合并后的 `ai-sdk-backend` 单文件测试 222 项全部通过。
- 新提交:`3db6c4dbf`。
- 按本地测试范围约束,未运行完整 Host 生命周期套件。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
Re: [PR] fix(runtime): deduplicate in-flight context compaction [maka]
Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han commented on PR #4624:
URL: https://github.com/apache/maka/pull/4624#issuecomment-5549057136
Thanks for landing every point from the last two rounds; the abort lifetime, the checkpoint identity and the rebase are all done as asked. Having re-derived the entry paths on current `main`, I think the PR should close rather than merge, and this time it is provable rather than "no reproduction yet".
**The race cannot happen on a supported path.** The Host claims a root execution synchronously: `context-coordinator.ts:116-132` calls `#executions.prepare()` first and only then awaits `#preflight`, and `hosted-execution-admission-registry.ts:76-86` is a synchronous check-and-set per session. A second `context.compact` gets `session_busy`; a normal Turn (which contains the mid-turn `context_limit` compaction) is the same root execution; the Agent Graph overflow path takes the same `reserveRootTurn` slot (`root-turn-coordinator.ts:573-599`). Child sessions have their own backend instance, so `inFlightHistorySummaries` is never shared. And this PR's own `checkpointIntent` scoping finishes the job: `pre_turn` and `mid_turn` never coalesce, and two mid-turn compactions from different Turns differ in `headAnchor.turnId`. The only thing the coalescer can ever merge is two concurrent `pre_turn` manual compactions, which the Host guarantees do not exist.
**What it costs.** One resident `Map`, one `Set<AbortController>`, one `Set<symbol>` plus one extra controller per compaction, `waitForAbortablePromise`, `invocationsForFoldedEvents`, and a second checkpoint-replacement predicate (`history-compact-checkpoint-coordinator.ts:170-186`) that runs on every write and has no test. Nothing is deleted. The regression test drives `backend.compactHistory` twice on one instance, which bypasses the owner of "two concurrent compactions", the Host admission; written at the Host layer it would receive `session_busy`. #4360's two reported problems are already fixed on `main` by #4348/#4653 and `/compact`, and this PR only `Refs` it.
Two things I would keep, in their own small PR if you want them: `abortHistoryCompact` as a `Set` rather than one nullable controller (a real hardening even on serial paths), and the `invocationsForFoldedEvents` dedup, but only after deciding whether the filter should change the summarizer's actual input (`ai-sdk-compaction.ts:411-414`, `:1178`), because on `main` the callers pass the full set and only the fingerprint filters.
Closing. If there is an entry into `summarizeWithFailureCircuit` for one session that does not go through root-turn admission, please reopen with that path and I will look again.
Evidence boundary: static read of `12bb2c3e` (30 commits behind) and current `main`; no build, no tests, no race constructed.
AI-assisted review: drafted with Maka; I verified the admission ordering, the intent scoping and the test's entry point myself.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
Re: [PR] fix(runtime): deduplicate in-flight context compaction [maka]
Posted by "testikun (via GitHub)" <gi...@apache.org>.
testikun commented on PR #4624:
URL: https://github.com/apache/maka/pull/4624#issuecomment-5535267711
Addressed the review findings on cb8ff3daa.
- Rebased onto current apache/main; the removed ContextBudgetPolicy.maxHistoryEstimatedTokens path is gone and the compaction test now uses the supported historyCompact policy.
- Coalescing now shares only the physical summarizer call. Each caller keeps an independent abort wait; one caller stopping no longer cancels work still needed by another caller, and the shared provider signal is cancelled only after all consumers detach.
- Concurrent callers that produce the same effective checkpoint now record the already-durable checkpoint object, preserving one checkpoint ID and preventing an orphaned rider ID; the existing forward-progress authority remains canReplaceHistoryCompactCheckpoint.
- Removed the forwarding compactHistoryOnce wrapper and centralized folded-run-header filtering before fingerprinting.
Verification on the rebased head: Runtime typecheck, Biome, Runtime build, and the focused compaction tests passed (11 model-history tests, including the coalescing regression).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
Re: [PR] fix(runtime): deduplicate in-flight context compaction [maka]
Posted by "testikun (via GitHub)" <gi...@apache.org>.
testikun commented on PR #4624:
URL: https://github.com/apache/maka/pull/4624#issuecomment-5527371532
已处理并重新提交。
- 已将并发去重下沉到 effective-history summarizer/provider-call 边界。
- 每个并发 Turn 保留自己的 checkpoint 和 ledger attribution。
- 修正 run headers 与 fingerprint 的过滤一致性。
- 并发测试现在在 Promise 完成后验证只发生一次 summarizer 调用,同时验证两次独立 checkpoint 记录。
- 已将 issue 关联改为 `Refs #4360`,避免错误关闭原 issue。
- Runtime 构建通过;针对性 ai-sdk-backend 单文件测试 221 项全部通过。
- 按本地测试范围约束,未运行完整 Host 生命周期套件。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org
Re: [PR] fix(runtime): deduplicate in-flight context compaction [maka]
Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han commented on code in PR #4624:
URL: https://github.com/apache/maka/pull/4624#discussion_r3927056992
##########
packages/runtime/src/__tests__/ai-sdk-backend.test.ts:
##########
@@ -4690,6 +4690,93 @@ describe('AiSdkBackend model history', () => {
assert.equal(result.contextBudget?.compactionDecisions?.[0]?.decision, 'replaced');
});
+ test('coalesces identical in-flight compactHistory requests', async () => {
+ const recorded: HistoryCompactCheckpoint[] = [];
+ let summarizeCalls = 0;
+ let releaseSummary!: () => void;
+ const summaryReady = new Promise<void>((resolve) => {
+ releaseSummary = resolve;
+ });
+ const backend = createTestAiSdkBackend({
+ sessionId: 'session-1',
+ header: header(),
+ appendMessage: async () => {},
+ connection: connection(),
+ apiKey: 'sk-test',
+ modelId: 'mock-model-id',
+ modelFactory: () => completionModel(),
+ tools: [],
+ newId: idGenerator(),
+ now: monotonicClock(),
+ contextBudget: {
+ name: 'in-flight-dedup-test',
+ maxHistoryEstimatedTokens: 10_000,
Review Comment:
P1: this is the line CI dies on. `ContextBudgetPolicy.maxHistoryEstimatedTokens` was removed outright by #4559, so on the merge ref this is `error TS2353` and the whole `test` job fails at Build. The rebase is not mechanical: the policy no longer carries a token ceiling at all, and this branch still reads `policy.maxHistoryEstimatedTokens` in `ai-sdk-compaction.ts` (`:435`, `:468`). After the rebase the test needs a different way to make compaction fire, through `policy.historyCompact`.
##########
packages/runtime/src/history-compact-checkpoint-coordinator.ts:
##########
@@ -145,3 +153,35 @@ export class HistoryCompactCheckpointCoordinator {
this.cleanups.set(sessionId, tracked);
}
}
+
+function hasSameEffectiveCoverage(
Review Comment:
P2: this is a second predicate for "may this checkpoint replace the current one", next to `canReplaceHistoryCompactCheckpoint`. Two costs. First, it hand-enumerates the checkpoint's fields, so any field added to `HistoryCompactCheckpoint` later is silently treated as not mattering. Second, it exists only because the two checkpoints are genuinely different: `checkpointId` hashes `highWaterSeq`, which defaults to `max(now, maxEventTs)` (`history-compact-checkpoint.ts:293-309`), so the rider's id differs from the one the first turn already reported in its `complete` diagnostic `boundaryIds`. Line 101 then flips the session pointer to the rider's checkpoint, and the next compaction chains `previousCheckpointId` to that one, orphaning the first id.
Smaller fix that needs no new predicate: when the durable checkpoint already covers the rider's fold, return through the existing `already_compacted` outcome with the durable `checkpointId`. One checkpoint, one id, and `canReplaceHistoryCompactCheckpoint` stays the only authority.
##########
packages/runtime/src/ai-sdk-compaction.ts:
##########
@@ -399,7 +416,11 @@ export class AiSdkCompaction {
source: {
foldedRuntimeEvents: [...coveredRuntimeEvents],
...(input.runtimeContextRunHeaders
- ? { runHeaders: input.runtimeContextRunHeaders }
+ ? {
+ runHeaders: input.runtimeContextRunHeaders.filter((run) =>
Review Comment:
P3: this filter and the `foldedRunIds` filter in `summarizeWithFailureCircuit` (`:559-561`) are the same rule over the same set, since `foldedRuntimeEvents` is `coveredRuntimeEvents`. Keeping it here is the right call, so the one in the fingerprint can go.
##########
packages/runtime/src/ai-sdk-compaction.ts:
##########
@@ -287,15 +297,22 @@ export class AiSdkCompaction {
/** Abort an in-flight manual history compaction (called by AiSdkBackend.stop). */
public abortHistoryCompact(): void {
- this.historyCompactAbortController?.abort();
+ for (const controller of this.historyCompactAbortControllers) controller.abort();
}
public async compactHistory(
input: Omit<BackendCompactHistoryInput, 'runId'> & { runId: string | undefined },
automaticMemoryBoundary?: HistoryCompactMemoryExtractionBoundary,
+ ): Promise<AiSdkCompactHistoryResult> {
+ return this.compactHistoryOnce(input, automaticMemoryBoundary);
Review Comment:
P3: `compactHistory` is now a pure forward to `compactHistoryOnce` with no added behavior. Rename `compactHistoryOnce` back to `compactHistory` and drop the wrapper.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org