Repository navigation
Description
Problem Description
The brain digest of #4682 (merged in #7496) is not fail-soft for a store value of a wrong form. Two inputs raise out of the digest read and fail the whole alternatives round:
_held_iteminsrc/devops_cli/roadmap/brain_index.pyparses each word of thenearfield withint()afterisdecimal(). A word of more than 4,300 digits passesisdecimal()and makesint()raiseValueError. The watermark read has the same parse.ValkeyClient.hscaninsrc/devops_cli/valkey/client.pydecodes the field names in strict mode, after the call. A field name that is not valid UTF-8 raisesUnicodeDecodeError, andValkeyCacheTier._senddoes not catch it.
The error goes from read_digest through _verdict_check, _check_one and _settled to plan_alternatives. The item gets no failure mark, and sync_alternatives_round does not run, so it does not write the entry again. _hash_write writes with HSET and EXPIRE and no DEL, so a bad field can stay until the TTL of 45 days, and each round fails until then. The sync never writes such a value, and only the user brain can write, so one bad write is the cause.
Evidence
An independent review of #7496 at 04e34ce corrupted a fixture brain that the real BrainIndex.write wrote, and ran the real plan_alternatives:
near-5000-digits: round raised ValueError; checked=[]; failure marks=[]
field-name-not-utf8: round raised UnicodeDecodeError; checked=[]; failure marks=[]
The same review found three small defects: the 2,000-token cap counts the digest as top-level JSON, but the request nests it one level deeper (up to 10 tokens more than the cap); an item in its own near list or a repeated near number repeats an entry; and two tests cannot see the rule that they name.
Expected Behavior
A store value of a wrong form gives an empty or partial digest, and the round writes the verdict of each check. The cap counts the digest as the request holds it. The near items leave out the item itself and repeated numbers.
Acceptance Criteria
- A test: the real round over a brain with a near word of 5,000 digits, and with a field name that is not UTF-8 on the entry of the item and on a near entry, writes each verdict.
- A test: the
brainpart of the real request text holds at most 2,000 tokens at the boundary. - A test: near
1 1 2 2on item 1 gives the near items 2 only once and not item 1.
Related
- feat(roadmap): the alternatives check reads the brain digest #4682 (the digest), feat(roadmap): the alternatives check reads the brain digest #7496.
Proposed design
Problem statement
The brain digest of #4682 reads the project brain in the alternatives round. Two store values of a wrong form still raise out of that read. The first is a near word that isdecimal() accepts and int() rejects. The second is a field name that is not valid UTF-8. One such write fails each round for the 45-day TTL of the entry, and the round writes no verdict. The digest must read an empty or partial entry, and the round must write each verdict. The digest must also count its 2,000-token cap as the request nests it, and give each near item once, without the item itself.
Acceptance criteria
Requirement: Near word that int() cannot parse
The brain index MUST treat a near word that int() cannot parse as no near item, and MUST NOT raise.
Scenario: Near word of 5,000 digits
- WHEN A test reads an item whose
nearfield holds a word of 5,000 digits throughBrainIndex.items. - THEN The result holds the item with an empty near tuple, and no error.
Requirement: Watermark number that int() cannot parse
The brain index MUST give an empty watermark for a number field that int() cannot parse, and MUST NOT raise.
Scenario: Watermark number of 5,000 digits
- WHEN A test reads the sync hash whose
numberfield holds 5,000 digits throughBrainIndex.watermark. - THEN The result is an empty
Watermark, and no error.
Requirement: Field name that is not UTF-8
The hash read MUST decode a field name that is not valid UTF-8 with replacement, and MUST NOT raise.
Scenario: Field name of the bytes b"\xff"
- WHEN A test reads a hash whose field name is not valid UTF-8 through
ValkeyClient.hscan. - THEN The result holds the fields of the hash with the replacement name, and no
UnicodeDecodeError.
Requirement: Round writes each verdict on a corrupt brain
The alternatives round MUST write the verdict of each check when a brain entry holds a value of a wrong form.
Scenario: Round over a corrupt fixture brain
- WHEN A test corrupts a fixture brain that
BrainIndex.writewrote, with anearword of 5,000 digits and a field name that is not UTF-8 on the item and on a near item, and runs the realplan_alternativeswith its model call stubbed. - THEN The round raises no error, and it writes the verdict of each item that it checked.
Requirement: Token cap counts the digest as the request nests it
The digest MUST hold at most 2,000 tokens as the brain part of the request text.
Scenario: Digest at the cap
- WHEN A test builds a digest at the cap and renders the real alternatives request text with it.
- THEN The
brainpart of the text holds at most 2,000 tokens.
Requirement: Near items leave out the item and the repeats
The near items of an entry MUST hold each number once and MUST NOT hold the item itself.
Scenario: Near field 1 1 2 2 on item 1
- WHEN A test reads item 1 whose
nearfield is1 1 2 2throughBrainIndex.items. - THEN The near tuple is
(2,).
Existing Tool Considered
No alternatives check has run on this item. No open, maintained tool or library covers the need: the defect is in the project's own parse in src/devops_cli/roadmap/brain_index.py and decode in src/devops_cli/valkey/client.py, and no library replaces those two functions. The change builds about 10 lines of code and 6 tests. The written cost is about 4,000 tokens to build, keep and fix that code, and about 4 hours of elapsed time.
Key questions
- How does the digest treat a
nearword thatint()cannot parse?: It catchesValueErroraround the parse and leaves that word out, as_timeandVerdictalready do for a wrong-form value. It does not bound the word length. (best practice) [sources: src/devops_cli/roadmap/brain_index.py:157]- Chosen: Catch ValueError around int(). The module already treats a wrong-form value as no entry in
_timeandVerdict, so the fix keeps one rule. - Rejected: Reject a word longer than a fixed number of digits. The 4,300-digit limit is a Python setting that can change, so a second bound is a second rule to keep.
- Rejected: Leave the whole near list empty on a bad word. It drops the good near numbers of the same entry.
- Chosen: Catch ValueError around int(). The module already treats a wrong-form value as no entry in
- How does the digest treat a watermark
numberthatint()cannot parse?: It applies the same catch as the near parse and gives an emptyWatermark, so a bad number reads as no watermark. (best practice) [sources: src/devops_cli/roadmap/brain_index.py]- Chosen: Catch ValueError and give an empty Watermark. It is the rule of the near parse, and a wrong-form value is no entry in this module.
- Rejected: Keep the time fields and set number to 0. A half-read watermark moves the sync to a false place.
- Where does a field name that is not UTF-8 fail soft?: In
ValkeyClient.hscan, each field name decodes witherrors="replace", as the pool and the value decode of_fieldsalready do. The read gives the field and raises nothing. (best practice) [sources: src/devops_cli/valkey/client.py, src/devops_cli/roadmap/brain_index.py]- Chosen: Decode the field name with errors=replace in hscan. It keeps the entry readable, and it matches the
encoding_errors="replace"of the pool and the value decode of_fields. - Rejected: Catch UnicodeDecodeError in ValkeyCacheTier._send. It turns a readable entry into no answer and hides the cause of the bad value.
- Rejected: Skip a field name that is not UTF-8. It adds a second decode path for one case.
- Chosen: Decode the field name with errors=replace in hscan. It keeps the entry readable, and it matches the
- Where do the near items lose the item itself and the repeated numbers?: In
_held_item, the parsed near numbers keep their first order and drop the number of the item. The stored value stays as it is. (best practice) [sources: src/devops_cli/roadmap/brain_index.py:157]- Chosen: Normalize at the read in _held_item. The store can hold any value, from an older write or from the user
brain, so the reader must give a clean list. - Rejected: Normalize in the sync before the write. A value that is already in the store stays wrong until its TTL of 45 days ends.
- Rejected: Normalize at both places. It keeps one rule in two places.
- Chosen: Normalize at the read in _held_item. The store can hold any value, from an older write or from the user
- How does the digest count its 2,000-token cap?: It counts the tokens of the digest as the request holds it, nested under its key, and not the top-level JSON of the digest. (best practice) [sources: src/devops_cli/roadmap/brain_digest.py, src/devops_cli/roadmap/alternatives.py]
- Chosen: Count the nested form that the request holds. The cap must bound what the model reads, and the request nests the digest.
- Rejected: Keep the top-level count and subtract 10 tokens. A fixed number does not follow the nesting.
- Rejected: Raise the cap to 2,010 tokens. The cap is the rule; the count is the defect.
- Does the fix delete a bad field that the store already holds?: No. After the fix a bad field changes no read, and it ends at the TTL of 45 days. The write stays as it is. (best practice) [sources: src/devops_cli/roadmap/brain_index.py:340]
- Chosen: Leave the bad field to its TTL. The read is fail-soft, so the field changes no result, and the write keeps its one path in the watched transaction.
- Rejected: Delete the key and write it again. A DEL inside the watched transaction races with the write of another check.
- Rejected: Read the hash and HDEL each field that the schema does not name. It adds a read and a second write path to the sync for no result.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 28, 2026
A single bad store value causes every alternatives round to fail for up to 45 days.The regression commit 04e34ce does not set P0: the author has no write access, and no caller attached it as evidence. A person can set P0 with the label priority/p0-critical.Both address the hscan UTF-8 decode error, but #7507 fixes hscan itself while the candidate makes the brain digest fail-soft and also fixes the int overflow, the token cap, and the near list dedup.devops-cli-service commentedon Nov 28, 2026
Next step: the alternatives check records a verdict. See the section Proposed design of the body.
devops-cli-service commentedon Nov 28, 2026
Released in v0.232.1: https://github.com/dan-petty/devops-cli/releases/tag/v0.232.1
devops-cli-service commentedon Nov 28, 2026
Live since 2026-11-28 05:01 UTC