Repository navigation
fix(python): keep the session Crystal when the write quota is used up (#749) - #750
Merged
Merged
Conversation
…#749) A session-end Crystal refused by the relay for quota (403 quota_exceeded) was only logged, so it was lost, and the user was not told unless an earlier write in the session had also been refused. - session_debrief now queues a quota-refused Crystal in the #747 encrypted retry queue and raises the once-per-session notice. - The drain stores a queued Crystal the way session_debrief does (no write gate, no embedding), after a per-sentence forget scrub, so anything the user forgot since it was queued is not written. - Queued facts keep the time they were refused as extracted_at, so their created_at matches the conversation they came from. - Notice grammar: "1 new memory is kept ..." (was "are kept"); drop "from this conversation", since a session-end notice shows later. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #749.
Problem
When the account's monthly write allowance was used up, the relay refused the session-end summary (Crystal) with
403 quota_exceeded.session_debriefcaught every store error and only logged it, so the Crystal was lost. Unless an earlier write in the same session had also been refused, the user was not told. This affected every path that writes a Crystal: session end, the idle-session roll, and the idle sweep.Changes
session_debriefcatchesRelayWriteQuotaExceededand passes the Crystal to_handle_write_quota, the same path Hermes: write-quota exhaustion (403 on /v1/bundler) never surfaces to user or agent — auto-extraction facts silently dropped (44+ since Nov 9) #747 uses for refused auto-extracted facts. This handles the encrypted retry queue, billing-cache invalidation and the once-per-session notice._drain_entriesrecognises a queued Crystal (extra_metadata.subtype == "session_crystal"). It stores the Crystal the waysession_debriefdoes: no write gate, no embedding, v1summary, provenancederived. Before that, it rebuilds aCrystaland runs_scrub_crystal, so any sentence or list item the user has forgotten since it was queued is removed. If nothing is left, the entry is dropped. The whole-text forget check used for facts would miss a single forgotten sentence inside a longer narrative.PendingStoreQueue.addstampsextracted_atwith the refusal time; existing values are kept.store_fact_batchalready turnsextracted_atinto the blob'screated_at. Before this change, a fact or Crystal stored weeks later carried the drain time, so the vault showed it apart from its conversation. This applies to queued facts too, not only the Crystal.client-consistency.mdrule 4, HermesSKILL.md, and the CLAUDE.md feature matrix row.Testing
python/tests/test_write_quota_747.py(TestSessionCrystalQuota,TestQueuedFactTime,test_notice_counts_read_correctly). All failed before the fix, for the expected reasons. With only the drain-side Crystal handling reverted, the two forget-scrub drain tests fail.pyzbar).api-staging.totalreclaw.xyzand returns the relay's realquota_exceededbody foreth_sendUserOperationwhile refusing. The run used a fresh throwaway account:sumwith the session'ssession_idtype: summary,subtype: session_crystalandkey_outcomeskeptcreated_atequals the refusal time, not the drain time🤖 Generated with Claude Code