You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by "xxhZs (via GitHub)" <gi...@apache.org> on 2026/10/19 16:25:40 UTC

[PR] fix(runtime): preserve context history for prompt caching [maka]

xxhZs opened a new pull request, #6177:
URL: https://github.com/apache/maka/pull/6177

   Time and Inbox context used to be replaced at the end of each model request. Updating the clock therefore changed an existing request prefix, reducing cache reuse even when the conversation had only grown.
   
   Persist named runtime context as internal events and append a new value only when it changes. Historical values remain unchanged, retries reuse the same snapshot, and replay preserves event order. Split the matter clock from its Inbox so observation-only revision changes do not resend the Inbox. Context removed by compaction is refreshed afterward; internal context remains hidden from the chat transcript.
   
   Validation on current main:
   - 700 targeted tests passed: runtime history, context, retries, replay, compaction and recovery (662), core event decoding (29), Host composition/steering (7), and MatterController (2).
   - Core, runtime and runtime-host builds; UI and desktop type checks passed. Staged lint, formatting, license headers and diff checks passed.
   - Prior isolated real-model validation used GPT-6.1 Sol at medium effort with the modified runtime and actual MatterStore/Controller. A running Inbox amendment and a steering message both reached the next model request. Four calls retained the full previous input prefix; cache hits were 0%, 88.9%, 96.7%, and 96.6%. One earlier repeat still had a cache miss despite an unchanged prefix, so this does not guarantee provider cache availability or resolve every timeout.
   
   Real-model tools were read-only synthetic fixtures outside the repository, not a production business-workflow test. An earlier broader Host test process did not exit naturally and is not counted as passing; the relevant targeted Host tests completed successfully.
   


-- 
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): preserve context history for prompt caching [maka]

Posted by "xxhZs (via GitHub)" <gi...@apache.org>.
xxhZs merged PR #6177:
URL: https://github.com/apache/maka/pull/6177


-- 
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): preserve context history for prompt caching [maka]

Posted by "Astro-Han (via GitHub)" <gi...@apache.org>.
Astro-Han commented on code in PR #6177:
URL: https://github.com/apache/maka/pull/6177#discussion_r4316729164


##########
packages/runtime/src/runtime-context.ts:
##########
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import type { ModelMessage } from './model-protocol.js';
+import { runtimeContextProviderOptions } from './model-history.js';
+
+/** Compare only host-tagged context still present in the effective model history.
+ * Compaction may remove a snapshot; in that case the current value is sent again.
+ */
+export function changedRuntimeContexts(
+  contexts: readonly { readonly name: string; readonly text: string }[],
+  messages: readonly ModelMessage[],
+): { name: string; text: string }[] {
+  const latest = new Map<string, string>();
+  for (const message of messages) {
+    const name = message.providerOptions?.makaRuntimeContext?.name;
+    if (message.role !== 'user' || typeof name !== 'string') continue;
+    const text =
+      typeof message.content === 'string'
+        ? message.content
+        : message.content
+            .filter((part) => part.type === 'text')
+            .map((part) => part.text)
+            .join('');
+    latest.set(name, text);
+  }
+  const changes: { name: string; text: string }[] = [];
+  for (const context of contexts) {
+    const text = `Runtime context (${context.name}; host metadata, not a user request; later updates supersede earlier values):\n${context.text}`;

Review Comment:
   [P2] Update the Host integration fixtures for the new wrapped context history. The existing runtimeEnvironment() helper only recognizes the old plain prefix, while the Agent Graph/Swarm provider fixtures now mistake wrapped environment snapshots for user requests. Exact-head CI 39285344761 and five unchanged local Host cases fail (four failures, one cancellation); swapping only AiSdkTurn back to its parent makes all five pass, and adapting only the four corresponding fixture helpers makes those four pass with current production code. The cold WorkHub scenario also needs to distinguish historical topic instructions. Please update the fixtures and rerun the full Host suite.



-- 
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