Repository navigation
runs: build_record, record_json, done_status for hosts that write their own run record - #122
Merged
Merged
Conversation
…ir own run record A host that makes its run-record folder itself (owner marker when the run starts) and must never prune had to copy runs.record. Three pure functions now carry what it needs: build_record (the content of run.json, exactly what record writes; run_id and started_utc only when given), record_json (its text) and done_status (the .lc-done.json status, SPEC 3.2: a crash after Cancel is cancelled). record uses them; the CLI's record is unchanged except that a crash after Cancel is cancelled, a case the CLI cannot produce. No features id (an additive helper of the Python package); hosts require the first Tools release after 0.2.0rc1. Documented in PROTOCOL.md and OPERATIONS.md, with tests, sabotage rows and a ledger row. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y2SN8SuEakTdiWy3F2WUqN
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y2SN8SuEakTdiWy3F2WUqN
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.
Small code PR, second of two (the first, docs and data, is #121). Found by napari phase 2 theme 1 (LabConstrictor-napari #51), which had to copy
runs.recordbecause a host that makes its own folder and never prunes could not use it.What
Three functions in
labconstrictor_tools.runs. None of them creates a folder, deletes anything or prunes.build_record(app, tool_id, inputs, task, seconds, stderr="", *, run_id=None, started_utc=None, finished_utc=None) -> dict: the content ofrun.json, the same dictrecordwrites. Withrun_idandstarted_utcthe record also carries them; without them it has neither key, so the CLI's record is byte-for-byte what it was.record_json(content) -> str: the text ofrun.json.done_status(task_status, cancel_requested=False) -> str: the.lc-done.jsonstatus (COMPLETE ok, CANCELED cancelled, FAILED failed, CRASHED cancelled after Cancel and failed otherwise; SPEC 3.2, decision of 13 Oct in Record two decisions of 13 Oct: changed-size sentence, crash after Cancel (spec, data, fixtures) #121).recordis rebuilt from them. I did not addrecord(..., prune=False):recordcreates the folder at the end of the run, and a host (Napari) creates it when the run starts, owner marker first, so only the pure pieces help.retention.write_ownerandwrite_doneare unchanged; hosts keep starting the CLIpruneas a subprocess.Behaviour of
runs.record/ the CLIUnchanged for every case the CLI can produce (tested for all four task statuses, the content, the owner
host, the prune call, never raising). One difference, by the decision in #121: a task that isCRASHEDwithcancel_requestedset getscancelledinstead offailed.client.run_oncenever callsTask.canceland Ctrl-C already writescancelled, so the CLI cannot reach it; a host callingruns.recorditself can.Compat: which Tools a host must require
retention_prune); they are NOT in 0.2.0rc1 (_version.pyis still0.2.0rc1, tagv0.2.0-rc.1). A host that calls them requires that release asmin_tools_version; until its number exists it can checkhasattr(runs, "build_record"). Written in docs/PROTOCOL.md (retention section) and docs/OPERATIONS.md (the release procedure reminder to write the number and tell the hosts).featuresid. An id says a worker or CLI behaviour exists, something a Fiji or QuPath host can check in the schema. These are additive functions of the Python package that only a Python host imports; a version minimum states the same thing without a second list.FEATURESis unchanged (a test pins it).Tests
tests/test_run_record_builder.py: content against a hand-written dict (keys and order), nothing written or pruned,recordwrites the same content, text equals whatrecordwrites,run_id/started_utconly when given, the stderr tail cut, non-JSON values, every status and Cancel combination ofdone_status,recordkeeps its behaviour, and the Napari flow end to end (owner first, finish without prune, laterretention.pruneleaves 50).For the napari follow-up
In
napari_labconstrictor/_retention.pyit can delete_DONE_STATUSanddone_status(useruns.done_status(task.status, task.cancel_requested)), and in_widget.py::_record_runthe 20-linecontent = {...}dict becomesruns.build_record(app, tool, request, task, seconds, stderr, run_id=snapshot.run_id, started_utc=snapshot.started);json.dumps(content, indent=2, default=str)in_finish_recordbecomesruns.record_json(content), and itsSTDERR_TAIL_CHARSimport can go (runs.STDERR_TAIL_CHARS). It keepsRunRecord.start,_make_folder,ResultsFolder,discard_job_dir,start_pruneand itsretention_prunegate. It must raise its Tools minimum (or guard withhasattr) before it deletes the copies. Note one key-order detail: napari writesrun_idfirst andstarted_utcaftertool, and so doesbuild_record; napari currently writesrun_idandstarted_utcasnullwhen it has no snapshot,build_recordomits them.🤖 Generated with Claude Code
https://claude.ai/code/session_01Y2SN8SuEakTdiWy3F2WUqN
Generated by Claude Code