Repository navigation
Agents read and retry their own deferred extraction batches with memory.extraction_status_mine and memory.extraction_retry_mine - #138
Merged
Conversation
…ueued, by id memory.extraction_status is hidden from MCP: it is the namespace-wide view, every principal's and user's batches up to 500 a call, so an agent that defers memory.set_from_messages over MCP had no way to follow up on its own batches. memory.extraction_status_mine takes 1-20 queue ids and answers only the batches the calling principal queued (the enqueuer the queue row's payload stores) in the named namespace, inside the token's read scope; every other id comes back in `unknown`, as one never queued does. It is a read-only viewer op in SCOPED_OPS, callable by tool name and through loom_op (no roster lists it), drawing from the namespace's memory rate-limit bucket. The id and the scope's user and session are sort-key columns every version of a batch shares, so they filter in PREWHERE under FINAL and only the asked batches' payloads are read. The hidden op's MCP refusal now names this one. Generated: the SDK op tables and client, the operations reference, the SDK surface snapshot and the op's two analyzer shapes. Signed-off-by: pufit <[email protected]>
…batch status The extraction page and the memory architecture say which op reads the namespace's queued batches and which the caller's own by queue_id, and the MCP reference names memory.extraction_status_mine beside namespace.list_mine as the bounded variant of a hidden namespace-wide view. Signed-off-by: pufit <[email protected]>
…l that queued it A new integration module, run again in CI's auth-on isolation step: the queuing principal reads its batch over MCP (loom_op) and HTTP; another principal in the namespace, a token for another namespace, the queuing principal asking in another namespace and the same subject in another org get the id back in `unknown` or the namespace gate's refusal; the hidden namespace-wide op still answers OP_NOT_ON_MCP and names the bounded one. The read-scope suite adds one principal's tokens pinned to two users: each defers a batch, and the first user's token gets the other's id in `unknown` while the principal's namespace-wide token reads both. Its walks and the leakage walk now build the op's body. Signed-off-by: pufit <[email protected]>
…once more A deferred batch whose replays all failed stays `failed` until the queue's TTL removes it, and nothing could run it again once the cause was fixed. memory.extraction_retry_mine takes the same 1-20 queue ids and bounds as memory.extraction_status_mine: each `failed` batch the calling principal queued in the namespace, inside the token's read scope, is rewritten `pending` (every column carried) with one attempt left under extraction_queue_max_attempts, so the next pass replays it once and a failure marks it `failed` again. A batch still waiting or done is left alone (`not_failed`); any other id is `unknown`. It is a writer op in SCOPED_OPS, callable by name and through loom_op (not on a read-only connection), in the memory rate-limit bucket; a retried call finds the batch pending and leaves it. Both ops read through one caller-bound query. Generated: the SDK op tables and client, the operations reference, the SDK surface snapshot and the requeue read's two analyzer shapes. Signed-off-by: pufit <[email protected]>
The extraction page and the memory architecture say that the principal that queued a failed batch can replay it once more with memory.extraction_retry_mine, and the MCP reference names it as the bounded status op's write twin. Signed-off-by: pufit <[email protected]>
With the batch marked failed in the store, another principal's retry gets the id back in `unknown` and changes nothing, the queuing principal's retry over MCP puts it back to `pending`, and a second call finds it waiting and leaves it. Signed-off-by: pufit <[email protected]>
… failed, and match no batch for a principal-less token Review fixes: - Both ops' read runs under own_write_reads: a deferral, or a retry's requeue, may have landed a moment ago on another replica, and a stale `failed` must never be put back over a batch already running again. - memory.extraction_retry_mine reads the asked batches' states first and the full rows of the failed ones only, and requeues those still failed on that second read. - While the org's model calls are switched off the retry puts nothing back and answers the failed ids in a new `model_calls_off` field: the batch could only wait, and the switched-off drop would record it dropped again on each try. An unread switch refuses the call. Once the org is back on, a retry buys the one replay, also for a batch that drop marked failed. - A token that names no principal (writer_actor empty although a token is present) matches no batch, rather than the ones a dev-mode server queued without one. - A read scope these ops cannot complete (a session scope, or a user scope with no pinned user) is refused saying the op takes no user_id or session_id, instead of asking for one in the request body; the gate words it so for any scoped op without those fields. - The enqueue docstring names the ops that read the queue_id. Tests: a requeue followed by the worker's mark_error is failed again (exactly one more replay); the switched-off and unread-switch cases; the two-step read; the consistency scope; another org's batch on clickhouse-local; the refusal's wording for both scopes. The analyzer case now drives the full-row read too. Signed-off-by: pufit <[email protected]>
… at the batch ops The extraction page says the principal is the token's kind:subject (each Setup-page or delegated token its own, so a newly minted token, another client or the creator do not see each other's batches; subjects compare as stored), which read scopes the ops refuse, what an auth-off call sees, and that a retry puts nothing back while the org's model calls are switched off. The memory architecture notes the consistent read. memory.set_from_messages's MCP description names the status and retry ops, reached via loom_op. Signed-off-by: pufit <[email protected]>
… takes the batch Only the retry case depends on a batch's state. It checks the batch is still pending before marking it failed and after the retry, and skips on a server whose extraction worker claimed it instead of racing the worker; the module docstring says so. Signed-off-by: pufit <[email protected]>
…n, not waiting requeue_own_failed reported every failed id it did not put back as not failed. One the full-row read no longer finds (erased, or past the TTL since the states were read) is now in no list, so the handler answers it `unknown`; one another retry put back meanwhile stays `not_failed`. Signed-off-by: pufit <[email protected]>
zlareb1
approved these changes
Oct 21, 2026
Member
Author
|
Re-opening to re-run CI against current main (the last run predates the fixes merged on main). |
Signed-off-by: pufit <[email protected]>
Update only the observed failed row versions in place. Delayed or repeated requests keep newer worker results and never copy payloads across erasure. Signed-off-by: Lareb Zafar <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
Replacing the shared monotonic clock can expire the model-call switch snapshot on a short-uptime runner. Replace only the hold module clock so unrelated caches keep real time. Signed-off-by: Lareb Zafar <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]>
A long integration run can outlive the session token. Fresh per-test credentials keep the one-hour lifetime and preserve caller-supplied keys. Signed-off-by: Lareb Zafar <[email protected]>
An adaptive queue may flush its first request immediately after an idle period. Use a fixed window for the shared-flush assertion and drain tasks even if the cleanup flush fails. Signed-off-by: Lareb Zafar <[email protected]>
Clear graph-write buffers and timers at teardown so model transitions do not inherit pending work. Wait for a settings reset before reading the baseline on another worker, and check that cleanup succeeds. Signed-off-by: Lareb Zafar <[email protected]>
Signed-off-by: Lareb Zafar <[email protected]> # Conflicts: # tests/unit/conftest.py # tests/unit/test_integration_credentials.py
…t day is expired requeue_own_failed skips batches whose earlier retry is still unfinished in system.mutations, found by a tag in the command, and answers them requeued. A failed batch queued 29 or more days ago is reported in a new expired list instead of being resubmitted for drop_expiring to drop again. The update stamps updated_at with now64 on the server. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lareb Zafar <[email protected]>
…te binds the time The lookup spelled its quote as '\'' in a plain Python string, which reached ClickHouse as ''' and never matched; it uses char(39). The update stamps updated_at from a bound epoch instead of now64(), which a replicated table refuses in a mutation. The duplicate test now runs the real lookup against an unfinished mutation, the analyzer stub row carries past_last_day so the corpus reaches every statement again, the enqueuer expression is one constant, and the docs list the retry with the other mutation call sites. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lareb Zafar <[email protected]>
…atch An earlier retry's mutation can still be unfinished on other parts after the worker has failed the batch again at a newer version; the lookup now matches each batch's id and version in the stored command, so that newer failure is submitted. Requeued is built by keyword, list_status reads the shared status columns, and the lifecycle diagram shows the retry. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lareb Zafar <[email protected]>
…cks behaviour only Requeued is built by keyword at every site, the batch-id bound names both ops, and the stub test keeps only what a request must not do: wait on the mutation or insert a row. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lareb Zafar <[email protected]>
The duplicate lookup now runs before the model-call switch, so a batch whose earlier retry is still to apply is answered requeued, not model_calls_off. The read-scope error reads the input model's fields directly, and the integration module states that it needs background workers off. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lareb Zafar <[email protected]>
…he retry returns once The op docstring and feature page say an accepted, unapplied retry stays requeued after a switch-off, and that two simultaneous calls can each submit an update. requeue_own_failed decides the switch-off once and returns once, with the update in its own helper. A test pins the read-scope wording for other scoped ops without identity fields. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lareb Zafar <[email protected]>
memory.extraction_status and memory.extraction_status_mine share _counts, so a new queue state cannot count as pending in one and not the other. requeue_own_failed names its retryable ids and its rows to submit apart from the read, and the handler's result is outcome. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lareb Zafar <[email protected]>
…L text The clickhouse-local isolation test adds a batch in another session of the same user and checks own_session returns only its own; the two tests that matched SQL substrings are replaced by one that the transcript is never selected. Each _mine entry in SCOPED_OPS carries its own comment. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lareb Zafar <[email protected]>
…op record stays The feature page says so and a clickhouse-local test pins it. The status isolation test checks that no returned row carries the transcript, replacing the SQL-text stub, and SCOPED_OPS carries one comment naming both _mine ops. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lareb Zafar <[email protected]>
…OPS lists the ops bare The op docstrings already say the _mine ops read the caller's own batches inside its scope, so the list carries no comment that could seem to cover its neighbour. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lareb Zafar <[email protected]>
…a read helper _read_scope_error's docstring names ops whose input has neither user_id nor session_id, as its check does, and the isolation test's status calls go through _read. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lareb Zafar <[email protected]>
Only sort-key columns sit in it, so every version of a batch filters alike, and the payload is read for the asked ids only. The isolation test calls its status reads through _write, whose docstring now says it serves reads too, instead of an alias. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Lareb Zafar <[email protected]>
Merged
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.
Related: #111
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
Agents can inspect and retry their own deferred extraction batches over MCP, HTTP and the SDKs.
memory.extraction_status_minereports up to 20 batch ids, andmemory.extraction_retry_minegives failed batches one more attempt.Why
An MCP caller needs the status of a deferred
memory.set_from_messagesrequest and a way to retry it after fixing a failure. The namespace-wide status operation stays hidden from MCP because it includes other principals' batches. The caller-bound operations answer foreign and missing ids with the sameunknownresult.Scope and risk
Both operations require the stored enqueuer to match the caller's principal in the authorized namespace and the token's user and session scope. Status reports
heldconsistently with the namespace-wide operation. Ownership uses the queue's enqueuer column, falling back to the stored payload for rows created before that column existed.Retry reads states first and submits an asynchronous in-place update for the exact failed versions observed.
requeuedmeans accepted; status eventually changes topendingwith one attempt left. The mutation binds every sort-key identity field, the version, namespace, principal and read scope. It preserves payload and version, so a newer worker result stays current and a late or cancelled request cannot restore erased bytes.A retry asked again for the same failed version before its update finishes is answered
requeuedwith no second mutation: the handler finds the unfinished one insystem.mutationsby a tag and the batch's'<id>', <version>)in its command. A batch that failed again at a newer version is submitted anew. Sequential polls and SDK retries therefore do not pile up mutations on the queue table ahead of an erasure's delete; two calls arriving at once can each submit one, and the later one changes nothing. A failed batch queued 29 or more days ago comes back inexpiredand is not resubmitted, sincedrop_expiringwould drop it again before the 30-day TTL.Waiting and completed batches stay unchanged. A switched-off organization leaves failed batches in
model_calls_off, except one whose earlier retry is still to apply, which staysrequeued; an unread switch refuses the retry. Queue retention and worker identity checks still apply.Compatibility, rollout and rollback
memory.extraction_status_mineand writer operationmemory.extraction_retry_mine. Both takeorg,namespaceand 1–20queue_ids, each at most 64 characters. Status returnsbatches,unknown,pendingandfailed; retry returnsrequeued,not_failed,model_calls_off,expiredandunknown.loom_op, without adding to MCP listings.loom_oprefuses retry on thereadonlytoolset. The namespace-wide status refusal points to the caller-bound operation. An incomplete read scope on any scoped operation whose input takes nouser_idorsession_id(these two, and for examplememory.get_by_id) now gets an error that says so, instead of one asking for the field in the request body; operations that take the fields keep the old wording.Tests
tests/unit/test_extraction_status_mine.pyandtests/unit/test_extraction_retry_mine.py, on the production table inclickhouse local: held status, current and N-1 owner fields, tenant, principal and read-scope isolation, every column but status, attempts, lease and update time left as stored, the attempt left after a retry, switched-off and unread switches, a batch past its last day answeredexpiredwith nothing submitted, and a batch dropped while model calls were off retried once they are back on, itsmemory_dropsrecord left as the history of that drop.tests/unit/test_extraction_retry_erasure.py: both orders of a delayed retry and an erasure, a cancelled or lost response, a newer worker version, two calls before the update applies submitting one mutation, a newer failed version submitted while an older retry is unfinished, and an unfinished retry still answeredrequeuedafter the org is switched off. That last case runs the realsystem.mutationslookup against a held, unfinished mutation (merges stopped), and fails if the quote in the lookup is lost.tests/integration/test_extraction_status_mine.py,test_cross_principal_leakage.pyandtest_read_scope_isolation.pycover the ops over HTTP and MCP for the queuing principal, another principal and a scoped token.memory.extraction_status_mineread, the retry update, its state read and thesystem.mutationslookup; no other shape changed.make format-check lint typecheckand the focused unit suites above (110 passed; two analyzer cases skip without a server). The full unit and integration suites run in CI.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): coding agents checked the ownership and read-scope predicates, replay bounds, transport routing, generated SDKs and queue lifecycle behavior.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed (format, lint and typecheck pass locally; the unit and integration suites are ticked once CI is green).main(not applicable).frontend/changed (not applicable).