Skip to content

feat(calendar): carry natural-language preferences through the loader - #45

Open
Luiz do Valle (luizvalle) wants to merge 3 commits into
mainfrom
luizdovalle/soft-prefs-01-schema-loader
Open

feat(calendar): carry natural-language preferences through the loader#45
Luiz do Valle (luizvalle) wants to merge 3 commits into
mainfrom
luizdovalle/soft-prefs-01-schema-loader

Conversation

@luizvalle

@luizvalle Luiz do Valle (luizvalle) commented Jul 27, 2026

Copy link
Copy Markdown

Goal

Let a calendar task state its principal's preferences as prose in a Markdown file, instead of the numeric hourly table preferences holds today. This PR only carries the text; nothing reads it yet, so behavior is unchanged.

Summary of changes

CalendarAssistant gains preference_file and preference_md. The first is a path relative to the task YAML, the second its contents.

The loader inlines the file before validation. CalendarTask is frozen, so the text has to be in the dict passed to model_validate. Doing it there also folds the document into the task content hash, so editing a preference invalidates cached runs graded against the old wording. A missing file raises FileNotFoundError naming both the document and the task YAML.

Tasks with no document hash exactly as they do on main. _hash_exclude drops both fields when preference_file is unset, so existing checkpoints keep resolving.

How to test

uv run pytest packages/srbench/tests/test_calendar_preference_loading.py

Tracked by #50.

First of a stack adding natural-language scheduling preferences alongside the
existing numeric ones. This PR only teaches the schema and loader to carry the
text; nothing reads it yet, so behaviour is unchanged.

`CalendarAssistant` gains two optional fields: `preference_file`, a path
relative to the task YAML, and `preference_md`, its contents. The loader inlines
the file before `model_validate` because `CalendarTask` is frozen and the text
cannot be assigned afterwards. Resolving it there also folds the preference into
the task content hash, so editing a preference document correctly invalidates
checkpointed runs of that task rather than silently reusing them.

A declared but missing file raises `FileNotFoundError` naming both the reference
and the path it resolved to, since a silently unpreferenced task would otherwise
grade as if it had no preferences at all.

Tasks that declare no `preference_file` are untouched: `preference_md` stays
`None` and the numeric `preferences` list loads exactly as before. Tests cover
resolution, relative paths, the missing-file error, hash sensitivity, and that
all 21 shipped `small.yaml` tasks still load with numeric preferences intact.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4709c4ae-3295-4bbb-866b-dff62e7ad4d3
The docstring explained that preference paths resolve relative to the declaring
YAML file but never showed the shape, which is the part that is easy to get
wrong. Adds a worked example and notes that yaml_path may be relative or
absolute depending on how the benchmark was invoked.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4709c4ae-3295-4bbb-866b-dff62e7ad4d3
The hash behind checkpoint dedup dumps the whole model with unset fields
included, so adding preference_file and preference_md rewrote the hash of
every existing task even though none of them set either one. All 21
small.yaml tasks changed identity, which strands any checkpoint or
results.json written before this branch: the tasks look new and re-execute
from scratch.

Task gains an overridable _hash_exclude(), and CalendarTask drops both
fields from the hash when no document is declared. The 21 tasks hash
exactly as they did before, while a task that does declare a document
keeps the text in its hash, so editing the prose still invalidates runs
graded against the old wording.

The old hashes are pinned in the test as literals rather than recomputed,
since a test that derives them from the same code it is checking would
follow the bug rather than catch it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4709c4ae-3295-4bbb-866b-dff62e7ad4d3
@safooray

Copy link
Copy Markdown
Collaborator

Looks good to me, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants