Skip to content

feat: timestamp scheduler log lines - #68

Open
MrJoy wants to merge 2 commits into
wandercom:mainfrom
MrJoy:feat/timestamp-scheduler-logs
Open

MrJoy wants to merge 2 commits into
wandercom:mainfrom
MrJoy:feat/timestamp-scheduler-logs

Conversation

@MrJoy

@MrJoy MrJoy commented Sep 29, 2026 •

Copy link
Copy Markdown

Summary

The scheduler logs in ~/.kindex/logs (cron.log, cron-error.log, reminders.log, reminders-error.log, dream.log) hold the raw stdout/stderr that launchd and cron redirect into them. They record what happened but never when. After this change each line starts with the local time it was written:

2026-09-29T14:36:02-07:00 Checked [hoo3]: 0 fired, 0 auto-snoozed

How

  • New src/kindex/logstamp.py. When KIN_LOG_TIMESTAMPS is set, kin's main() wraps sys.stdout and sys.stderr in a proxy that puts an ISO-8601 stamp at the start of each line. The time comes from when the line's first character is written, not from when the buffer flushes.
  • The launchd plists (via setup.scheduler_environment()), the crontab lines (via setup.cron_env_assignments(), which the adaptive repack in scheduling._apply_crontab also uses) and dream.detach_dream all set the variable.
  • Nothing sets it for interactive or piped runs, so that output stays unstamped, --json included.
  • install_from_env removes the variable once it has read it, so only the process whose stdout is the log stamps. A scheduled reminder action launches agents whose kin hooks answer in JSON on a captured stdout, and an inherited opt-in would stamp that JSON and break it. Anything a scheduled job launches writes to the inherited log unstamped.

Existing installs pick this up once someone re-runs kin setup-cron. The CHANGELOG entry says so.

Tests

  • tests/test_log_timestamps.py covers line splitting across partial writes, blank lines, the falsey env values, idempotent install, children not inheriting the opt-in, main() with and without the variable, and the crontab, plist and dream env wiring.
  • Five existing crontab-shape assertions in test_cron_reliability.py and test_reminder_action_safety.py now include the new KIN_LOG_TIMESTAMPS=1 token.
  • Full suite locally: 2887 passed, 8 failed. The same 8 fail on clean main on my machine, because the tests pick up my local profile config and my global core.hooksPath. CI should show whether they pass on a clean machine.

🤖 Generated with Claude Code

https://claude.ai/code/session_015hsvicquw9yuB4UEdPyCoo


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

cron.log, reminders.log and dream.log captured launchd/cron stdout and
stderr verbatim, so a log showed what happened but never when. Scheduled
jobs now set KIN_LOG_TIMESTAMPS=1 and kin prefixes each stdout/stderr
line with the local ISO-8601 time its first character was written.
Interactive and piped output is unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015hsvicquw9yuB4UEdPyCoo
@MrJoy
MrJoy force-pushed the feat/timestamp-scheduler-logs branch from fbb466a to 32753c7 Compare September 29, 2026 22:09

@adaptcom adaptcom Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confidence Score: 1/5

Summary

Adds timestamps to scheduler logs, but the reviewed revision corrupts captured child JSON. Review is stale: the PR advanced from fbb466a to 32753c7 during validation.

Important Files Changed

File Overview
CHANGELOG.md Documents timestamp opt-in and existing-install migration
src/kindex/cli.py Installs timestamp wrappers before command parsing
src/kindex/dream.py Enables timestamps for detached dreams
src/kindex/logstamp.py Inherited opt-in also decorates machine-readable child output
src/kindex/scheduling.py Preserves timestamp opt-in during crontab repacking
src/kindex/setup.py Enables timestamps in cron and launchd environments
tests/test_cron_reliability.py Updates expected scheduler environment assignments
tests/test_log_timestamps.py Covers formatting and installation but misses captured child protocols
tests/test_reminder_action_safety.py Updates crontab environment expectations

Findings

  • At fbb466a, scheduled actions and detached dreams propagate timestamping into child hooks, invalidating JSON; clear KIN_LOG_TIMESTAMPS for captured subprocesses and add regression coverage.
  • Rerun review against current head 32753c7 before merging; the passing suite and reproduced regression cover only requested revision fbb466a.

↻ Re-run review · View in Adapt

KIN_LOG_TIMESTAMPS was inherited, so a scheduled reminder action that
launched an agent had that agent's kin hooks stamp their JSON replies on
a captured stdout, which broke them. install_from_env now removes the
variable once read: only the process whose stdout is the log stamps.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015hsvicquw9yuB4UEdPyCoo
@MrJoy

MrJoy commented Sep 29, 2026

Copy link
Copy Markdown
Author

Confirmed and fixed in 6f963ba. KIN_LOG_TIMESTAMPS was inherited. A scheduled reminder action launches an agent, and the agent's kin hooks would stamp their JSON replies on a captured stdout. I reproduced it: with the variable set, a parent capturing kin --version from a child got 2026-09-29T15:11:47-07:00 kin 0.45.0 (Kindex).

install_from_env now removes the variable once it has read it, so only the process whose stdout is the log stamps. The new test_children_do_not_inherit_the_opt_in runs a real child kin after install and asserts its captured stdout is unstamped. The test failed before the fix and passes now. The detached dream still sets the variable on its own Popen, because its stdout is dream.log.

This comment answers the review of fbb466a. The current head is 6f963ba, rebased onto main at 092cd98.

🤖 Generated with Claude Code

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant