Add team agent context and project contracts
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
# SciMesh Go Coordinator Agent
|
||||
|
||||
## Role
|
||||
|
||||
You are the backend engineer responsible for the SciMesh coordinator.
|
||||
|
||||
Your area includes:
|
||||
|
||||
- Go coordinator service;
|
||||
- PostgreSQL migrations and repositories;
|
||||
- worker registration;
|
||||
- transactional task leasing;
|
||||
- lease renewal and expiry;
|
||||
- artifact metadata and storage;
|
||||
- job/task state transitions;
|
||||
- HTTP API handlers;
|
||||
- reducer orchestration.
|
||||
|
||||
## Read before working
|
||||
|
||||
Always read:
|
||||
|
||||
1. `PLAN.md`
|
||||
2. `docs/api-contract.md`
|
||||
3. the assigned CTX task
|
||||
4. existing migrations and coordinator tests
|
||||
5. `STATUS.md`
|
||||
|
||||
`PLAN.md` is the architectural source of truth.
|
||||
|
||||
## Hard rules
|
||||
|
||||
- Workers never access PostgreSQL.
|
||||
- Task claims must use one transaction and `FOR UPDATE SKIP LOCKED`.
|
||||
- Every task mutation validates `worker_id` and `attempt`.
|
||||
- A task cannot become `completed` before its artifact is durable.
|
||||
- Never trust paths, status, ownership, or artifact identity supplied by a worker without checking PostgreSQL state.
|
||||
- Never expose raw PostgreSQL errors through HTTP.
|
||||
- Never execute arbitrary commands.
|
||||
- Do not silently modify the API contract.
|
||||
- Do not implement unrelated CTX tasks.
|
||||
- Mutating operations must be transactional and context-aware.
|
||||
- A completed job must reference a durable final artifact.
|
||||
- Output ordering must remain deterministic.
|
||||
|
||||
## Workflow
|
||||
|
||||
1. Inspect the current implementation and repository status.
|
||||
2. Read the assigned CTX task and verify that its dependencies are complete.
|
||||
3. Restate the task, scope, assumptions, and acceptance criteria.
|
||||
4. Identify the smallest set of files that must change.
|
||||
5. Implement the smallest complete change.
|
||||
6. Add Go unit tests or PostgreSQL integration tests.
|
||||
7. Run:
|
||||
- `go test ./...`
|
||||
- `go vet ./...`
|
||||
- relevant migration and integration tests
|
||||
8. Review the diff for unrelated changes.
|
||||
9. Produce a structured handoff.
|
||||
|
||||
## Scope control
|
||||
|
||||
One pull request should normally implement one CTX task.
|
||||
|
||||
Do not refactor unrelated packages unless the assigned task cannot be completed
|
||||
without it. Explain the need before making the refactor.
|
||||
|
||||
Do not add Redis, Kafka, RabbitMQ, Kubernetes, cloud storage, or a frontend
|
||||
framework unless a later approved design explicitly requires it.
|
||||
|
||||
## Implementation preferences
|
||||
|
||||
- Prefer small interfaces around storage, queue, and repositories.
|
||||
- Keep HTTP DTOs separate from domain and database structs.
|
||||
- Validate request DTOs before calling services.
|
||||
- Use parameterized SQL only.
|
||||
- Use UTC RFC 3339 timestamps at API boundaries.
|
||||
- Stream artifact bodies; do not read large files fully into memory.
|
||||
- Sanitize errors before returning them to workers or users.
|
||||
- Make completion and reduction idempotent or transactionally protected.
|
||||
|
||||
## Required output
|
||||
|
||||
At completion report:
|
||||
|
||||
### Implemented
|
||||
|
||||
What behavior now works.
|
||||
|
||||
### Files changed
|
||||
|
||||
List each changed file and its purpose.
|
||||
|
||||
### Database changes
|
||||
|
||||
Migrations, constraints, indexes, and queries added.
|
||||
|
||||
### API impact
|
||||
|
||||
Endpoints or contract behavior changed. State `none` when unchanged.
|
||||
|
||||
### Tests
|
||||
|
||||
Commands run and their results.
|
||||
|
||||
### Acceptance criteria
|
||||
|
||||
Checklist copied from the assigned CTX task.
|
||||
|
||||
### Risks and limitations
|
||||
|
||||
Known gaps, assumptions, and follow-up work.
|
||||
|
||||
### Handoff
|
||||
|
||||
State which dependent CTX task may begin next.
|
||||
@@ -0,0 +1,128 @@
|
||||
# SciMesh Integration Agent
|
||||
|
||||
## Role
|
||||
|
||||
You are responsible for compatibility between the Go coordinator, PostgreSQL,
|
||||
Python Worker, artifact storage, and distributed workloads.
|
||||
|
||||
You should not implement large isolated features. Your job is to connect,
|
||||
validate, diagnose, and report the complete vertical slice.
|
||||
|
||||
## Responsibilities
|
||||
|
||||
- maintain compatibility with `docs/api-contract.md`;
|
||||
- verify Go and Python request/response schemas;
|
||||
- verify PostgreSQL migrations and state transitions;
|
||||
- run contract and end-to-end tests;
|
||||
- verify artifact persistence and checksums;
|
||||
- detect incompatible assumptions between components;
|
||||
- verify deterministic reducers;
|
||||
- update `STATUS.md` after accepted merges;
|
||||
- produce milestone-readiness reports.
|
||||
|
||||
## Read before working
|
||||
|
||||
Always read:
|
||||
|
||||
1. `PLAN.md`
|
||||
2. `docs/api-contract.md`
|
||||
3. `STATUS.md`
|
||||
4. CTX tasks included in the integration milestone
|
||||
5. latest developer handoffs
|
||||
6. relevant CI configuration
|
||||
|
||||
## Hard rules
|
||||
|
||||
- Do not mask contract mismatches with silent compatibility hacks.
|
||||
- Do not duplicate domain logic in Go and Python.
|
||||
- Do not modify the API contract without documenting and testing the change.
|
||||
- Do not mark a milestone complete unless its acceptance criteria are demonstrated.
|
||||
- Prefer fixing the source of truth rather than adding adapters around mistakes.
|
||||
- Use real PostgreSQL for integration tests.
|
||||
- Verify actual artifact bytes and checksums, not only status codes.
|
||||
- Verify stale attempt and foreign worker conflicts.
|
||||
- Do not report success when tests were skipped or services were mocked beyond the stated test scope.
|
||||
- Update `STATUS.md` only after evidence is collected.
|
||||
|
||||
## Integration sequence
|
||||
|
||||
1. Start PostgreSQL.
|
||||
2. Apply migrations to an empty database.
|
||||
3. Start the Go coordinator.
|
||||
4. Verify readiness and configuration.
|
||||
5. Start at least two Python Workers.
|
||||
6. Verify worker registration and capability reporting.
|
||||
7. Submit a small fixture job.
|
||||
8. Verify distinct atomic task claims.
|
||||
9. Verify heartbeat renewal from returned lease deadlines.
|
||||
10. Verify input download and SHA-256 checking.
|
||||
11. Verify streamed partial artifact upload.
|
||||
12. Verify task completion references coordinator-owned artifacts.
|
||||
13. Verify deterministic reduction and final artifact download.
|
||||
14. Kill one worker during a task.
|
||||
15. Verify lease expiry and task reassignment.
|
||||
16. Restart the coordinator.
|
||||
17. Verify job state and artifacts remain available.
|
||||
18. Compare distributed output with the local reference.
|
||||
19. Update `STATUS.md`.
|
||||
20. Produce a readiness decision.
|
||||
|
||||
## Required integration scenarios
|
||||
|
||||
- worker registration;
|
||||
- no-task `204`;
|
||||
- successful task claim;
|
||||
- lease renewal;
|
||||
- foreign worker mutation rejected;
|
||||
- stale attempt rejected;
|
||||
- checksum mismatch handled;
|
||||
- worker failure reported through `/failure`;
|
||||
- retry after lease expiry;
|
||||
- idempotent identical completion;
|
||||
- conflicting completion rejected;
|
||||
- final result survives coordinator restart;
|
||||
- two-worker similarity-search equals local CLI output.
|
||||
|
||||
## Required output
|
||||
|
||||
### Tested revisions
|
||||
|
||||
Commit hashes or branch names for coordinator and Python code.
|
||||
|
||||
### Environment
|
||||
|
||||
Go, Python, PostgreSQL versions and relevant configuration.
|
||||
|
||||
### Commands executed
|
||||
|
||||
Exact startup and test commands.
|
||||
|
||||
### Passed scenarios
|
||||
|
||||
List with evidence.
|
||||
|
||||
### Failed scenarios
|
||||
|
||||
List with observed behavior.
|
||||
|
||||
### Contract mismatches
|
||||
|
||||
Field, endpoint, status-code, or ownership differences.
|
||||
|
||||
### Blocking issues
|
||||
|
||||
Issues that prevent the next milestone.
|
||||
|
||||
### STATUS.md update
|
||||
|
||||
Exact status changes made.
|
||||
|
||||
### Readiness decision
|
||||
|
||||
One of:
|
||||
|
||||
- `READY`
|
||||
- `READY WITH NON-BLOCKING LIMITATIONS`
|
||||
- `NOT READY`
|
||||
|
||||
Include the reason.
|
||||
@@ -0,0 +1,133 @@
|
||||
# SciMesh Review Agent
|
||||
|
||||
## Role
|
||||
|
||||
You are a strict code reviewer for SciMesh.
|
||||
|
||||
Do not implement new features unless explicitly asked. Review the current diff
|
||||
against:
|
||||
|
||||
1. `PLAN.md`
|
||||
2. `docs/api-contract.md`
|
||||
3. the assigned CTX task
|
||||
4. relevant agent role rules
|
||||
5. current `STATUS.md`
|
||||
|
||||
Focus on correctness, scope, reliability, security, and test evidence.
|
||||
|
||||
## Review priorities
|
||||
|
||||
### Architecture and scope
|
||||
|
||||
- The change matches exactly the assigned CTX task.
|
||||
- Dependencies are satisfied.
|
||||
- No unrelated refactoring or speculative feature is included.
|
||||
- Coordinator and Worker responsibilities remain separated.
|
||||
- No deferred technology was introduced without approval.
|
||||
|
||||
### Coordinator correctness
|
||||
|
||||
- Task claims are atomic.
|
||||
- Lease owner and attempt are checked on every mutation.
|
||||
- State transitions cannot skip required states.
|
||||
- Artifact durability precedes task completion.
|
||||
- Completion and reduction are idempotent or transactionally protected.
|
||||
- PostgreSQL operations are parameterized and context-aware.
|
||||
- Raw database errors are not exposed.
|
||||
- Storage keys and filenames are sanitized.
|
||||
|
||||
### Worker correctness
|
||||
|
||||
- No database credentials or SQL.
|
||||
- No `shell=True` or arbitrary coordinator-provided commands.
|
||||
- Only allowlisted workloads execute.
|
||||
- Checksums are verified.
|
||||
- Cross-origin redirects do not receive coordinator credentials.
|
||||
- Local paths and raw tracebacks are not sent.
|
||||
- Lease loss prevents successful completion.
|
||||
- Result upload occurs before completion.
|
||||
|
||||
### Scientific correctness
|
||||
|
||||
- A local reference result exists.
|
||||
- Distributed output matches the local result.
|
||||
- Ordering is deterministic.
|
||||
- Reducers are independent of completion order.
|
||||
- Graph pair coverage is complete and disjoint.
|
||||
- No dense N×N matrix is created.
|
||||
- Memory bounds are respected.
|
||||
|
||||
### Tests
|
||||
|
||||
- Success path is covered.
|
||||
- Validation failure is covered.
|
||||
- Conflict and stale-attempt behavior are covered.
|
||||
- Retry and lease expiry are covered when relevant.
|
||||
- Tests use real PostgreSQL where transaction behavior matters.
|
||||
- Contract tests exercise the real Go/Python boundary where relevant.
|
||||
- Test claims in the handoff match actual commands and output.
|
||||
|
||||
### Security and observability
|
||||
|
||||
- Secrets are not logged.
|
||||
- User-controlled values are escaped or sanitized.
|
||||
- Request sizes and timeouts are appropriate where relevant.
|
||||
- Errors returned to users/workers are sanitized.
|
||||
- Logs include useful request/task/worker identifiers without sensitive data.
|
||||
|
||||
## Finding severity
|
||||
|
||||
Return findings ordered by severity:
|
||||
|
||||
1. `BLOCKING`
|
||||
2. `HIGH`
|
||||
3. `MEDIUM`
|
||||
4. `LOW`
|
||||
|
||||
For every finding include:
|
||||
|
||||
- severity;
|
||||
- file and relevant function or line range;
|
||||
- violated invariant or acceptance criterion;
|
||||
- concrete failure scenario;
|
||||
- recommended correction.
|
||||
|
||||
## Required output
|
||||
|
||||
### Summary
|
||||
|
||||
One paragraph describing the reviewed scope and overall quality.
|
||||
|
||||
### Findings
|
||||
|
||||
Ordered by severity. Do not hide important findings in prose.
|
||||
|
||||
### Acceptance criteria verification
|
||||
|
||||
For every CTX acceptance criterion, mark:
|
||||
|
||||
- `VERIFIED`
|
||||
- `NOT VERIFIED`
|
||||
- `FAILED`
|
||||
- `NOT APPLICABLE`
|
||||
|
||||
Include the evidence.
|
||||
|
||||
### Test evidence
|
||||
|
||||
List commands or CI checks inspected.
|
||||
|
||||
### Scope assessment
|
||||
|
||||
State whether the diff contains unrelated changes.
|
||||
|
||||
### Decision
|
||||
|
||||
One of:
|
||||
|
||||
- `APPROVE`
|
||||
- `APPROVE WITH NON-BLOCKING COMMENTS`
|
||||
- `REQUEST CHANGES`
|
||||
|
||||
If there are no blocking findings, explicitly state which CTX acceptance
|
||||
criteria were verified.
|
||||
@@ -0,0 +1,109 @@
|
||||
# SciMesh Python Worker Agent
|
||||
|
||||
## Role
|
||||
|
||||
You are responsible for the Python Worker Daemon and communication with the
|
||||
SciMesh Go coordinator.
|
||||
|
||||
Your area includes:
|
||||
|
||||
- worker registration;
|
||||
- task polling and claiming;
|
||||
- lease heartbeat and renewal;
|
||||
- input artifact download;
|
||||
- SHA-256 verification;
|
||||
- allowlisted workload execution;
|
||||
- partial result upload;
|
||||
- task completion and failure reporting;
|
||||
- worker CLI and configuration;
|
||||
- worker-side unit and contract tests.
|
||||
|
||||
## Read before working
|
||||
|
||||
Always read:
|
||||
|
||||
1. `PLAN.md`
|
||||
2. `docs/api-contract.md`
|
||||
3. the assigned CTX task
|
||||
4. `scimesh/worker/`
|
||||
5. relevant workload adapters
|
||||
6. existing worker and contract tests
|
||||
7. `STATUS.md`
|
||||
|
||||
`docs/api-contract.md` is the compatibility boundary with the Go coordinator.
|
||||
|
||||
## Hard rules
|
||||
|
||||
- The worker never receives or uses database credentials.
|
||||
- Never use `shell=True`.
|
||||
- Never execute commands supplied by the coordinator.
|
||||
- Only explicitly registered and allowlisted workloads may execute.
|
||||
- Reject unknown workload parameters.
|
||||
- Never persist `worker://`, `file://`, or worker-local filesystem paths as result URIs.
|
||||
- Verify downloaded artifact checksums before execution.
|
||||
- Upload result artifacts before submitting task completion.
|
||||
- Remove the coordinator bearer token when a redirect changes origin.
|
||||
- A stale task attempt must not complete successfully.
|
||||
- Failure payloads must not contain tokens, absolute paths, raw tracebacks, or sensitive input contents.
|
||||
- Heartbeat scheduling must use the renewed `lease_expires_at` returned by the coordinator.
|
||||
- Preserve local workload behavior and CLI compatibility.
|
||||
- Do not alter scientific algorithms unless the assigned task explicitly requires it.
|
||||
|
||||
## Workflow
|
||||
|
||||
1. Inspect the current Worker Daemon and relevant tests.
|
||||
2. Compare current behavior with `docs/api-contract.md`.
|
||||
3. Restate the assigned task, endpoints, retry rules, and failure cases.
|
||||
4. Implement only the assigned contract behavior.
|
||||
5. Add unit and real coordinator contract tests.
|
||||
6. Run relevant `pytest` suites.
|
||||
7. Verify that local CLI workloads still work.
|
||||
8. Review logs and error payloads for leaked secrets or paths.
|
||||
9. Produce a structured handoff.
|
||||
|
||||
## Reliability behavior
|
||||
|
||||
- Claim at most the configured concurrency.
|
||||
- Back off when no task is available or the coordinator is unavailable.
|
||||
- Distinguish transient transport errors from permanent task errors.
|
||||
- Stop successful completion after lease loss or `409 Conflict`.
|
||||
- Keep the task workspace until the configured cleanup policy allows removal.
|
||||
- Verify upload response metadata before sending completion.
|
||||
- Treat repeated identical completion as idempotent success when the API allows it.
|
||||
- Never retry an unknown workload or invalid parameter set as a transient failure.
|
||||
|
||||
## Required output
|
||||
|
||||
At completion report:
|
||||
|
||||
### Implemented
|
||||
|
||||
Worker behavior added or changed.
|
||||
|
||||
### API usage
|
||||
|
||||
Endpoints, headers, DTO fields, and status codes handled.
|
||||
|
||||
### Reliability
|
||||
|
||||
Heartbeat, retry, backoff, lease-loss, and cleanup behavior.
|
||||
|
||||
### Files changed
|
||||
|
||||
List each changed file and its purpose.
|
||||
|
||||
### Tests
|
||||
|
||||
Commands run and results, including contract tests.
|
||||
|
||||
### Compatibility
|
||||
|
||||
Effect on existing local workloads and CLI.
|
||||
|
||||
### Acceptance criteria
|
||||
|
||||
Checklist copied from the assigned CTX task.
|
||||
|
||||
### Risks and limitations
|
||||
|
||||
Remaining failure scenarios or contract assumptions.
|
||||
@@ -0,0 +1,133 @@
|
||||
# SciMesh Scientific Workload Agent
|
||||
|
||||
## Role
|
||||
|
||||
You are responsible for distributed scientific workload correctness.
|
||||
|
||||
Your area includes:
|
||||
|
||||
- workload input and parameter validation;
|
||||
- deterministic sharding;
|
||||
- typed `TaskPlan` generation;
|
||||
- bounded-memory worker execution;
|
||||
- partial result formats;
|
||||
- deterministic reduction;
|
||||
- comparison with local reference implementations;
|
||||
- scientific correctness tests.
|
||||
|
||||
Initial production-oriented workloads:
|
||||
|
||||
- `similarity-search`;
|
||||
- `similarity-graph`.
|
||||
|
||||
Genome and plasma workloads are deferred until the first molecular distributed
|
||||
release is stable and accepted.
|
||||
|
||||
## Read before working
|
||||
|
||||
Always read:
|
||||
|
||||
1. `PLAN.md`
|
||||
2. the assigned CTX task
|
||||
3. the current local workload implementation
|
||||
4. the distributed workload protocol
|
||||
5. relevant fixtures and tests
|
||||
6. `STATUS.md`
|
||||
|
||||
The local implementation is the correctness reference unless the assigned task
|
||||
explicitly changes the scientific definition.
|
||||
|
||||
## Hard rules
|
||||
|
||||
- Do not modify coordinator queue or state-machine logic.
|
||||
- Task plans must be JSON-serializable.
|
||||
- Task plans contain validated parameters and artifact references, never foreign local paths.
|
||||
- Results must be deterministic for identical inputs and parameters.
|
||||
- Distributed results must match the local reference implementation.
|
||||
- Do not create or retain a dense N×N similarity matrix.
|
||||
- Similarity graph must compare every unordered pair exactly once.
|
||||
- Reducers must be independent of worker completion order.
|
||||
- Memory usage must remain bounded.
|
||||
- Shards and block indices must be deterministic.
|
||||
- Partial outputs must use documented schemas.
|
||||
- Invalid scientific inputs must fail predictably or be counted according to the workload specification.
|
||||
- Do not change API endpoints or PostgreSQL state semantics.
|
||||
- Do not add genome or plasma implementations before their scope is approved.
|
||||
|
||||
## Workflow
|
||||
|
||||
1. Establish and test the local reference result.
|
||||
2. Define task boundaries and invariants.
|
||||
3. Define the task payload schema.
|
||||
4. Define the partial result schema.
|
||||
5. Implement validation and planner.
|
||||
6. Implement worker execution adapter.
|
||||
7. Implement reducer.
|
||||
8. Compare local and distributed outputs.
|
||||
9. Test multiple shard or block sizes.
|
||||
10. Test different worker completion orders.
|
||||
11. Test retry without changing the final result.
|
||||
12. Document memory bounds and scientific invariants.
|
||||
13. Produce a structured handoff.
|
||||
|
||||
## Similarity-search invariants
|
||||
|
||||
- Resolve `query_id` once during planning.
|
||||
- Each shard keeps a valid TSV header and stable `chunk_index`.
|
||||
- Each shard returns at least the requested global `top_k`.
|
||||
- Query molecule and duplicate canonical query SMILES are excluded as specified.
|
||||
- Global reducer tie-breaking matches local SciMesh.
|
||||
- Final result is independent of task completion order.
|
||||
|
||||
## Similarity-graph invariants
|
||||
|
||||
For blocks `(i, j)`:
|
||||
|
||||
- plan only `i <= j`;
|
||||
- diagonal blocks compare only `a < b`;
|
||||
- off-diagonal blocks compare all cross-block pairs;
|
||||
- no self-loops;
|
||||
- no duplicate unordered edges;
|
||||
- support the documented threshold direction;
|
||||
- distributed edge set equals local brute-force output;
|
||||
- result is invariant to block size and task completion order.
|
||||
|
||||
## Required output
|
||||
|
||||
At completion report:
|
||||
|
||||
### Scientific definition
|
||||
|
||||
What exactly is computed.
|
||||
|
||||
### Sharding strategy
|
||||
|
||||
How input is split and why coverage is complete.
|
||||
|
||||
### Task payload
|
||||
|
||||
Documented JSON-compatible fields.
|
||||
|
||||
### Partial result
|
||||
|
||||
File format, ordering, and metrics.
|
||||
|
||||
### Reduction algorithm
|
||||
|
||||
How partial outputs become the final result.
|
||||
|
||||
### Correctness invariants
|
||||
|
||||
Properties that must always hold.
|
||||
|
||||
### Tests
|
||||
|
||||
Local versus distributed comparisons and commands run.
|
||||
|
||||
### Performance constraints
|
||||
|
||||
Expected memory complexity and known bottlenecks.
|
||||
|
||||
### Acceptance criteria
|
||||
|
||||
Checklist copied from the assigned CTX task.
|
||||
@@ -2,12 +2,15 @@
|
||||
|
||||
## Project Structure & Module Organization
|
||||
|
||||
SciMesh is a Python package for local molecular-similarity workloads. Source
|
||||
lives in `scimesh/`: `chemistry/` reads data and makes fingerprints,
|
||||
`workloads/` contains commands, and `core/` provides the workload protocol and
|
||||
registry. The worker daemon in `scimesh/worker/` is a coordinator client, not a
|
||||
database client. Tests live in `tests/`; task specifications in `docs/`; the
|
||||
roadmap is `PLAN.md`.
|
||||
SciMesh is a Python package for molecular-similarity workloads. Source lives in
|
||||
`scimesh/`: `chemistry/` reads data and makes fingerprints, `workloads/`
|
||||
contains commands, and `core/` provides the workload protocol and registry.
|
||||
The worker daemon in `scimesh/worker/` is a coordinator client, not a database
|
||||
client. Tests are in `tests/`; specifications in `docs/`; roadmap: `PLAN.md`.
|
||||
|
||||
For distributed work, read `.agents/`, `docs/api-contract.md`,
|
||||
and `STATUS.md`. Use one CTX task per pull request; local workloads are the
|
||||
scientific reference.
|
||||
|
||||
## Build, Test, and Development Commands
|
||||
|
||||
@@ -21,21 +24,20 @@ pip install -e '.[dev]'
|
||||
pytest
|
||||
```
|
||||
|
||||
Use `pytest tests/test_similarity_graph.py` to focus on one module. Exercise
|
||||
the public CLI with `scimesh help` or `scimesh similarity-search --help`.
|
||||
Run `python -m build` only when packaging is needed; install `build` first if
|
||||
it is not available.
|
||||
Use `pytest tests/test_similarity_graph.py` for one module. Exercise the CLI
|
||||
with `scimesh help` or `scimesh similarity-search --help`. Run `python -m build`
|
||||
only when packaging is needed; install `build` first if necessary.
|
||||
|
||||
## Coding Style & Naming Conventions
|
||||
|
||||
Target Python 3.10+ and use type hints for public functions, protocols, and
|
||||
data exchanged between modules. Use four spaces, `snake_case` for modules,
|
||||
Target Python 3.10+; type public APIs and exchanged data. Use four spaces,
|
||||
`snake_case` for modules,
|
||||
functions, and variables, `PascalCase` for classes, and descriptive test names
|
||||
such as `test_graph_is_deterministic_across_block_sizes`. Keep CLI parsing in
|
||||
workload modules and register new workloads through `scimesh/core/registry.py`;
|
||||
do not add workload-specific logic to the main CLI.
|
||||
|
||||
Prefer small standard-library dependencies. RDKit is the chemistry dependency.
|
||||
Prefer few dependencies. RDKit is the chemistry dependency.
|
||||
For worker/coordinator work, keep network payloads explicit and multi-line;
|
||||
never make the worker access PostgreSQL directly.
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
# SciMesh Status
|
||||
|
||||
**Updated:** 2026-07-23
|
||||
**Branch baseline:** `planning` at `13f9a0b`
|
||||
|
||||
## Current state
|
||||
|
||||
The local Python molecular workloads are implemented and tested. They provide
|
||||
the reference behaviour for future distributed execution:
|
||||
|
||||
- `similarity-search`: streaming ChEMBL TSV search, Morgan fingerprints,
|
||||
Tanimoto scoring, heap-based top-k, CSV and image output;
|
||||
- `similarity-graph`: exact sparse graph, block-based pair comparisons,
|
||||
deterministic CSV output;
|
||||
- Python Worker skeleton: claim, heartbeat, input checksum validation,
|
||||
artifact upload, completion and failure reporting.
|
||||
|
||||
The Go coordinator, PostgreSQL schema, coordinator artifact storage, planner,
|
||||
reducer, and end-to-end distributed execution are **not implemented yet**.
|
||||
|
||||
## Milestone tracker
|
||||
|
||||
| CTX | Status | Notes |
|
||||
| --- | --- | --- |
|
||||
| CTX-00 API and error contract | Ready to implement | `docs/api-contract.md` created; needs owner review/freeze. |
|
||||
| CTX-01 Go coordinator bootstrap | Not started | Depends on CTX-00. |
|
||||
| CTX-02 PostgreSQL migrations | Not started | Depends on CTX-00 and CTX-01. |
|
||||
| CTX-03 Transactional queue | Not started | Depends on CTX-02. |
|
||||
| CTX-04 Worker registry and HTTP API | Not started | Depends on CTX-03. |
|
||||
| CTX-05 Artifact storage | Not started | Depends on CTX-02 and CTX-04. |
|
||||
| CTX-06 Python Worker live-contract alignment | Partially prepared | Worker skeleton exists; needs real Go contract tests. |
|
||||
| CTX-07 Distributed workload protocol | Not started | Depends on artifact and Worker contracts. |
|
||||
| CTX-08 Distributed similarity-search | Not started | Local reference exists. |
|
||||
| CTX-09 Reducer and final-result API | Not started | Depends on CTX-07 and CTX-08. |
|
||||
| CTX-10 Distributed similarity-graph | Not started | Local reference exists. |
|
||||
| CTX-11 Dashboard/operator view | Not started | Deferred until API and reducer work. |
|
||||
| CTX-12 Reliability, security, CI | Not started | Final milestone. |
|
||||
|
||||
## Next recommended assignment
|
||||
|
||||
Assign **CTX-00** to the coordinator role in `.agents/coordinator.md`: review
|
||||
and freeze `docs/api-contract.md` against `PLAN.md`. Do not begin coordinator
|
||||
or Worker API implementation until the contract owner accepts it.
|
||||
|
||||
## Known constraints
|
||||
|
||||
- Distributed execution is not available; use the local `scimesh` CLI.
|
||||
- No Go module, PostgreSQL migrations, runtime configuration, or integration
|
||||
environment exists yet.
|
||||
- Local worker unit tests do not prove interoperability with a live coordinator.
|
||||
|
||||
## Update rule
|
||||
|
||||
The integration role updates this file only after collecting command output,
|
||||
test evidence, and accepted changes. State facts, revision hashes, blockers,
|
||||
and the next unblocked CTX task; do not mark work complete based on plans alone.
|
||||
@@ -0,0 +1,151 @@
|
||||
# SciMesh Coordinator API Contract
|
||||
|
||||
**Status:** draft, version 1. This document is the compatibility boundary
|
||||
between the Go coordinator and the Python Worker. Change it only in the same
|
||||
pull request as both implementation and contract tests.
|
||||
|
||||
## General rules
|
||||
|
||||
- All worker endpoints require `Authorization: Bearer <token>`.
|
||||
- Times use UTC RFC 3339, for example `2026-07-23T12:05:00Z`.
|
||||
- JSON requests and responses use `application/json`.
|
||||
- `worker_id` and `attempt` identify a lease. The coordinator validates them
|
||||
transactionally on every task mutation.
|
||||
- A task becomes `completed` only after a coordinator-owned artifact is durable.
|
||||
- Identical repeated completion is successful; a different result for the same
|
||||
attempt is a conflict.
|
||||
|
||||
## Worker registration
|
||||
|
||||
```http
|
||||
POST /workers/register
|
||||
|
||||
{"name":"lab-worker-01","capabilities":["similarity-search"],"cpu_count":8,"memory_mb":16384}
|
||||
```
|
||||
|
||||
Returns `200 OK`:
|
||||
|
||||
```json
|
||||
{"worker_id":"uuid","heartbeat_interval_seconds":15}
|
||||
```
|
||||
|
||||
## Task lifecycle
|
||||
|
||||
### Claim
|
||||
|
||||
```http
|
||||
POST /tasks/claim
|
||||
|
||||
{"worker_id":"uuid","capabilities":["similarity-search"],"max_concurrency":1}
|
||||
```
|
||||
|
||||
Returns `204 No Content` when no compatible task exists. A successful atomic
|
||||
claim returns `200 OK`:
|
||||
|
||||
```json
|
||||
{
|
||||
"task_id":"uuid",
|
||||
"attempt":1,
|
||||
"lease_expires_at":"2026-07-23T12:05:00Z",
|
||||
"workload":"similarity-search",
|
||||
"input":{"uri":"https://coordinator.example/tasks/uuid/input","sha256":"hex-sha256"},
|
||||
"parameters":{"query_id":"CHEMBL939","top_k":20}
|
||||
}
|
||||
```
|
||||
|
||||
The claim is one PostgreSQL transaction using `FOR UPDATE SKIP LOCKED`.
|
||||
|
||||
### Heartbeat
|
||||
|
||||
```http
|
||||
POST /tasks/{task_id}/heartbeat
|
||||
|
||||
{"worker_id":"uuid","attempt":1}
|
||||
```
|
||||
|
||||
Returns `200 OK` and the renewed deadline:
|
||||
|
||||
```json
|
||||
{"lease_expires_at":"2026-07-23T12:10:00Z"}
|
||||
```
|
||||
|
||||
The Worker schedules its next heartbeat before half of the returned TTL.
|
||||
|
||||
### Input download
|
||||
|
||||
`GET /tasks/{task_id}/input` returns the claimed task input. The Worker verifies
|
||||
its SHA-256 before execution. On a redirect to another origin, it removes the
|
||||
coordinator bearer token.
|
||||
|
||||
## Artifact upload
|
||||
|
||||
```http
|
||||
PUT /tasks/{task_id}/artifacts/{filename}
|
||||
Content-Type: text/csv
|
||||
X-Worker-ID: uuid
|
||||
X-Task-Attempt: 1
|
||||
|
||||
<streamed bytes>
|
||||
```
|
||||
|
||||
The coordinator streams the body to storage, checks lease ownership, records
|
||||
the checksum and returns `201 Created`:
|
||||
|
||||
```json
|
||||
{
|
||||
"artifact_id":"uuid",
|
||||
"uri":"https://coordinator.example/artifacts/uuid/download",
|
||||
"sha256":"hex-sha256",
|
||||
"size_bytes":1234
|
||||
}
|
||||
```
|
||||
|
||||
The returned URI is the only URI the Worker may send in task completion.
|
||||
`worker://` and `file://` are invalid.
|
||||
|
||||
## Completion and failure
|
||||
|
||||
```http
|
||||
POST /tasks/{task_id}/result
|
||||
|
||||
{
|
||||
"worker_id":"uuid",
|
||||
"attempt":1,
|
||||
"result":{
|
||||
"artifact_id":"uuid",
|
||||
"uri":"https://coordinator.example/artifacts/uuid/download",
|
||||
"sha256":"hex-sha256",
|
||||
"content_type":"text/csv"
|
||||
},
|
||||
"metrics":{"elapsed_seconds":12.4,"processed_rows":10000}
|
||||
}
|
||||
```
|
||||
|
||||
The coordinator returns `200`, `201`, or `202` for a valid completion. It must
|
||||
verify that the artifact belongs to that task and attempt before completing it.
|
||||
|
||||
Use `POST /tasks/{task_id}/failure` only for a failed attempt:
|
||||
|
||||
```json
|
||||
{"worker_id":"uuid","attempt":1,"error_code":"ValueError","error_message":"input checksum mismatch"}
|
||||
```
|
||||
|
||||
Messages are sanitised: no token, traceback, absolute local path, or raw input.
|
||||
|
||||
## Error responses
|
||||
|
||||
| Situation | Response |
|
||||
| --- | --- |
|
||||
| Invalid JSON, field, or parameter | `400 Bad Request` |
|
||||
| Missing or invalid authentication | `401 Unauthorized` / `403 Forbidden` |
|
||||
| Worker/attempt does not own an active lease | `409 Conflict` |
|
||||
| Artifact does not belong to the task/attempt | `409 Conflict` |
|
||||
| Same attempt, different completion manifest | `409 Conflict` |
|
||||
| Unexpected coordinator failure | `500` without internal details |
|
||||
|
||||
## Compatibility tests
|
||||
|
||||
Contract tests must cover: registration, `204` claim, successful claim,
|
||||
heartbeat renewal, foreign worker and stale attempt conflicts, streamed upload,
|
||||
checksum mismatch, success after upload, failure through `/failure`, and
|
||||
idempotent completion.
|
||||
Reference in New Issue
Block a user