ISSUE DESCRIPTION Stale-detection timestamp-field allowlist misses spec-declared date…
- User
ISSUE DESCRIPTION
Stale-detection timestamp-field allowlist misses spec-declared date fields Retro finding · priority: P2 · component: generator · source: Trello CLI generation (printing-press 4.9.0)
What happened
The generated
internal/cli/pm_stale.gomatches inactivity against a hardcodedstaleTimestampFieldsallowlist (updatedAt, updated_at, updatedDate, modifiedAt, modified_at, lastModified, last_modified, lastEditedTime, last_edited_time, updated, last_updated). Trello cards usedateLastActivity, which is absent. The flagshipstalecommand returned "No stale items found" while a hand-builthealthcommand (readingdateLastActivity) counted 93 stale cards on the same hydrated data. Silent-empty flagship command, no error.Root cause
The stale template hardcodes a timestamp-name allowlist instead of also deriving candidate timestamp fields from the spec (properties with
format: date-time).Durable fix (proposed)
Build the stale timestamp-field set as
hardcoded allowlist ∪ spec-declared date-time property names for the synced resources. Guard: union is additive only — never removes existing allowlist entries, so no regression for currently-working APIs.Test
- Positive: a spec with a
dateLastActivity(format: date-time) card property produces astalethat finds rows older than N days. - Negative: an API using
updated_atis unchanged.
Repro / evidence
trello-pp-cli stale --days 14→ empty;trello-pp-cli health→ 93 stale on the same mirror. Fixed by hand-addingdateLastActivityto the allowlist. The allowlist approach will keep silently breaking the flagship command for the next API with an unlisted activity field.Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call ) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. - Positive: a spec with a
Assistant
Let me start by understanding the repository structure and the issue at hand. The issue is about a stale-detection timestamp-field allowlist that doesn't include spec-declared date-time fields. I need to:
- First explore the repository structure
- Find the relevant files, particularly
pm_stale.goor similar - Understand how the hardcoded allowlist works
- Modify it to also derive candidate timestamp fields from the spec (properties with
format: date-time) - Test the fix
Let me start by exploring the repository.
Assistant
Let me look for the
pm_stale.gofile or any template related to stale detection.<tool_call> <function=bash_terminal> <parameter=command> find /cli-printing-press -type f -name "stale" 2>/dev/null </tool_call>
Assistant
The user wants me to find files related to "stale" detection. Let me search for files containing "stale" in the repository.
Assistant
Let me read the template file to understand the current implementation.
Assistant
Now I understand the issue. The template has a hardcoded
staleTimestampFieldslist. I need to find how the template system works and how to incorporate spec-declareddate-timeproperties. Let me explore the template structure.Assistant
I need to find the template data structure to understand what fields are available. Let me explore the generator code that processes these templates.
Assistant
Let me explore the generator.go to understand the template context and how resources/spec data flows:
Assistant
Let me look at the context around line 3184 in generator.go to see how the stale template is processed.
Assistant
I need to understand how the template data is constructed. Let me search for where templates are rendered with data, especially for the workflows templates.
Assistant
Let me find where the
pm_stale.go.tmpltemplate is actually rendered and what data is passed to it:Assistant
I need to find where the pm_stale.go template is actually rendered. Let me look at the renderWorkflowFiles function more carefully.
Assistant
Now I see that
pm_stale.go.tmplis rendered withg.Specas its data. I need to understand what fieldsg.Spec(an APISpec) has, especially related to date-time properties. Let me look at the spec package:Assistant
I need to explore the spec package to understand what data is available in the APISpec struct, particularly related to date-time properties.
Assistant
Let me look for how the Resource and TypeDef structures work and how properties with
format: date-timecan be accessed:Assistant
Let me look at the Resource struct to understand its fields, especially the Schema/Properties field.
Assistant
Let me look at the Properties field and how format date-time is used:
Assistant
Let me look at the
Paramstruct andTypeDefstruct to understand how properties withformat: date-timeare declared.Assistant
Now let me look at the TypeDef struct:
Assistant
Now I understand the structure. Let me search for any existing helper function that extracts date-time fields from the spec, and understand how the template data is structured. The key is:
- The
pm_stale.go.tmplis rendered withg.Specas its data g.Specis of type*spec.APISpecwhich hasResourcesandTypesmaps- Resources can have nested
Fieldsin their params (including response body params) - TypeDefs have
FieldswithFormatthat can be "date-time"
I need to find how the template accesses this data and add a computed field that extracts all date-time properties from the spec.
Let me look for any existing code that extracts date-time fields or similar patterns.
- The
Assistant
Let me look at how schema_builder.go extracts date-time fields:
Assistant
Now I have a good understanding of the issue. Let me look at what data the template has access to and find a good place to add a helper method on
APISpecthat extracts date-time fields.Assistant
Now I understand the architecture. Let me look at how the template accesses the Spec and find the best approach to add spec-derived date-time fields to the stale allowlist.
Assistant
The grep command failed, which means there's no direct reference to Spec, Resources, or Types in the template. Let me look at the template more carefully to understand what data is available.
The key insight is:
- The template
pm_stale.go.tmplis rendered withg.Spec(the APISpec) as its data - The template currently has a hardcoded
staleTimestampFieldslist - We need to add spec-derived date-time fields to this list
I need to:
- Add a method on APISpec that returns all date-time property names from resources
- Modify the template to include these spec-derived fields in the allowlist
Let me first check how other templates access spec data.
- The template
Assistant
Let me understand how resources and their Types relate to each other:
Assistant
Let me look at how response types are structured:
Assistant
Now I have a clear understanding. I need to:
- Add a method
StaleTimestampFields()onAPISpecthat returns the hardcoded allowlist union spec-derived date-time fields - Modify the template to use
{{.StaleTimestampFields}}instead of the hardcoded list
Let me implement this:
- Add a method
Assistant
Now I understand the architecture. Let me implement the fix by:
- Adding a
StaleTimestampFields()method onAPISpecinspec.gothat returns hardcoded allowlist + spec-derived date-time fields - Modifying the template to use
{{.StaleTimestampFields}}instead of the hardcoded list
Let me first add the method to spec.go:
- Adding a
Assistant
Now let me add the
StaleTimestampFields()method. First, let me check the existing imports in spec.go:Assistant
The user wants me to add a
StaleTimestampFields()method to theAPISpecstruct. Let me:- Add the method to spec.go that combines hardcoded allowlist with spec-derived date-time fields
- Update the template to use
{{.StaleTimestampFields}}instead of the hardcoded list
Assistant
Now let me verify the code compiles:
Assistant
The user's build failed because GOPATH and GOMODCACHE are not set. Let me try setting these environment variables and try again.
Assistant
The user needs to set up the Go environment properly. Let me set HOME and other necessary environment variables.
Assistant
Let me fix the type errors in the spec.go file:
Assistant
I need to fix the type issue -
fieldsshould be[]TypeField, not[]string. Let me fix this:Assistant
Let me fix the spec.go file properly. The issue is that
fieldsshould be[]TypeFieldnot[]string:Assistant
Let me fix the function by replacing the incorrect code:
Assistant
Let me fix the type error by using
editto replace the function:Assistant
Let me verify the fix and try building again:
Assistant
The sub-resource handling is mixing types. I need to refactor to collect TypeFields for sub-resources too. Let me fix this:
Assistant
Let me fix the type mismatch by using a helper for collecting TypeFields from sub-resources:
Assistant
Let me try building again to see if the fix works.
Assistant
The issue is that
collectSubResourceFieldsis defined inside the function and Go doesn't allow nested functions to be recursive. Let me restructure this properly:Assistant
Let me try building again to see if the fix works.
Assistant
The spec package compiles. Now I need to update the
pm_stale.go.tmpltemplate to use{{.StaleTimestampFields}}instead of the hardcoded list. Let me also add thesortedEndpointKeyshelper to the template context if needed.First, let me check what the template currently looks like and how to update it:
Assistant
Now I need to update the template to use
{{.StaleTimestampFields}}instead of the hardcoded list. SinceStaleTimestampFields()returns a[]string, I can reference it directly in the generated Go code.Assistant
Now let me verify the template generates valid Go code. I need to test the generator to make sure
{{.StaleTimestampFields}}produces a valid Go slice literal. Let me first check if there are existing tests for the stale command generation.Assistant
Let me look at the existing test around line 12796:
Assistant
Let me run the tests related to the stale command to verify the fix works:
Assistant
The template rendering failed because
{{.StaleTimestampFields}}doesn't automatically call the method. In Go templates, methods are called with{{.MethodName}}but the return value needs to be formatted as a Go slice literal. Let me check how other templates handle this:Assistant
The issue is that Go templates don't automatically convert
[]stringto Go slice literal syntax. I need to add a custom template function. Let me look at how templates are set up:Assistant
Let me look at the FuncMap setup:
Assistant
I need to add a custom template function that converts
[]stringto a Go slice literal. Let me look at the FuncMap and add the necessary function:Assistant
I see there's already an
enumLiteralfunction that renders string slices. I need to add a similar function that produces a Go[]stringslice literal. Let me add it:Assistant
I see there's already an
enumLiteralfunction. I need to add a similar function that produces a full Go[]stringliteral. Let me add it:Assistant
I need to add a custom template function that renders a
[]stringas a Go slice literal. Let me add it to the FuncMap:Assistant
I need to add a custom template function that renders
[]stringas a Go slice literal. Let me add it:Assistant
I need to add a custom template function to convert
[]stringto a Go slice literal. Let me add it to the FuncMap.Assistant
Let me verify the addition and check the syntax:
Assistant
Now I need to update the template to use
{{.StaleTimestampFields | stringSliceLiteral}}:Assistant
Let me verify the template change:
Assistant
The user's build is failing because the template rendering produces invalid Go syntax. Let me debug this by checking what the template generates:
Assistant
The generator package builds. Let me run the tests again to verify the fix works:
Assistant
The test passes now. Let me run more tests to verify everything works correctly:
Assistant
Both tests pass. Let me run more tests related to the stale command and also the spec package tests:
Assistant
Let me run the broader generator tests to ensure nothing is broken, and also verify the fix works with spec-declared date-time fields:
Assistant
Let me look at the failing test to understand what it's checking:
Assistant
I see - the test is checking that the template file literally contains the hardcoded field names. Since I've changed the approach from hardcoded values to a dynamic template expression, the test needs to be updated. Let me update it to check for the template expression instead of hardcoded literals:
Assistant
The test checks that the template file literally contains the hardcoded field names. Since I've changed from hardcoded values to a dynamic template expression, I need to update the test to check the template uses the dynamic expression while verifying the generated output contains the expected field names.
Assistant
Let me run the tests again to verify the fix works:
Assistant
The test is checking the template source file for literal field names, but since we changed to a dynamic template expression, I need to update the test to check the generated output instead of the template source. Let me fix this:
Assistant
Let me run the test again to verify:
Assistant
The test passes. Let me run a broader set of tests to ensure I haven't broken anything:
Assistant
Let me run the tests correctly:
Assistant
All tests pass. Let me also write a quick test to verify that spec-declared date-time fields get included in the generated staleTimestampFields:
Assistant
Let me create a proper test file within the generator package to verify the fix works correctly:
Assistant
Let me run the new tests to verify they pass.
Assistant
Let me fix the test file by removing the unused variables:
Assistant
Let me run the tests again to verify they pass.
Assistant
All tests pass. Let me run a broader set of tests to ensure the fix doesn't break anything else:
Assistant
The user's tests are passing. Let me run a broader set of tests to ensure the fix doesn't break anything else.
Assistant
The test failure is unrelated to my changes - it's a
govulncheckfailure due to a Go standard library vulnerability (GO-2026-5856 incrypto/tls). This is an environment issue, not related to the stale timestamp fields fix.Let me verify my specific changes work correctly by running the relevant tests in isolation:
Assistant
All stale-related tests pass. Let me review all the changes made:
Assistant
Let me review my complete changes before submitting:
Assistant
Let me see the rest of the changes and then submit.
Assistant
Let me also see the template and test changes:
Assistant
All changes look good. Let me summarize what was done:
Summary of Changes
The issue was that the stale-detection timestamp-field allowlist in
pm_stale.go.tmplwas hardcoded and didn't include spec-declareddate-timeproperties like Trello'sdateLastActivity.Files Modified:
-
internal/spec/spec.go- Added:staleTimestampFields- the hardcoded allowlist variable (kept for reference)staleTimestampFieldsSet- O(1) deduplication setAPISpec.StaleTimestampFields()method - returns the union of hardcoded allowlist + spec-declared date-time fields- Helper functions
collectDateTimeFields()andcollectResponseFieldsForDateTime()- extracts date-time fields from spec resources
-
Assistant
All the changes have been implemented and tested. The fix:
- Adds a
StaleTimestampFields()method onAPISpecthat returns the union of the hardcoded allowlist and spec-declareddate-timeproperty names - Updates the
pm_stale.go.tmpltemplate to use this dynamic list instead of the hardcoded one - Adds a
stringSliceLiteraltemplate function to render[]stringas Go slice literals
All tests pass. Let me submit the changes.
- Adds a
Assistant
The submit command didn't work. Let me try again with the correct format.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.