howhard 2.1.0__tar.gz → 2.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. {howhard-2.1.0 → howhard-2.2.0}/.antigravity-plugin/plugin.json +1 -1
  2. {howhard-2.1.0 → howhard-2.2.0}/.claude-plugin/plugin.json +1 -1
  3. {howhard-2.1.0 → howhard-2.2.0}/CHANGELOG.md +14 -0
  4. {howhard-2.1.0 → howhard-2.2.0}/PKG-INFO +1 -1
  5. howhard-2.2.0/docs/concurrency.md +124 -0
  6. {howhard-2.1.0 → howhard-2.2.0}/docs/index.md +3 -0
  7. {howhard-2.1.0 → howhard-2.2.0}/docs/reference.md +6 -1
  8. {howhard-2.1.0 → howhard-2.2.0}/docs/retrieval.md +2 -0
  9. {howhard-2.1.0 → howhard-2.2.0}/docs/semantic-memory.md +6 -2
  10. {howhard-2.1.0 → howhard-2.2.0}/docs/skills.md +6 -0
  11. {howhard-2.1.0 → howhard-2.2.0}/plugin.json +1 -1
  12. {howhard-2.1.0 → howhard-2.2.0}/skills/howhard/SKILL.md +5 -0
  13. {howhard-2.1.0 → howhard-2.2.0}/skills/howhard/references/workflow.md +18 -0
  14. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/__init__.py +4 -2
  15. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/cli.py +17 -2
  16. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/config.py +5 -0
  17. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/decisions.py +6 -1
  18. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/engine.py +52 -17
  19. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/memory.py +54 -15
  20. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/native.py +1 -1
  21. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/retrieval.py +66 -39
  22. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/semantic.py +6 -4
  23. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/state.py +14 -17
  24. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/storage.py +49 -13
  25. howhard-2.2.0/src/howhard/writes.py +186 -0
  26. {howhard-2.1.0 → howhard-2.2.0}/src/howhard.egg-info/PKG-INFO +1 -1
  27. {howhard-2.1.0 → howhard-2.2.0}/src/howhard.egg-info/SOURCES.txt +4 -1
  28. howhard-2.2.0/tests/test_write_queue.py +458 -0
  29. {howhard-2.1.0 → howhard-2.2.0}/.agents/plugins/marketplace.json +0 -0
  30. {howhard-2.1.0 → howhard-2.2.0}/.claude-plugin/marketplace.json +0 -0
  31. {howhard-2.1.0 → howhard-2.2.0}/.readthedocs.yaml +0 -0
  32. {howhard-2.1.0 → howhard-2.2.0}/AGENTS.md +0 -0
  33. {howhard-2.1.0 → howhard-2.2.0}/MANIFEST.in +0 -0
  34. {howhard-2.1.0 → howhard-2.2.0}/README.md +0 -0
  35. {howhard-2.1.0 → howhard-2.2.0}/benchmarks/__init__.py +0 -0
  36. {howhard-2.1.0 → howhard-2.2.0}/benchmarks/bench_rule_retrieval.py +0 -0
  37. {howhard-2.1.0 → howhard-2.2.0}/benchmarks/rule_cases.json +0 -0
  38. {howhard-2.1.0 → howhard-2.2.0}/benchmarks/rule_retrieval.py +0 -0
  39. {howhard-2.1.0 → howhard-2.2.0}/docs/changelog.md +0 -0
  40. {howhard-2.1.0 → howhard-2.2.0}/docs/conf.py +0 -0
  41. {howhard-2.1.0 → howhard-2.2.0}/docs/configuration.md +0 -0
  42. {howhard-2.1.0 → howhard-2.2.0}/docs/context.md +0 -0
  43. {howhard-2.1.0 → howhard-2.2.0}/docs/contributing.md +0 -0
  44. {howhard-2.1.0 → howhard-2.2.0}/docs/evaluation.md +0 -0
  45. {howhard-2.1.0 → howhard-2.2.0}/docs/quickstart.md +0 -0
  46. {howhard-2.1.0 → howhard-2.2.0}/docs/releasing.md +0 -0
  47. {howhard-2.1.0 → howhard-2.2.0}/docs/requirements.txt +0 -0
  48. {howhard-2.1.0 → howhard-2.2.0}/docs/rule-benchmark.md +0 -0
  49. {howhard-2.1.0 → howhard-2.2.0}/docs/session_handoff_format.md +0 -0
  50. {howhard-2.1.0 → howhard-2.2.0}/docs/upgrading-1.0.md +0 -0
  51. {howhard-2.1.0 → howhard-2.2.0}/docs/upgrading-2.0.md +0 -0
  52. {howhard-2.1.0 → howhard-2.2.0}/pyproject.toml +0 -0
  53. {howhard-2.1.0 → howhard-2.2.0}/scripts/check +0 -0
  54. {howhard-2.1.0 → howhard-2.2.0}/scripts/check-plugins.py +0 -0
  55. {howhard-2.1.0 → howhard-2.2.0}/scripts/check-skills.py +0 -0
  56. {howhard-2.1.0 → howhard-2.2.0}/scripts/verify-wheel.py +0 -0
  57. {howhard-2.1.0 → howhard-2.2.0}/setup.cfg +0 -0
  58. {howhard-2.1.0 → howhard-2.2.0}/skills/attribute-failure/SKILL.md +0 -0
  59. {howhard-2.1.0 → howhard-2.2.0}/skills/howhard/references/accounting.md +0 -0
  60. {howhard-2.1.0 → howhard-2.2.0}/skills/howhard/references/hosts.md +0 -0
  61. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/__main__.py +0 -0
  62. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/accounting.py +0 -0
  63. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/context.py +0 -0
  64. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/data/context.toml +0 -0
  65. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/data/default_config.toml +0 -0
  66. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/data/semantic.toml +0 -0
  67. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/files.py +0 -0
  68. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/llm.py +0 -0
  69. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/report.py +0 -0
  70. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/selector.py +0 -0
  71. {howhard-2.1.0 → howhard-2.2.0}/src/howhard/validation.py +0 -0
  72. {howhard-2.1.0 → howhard-2.2.0}/src/howhard.egg-info/dependency_links.txt +0 -0
  73. {howhard-2.1.0 → howhard-2.2.0}/src/howhard.egg-info/entry_points.txt +0 -0
  74. {howhard-2.1.0 → howhard-2.2.0}/src/howhard.egg-info/requires.txt +0 -0
  75. {howhard-2.1.0 → howhard-2.2.0}/src/howhard.egg-info/top_level.txt +0 -0
  76. {howhard-2.1.0 → howhard-2.2.0}/tests/conftest.py +0 -0
  77. {howhard-2.1.0 → howhard-2.2.0}/tests/test_cli.py +0 -0
  78. {howhard-2.1.0 → howhard-2.2.0}/tests/test_configured_candidates.py +0 -0
  79. {howhard-2.1.0 → howhard-2.2.0}/tests/test_context.py +0 -0
  80. {howhard-2.1.0 → howhard-2.2.0}/tests/test_current_contract.py +0 -0
  81. {howhard-2.1.0 → howhard-2.2.0}/tests/test_execution_accounting.py +0 -0
  82. {howhard-2.1.0 → howhard-2.2.0}/tests/test_fast_reranking.py +0 -0
  83. {howhard-2.1.0 → howhard-2.2.0}/tests/test_measurement_corrections.py +0 -0
  84. {howhard-2.1.0 → howhard-2.2.0}/tests/test_memory.py +0 -0
  85. {howhard-2.1.0 → howhard-2.2.0}/tests/test_native_startup.py +0 -0
  86. {howhard-2.1.0 → howhard-2.2.0}/tests/test_portable_core.py +0 -0
  87. {howhard-2.1.0 → howhard-2.2.0}/tests/test_retrieval.py +0 -0
  88. {howhard-2.1.0 → howhard-2.2.0}/tests/test_retrieval_config.py +0 -0
  89. {howhard-2.1.0 → howhard-2.2.0}/tests/test_rule_benchmark.py +0 -0
  90. {howhard-2.1.0 → howhard-2.2.0}/tests/test_semantic.py +0 -0
  91. {howhard-2.1.0 → howhard-2.2.0}/tests/test_semantic_cli.py +0 -0
  92. {howhard-2.1.0 → howhard-2.2.0}/tests/test_semantic_only.py +0 -0
  93. {howhard-2.1.0 → howhard-2.2.0}/tests/test_skill_workflow.py +0 -0
  94. {howhard-2.1.0 → howhard-2.2.0}/tests/test_storage.py +0 -0
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://antigravity.google/schemas/v1/plugin.json",
3
3
  "name": "howhard",
4
4
  "displayName": "howhard",
5
- "version": "2.1.0",
5
+ "version": "2.2.0",
6
6
  "description": "Recommend model and reasoning effort from task context, then learn from actual feedback through writable semantic memory.",
7
7
  "author": {"name": "howhard contributors"},
8
8
  "repository": "https://github.com/xu-hao/howhard"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "howhard",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Recommend model and reasoning effort from task context, then learn from actual feedback through writable semantic memory.",
5
5
  "author": {"name": "howhard contributors"},
6
6
  "repository": "https://github.com/xu-hao/howhard"
@@ -2,6 +2,20 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.2.0 — 2026-11-08
6
+
7
+ - Coordinate concurrent writes inside howhard with per-store FIFO admission, finite
8
+ waits, cancellation, automatic crash release and `writes --json` queue inspection.
9
+ CLI `--write-timeout` and Python cancellation/error types expose contention without
10
+ requiring agent-channel writer windows or a separate coordinator.
11
+ - Admit requests, receipts, evidence, usage amendments, memory and cache publication
12
+ through the same store queue. Keep model calls and embedding outside write turns,
13
+ let readers bypass waiting writers, and preserve independent store concurrency.
14
+ - Recheck evidence, memory revisions and learning events after admission. Preserve
15
+ append-only evidence and matching stable-ID retries; refuse stale forecasts and
16
+ conflicting patches. Unrelated historical model admission leaves disjoint inventories
17
+ usable. Document concurrency boundaries and update native skill guidance.
18
+
5
19
  ## 2.1.0 — 2026-11-08
6
20
 
7
21
  - Accept explicitly named `[inventories]` in `howhard.toml`, selected through Python
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: howhard
3
- Version: 2.1.0
3
+ Version: 2.2.0
4
4
  Summary: Choose an agent's model and reasoning effort, and learn from outcomes.
5
5
  Project-URL: Repository, https://github.com/xu-hao/howhard
6
6
  Project-URL: Issues, https://github.com/xu-hao/howhard/issues
@@ -0,0 +1,124 @@
1
+ # Concurrent CLI and API clients
2
+
3
+ Normal clients submit normal operations. Howhard owns write admission, waiting and
4
+ release inside the backend; agents need no acquire/release messages, writer windows,
5
+ scratch ledger, external broker or daemon. Fresh Git worktrees use the same repository
6
+ store automatically. Independently selected stores have independent queues.
7
+
8
+ ## Admission boundaries
9
+
10
+ Each store has a FIFO queue in `write-queue/`, protected during registration by
11
+ `write-queue.lock`. A client holds an OS advisory lock on its ticket while waiting and
12
+ writing. Registration under the short queue guard defines order: no later registered
13
+ writer overtakes a live earlier ticket. Arrival at the guard itself has no ordering
14
+ guarantee. Nested mutations within an admitted operation share that turn. A sequence
15
+ number may restart after the queue empties; the random ticket suffix distinguishes requests.
16
+
17
+ | Operation | Serialized boundary |
18
+ | --- | --- |
19
+ | First use | Validate evidence, establish project/store identity; initialize memory schema when needed |
20
+ | Native inventories | Validate and merge historical identity metadata |
21
+ | `context` / `retrieve` | Publish the immutable request artifact after checking evidence and memory again |
22
+ | `decide` / `pick` | Commit the receipt after checking its forecast inputs again; audit events have separate turns |
23
+ | `observe` / amendments | Read current evidence, validate IDs, provenance and corrections, then append/fsync |
24
+ | `usage attach` | Collect the owned source outside admission; validate and append the correction inside admission |
25
+ | Memory operations / learning | Recheck current evidence, event key, expected revision/version, then commit the SQLite transaction |
26
+ | Retrieval / inference caches | Serialize howhard-owned SQLite cache transactions and atomic response-cache publication |
27
+ | `flush` | Validate, append/fsync, then truncate/fsync under one turn |
28
+
29
+ The queue does not reserve a whole workflow. External LLM forecasts, local embedding,
30
+ graph construction, reranking, source collection, worker execution, review and gate
31
+ waits happen outside the write turn. Retrieval cache publication is separate from its
32
+ expensive computation. Pretrained model loading/downloads belong to the inference
33
+ libraries, outside store admission. A caller-selected receipt export is an ordinary
34
+ output file, outside backend state coordination.
35
+
36
+ Admitted mutations also hold `storage.lock` and the existing journal advisory lock.
37
+ This keeps JSONL snapshots consistent, including clients selecting different journals
38
+ inside one store. Evidence readers bypass the FIFO queue and take shared data locks;
39
+ they wait only for an active mutation, with the same bounded waiting policy. Memory
40
+ reads use SQLite snapshots without schema writes after initialization. First-use
41
+ schema initialization is a write. `writes` inspects tickets without joining the queue,
42
+ creating a store, or waiting for data locks.
43
+
44
+ The independent project identity lock is held only while claiming a new store/anchor,
45
+ not across every operation. Existing independent stores of the same project therefore
46
+ do not serialize their work through that anchor. Identity is checked before admission
47
+ and again after waiting. Use the same updated backend for concurrent clients; FIFO
48
+ admission applies to clients using this protocol. POSIX advisory locks and a local
49
+ filesystem shared by the participating processes are required. This is not a
50
+ cross-machine queue or a lease with a forced expiry during a mutation.
51
+
52
+ ## Waiting, cancellation and failures
53
+
54
+ Every admission has a finite deadline: 30 seconds by default. The deadline covers queue
55
+ registration, time behind other writers, and acquisition of data/identity locks. A
56
+ multi-step call can have several admissions; this is not a whole-call time limit or a
57
+ transaction across the entire call. An admitted mutation is not forcibly interrupted
58
+ when its admission deadline passes. Ordinary clients never need manual lock ownership.
59
+
60
+ ```sh
61
+ howhard writes --json
62
+ howhard observe task actual-model high clean --native --id actual-execution \
63
+ --write-timeout 10 --json
64
+ ```
65
+
66
+ `writes` returns the resolved store, ordering policy and live entries, each with a
67
+ ticket, PID, operation, enqueue timestamp, waiting seconds, position and state (`head`
68
+ or `waiting`). The head may still be acquiring a data lock; it does not imply a mutation
69
+ has begun. Status is a nonblocking, observational snapshot, not a claim protocol.
70
+ PIDs are diagnostic metadata; ownership and crash recovery use locks, never PID reuse
71
+ heuristics. Wait age uses wall-clock time for display; deadlines use a monotonic clock.
72
+
73
+ `--write-timeout` is available on store commands. On exhaustion, the client withdraws
74
+ its ticket and returns `WriteTimeout`; CLI exit status is 2. With `--json`, admission
75
+ errors are JSON on stderr under `error`, with `code`, `message`, `store`, `operation`
76
+ and `ticket`. Codes are `write_timeout`, `write_cancelled` and
77
+ `write_dependency_failed`. Ctrl-C withdraws the ticket and exits 130. Killing a client
78
+ releases its kernel locks; the next writer skips/removes abandoned tickets. A stopped
79
+ but living client still owns its ticket; other clients terminate at their own deadlines.
80
+ Filesystem/lock errors and SQLite dependency failures have a typed terminal outcome
81
+ without an automatic retry loop. An out-of-protocol SQLite writer can cause an immediate
82
+ dependency failure rather than extending the queue deadline.
83
+
84
+ ```python
85
+ from threading import Event
86
+ from howhard import Engine, WriteTimeout, WriteCancelled, WriteDependencyError
87
+
88
+ cancel = Event()
89
+ engine = Engine(write_timeout=10, write_cancel=cancel.is_set)
90
+ print(engine.write_status())
91
+ # Another thread may call cancel.set() while this client waits.
92
+ try:
93
+ engine.memory.add("Observed lesson", "A provisional lesson from actual work")
94
+ except (WriteTimeout, WriteCancelled, WriteDependencyError):
95
+ pass # Reconcile durable state and retry through the normal API when appropriate.
96
+ ```
97
+
98
+ Cancellation is checked while acquiring admission and data locks. A callback is not a
99
+ rollback request for an already executing mutation. API `KeyboardInterrupt` unwinds the
100
+ same cleanup. A process crash during a SQLite transaction rolls it back; existing JSONL
101
+ crash/flush recovery rules still apply. Queueing does not make a multi-file flush atomic.
102
+
103
+ ## Revalidation and retries
104
+
105
+ For example, an observation and a memory update from two worktrees register in one
106
+ store queue. The memory update waits its turn, then checks the expected revision
107
+ against current memory. A stale revision still returns the existing actionable
108
+ conflict; howhard never silently rebases a patch. Learning also checks the effective
109
+ evidence event after admission. A prepared request remains bound to its worktree,
110
+ actual candidate inventory, evidence and memory revision. Evidence or memory changes
111
+ during forecasting, retrieval or a queue wait require a new request. Adding an unrelated
112
+ historical model identity alone does not invalidate a disjoint inventory.
113
+
114
+ A timeout does not execute later in the background. Resubmit a normal call if needed;
115
+ no manual queue cleanup is required. Reuse the same stable observation/attachment ID
116
+ and identical inputs. Matching retries return the original row; conflicting retries
117
+ are refused. Refresh and regenerate stale decisions or writer patches instead of
118
+ resubmitting them unchanged. Keep retries bounded and report repeated failures.
119
+
120
+ Earlier steps may already be durable when a later admission fails. In particular,
121
+ an observed outcome survives failed usage collection or learning. Inspect
122
+ `evidence ID --raw` after ambiguous feedback and retry the same ID, rather than
123
+ minting another original execution. Append-only evidence, immutable receipts and
124
+ transactional memory revisions retain their existing contracts.
@@ -3,6 +3,8 @@
3
3
  - [Quickstart](quickstart.md) — install, choose, record an outcome and learn, with no setup.
4
4
  - [Model and storage contracts](reference.md) — LLM forecasts, cost/risk selection, strict rows,
5
5
  reproducibility and storage.
6
+ - [Concurrent clients](concurrency.md) — backend-owned FIFO write admission, bounded waits,
7
+ cancellation, queue status and safe retries across worktrees.
6
8
  - [Task text and changing project context](context.md) — original task/project text, immutable
7
9
  snapshots and decision receipts.
8
10
  - [LLM reasoning and writable semantic memory](semantic-memory.md) — reader/writer
@@ -30,6 +32,7 @@
30
32
 
31
33
  quickstart
32
34
  reference
35
+ concurrency
33
36
  context
34
37
  semantic-memory
35
38
  retrieval
@@ -211,7 +211,9 @@ Readers without this field's support refuse such rows.
211
211
 
212
212
  `flush` validates all files before writing. Duplicate refusals list every duplicate and
213
213
  leave log and journal unchanged. It appends, fsyncs the log, then truncates and fsyncs the
214
- journal. A shared advisory lock serializes storage commands within a project. A crash
214
+ journal. Backend-owned [FIFO write admission](concurrency.md) serializes mutations per
215
+ store with bounded waiting, automatic release and observable queue status. Data locks
216
+ preserve consistent reads without making readers join the write queue. A crash
215
217
  between append and truncate can leave duplicate rows, which are refused on the next read;
216
218
  there is no claim of an atomic transaction across two files. Preserve a copy and remove
217
219
  the already-flushed journal entries after comparing their ids with the log.
@@ -272,4 +274,7 @@ Calling-agent `prepare`/`retrieve`/`decide` never invoke a provider. A fresh eng
272
274
  observations return pending learning; apply an external writer response or call
273
275
  `memory_learn` explicitly. An engine already holding a provider adapter runs its writer
274
276
  after durable observation. `refresh()` reloads external evidence; no fitting occurs.
277
+ `Engine(write_timeout=30, write_cancel=callback)` bounds admission and supports
278
+ cancellation. `write_status()` and CLI `writes --json` expose contention. See
279
+ [concurrent clients](concurrency.md) for boundaries, typed errors and stable-ID retries.
275
280
  Python 3.11+ and POSIX are required; runtime dependencies are limited to NumPy.
@@ -157,6 +157,8 @@ HNSW graph. Changes in the indexed content or embedding identity rebuild the cur
157
157
  graph while reusing unchanged vectors. Graph and mapping publication is transactional;
158
158
  corrupt graph bytes are rebuilt. These caches never replace `memory.sqlite3` or outcome
159
159
  logs. Removed lessons are excluded unless the caller explicitly requests archives.
160
+ Cache transactions use the store's [write queue](concurrency.md). Embedding, graph
161
+ construction and reranking run outside admission; only cache publication is serialized.
160
162
  Prepared requests retain candidate IDs, scores, stage identities and selected IDs;
161
163
  receipts freeze the selected evidence and forecast inputs.
162
164
 
@@ -71,8 +71,12 @@ and the corresponding fields. For example:
71
71
  ]
72
72
  ```
73
73
 
74
- Batches are transactional: one invalid operation changes nothing. Writer edits carry
75
- the revision they read and reject concurrent stale writes. Evidence IDs must refer to
74
+ Batches are transactional: one invalid operation changes nothing. Writer edits retain
75
+ their expected revision through the backend's [write queue](concurrency.md). Memory
76
+ mutations share admission with observations, amendments, receipts and cache publication;
77
+ revision and evidence-event checks run after waiting. Clients do not coordinate writer
78
+ windows through conversation channels. The queue never silently rebases a stale patch.
79
+ Evidence IDs must refer to
76
80
  recorded runs. Edits create new content versions and receive no inherited predictive
77
81
  credit. Merge and split create new IDs and preserve parent/evidence links without
78
82
  combining old scores. Remove stops active use; archived versions, evidence and audit
@@ -167,6 +167,12 @@ separate identity labels; generic categorical controls such as ultra remain exac
167
167
  rather than mapping to max/default. Missing candidate model/control values remain a
168
168
  capability gap. A separate resolved worker identity need not be returned after execution
169
169
  when accepted explicit overrides and task completion establish attribution as above.
170
+ Concurrent clients rely on [backend-owned write admission](concurrency.md). The skill
171
+ instructs agents to submit normal calls, inspect `writes --json` for contention and
172
+ retry with stable IDs after a timeout. Agents must not create a writer-window or
173
+ acquire/release protocol in their conversation channels. Stale writer patches still
174
+ require fresh context and a regenerated response.
175
+
170
176
  No project bridge, model mapping, statistical settings, lock feature or extra audit
171
177
  ledger is needed. Native manifests and the stateful Python backend remain separate.
172
178
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
3
  "name": "howhard",
4
- "version": "2.1.0",
4
+ "version": "2.2.0",
5
5
  "description": "Recommend model and reasoning effort from task context, then learn from actual feedback through writable semantic memory.",
6
6
  "author": {"name": "howhard contributors"},
7
7
  "repository": "https://github.com/xu-hao/howhard"
@@ -28,6 +28,11 @@ the host's actual tools execute the task.
28
28
  each task captures its current checkout. Explicit store selection remains available.
29
29
  Keep protocol inputs/responses in temporary artifacts outside project source.
30
30
  Do not create project wrappers, state contracts or a second memory store.
31
+ Submit concurrent operations normally: the backend owns FIFO write admission,
32
+ bounded waiting and crash release. Do not exchange writer-window/acquire/release
33
+ messages or maintain an agent-channel mutex. Inspect `howhard writes --json` for
34
+ contention; use `--write-timeout` when needed. After a timeout resubmit normally
35
+ with the same stable IDs; refresh/regenerate stale requests or writer patches.
31
36
  Honor the user/application's fixed retrieval configuration. Do not edit it or try
32
37
  to upgrade its reranker when results are weak; retrieval tools accept no tier,
33
38
  model or configuration override.
@@ -225,3 +225,21 @@ with the project. The resolved state subtree is excluded from source capture/ret
225
225
  state must not equal or contain the capture root. Do not create symlink/config wrappers to stitch
226
226
  state together, and do not copy memory between projects. Native identity metadata,
227
227
  receipts, outcomes and writer events are owned by the backend.
228
+
229
+ Concurrent clients submit normal operations. The backend queues mutations per store
230
+ in FIFO registration order, including preparation/retrieval artifacts, receipts,
231
+ observations, usage attachments and memory updates. It releases ownership on completion,
232
+ error or process death. Do not invent writer windows, acquire/return messages, scratch
233
+ ledgers or an external broker. Independent model calls and embedding run outside the
234
+ write turn; readers bypass waiting writers and independent stores have separate queues.
235
+
236
+ `howhard writes --json` reports live tickets, positions and operations without waiting
237
+ for a write turn. Admission defaults to 30 seconds; `--write-timeout SECONDS` changes
238
+ it per command. Python uses `Engine(write_timeout=..., write_cancel=callback)` and
239
+ `write_status()`. Timeouts withdraw the ticket and do not write later. The CLI returns
240
+ exit 2, or 130 for Ctrl-C; JSON admission errors on stderr have `write_timeout`,
241
+ `write_cancelled` or `write_dependency_failed` codes. Retry a transient failure once
242
+ through the same normal operation, preserving stable IDs and inputs. Earlier steps
243
+ may already be durable: inspect evidence after ambiguous feedback. Admission still
244
+ rechecks identity, evidence and expected revisions; refresh and regenerate a stale
245
+ forecast or writer patch instead of silently rebasing it. Report repeated failure.
@@ -1,9 +1,11 @@
1
1
  """LLM model and effort selection, with a zero-configuration starting point."""
2
2
 
3
- __version__ = "2.1.0"
3
+ __version__ = "2.2.0"
4
4
 
5
5
  from .config import load_config
6
6
  from .engine import Engine
7
7
  from .retrieval import RetrievalPipeline
8
+ from .writes import WriteError, WriteTimeout, WriteCancelled, WriteDependencyError
8
9
 
9
- __all__ = ["Engine", "RetrievalPipeline", "load_config", "__version__"]
10
+ __all__ = ["Engine", "RetrievalPipeline", "load_config", "__version__",
11
+ "WriteError", "WriteTimeout", "WriteCancelled", "WriteDependencyError"]
@@ -16,13 +16,15 @@ def common(command):
16
16
  command.add_argument("--journal", metavar="PATH", help=argparse.SUPPRESS)
17
17
  command.add_argument("--state-dir", metavar="PATH", help="explicit durable state directory; current project capture stays separate")
18
18
  command.add_argument("--json", action="store_true")
19
+ command.add_argument("--write-timeout", type=float, default=30.0,
20
+ help="maximum seconds to wait per store admission (default: 30)")
19
21
 
20
22
 
21
23
  def parser():
22
24
  root = argparse.ArgumentParser(prog="howhard", description="Choose a model and effort, then learn from the outcome. No setup required.")
23
25
  root.add_argument("--version", action="version", version=f"howhard {__version__}")
24
26
  commands = root.add_subparsers(dest="command", required=True)
25
- for name in ("pick", "summary", "observe", "flush", "context", "decide", "retrieve", "report", "evidence", "paths"):
27
+ for name in ("pick", "summary", "observe", "flush", "context", "decide", "retrieve", "report", "evidence", "paths", "writes"):
26
28
  command = commands.add_parser(name)
27
29
  common(command)
28
30
  if name in ("pick", "summary", "observe", "context"):
@@ -198,11 +200,15 @@ def main(argv=None):
198
200
  print(json.dumps(result, allow_nan=False, sort_keys=True))
199
201
  return 0
200
202
  config = load_config(args.config, directory=Path.cwd(), state_directory=args.state_dir)
203
+ if args.command == "writes":
204
+ from .writes import status
205
+ print(json.dumps(status(config.state_root), sort_keys=True))
206
+ return 0
201
207
  native_candidates = None
202
208
  if args.command in ("pick", "summary", "context"):
203
209
  from .native import resolve
204
210
  native_candidates = resolve(config, read_json(args.candidates) if args.candidates is not None else None, args.inventory)
205
- engine = Engine(config, journal_path=args.journal)
211
+ engine = Engine(config, journal_path=args.journal, write_timeout=args.write_timeout)
206
212
  context_options = {}
207
213
  if args.command in ("pick", "summary", "observe", "context"):
208
214
  if args.text_file is not None:
@@ -258,6 +264,15 @@ def main(argv=None):
258
264
  result = {"moved": len(ids), "ids": ids}
259
265
  print(json.dumps(result, allow_nan=False, sort_keys=True) if args.json else render(result))
260
266
  return 0
267
+ except KeyboardInterrupt:
268
+ from .writes import WriteCancelled
269
+ error = WriteCancelled(args.state_dir or Path.cwd(), args.command, "interrupted")
270
+ print(json.dumps({"error": error.as_dict()}) if args.json else f"howhard: {error}", file=sys.stderr)
271
+ return 130
261
272
  except (HowHardError, OSError) as exc:
273
+ from .writes import WriteError
274
+ if args.json and isinstance(exc, WriteError):
275
+ print(json.dumps({"error": exc.as_dict()}), file=sys.stderr)
276
+ return 2
262
277
  print(f"howhard: {exc}", file=sys.stderr)
263
278
  return 2
@@ -8,6 +8,7 @@ import re
8
8
  import tomllib
9
9
 
10
10
  from .validation import HowHardError, keys, number, table, text
11
+ from .writes import WritePolicy
11
12
 
12
13
 
13
14
  def merge(base, changes):
@@ -67,6 +68,7 @@ class Config:
67
68
  identity_path: Path | None = None
68
69
  project_identity: str = ""
69
70
  native_models: dict = field(default_factory=dict)
71
+ write_policy: WritePolicy = field(default_factory=WritePolicy)
70
72
 
71
73
  def path(self, value):
72
74
  relative = Path(text(value, "path"))
@@ -85,6 +87,9 @@ class Config:
85
87
  paths = [self.path(name).resolve() for name in names]
86
88
  if len(set(paths)) != len(paths):
87
89
  raise HowHardError("config paths: logs, journal and lock files must be distinct")
90
+ reserved = {self.state_root / "storage.lock", self.state_root / "write-queue.lock"}
91
+ if any(p in reserved or p.is_relative_to(self.state_root / "write-queue") for p in paths):
92
+ raise HowHardError("config paths: logs and journal must not overlap backend write coordination")
88
93
 
89
94
 
90
95
  def load_config(path=None, *, directory=None, state_directory=None):
@@ -21,11 +21,16 @@ def save(config, result):
21
21
  value["cost_policy"] = result["cost_policy"]
22
22
  value["native_candidates"] = result["native_candidates"]
23
23
  decision_id = digest(value)
24
- atomic_write(receipt_path(config, decision_id), canonical(value) + b"\n")
24
+ from .storage import locked
25
+ with locked(config, operation="receipt commit"):
26
+ atomic_write(receipt_path(config, decision_id), canonical(value) + b"\n")
25
27
  return decision_id
26
28
 
27
29
 
28
30
  def load(config, source, *, for_scoring=False):
31
+ from . import state, native
32
+ state.check(config)
33
+ native.apply(config, native.read(config))
29
34
  if isinstance(source, dict):
30
35
  if "decision_id" in source:
31
36
  source = source["decision_id"]
@@ -18,14 +18,19 @@ from . import semantic
18
18
 
19
19
 
20
20
  class Engine:
21
- def __init__(self, config=None, *, directory=None, state_directory=None, journal_path=None, llm=None, retrieval=None):
21
+ def __init__(self, config=None, *, directory=None, state_directory=None, journal_path=None, llm=None, retrieval=None,
22
+ write_timeout=30.0, write_cancel=None):
22
23
  if llm is not None and not callable(getattr(llm, "complete", None)):
23
24
  raise LLMError("llm: expected an adapter with complete(request)")
24
25
  self.config = config if isinstance(config, Config) else load_config(config, directory=directory, state_directory=state_directory)
26
+ from .writes import WritePolicy
27
+ from copy import copy, deepcopy
28
+ self.config = copy(self.config)
29
+ self.config.data = deepcopy(self.config.data)
30
+ self.config.native_models = deepcopy(self.config.native_models)
31
+ self.config.write_policy = WritePolicy(write_timeout, write_cancel)
25
32
  if isinstance(config, Config) and (directory is not None or state_directory is not None):
26
- from copy import deepcopy
27
33
  from .state import roots
28
- self.config = deepcopy(config)
29
34
  project, store, identity_path, identity = roots(directory or config.project_root, explicit=config.explicit,
30
35
  state_directory=state_directory or config.state_root)
31
36
  self.config.project_root, self.config.state_root, self.config.identity_path, self.config.project_identity = project, store, identity_path, identity
@@ -43,17 +48,24 @@ class Engine:
43
48
 
44
49
  def refresh(self):
45
50
  config = self.config
46
- with storage.locked(config):
51
+ claimed = (config.state_root / "store.json").exists()
52
+ boundary = storage.reading(config) if claimed else storage.locked(config, operation="store initialize")
53
+ with boundary:
47
54
  from . import native, state
48
55
  state.check(config)
49
56
  native.apply(config, native.read(config))
50
57
  raw_rows, _ = storage.snapshot(config)
51
- state.claim(config)
58
+ if not claimed:
59
+ state.claim(config)
52
60
  self.raw_rows = raw_rows
53
61
  self.rows = storage.effective_rows(config, raw_rows)
54
- self.evidence_key = digest({"config": config.data, "rows": self.raw_rows,
55
- "native_models": config.native_models})
56
- self._summaries.clear()
62
+ # Historical identity admission does not change forecasts for a disjoint
63
+ # inventory. Its actual cells are bound separately in every request.
64
+ configured = {k: v for k, v in config.data["models"].items() if not v.get("native")}
65
+ evidence_key = digest({"config": {**config.data, "models": configured}, "rows": self.raw_rows})
66
+ if evidence_key != getattr(self, "evidence_key", None):
67
+ self._summaries.clear()
68
+ self.evidence_key = evidence_key
57
69
 
58
70
  def _inference(self):
59
71
  if self.llm is None:
@@ -64,6 +76,10 @@ class Engine:
64
76
  def paths(self):
65
77
  return {"project_root": str(self.config.project_root), "state_root": str(self.config.state_root)}
66
78
 
79
+ def write_status(self):
80
+ from .writes import status
81
+ return status(self.config.state_root)
82
+
67
83
  def evidence(self, evidence_id, *, raw=False):
68
84
  from copy import deepcopy
69
85
  if raw:
@@ -75,10 +91,8 @@ class Engine:
75
91
 
76
92
  def _register(self, native_candidates):
77
93
  from .native import register
78
- previous = self.config.native_models
79
94
  inventory = register(self.config, native_candidates)
80
- if previous != self.config.native_models:
81
- self.refresh()
95
+ self.refresh()
82
96
  return inventory
83
97
 
84
98
  def _prepared(self, task_type, risk, task_text="", project_context=None, native_candidates=None):
@@ -102,7 +116,9 @@ class Engine:
102
116
  try:
103
117
  result = self._pick(task_type, task_text, project_context=project_context, risk=risk, seed=seed, native_candidates=native_candidates)
104
118
  except Exception as exc:
105
- self._decision_event(None, task_type, started, error=type(exc).__name__)
119
+ from .writes import WriteError
120
+ if not isinstance(exc, WriteError):
121
+ self._decision_event(None, task_type, started, error=type(exc).__name__)
106
122
  raise
107
123
  self._decision_event(result, task_type, started)
108
124
  return result
@@ -115,21 +131,30 @@ class Engine:
115
131
  "backend": result.get("backend", self.backend) if result else self.backend}
116
132
  if result and "semantic" in result:
117
133
  result["routing_overhead"]["end_to_end_seconds"] = event["seconds"]
118
- with storage.locked(self.config):
134
+ with storage.locked(self.config, operation="decision event"):
119
135
  storage.append_bytes(self.config.state_root / "decision-events.jsonl", canonical(event) + b"\n")
120
136
 
121
137
  def _pick(self, task_type, task_text="", *, project_context=None, risk=None, seed=None, native_candidates=None):
122
138
  if seed is not None and (type(seed) is not int or seed < 0):
123
139
  raise HowHardError("seed: expected a non-negative integer")
124
140
  inventory = self._register(native_candidates)
141
+ evidence_key = self.evidence_key
125
142
  prepared = self._semantic_prepared(self._prepared(task_type, risk, task_text, project_context, inventory))
126
143
  seed = secrets.randbits(64) if seed is None else seed
127
144
  parts = semantic.sample(prepared, seed)
128
145
  result = choose(prepared, self.config, seed, parts)
129
- result["decision_id"] = decisions.save(self.config, result)
146
+ with storage.locked(self.config, operation="decision commit"):
147
+ self._validate_state(evidence_key, prepared[0]["semantic"]["memory_revision"])
148
+ result["decision_id"] = decisions.save(self.config, result)
130
149
  return result
131
150
 
151
+ def _validate_state(self, evidence_key, revision):
152
+ self.refresh()
153
+ if evidence_key != self.evidence_key or revision != self.memory.snapshot()["revision"]:
154
+ raise HowHardError("request_id: stale evidence or memory; prepare a new decision")
155
+
132
156
  def _semantic_prepared(self, prepared, response=None, payload=None, snapshot=None):
157
+ evidence_key = self.evidence_key
133
158
  if payload is None:
134
159
  payload, snapshot = semantic.request(self, prepared)
135
160
  if response is None:
@@ -139,12 +164,15 @@ class Engine:
139
164
  response = semantic.validate_response(response, payload, snapshot)
140
165
  semantic.external_submission(self, payload)
141
166
  usage = {"backend": "calling-agent", "seconds": 0.0, "cost_usd": None, "calls": [], "cached": False, "call_seconds": 0.0, "call_cost_usd": None}
167
+ with storage.reading(self.config):
168
+ self._validate_state(evidence_key, snapshot["revision"])
142
169
  return semantic.augment(self, prepared, response, payload, snapshot, usage)
143
170
 
144
171
  def memory_beliefs(self):
145
172
  return semantic.beliefs(self)
146
173
 
147
174
  def memory_learn(self, evidence_id):
175
+ self.refresh()
148
176
  self._inference()
149
177
  self.last_memory_update = semantic.learn(self, evidence_id)
150
178
  return self.last_memory_update
@@ -162,7 +190,9 @@ class Engine:
162
190
  def _save_request(self, bundle):
163
191
  from .files import atomic_write
164
192
  request_id = digest(bundle)
165
- atomic_write(self.config.state_root / "requests" / f"{request_id}.json", canonical(bundle) + b"\n")
193
+ with storage.locked(self.config, operation="request commit"):
194
+ self._validate_state(bundle["evidence_key"], bundle["snapshot"]["revision"])
195
+ atomic_write(self.config.state_root / "requests" / f"{request_id}.json", canonical(bundle) + b"\n")
166
196
  return {"request_id": request_id, "request": semantic.visible_request(bundle["payload"]), "baseline_request": semantic.baseline_request(bundle["payload"])}
167
197
 
168
198
  def _load_request(self, request_id):
@@ -201,7 +231,9 @@ class Engine:
201
231
  try:
202
232
  result = self._decide(request_id, response, seed=seed)
203
233
  except Exception as exc:
204
- self._decision_event(None, "calling-agent", started, error=type(exc).__name__)
234
+ from .writes import WriteError
235
+ if not isinstance(exc, WriteError):
236
+ self._decision_event(None, "calling-agent", started, error=type(exc).__name__)
205
237
  raise
206
238
  self._decision_event(result, result["task_type"], started)
207
239
  return result
@@ -218,10 +250,13 @@ class Engine:
218
250
  raise HowHardError("seed: expected non-negative integer")
219
251
  parts = semantic.sample(prepared, seed)
220
252
  result = choose(prepared, self.config, seed, parts)
221
- result["decision_id"] = decisions.save(self.config, result)
253
+ with storage.locked(self.config, operation="decision commit"):
254
+ self._validate_state(bundle["evidence_key"], bundle["snapshot"]["revision"])
255
+ result["decision_id"] = decisions.save(self.config, result)
222
256
  return result
223
257
 
224
258
  def memory_learning_context(self, evidence_id):
259
+ self.refresh()
225
260
  request, event_key = semantic.learning_request(self, evidence_id)
226
261
  return {"request": request, "event_key": event_key, "memory_revision": request["memory_revision"]}
227
262