Add serve-origin marker + parent-task attribution to usage records - #80
Merged
Conversation
Records gain an optional origin field (cli|gui|serve) threaded from each entry surface through run_once/run_once_stream; --stats shows the per-origin split, with pre-existing records rolling up as "untagged" rather than being guessed at. The serve endpoint additionally reads an optional X-TangleBrain-Parent-Task header — trimmed, capped at 128 chars — and records it as parent_task_id for cross-system attribution. Both are additive, written-only-when-present record fields; old records and readers unaffected. No routing changes.
- Panel now shows the per-origin split (the issue names the panel as a contract surface), hidden while all history is untagged — same stance as the CLI's format_rollup. - sanitize_parent_task drops non-printable characters (folded-header \r\n, ANSI escapes) so no control bytes ever reach usage records; tested. - Router-path recording site in run_once_stream now has the same attribution assertion as the other two sites.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
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.
What
Fixes #74 — the two measurement gaps deferred from the #70 plan:
originfield (cli|gui|serve), threaded from each entry surface throughrun_once/run_once_stream(all five recording sites, including mid-stream/abandoned finalization).tanglebrain --statsand the knob panel show the per-origin split; records predating the field roll up asuntagged, never guessed at. Delegate records are structurally exempt (they roll up separately, as before).X-TangleBrain-Parent-Taskheader — trimmed, non-printables dropped (folded-header\r\n, ANSI escapes), capped at 128 chars — and records it asparent_task_idon the task record for cross-system attribution. Never routed on. Reverse linkage already existed (chatcmpl-<task_id>).Both are additive, written-only-when-present record fields; old records and readers are unaffected. No routing changes.
Why
TangleClaw's integration against the endpoint (TC#455) is imminent; records written without the origin marker can never be retroactively attributed, so this ships before serve traffic starts accruing. The header gives OpenAI-compat callers the same parent-task linkage the MCP delegate tree gets via
TANGLEBRAIN_TASK_ID.Test plan
make test), 12 new/updated: record field write/omit semantics, task-record parent linkage, rollupby_originbucketing with theuntaggedsentinel + delegate exemption,--statsline shown only when tagged, origin/parent threading through everyrun_once/run_once_streamrecording site (pin-streamed, pin-emulated, router-emulated), serve handler threading (plain + stream), dispatch-level header sanitization, control-char/length-cap sanitizer cases, GUI origin tag, and a real-socket proof that the header reaches routing.Fixes #74.
🤖 Generated with Claude Code