Repository navigation
feat(assistant): add tested condition waits and simplify Matter settlement #6193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| <!-- | ||
| 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. | ||
| --> | ||
|
|
||
| # Matter condition waits | ||
|
|
||
| Matter can wait for a tested, machine-checkable condition as well as an absolute | ||
| fallback time. It keeps its own session, settlement review and inbox; no Goal is | ||
| created. Time-only waits remain supported by `MatterSettle`. | ||
|
|
||
| ## Agent workflow | ||
|
|
||
| 1. Do useful work now. Only wait when immediate continuation cannot help. | ||
| 2. Call `MatterConditionTest` with either custom JavaScript or a preset. It executes | ||
| against real permitted data and returns `checkerId`, `testedAt` and the result. | ||
| Inspect that result and the evidence: a syntactically valid checker can still | ||
| express the wrong condition. Fix and retest if necessary. | ||
| 3. Call `MatterSettle` with `disposition: "wait"`, | ||
| `waitingFor`, `condition: {checkerId, intervalMs}`, and an absolute fallback | ||
| time in `wakes`. The existing settlement review must approve this submission. | ||
| 4. The Host observes without model calls. A match, repeated observation failure, | ||
| or the fallback deadline creates one durable task event. The ordinary Matter | ||
| dispatcher resumes the same session; the Agent reassesses current facts. | ||
|
|
||
| Testing does not install a wait. A checker ID binds the task, code and parameters; | ||
| another task cannot reuse it. Changing the code or parameters requires another | ||
| test. Repeating the same test does not mutate an installed code version. | ||
|
|
||
| Example, using an already configured source whose `queryHelp` describes the | ||
| following query parameters: | ||
|
|
||
| ```json | ||
| { | ||
| "preset": "source-appeared", | ||
| "input": { | ||
| "source": "supplier.orders", | ||
| "query": {"orderId": "example-order", "status": "shipped"} | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Use the returned checker ID in a normal settlement, for example: | ||
|
|
||
| ```js | ||
| { | ||
| summary: "Shipment is not ready; awaiting confirmation before proceeding.", | ||
| // Optional note retains useful working context. No draft or revision is required. | ||
| disposition: "wait", | ||
| waitingFor: "Supplier confirms this order has shipped", | ||
| condition: {checkerId: "<tested ID>", intervalMs: 60_000}, | ||
| wakes: [{kind: "at", at: /* future absolute Unix milliseconds */}] | ||
| } | ||
| ``` | ||
|
|
||
| The shipped presets are: | ||
|
|
||
| - `source-appeared`: a narrowed source query returns at least one object. | ||
| - `session-revision`: a permitted session's `historyRevision` differs from the | ||
| supplied baseline. Input: `{source?, id, revision}`. | ||
|
|
||
| Custom code is an async JavaScript body, with `input` and `checkpoint` available. | ||
| It returns: | ||
|
|
||
| ```js | ||
| return { | ||
| status: "pending", // or "triggered" | ||
| reason: "Still awaiting a confirmed shipment", | ||
| evidence: [], // optional, at most seven short source references | ||
| checkpoint: {} // optional, bounded JSON cursor carried to the next check | ||
| }; | ||
| ``` | ||
|
|
||
| The first background check starts with `checkpoint = null`. Successful pending | ||
| checks persist their cursor. Errors do not advance it. For history queries, only | ||
| advance past records the checker has actually examined. | ||
|
|
||
| ## Read boundary | ||
|
|
||
| Both testing and background observation use Maka's existing isolated Code Mode | ||
| executor, with four explicit read capabilities: | ||
|
|
||
| | Capability | Arguments and behavior | | ||
| | --- | --- | | ||
| | `tools.SourceList({})` | Lists installed source IDs, descriptions, query help and scopes. | | ||
| | `tools.SourceQuery({source, query})` | Queries metadata and checks current permission for every returned object. Source-specific pagination stays explicit. | | ||
| | `tools.SourceRead({source, object})` | Reads a source object with current permission and version checks. Deleted objects retain their deletion status; unavailable versions are errors. | | ||
| | `tools.SessionRead({source, id, query})` | Reads permitted history using the existing source/session query service. `source` defaults to `maka`; type selection and pagination use that service's query parameters. | | ||
|
|
||
| No shell, Node imports, arbitrary network client, write tools, or model tools are | ||
| exposed to checker code. External services need an installed read-only source | ||
| adapter. This first version does not add file watching, webhooks or remote-host | ||
| checker execution. Existing source adapters determine data freshness; checking a | ||
| cached source does not implicitly synchronize it. | ||
|
|
||
| The existing executor bounds memory, CPU work, bridge calls and result sizes. | ||
| Each observation also has a 30-second read deadline. These bounds apply to a | ||
| small background probe, **not** to the Agent activation or the duration of the | ||
| task. One blocked source cannot occupy unbounded Host capacity. | ||
|
|
||
| ## Persistence and scheduling | ||
|
|
||
| - Checker definitions and observation records live in the existing Matter | ||
| SQLite database. Installing a condition is part of the same transaction as | ||
| settlement, event acknowledgement and fallback registration. | ||
| - The shared event observation engine supplies reconciliation, bounded | ||
| concurrency, durable attempts/checkpoints, backoff, cancellation and deadlines. | ||
| Its Goal bridge still requires authenticated Goal storage and Goal ownership. | ||
| Matter uses a separate owner-neutral store guarded by its Host lease and wait | ||
| revision, rather than fabricating a Goal. | ||
| - `intervalMs` defaults to 60 seconds and accepts 1 second through 24 hours. | ||
| Source cooldowns, errors and Host availability can delay a check. This is | ||
| polling, not a real-time notification guarantee. | ||
| - Repeated failed checks wake the worker for repair. A deadline independently | ||
| wakes it even if source checks cannot run. The shared observation budget also | ||
| wakes the worker on exhaustion; it never silently completes or pauses Matter. | ||
| - Observation starts only after the current activation ends. Review time uses | ||
| the original submission timestamp, so a fallback that passes during review | ||
| remains valid and becomes due after the activation finishes. | ||
| - Condition resolution and the unique inbox event commit atomically. A late | ||
| result, duplicate callback, or simultaneous fallback cannot enqueue a second | ||
| condition wake. Claiming the next activation retires the old condition. | ||
| - User amendments, pause, cancel and manual checks retire the condition and its | ||
| fallback. Old observation writes fail revision/ownership checks. Restart | ||
| resumes committed waits, including their cursor and retry state. | ||
| - `MatterTasks` includes the condition ID, state, attempts, next check time and | ||
| diagnostic, alongside the existing time fallback. | ||
|
|
||
| ## Verification | ||
|
|
||
| `packages/runtime-host/src/__tests__/matter-conditions.test.ts` exercises the real | ||
| code sandbox and SQLite store with controlled source responses and business time. | ||
| It covers presets, isolation, permission failure, immutable test IDs, review | ||
| rejection/invalidation, restart, checkpoints, concurrent waits, lost leases, | ||
| deadline races, cancellation and source recovery. | ||
|
|
||
| The native Host integration test in | ||
| `packages/runtime-host/test/assistant/proactive-matters/test/plugin.test.ts` runs | ||
| the registered tools through the actual assistant service: test a source query, | ||
| settle, change the source, wake the same session, read inbox evidence and complete. | ||
| Its Agent and review responses are controlled fixtures, not a paid-model test. | ||
|
|
||
| ## Settlement and task tools | ||
|
|
||
| `MatterSettle` accepts `disposition`, `summary`, optional `note` and `update`, plus | ||
| the existing wait condition and fallback fields. It does not require writing a | ||
| draft or entering a revision. Omitted notes preserve the existing note. | ||
|
|
||
| The Host validates the exact task input materialized in the Runtime ledger before | ||
| the calling tool event, then captures a revision for settlement/review. New input | ||
| before submission or during review invalidates the old decision. Observation-only | ||
| revision changes do not resend an unchanged Inbox. `wait` and `complete` still | ||
| require independent review; `continue` does not. Rejection/transport errors leave | ||
| the task active. Persisted submission identity prevents duplicate notifications. | ||
|
|
||
| Delegated workers see their own lifecycle tools directly, without the Bot's | ||
| Matter delegation/management tools; ordinary business tools remain available. | ||
| `MatterRead` can claim a queued activation and inspect context, but no separate | ||
| file reads or draft write are required for submission. Legacy files and stored | ||
| notes remain readable; existing tasks are not rebuilt. | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Add the required ASF header to the new document
This new Markdown file has no ASF license header. CI run 39413553154 for the exact current head fails in
npm run check:asf-headers, naming only this file; the local check reproduces it. The same classifier reports no missing headers in current main's source archive. Add the repository's normal Markdown ASF header so the CI job can reach the build and test stages.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AI-assisted follow-up (OpenAI Codex): verified at current head
466338d849e1d121f9156d31734d474b1e184089thatdocs/matter-condition-waits.mdnow starts with the standard ASF Markdown header (added in5dd3afb58). No additional code change is needed for this finding. Leaving thread resolution to the reviewer.