Repository navigation
The state of a skill is one pure function over its recorded acts - #2212
Merged
Merged
Conversation
`server/identity/domain/skill_state.py` adds `fold`. It reads the rows of one skill (`seq`, `act`, `revision`, `content_sha256`) and answers the served revision and hash, the latest revision, the open draft, the next revision and `seq`, and the state of each revision. A `delete` row voids its revision, or every revision up to its number when its hash is empty. Among the rows that are not a `save`, a `reject` or a `delete` the highest `seq` decides, and it serves only when every row of that `seq` is a `publish` of one revision and one hash that is not void. An act the fold does not know and rows of the deciding `seq` that disagree serve nothing. The fold does no I/O and has no caller. The rule is tested on hand-built rows before a table, a writer or a read exists, so each of those is reviewed against it. Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
After a delete of the served revision with no archive row, nothing is served only while that revision's publish row is in the rows. Once it is removed, the older publish row decides and its revision is served. The comment in the void-revision test says so, and that a delete of the served revision depends on its archive row to keep the skill unserved. The fold sorts by seq, act, revision and hash, and the sort is stable, so rows equal in all four keep the order given. Two reads of the same rows give the same answers, and the row carried for such a tie follows the read's order: Served.row is the first given, Revision.row the last. The two comments that promise one order say so. Comments only; no behaviour changes. Signed-off-by: Mohammad Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <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.
Part of: #1143
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):
None. No op, field, table or setting changes, and nothing calls the new function.
Why
A skills library keeps a skill as rows of acts: a
savestores a revision, apublishor arejectdecides one, anarchivestops the skill being served, and adeleteremoves a revision or the whole skill. Every read and every write of such a library asks the same questions of those rows: which revision is served, which is the open draft, and which number comes next. Two callers that each answer with a rule of their own can disagree, and what a reader is served then depends on which caller answered.This change adds the rule as one pure function with its table tests, before a table, a writer or a read exists. Each of those is then reviewed against a fold that is already on
main.The fold,
server/identity/domain/skill_state.pyfold(rows) -> SkillStatetakes the rows of one skill as mappings withseq,act,revisionandcontent_sha256, plus any column the caller selected. It does no I/O.deleterow voids its revision. Adeleterow with an empty hash voids every revision up to its number. A void revision is never served, never the latest, never the open draft and has no state, whether its other rows are still present or already removed.save,rejectordelete, the highestseqdecides. The skill is served only when every row of thatseqis apublishof one revision and one hash, the hash is not empty and the revision is not void. When the deciding rows serve nothing, an olderpublishrow does not take their place. That holds for the rows given: once thepublishrow of a deleted served revision is removed, the olderpublishrow decides and its revision is served. A writer that deletes the served revision keeps the skill unserved by writing anarchiverow with thedeleterow; the fold alone does not.archive, an act the build does not know, and rows of the decidingseqthat differ in act, revision or hash serve nothing. A decision with a higherseqsettles them.saverow. The open draft is the latest revision when nopublishorrejectrow names it.seqare one above the highest on any row, the rows of void revisions included, so a number a deleted revision held is never given to another.SkillStateholds:servedServed(revision, content_sha256, row), orNonewhen nothing is servedlatest_revisionopen_draftnext_revision,next_seqrevisionsRevision(revision, content_sha256, state, row)A revision's
stateisdraft,published,rejected,supersededorwithdrawn.rowis the decidingpublishrow onServedand thesaverow onRevision, the same object the caller passed, so a caller reads its own columns from the fold's answer and does not search the rows a second time.Choices made where the rule above leaves a case open:
publishorrejectrow names a revision by number and hash. A revision whosesaverow has another hash than the row that decides stays adraft, sostate == "published"always means the stored bytes have the served hash.archiveis: it decides, it serves nothing, and it names no revision.publishrow with an empty hash serves nothing, and 0 is not a revision number.seq, then act, revision and hash. Two reads that return the same rows in different orders give the same answers: what is served, each revision's number, hash and state, the latest revision, the open draft and the next numbers. Of twosaverows that hold one number, the later in that order is the revision. Rows equal in all four columns keep the order given, so the carriedrowof such a tie follows the read's order:Served.rowis the first given of the agreeingpublishrows andRevision.rowis the last given of the equalsaverows. Two such folds agree in every answer and can differ in the columnsrowcarries, such asactorandat.Scope and risk
Touches:
server/identity/domain/skill_state.py(added):fold,SkillState,Served,Revision, and the names of the five acts and the five revision states.tests/unit/test_skill_state_fold.py(added).Left alone: every other file. This change adds no table, op, wire model, SDK method, command, dashboard view or docs page. The fold is described on the skills architecture page together with its table, when the table is added.
What could break: nothing that runs, because no module imports the new one.
domain/still imports noapp,storeorapi(tests/unit/test_package_contracts.py).Compatibility, rollout and rollback
Tests
The tests were written before the code:
tests/unit/test_skill_state_fold.pyfailed at import while the module did not exist. They build rows by hand and need no ClickHouse.test_a_void_revision_is_never_served_counted_or_answered: fails when a deleted revision is served, is the latest, is the open draft or has a state, with its rows present or removed, for a delete of one revision and of the whole skill. It also fails when an olderpublishrow serves while thepublishrow of the deleted served revision is still in the rows. Once that row is removed, the rows fold as a deleted draft's do and the older revision is served, which the same test asserts for the draft; keeping the skill unserved after such a delete depends on thearchiverow written with it.test_an_unknown_act_or_a_disagreeing_tie_serves_nothing: fails when the fold serves under an act it does not know, an act in another case, or deciding rows that differ in revision, hash or act.test_an_agreeing_tie_serves: fails when twopublishrows of oneseq, revision and hash are refused.test_a_number_is_never_reused_after_a_delete: fails when the next revision orseqis at or below one adeleterow holds.test_a_rejected_then_published_revision_is_served: fails when an earlierrejectoutranks a laterpublish, for what is served and for the revision's state after anarchive.test_a_later_publish_settles_an_unknown_act_or_a_tie: fails when an unread row keeps the skill unserved after a decision with a higherseq.test_a_publish_row_without_a_hash_serves_nothing: fails when apublishrow with an empty hash or revision 0 serves.test_a_draft_saved_or_rejected_leaves_the_served_revision_served: fails when asaveorrejectrow decides what is served, or a rejected revision reads as the open draft.test_each_revision_reads_its_state_from_the_last_decision_that_names_it: fails when an earlier published revision reads as served, or anarchiveleaves a revisionpublished.test_the_latest_revision_is_one_with_its_save_row: fails when a number only a decision row holds is the latest revision or gets a state.test_a_decision_names_a_revision_by_number_and_hash: fails when bytes read as published or rejected under a hash they do not have.test_rows_carry_their_columns_through: fails when the answer holds a copy of a row, or another act's row.test_the_answer_does_not_depend_on_the_order_rows_are_given_in: folds every order of six rows that hold two ties and compares the whole state. No two of the six are equal inseq, act, revision and hash, so it does not cover the carriedrowof such a tie;test_an_agreeing_tie_servespins thatServed.rowis the first given.test_a_skill_with_no_rows_serves_nothing_and_starts_at_one: fails when an empty skill serves, holds a revision, or numbers from 0.Each of these nineteen one-line defects, applied alone to the module, fails at least one of the tests above: a
publishof a void revision serves; a void revision keeps its entry inrevisions; an unknown act is skipped when the deciding row is picked; the first row of a disagreeing tie serves; an agreeing tie is refused; the next revision is one above the latest; the nextseqskipsdeleterows; arejectrow decides what is served; any earlierrejectgivesrejected; arejectoutranks the served state; rows are ordered byseqalone; a decision names a revision by number alone; apublishrow with an empty hash serves; a delete of the whole skill voids one number; the rows of void revisions are dropped before the deciding row is picked; a number with nosaverow is the latest;supersededreads aswithdrawn; the open draft ignores the revision's state; a revision'srowis a copy.What ran at this head:
pytest -n 2 -q tests/unit/test_skill_state_fold.py tests/unit/test_package_contracts.py tests/unit/test_op_transport_contract.py tests/unit/test_tunable_constants.py tests/unit/test_store_names_refused.py tests/unit/test_degraded_unnoted.py tests/unit/test_public_copy.py tests/unit/test_doc_links.py tests/unit/test_agent_instructions.py tests/analyzer: 615 passed, 12 skipped. Ten skipped cases are intest_store_names_refused.pyand need theclickhousebinary, which this machine does not have; the other two are the analyzer cases that need a ClickHouse server.ruff formatandruff checkon the two files: unchanged, no finding.make typecheck: the server ratchet reports 0 errors andmypy --strict sdk/python/loomreports no issues.mypy --stricton the two files reports no issues.scripts/gates/function_length_gate.py: at its baseline.make lint.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code wrote the diff and ran the checks listed under Tests.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make test-unitand applicable integration results are reported by CI; a full local run is not required before pushing.docs/reference/configuration.mdand thedocs/reference/tables (python scripts/codegen/docs_reference.py), the reach manifest,schemas/schema.sql(make schema-dump), the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py) and the standalone skill bundles (python3 scripts/codegen/standalone_skills.py).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.Unticked: this change has no generated file, no migration, no plugin file and no frontend file, so those four checks did not apply; the CLA line is the committer's to confirm. No page under
docs/changes: nothing a user or an operator can reach is added.🤖 Generated with Claude Code
Note
Low Risk
Isolated domain module with no production callers, no I/O, and no schema or API surface changes.
Overview
Introduces
foldinserver/identity/domain/skill_state.pyas the single rule for turning a skill’s act rows (save,publish,reject,archive,delete) into aSkillState: which revision is served, latest/open draft, next revision/seq, and per-revision states (draftthroughwithdrawn). The logic is pure (stdlib only), order-independent, and fails closed on unknown acts,archive, disagreeing same-seqrows, empty publish hashes, and void revisions fromdelete.Adds
tests/unit/test_skill_state_fold.pywith hand-built row cases (void deletes, ties, supersede/withdraw, number reuse, column passthrough, permutations). Nothing else in the repo imports this module yet—no table, API, or wire changes.Reviewed by Cursor Bugbot for commit 492844e. Bugbot is set up for automated code reviews on this repo. Configure here.